Skip to content

Commit 69628ab

Browse files
feat: implement sign in button for Kotlin
1 parent 05b9dd2 commit 69628ab

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.youversion.reactnativesdk
2+
3+
import com.youversion.reactnativesdk.views.YVPSignInWithYouVersionButton
4+
import expo.modules.kotlin.modules.Module
5+
import expo.modules.kotlin.modules.ModuleDefinition
6+
7+
class RNSignInWithYouVersionButtonModule : Module() {
8+
override fun definition() = ModuleDefinition {
9+
Name("SignInWithYouVersionButton")
10+
11+
View(YVPSignInWithYouVersionButton::class) {
12+
Events("onTap")
13+
}
14+
}
15+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.youversion.reactnativesdk.views
2+
3+
import android.content.Context
4+
import androidx.compose.foundation.isSystemInDarkTheme
5+
import androidx.compose.runtime.Composable
6+
import androidx.compose.runtime.MutableState
7+
import androidx.compose.runtime.mutableStateOf
8+
import androidx.compose.ui.Modifier
9+
import androidx.compose.ui.graphics.Shape
10+
import com.youversion.platform.ui.views.SignInWithYouVersionButton
11+
import com.youversion.platform.ui.views.SignInWithYouVersionButtonDefaults
12+
import com.youversion.platform.ui.views.SignInWithYouVersionButtonMode
13+
import expo.modules.kotlin.AppContext
14+
import expo.modules.kotlin.viewevent.EventDispatcher
15+
import expo.modules.kotlin.views.AutoSizingComposable
16+
import expo.modules.kotlin.views.ComposeProps
17+
import expo.modules.kotlin.views.Direction
18+
import expo.modules.kotlin.views.ExpoComposeView
19+
import java.util.EnumSet
20+
21+
data class SignInWithYouVersionButtonProps(
22+
val mode: MutableState<String?> = mutableStateOf("full"),
23+
val shape: MutableState<String?> = mutableStateOf("capsule"),
24+
val isStroked: MutableState<Boolean?> = mutableStateOf(true),
25+
val colorScheme: MutableState<String?> = mutableStateOf(null)
26+
) : ComposeProps
27+
28+
class YVPSignInWithYouVersionButton(context: Context, appContext: AppContext) :
29+
ExpoComposeView<SignInWithYouVersionButtonProps>(context, appContext, withHostingView = true) {
30+
override val props = SignInWithYouVersionButtonProps()
31+
private val onTap by EventDispatcher()
32+
33+
@Composable
34+
override fun Content(modifier: Modifier) {
35+
AutoSizingComposable(shadowNodeProxy, axis = EnumSet.of(Direction.HORIZONTAL, Direction.VERTICAL)) {
36+
SignInWithYouVersionButton(
37+
onClick = { onTap(mapOf()) },
38+
mode = mode(),
39+
stroked = stroked(),
40+
shape = shape(),
41+
dark = isDark()
42+
)
43+
}
44+
}
45+
46+
fun mode(): SignInWithYouVersionButtonMode {
47+
return when (props.mode.value) {
48+
"full" -> SignInWithYouVersionButtonMode.FULL
49+
"compact" -> SignInWithYouVersionButtonMode.COMPACT
50+
"iconOnly" -> SignInWithYouVersionButtonMode.ICON_ONLY
51+
else -> SignInWithYouVersionButtonMode.FULL
52+
}
53+
}
54+
55+
fun stroked(): Boolean {
56+
return props.isStroked.value ?: true
57+
}
58+
59+
@Composable
60+
fun shape(): Shape {
61+
return when(props.shape.value) {
62+
"capsule" -> SignInWithYouVersionButtonDefaults.capsuleShape
63+
"rectangle" -> SignInWithYouVersionButtonDefaults.rectangleShape
64+
else -> SignInWithYouVersionButtonDefaults.capsuleShape
65+
}
66+
}
67+
68+
@Composable
69+
fun isDark(): Boolean {
70+
return when(props.colorScheme.value) {
71+
"dark" -> true
72+
"light" -> false
73+
else -> isSystemInDarkTheme()
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)