Skip to content
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

Shared Element Transition (Solution provided) #6698

Closed
aymather opened this issue Nov 12, 2024 · 3 comments · Fixed by #6700
Closed

Shared Element Transition (Solution provided) #6698

aymather opened this issue Nov 12, 2024 · 3 comments · Fixed by #6700
Labels
Missing repro This issue need minimum repro scenario Platform: iOS This issue is specific to iOS

Comments

@aymather
Copy link
Contributor

aymather commented Nov 12, 2024

Description

It's really hard for me to know what's going on here, but I can sometimes reproduce this error by pressing a button in my app which leads to a crash. I used Claude to interpret the crash logs for me and it's saying that the error has to do with the Shared Element package. I've also attached the full crash logs in crash-logs.txt.

Exception Type: EXC_CRASH (SIGABRT)
Termination Reason: SIGNAL 6 Abort trap: 6

0   CoreFoundation                	__exceptionPreprocess + 160
1   libobjc.A.dylib               	objc_exception_throw + 56
2   CoreFoundation                	-[__NSArrayM removeAllObjects] + 0
3   alysium-dev                   	-[REASharedTransitionManager handleTabNavigatorChange:] + 128
4   alysium-dev                   	-[REASharedTransitionManager reanimated_viewDidLayoutSubviews] + 128
-[REASharedTransitionManager handleTabNavigatorChange:] + 128 (REASharedTransitionManager.m:579)
-[REASharedTransitionManager reanimated_viewDidLayoutSubviews] + 128 (REASharedTransitionManager.m:524)
0   CoreFoundation                	__exceptionPreprocess + 160
1   libobjc.A.dylib               	objc_exception_throw + 56
2   CoreFoundation                	-[__NSArrayM removeAllObjects] + 0

crash-logs.txt

Steps to reproduce

  1. Mount a component that has a shared element tag
  2. I have a button in my app that essentially unmounts the app and mounts a different "app". If i press that, it leads to this crash.

Snack or a link to a repository

unable to

Reanimated version

3.16.1

React Native version

0.74.3

Platforms

iOS

JavaScript runtime

None

Workflow

React Native

Architecture

Fabric (New Architecture)

Build type

Debug app & dev bundle

Device

iOS simulator

Device model

iPhone 15 Plus

Acknowledgements

Yes

Copy link

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

@github-actions github-actions bot added Missing repro This issue need minimum repro scenario Platform: iOS This issue is specific to iOS labels Nov 12, 2024
@aymather
Copy link
Contributor Author

I found the issue and implemented a fix. It's just some null/array checks.

Lines 573-586:

if (_isAsyncSharedTransitionConfigured) {
    // this is a new screen, let wait until header will be attached to a screen to make a proper snapshots
    _isTabNavigator = YES;
    return;
  }

  REAUIView *navTabScreen = _disappearingScreens[0];
  REAUIView *sourceScreen = _disappearingScreens[[_disappearingScreens count] - 1];
  REAUIView *targetTabScreen = [REAScreensHelper getActiveTabForTabNavigator:navTabScreen.reactSuperview];
  REAUIView *targetScreen = [REAScreensHelper findTopScreenInChildren:targetTabScreen];
  if (!layoutedScreen && _isTabNavigator) {
    // just wait for the next layout computation for your screen
    return;
  }

Changes:

if (_isAsyncSharedTransitionConfigured) {
    // this is a new screen, let wait until header will be attached to a screen to make a proper snapshots
    _isTabNavigator = YES;
    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;
  }

Is there any documentation on how to do a pull request here? I don't mind doing it.

@aymather aymather changed the title Shared Element Transition Shared Element Transition (Solution provided) Nov 13, 2024
aymather added a commit to aymather/react-native-reanimated that referenced this issue Nov 13, 2024
@aymather
Copy link
Contributor Author

Pull request open #6700

github-merge-queue bot pushed a commit that referenced this issue Dec 4, 2024
#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>
tomekzaw pushed a commit that referenced this issue Dec 9, 2024
#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>
tomekzaw pushed a commit that referenced this issue Dec 9, 2024
#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>
tjzel pushed a commit that referenced this issue Dec 13, 2024
#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>
tjzel pushed a commit that referenced this issue Dec 13, 2024
#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>
tjzel pushed a commit that referenced this issue Dec 13, 2024
#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Missing repro This issue need minimum repro scenario Platform: iOS This issue is specific to iOS
Projects
None yet
1 participant