firebase / FirebaseUI-Android

Optimized UI components for Firebase
https://firebaseopensource.com/projects/firebase/firebaseui-android/
Apache License 2.0
4.63k stars 1.83k forks source link

Firebase Auth UI is laggy #2031

Closed ArcherEmiya05 closed 2 years ago

ArcherEmiya05 commented 2 years ago

Step 1: Are you in the right place?

Yes

Step 2: Describe your environment

Step 3: Describe the problem:

Closing Firebase Auth UI using onbackpress causes UI to freeze.

Steps to reproduce:

Open Firebase Auth UI (Phone Auth), and close it via back press in navigation.

Observed Results:

That is a huge frame skipped! image

I suspect this is due to Material Component being used now in 8.0.0

Expected Results:

Smooth transition between project activity and Firebase UI Auth (Phone Auth)

Relevant Code:


SampleActivity: AppCompatActivity() {

   private val activityResultLauncher = activityForResult { result, _ ->
        PhoneAuthUtil.handleIntentResult(this, result)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
         // Launch OTP activity
         activityResultLauncher.launch(PhoneAuthUtil.getAuthIntent())
     }

}
object PhoneAuthUtil {
    private val AUTH_REQUEST: Intent by lazy {
        val builder = AuthUI.getInstance().createSignInIntentBuilder()
            .setTheme(R.style.AuthStyle)
            .setIsSmartLockEnabled(false)
            .setAvailableProviders(PROVIDER_LIST)
        builder.setTosAndPrivacyPolicyUrls(
            "https://firebase.google.com/terms/",
            "https://firebase.google.com/policies/analytics"
        )
        builder.build()
    }

    fun getAuthIntent() = AUTH_REQUEST

    fun handleIntentResult(phoneAuthCallback: PhoneAuthCallback, result: ActivityResult) {

        val response: IdpResponse? = IdpResponse.fromResultIntent(result.data)

        if (result.resultCode == RESULT_OK)
            phoneAuthCallback.onFPASuccess()
        else {

            // Sign in failed
            if (response == null) {
                // Probably the user pressed back button
                phoneAuthCallback.onFPAErrorMessage(R.string.fui_required_field)
                phoneAuthCallback.onFPACancel()
                return
            }

            if (response.error == null) {
                phoneAuthCallback.onFPAErrorMessage(R.string.fui_error_unknown)
                return
            }

            if (response.error!!.errorCode == ErrorCodes.NO_NETWORK) {
                phoneAuthCallback.onFPAErrorMessage(R.string.fui_no_internet)
                return
            }

            if (response.error!!.errorCode == ErrorCodes.ERROR_USER_DISABLED) {
                phoneAuthCallback.onFPAErrorMessage(R.string.fui_error_email_does_not_exist)
                return
            }

            if (response.error!!.errorCode == ErrorCodes.NO_NETWORK) {
                phoneAuthCallback.onFPAErrorMessage(R.string.fui_no_internet)
                return
            }

            if (response.error!!.errorCode == ErrorCodes.NO_NETWORK) {
                phoneAuthCallback.onFPAErrorMessage(R.string.fui_no_internet)
                return
            }

        }

    }
}
ArcherEmiya05 commented 2 years ago

It seems fixed with Material3 theme