Skip to content

Commit 233cb39

Browse files
committed
fix: support Compose previews for biometric authentication on Android
- Update `rememberBiometricPlatformWrapper` to check `LocalInspectionMode` and provide a fallback `FragmentActivity` instance during previews. - Prevent ClassCastExceptions in Compose Preview by avoiding the cast of `LocalActivity.current` when in inspection mode. - Update `SignInScreenPreview` to explicitly enable biometric visibility for layout verification.
1 parent df03fed commit 233cb39

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

app/android/src/main/java/com/softartdev/notedelight/MainPreview.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ annotation class PreviewDeviceMode
2525

2626
@PreviewDeviceMode
2727
@Composable
28-
fun SignInScreenPreview() = PreferableMaterialTheme { SignInScreenBody() }
28+
fun SignInScreenPreview() = PreferableMaterialTheme { SignInScreenBody(biometricVisible = true) }
2929

3030
@PreviewDeviceMode
3131
@Composable

core/ui/src/androidMain/kotlin/com/softartdev/notedelight/ui/BiometricPlatformHelper.android.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ package com.softartdev.notedelight.ui
33
import androidx.activity.compose.LocalActivity
44
import androidx.compose.runtime.Composable
55
import androidx.compose.runtime.remember
6+
import androidx.compose.ui.platform.LocalInspectionMode
67
import androidx.fragment.app.FragmentActivity
78
import com.softartdev.notedelight.interactor.BiometricPlatformWrapper
89

910
@Composable
1011
actual fun rememberBiometricPlatformWrapper(): BiometricPlatformWrapper {
11-
val fragmentActivity = LocalActivity.current as FragmentActivity
12+
val fragmentActivity: FragmentActivity = when (LocalInspectionMode.current) {
13+
true -> FragmentActivity() // Create a new FragmentActivity instance for preview mode
14+
false -> LocalActivity.current as FragmentActivity
15+
}
1216
return remember(key1 = fragmentActivity) { BiometricPlatformWrapper(fragmentActivity) }
1317
}

0 commit comments

Comments
 (0)