Skip to content

Commit

Permalink
fix: Empty array & null checks in handleTabNavigatorChange method fixes
Browse files Browse the repository at this point in the history
#6698 (#6700)

Fixes:  Shared Element Transition (Solution provided) #6698 

Add safety checks in handleTabNavigatorChange to prevent crash

This fixes a crash that occurs when _disappearingScreens array is empty
or
contains invalid objects by adding appropriate null checks and bounds
checking.

The crash would occur when:
- The _disappearingScreens array is empty
- navTabScreen or its reactSuperview is null
- targetScreen is null

App was crashing during shared element transition because of invalid
array access.

Fixes #6698

---------

Co-authored-by: Krzysztof Piaskowy <krzysztof.piaskowy@swmansion.com>
  • Loading branch information
2 people authored and tomekzaw committed Dec 9, 2024
1 parent 34fa4de commit 7a16ea6
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,26 @@ - (void)handleTabNavigatorChange:(REAUIView *)layoutedScreen
return;
}

// Add safety check for disappearing screens
if ([_disappearingScreens count] == 0) {
return;
}

REAUIView *navTabScreen = _disappearingScreens[0];
REAUIView *sourceScreen = _disappearingScreens[[_disappearingScreens count] - 1];

// Add null checks
if (!navTabScreen || !navTabScreen.reactSuperview) {
return;
}

REAUIView *targetTabScreen = [REAScreensHelper getActiveTabForTabNavigator:navTabScreen.reactSuperview];
REAUIView *targetScreen = [REAScreensHelper findTopScreenInChildren:targetTabScreen];

if (!targetScreen) {
return;
}

if (!layoutedScreen && _isTabNavigator) {
// just wait for the next layout computation for your screen
return;
Expand Down

0 comments on commit 7a16ea6

Please sign in to comment.