stevdza-san / OneTapCompose

This library allow you to easily integrate One-Tap Sign in with Google(Credential Manager) in your project with Jetpack Compose. It keeps away all the boilerplate code.
Apache License 2.0
177 stars 15 forks source link

Fix Compose Previews and persist OneTapSignInState on configuration changes #16

Closed shubhamsinghshubham777 closed 6 months ago

shubhamsinghshubham777 commented 6 months ago

This PR fixes the issue of OneTapSignInWithGoogle not being usable in Compose Previews and throwing preview errors like:

java.lang.ClassCastException: class com.android.layoutlib.bridge.android.BridgeContext cannot be cast to class android.app.Activity 
(com.android.layoutlib.bridge.android.BridgeContext and android.app.Activity are in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @597d2605)
   at com.stevdzasan.onetap.OneTapComposeKt.OneTapSignInWithGoogle(OneTapCompose.kt:48)

This PR also introduces some Compose best practices like:

  1. Use @Stable and @Immutable annotations
  2. Introduce a custom Saver for OneTapSignInState to be used with rememberSaveable in order to make OneTapSignInState persist configuration changes.
shubhamsinghshubham777 commented 6 months ago

@stevdza-san Could you please have a look at this?