[ANDROID] [FIXED] - Fix BackHandle callback undefined cause crash issue #48388
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
Error message:
we got an error
it related the BackHandle execute handle function.
Investigation result
our project has screen files
App.tsx
,Dashboard.tsx
, andProfile.tsx
.When launching the app, the screen order is
App.tsx
->Dashboard.tsx
, then user can switch toProfile.tsx
For
App.tsx
andDashboard.tsx
, we just prevent the hardware button action useusePreventHardwareBackPressEffect()
in the first line of screen code.currently,
_backPressSubscriptions
has 2 callback functions.then user switch to
Profile.tsx
screen, and has the below code for hardwareback button and the second doesn'treturn true
:currently,
_backPressSubscriptions
has 4 callback functions, include previous 2 and new 2 ofProfile.tsx
.When the user press hardwareback button, it will navigate to the login screen, so the issue occurs:
the latest callback will be executed first, then the navigation will let the screen unmount, which will destroy the effect, so the code removing 2 hardwareBackPress callback of
Profile.tsx
by executedAfter the navigation ends and the loop is restored, the init
i
is 3, theni--
,i
is 2, then_backPressSubscriptions[2]
isundefined
now and executes as a function, so the app crashes.that's the issue I met.
Changelog:
[ANDROID] [FIXED] - Fix BackHandle callback undefined cause crash issue
Test Plan: