Skip to content

fix (bottom-navigation-bar): pick the correct activity for checking lifecycle #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

mukaschultze
Copy link

@mukaschultze mukaschultze commented Sep 2, 2021

This PR fixes an issue where the bottom navigation tabs are not correctly instantiated when returning to the application if the foreground activity is not an AppCompatActivity.

@farfromrefug
Copy link
Member

@mukaschultze good idea. But would be best to use || with foreground first( current activity so should be first). Could you change it ?

@edusperoni
Copy link
Contributor

@farfromrefug I believe the issue is that foregroundActivity isn't necessarily an AppCompatActivity, so it may not have the getLifecycle method. If you're in a modal, for example, which has it's own activity, it'll be set as the foregroundActivity, so using the code as is will and switching apps with a modal open will break the BottomNavigation.

Maybe we can add some other feature on core to track the foregroundAppActivity (or you could listen to activityResumed events).

Looking at this issue I even found a potential issue on core even (still have to test this scenario). On activity resume it will set the activity as foregroundActivity. On destroy it'll check if it's the foregroundActivity/startActivity and set them to undefined if it is. So opening a modal and closing leaves no foregroundActivity, and opening a modal inside a modal then closing the topmost one leaves no foregroundActivity (but it should). Although I think this might be fine because it might trigger a resume on the background activity as it gets to the foreground.

In any case, I believe you should probably use foregroundActivity || startActivity for almost every case, but on this case you probably need startActivity otherwise you can't guarantee it has the getLifecycle method.

@farfromrefug
Copy link
Member

@edusperoni you are right and we already test getLifecycle with the ?.

@edusperoni
Copy link
Contributor

@farfromrefug !activity.getLifecycle?.().getCurrentState().isAtLeast(androidx.lifecycle.Lifecycle.State.STARTED). If getLifecycle is null, then it's the same as the whole condition evaluating to true, which means if you resume the app from a modal this method will return instead of attaching to the window, which is the incorrect behavior because clearly the activity's lifecycle is at least STARTED.

@edusperoni
Copy link
Contributor

@farfromrefug to give you some context, we're using bottom nav with google play billing, which detaches and then attaches the activities. If we use the plugin in the current form, this is what happens on some flows (mainly switching apps during the play billing flow, like tapping to view the google play policies):

image

If you're uncomfortable with changing it to startActivity, you could save the activity reference for the bottom-nav somewhere during the lifecycle (maybe createnativeview and disposenativeview). Or you could fallback to startActivity if activity.getLifecycle is null, but treating activity.getLifecycle being null as a false statement is causing issues.

@farfromrefug
Copy link
Member

@edusperoni good catch! will fix

@mukaschultze
Copy link
Author

Just tested and commit ffa38ab also fixes the issues we were having, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants