Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.youversion.reactnativesdk

import com.youversion.reactnativesdk.views.YVPSignInWithYouVersionButton
import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition

class RNSignInWithYouVersionButtonModule : Module() {
override fun definition() = ModuleDefinition {
Name("SignInWithYouVersionButton")

View(YVPSignInWithYouVersionButton::class) {
Events("onTap")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.youversion.reactnativesdk.views

import android.content.Context
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Shape
import com.youversion.platform.ui.views.SignInWithYouVersionButton
import com.youversion.platform.ui.views.SignInWithYouVersionButtonDefaults
import com.youversion.platform.ui.views.SignInWithYouVersionButtonMode
import expo.modules.kotlin.AppContext
import expo.modules.kotlin.viewevent.EventDispatcher
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

data class SignInWithYouVersionButtonProps(
val mode: MutableState<String?> = mutableStateOf("full"),
val shape: MutableState<String?> = mutableStateOf("capsule"),
val isStroked: MutableState<Boolean?> = mutableStateOf(true),
val colorScheme: MutableState<String?> = mutableStateOf(null)
) : ComposeProps

class YVPSignInWithYouVersionButton(context: Context, appContext: AppContext) :
ExpoComposeView<SignInWithYouVersionButtonProps>(context, appContext, withHostingView = true) {
override val props = SignInWithYouVersionButtonProps()
private val onTap by EventDispatcher()

@Composable
override fun Content(modifier: Modifier) {
AutoSizingComposable(shadowNodeProxy, axis = EnumSet.of(Direction.HORIZONTAL, Direction.VERTICAL)) {
SignInWithYouVersionButton(
onClick = { onTap(mapOf()) },
mode = mode(),
stroked = stroked(),
shape = shape(),
dark = isDark()
)
}
}

fun mode(): SignInWithYouVersionButtonMode {
return when (props.mode.value) {
"full" -> SignInWithYouVersionButtonMode.FULL
"compact" -> SignInWithYouVersionButtonMode.COMPACT
"iconOnly" -> SignInWithYouVersionButtonMode.ICON_ONLY
else -> SignInWithYouVersionButtonMode.FULL
}
}

fun stroked(): Boolean {
return props.isStroked.value ?: true
}

@Composable
fun shape(): Shape {
return when (props.shape.value) {
"capsule" -> SignInWithYouVersionButtonDefaults.capsuleShape
"rectangle" -> SignInWithYouVersionButtonDefaults.rectangleShape
else -> SignInWithYouVersionButtonDefaults.capsuleShape
}
}

@Composable
fun isDark(): Boolean {
return when (props.colorScheme.value) {
"dark" -> true
"light" -> false
else -> isSystemInDarkTheme()
}
}
}
5 changes: 4 additions & 1 deletion expo-module.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
]
},
"android": {
"modules": ["com.youversion.reactnativesdk.RNYouVersionPlatformModule"]
"modules": [
"com.youversion.reactnativesdk.RNYouVersionPlatformModule",
"com.youversion.reactnativesdk.RNSignInWithYouVersionButtonModule"
]
}
}