-
Notifications
You must be signed in to change notification settings - Fork 1
feat: implement Bible reader view for Android #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with Greptile that we should not use |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,55 +1,68 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| package com.youversion.reactnativesdk.views | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| import android.content.Context | ||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.foundation.layout.Box | ||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.foundation.layout.fillMaxSize | ||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.foundation.layout.padding | ||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.material3.Text | ||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.runtime.Composable | ||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.runtime.MutableState | ||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.runtime.mutableStateOf | ||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.ui.Alignment | ||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.ui.Modifier | ||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.ui.graphics.Color | ||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.ui.unit.dp | ||||||||||||||||||||||||||||||||||||||||||||
| import com.youversion.platform.core.bibles.domain.BibleReference | ||||||||||||||||||||||||||||||||||||||||||||
| import com.youversion.platform.reader.BibleReader | ||||||||||||||||||||||||||||||||||||||||||||
| import expo.modules.kotlin.AppContext | ||||||||||||||||||||||||||||||||||||||||||||
| import expo.modules.kotlin.views.AutoSizingComposable | ||||||||||||||||||||||||||||||||||||||||||||
| import expo.modules.kotlin.views.ComposeProps | ||||||||||||||||||||||||||||||||||||||||||||
| import expo.modules.kotlin.views.Direction | ||||||||||||||||||||||||||||||||||||||||||||
| import expo.modules.kotlin.views.ExpoComposeView | ||||||||||||||||||||||||||||||||||||||||||||
| import java.util.EnumSet | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+11
to
+15
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused imports
Suggested change
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sense unless I am missing context. |
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| data class BibleReaderViewProps( | ||||||||||||||||||||||||||||||||||||||||||||
| // Bible reference | ||||||||||||||||||||||||||||||||||||||||||||
| val versionId: MutableState<Int?> = mutableStateOf(null), | ||||||||||||||||||||||||||||||||||||||||||||
| val bookUSFM: MutableState<String?> = mutableStateOf(null), | ||||||||||||||||||||||||||||||||||||||||||||
| val chapter: MutableState<Int?> = mutableStateOf(null), | ||||||||||||||||||||||||||||||||||||||||||||
| val verse: MutableState<Int?> = mutableStateOf(null), | ||||||||||||||||||||||||||||||||||||||||||||
| val verseStart: MutableState<Int?> = mutableStateOf(null), | ||||||||||||||||||||||||||||||||||||||||||||
| val verseEnd: MutableState<Int?> = mutableStateOf(null), | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| val appName: MutableState<String?> = mutableStateOf(null), | ||||||||||||||||||||||||||||||||||||||||||||
| val signInMessage: MutableState<String?> = mutableStateOf(null), | ||||||||||||||||||||||||||||||||||||||||||||
| val hasReference: MutableState<Boolean?> = mutableStateOf(false), | ||||||||||||||||||||||||||||||||||||||||||||
| val hasReference: MutableState<Boolean?> = mutableStateOf(null) | ||||||||||||||||||||||||||||||||||||||||||||
| ) : ComposeProps | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| class YVPBibleReaderView(context: Context, appContext: AppContext) : | ||||||||||||||||||||||||||||||||||||||||||||
| ExpoComposeView<BibleReaderViewProps>(context, appContext, withHostingView = true) { | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| override val props = BibleReaderViewProps() | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| @Composable | ||||||||||||||||||||||||||||||||||||||||||||
| override fun Content(modifier: Modifier) { | ||||||||||||||||||||||||||||||||||||||||||||
| // TODO: Replace with actual BibleReaderView composable when Kotlin SDK is ready | ||||||||||||||||||||||||||||||||||||||||||||
| Box( | ||||||||||||||||||||||||||||||||||||||||||||
| modifier = modifier | ||||||||||||||||||||||||||||||||||||||||||||
| .fillMaxSize() | ||||||||||||||||||||||||||||||||||||||||||||
| .padding(16.dp), | ||||||||||||||||||||||||||||||||||||||||||||
| contentAlignment = Alignment.Center | ||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||
| Text( | ||||||||||||||||||||||||||||||||||||||||||||
| text = "BibleReaderView placeholder\n" + | ||||||||||||||||||||||||||||||||||||||||||||
| "App: ${props.appName.value}\n" + | ||||||||||||||||||||||||||||||||||||||||||||
| "Reference: ${props.bookUSFM.value} ${props.chapter.value}", | ||||||||||||||||||||||||||||||||||||||||||||
| color = Color.Gray | ||||||||||||||||||||||||||||||||||||||||||||
| BibleReader( | ||||||||||||||||||||||||||||||||||||||||||||
| appName = props.appName.value!!, | ||||||||||||||||||||||||||||||||||||||||||||
| appSignInMessage = props.signInMessage.value!!, | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+36
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Force-unwrapping nullable props will crash on initial render
Consider adding a guard to return early if the required props are not yet set:
Suggested change
Context Used: Rule from |
||||||||||||||||||||||||||||||||||||||||||||
| bibleReference = bibleReference(), | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| fun bibleReference(): BibleReference? { | ||||||||||||||||||||||||||||||||||||||||||||
| val start = props.verseStart.value | ||||||||||||||||||||||||||||||||||||||||||||
| val end = props.verseEnd.value | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if (start != null && end != null) { | ||||||||||||||||||||||||||||||||||||||||||||
| return BibleReference( | ||||||||||||||||||||||||||||||||||||||||||||
| versionId = props.versionId.value!!, | ||||||||||||||||||||||||||||||||||||||||||||
| bookUSFM = props.bookUSFM.value!!, | ||||||||||||||||||||||||||||||||||||||||||||
| chapter = props.chapter.value!!, | ||||||||||||||||||||||||||||||||||||||||||||
| verseStart = start, | ||||||||||||||||||||||||||||||||||||||||||||
| verseEnd = end | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+47
to
55
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Force-unwraps on Similar to the Consider using null-safe access and returning
Suggested change
Context Used: Rule from |
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if (props.hasReference.value == true) { | ||||||||||||||||||||||||||||||||||||||||||||
| return BibleReference( | ||||||||||||||||||||||||||||||||||||||||||||
| versionId = props.versionId.value!!, | ||||||||||||||||||||||||||||||||||||||||||||
| bookUSFM = props.bookUSFM.value!!, | ||||||||||||||||||||||||||||||||||||||||||||
| chapter = props.chapter.value!!, | ||||||||||||||||||||||||||||||||||||||||||||
| verse = props.verse.value | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| return null | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import of
YVPBibleWidgetViewYVPBibleWidgetViewis imported but never referenced in this module — onlyYVPBibleReaderViewis registered.YVPBibleWidgetViewis already imported in its own module (RNBibleWidgetViewModule.kt). This appears to be accidentally added.