Skip to content

fix(iOS) pushing a removing screen to controller#2766

Closed
wvq wants to merge 1 commit intosoftware-mansion:mainfrom
wvq:fix-swiping-back-quickly
Closed

fix(iOS) pushing a removing screen to controller#2766
wvq wants to merge 1 commit intosoftware-mansion:mainfrom
wvq:fix-swiping-back-quickly

Conversation

@wvq
Copy link
Copy Markdown

@wvq wvq commented Mar 9, 2025

Description

Fixes #2559

Bug track:
The logic waiting for the transition complete and then call updateContainer has problem.
An old screen may be about to be removed but has not yet been removed.
which not in _controllers, but _reactSubviews not remove it yet.
updateContainer iterates _reactSubviews and call setPushViewControllers.
The old screen will push again.

This change add a property disappeared to RNSScreen, defaults to NO.

  • on viewWillAppear/viewDidAppear/viewWillDisappear set NO
  • on viewDidDisappear set YES

In RNSScreenStack's setPushViewControllers, check if it's not an new screen.

if(!((RNSScreen *)top).disappeared) {
  [_controller pushViewController:top animated:YES];
}

Copy link
Copy Markdown
Member

@kkafar kkafar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, that looks great, thanks. I'll test that when I have a moment & we'll see how do we proceed here.

@wvq
Copy link
Copy Markdown
Author

wvq commented Mar 21, 2025

@kkafar This fix conflicts with react-navigation's usePreventRemove, should not be approved.
The logic of usePreventRemove is to add disappeared screen again,
This bug is also because add disappeared screen again.
In this repo, there is no way to check if the screen is disappeared and should't add it.
It's need react-navigation passing some neccessary information to check it.

@wvq wvq closed this Mar 22, 2025
@JustJoostNL
Copy link
Copy Markdown

@wvq So do I understand correctly that, to fix the issue, changes in react-navigation are needed rather than in react-native-screens?

If so, are you planning to do a PR there? I would love to see this fixed. 😄

@wvq
Copy link
Copy Markdown
Author

wvq commented Apr 8, 2025

@JustJoostNL No, the bug is on this project, I just can't find a proper way to mark the expired screen.
my PR is marking expired screen and prevent it add again, it work for my case, not for all.
react-navigation usePreventRemove just an example which not suite.
So I close this PR.

@JustJoostNL
Copy link
Copy Markdown

Ah right. I guess someone has to come up with a global working solution then.

@wvq
Copy link
Copy Markdown
Author

wvq commented Apr 8, 2025

For now, my temporary solution is run hook after npm install.

#!/bin/bash

#
# temporary fix react-native-screens
# 
# https://github.com/software-mansion/react-native-screens/issues/2559
#

check='disappeared'

screen_header='./node_modules/react-native-screens/ios/RNSScreen.h'
screen_mm='./node_modules/react-native-screens/ios/RNSScreen.mm'
screen_stack_mm='./node_modules/react-native-screens/ios/RNSScreenStack.mm'


if ! grep -qw $check $screen_header; then
    sed -i '' '43i\
@property (nonatomic, readonly) BOOL disappeared;\
' $screen_header
fi

if ! grep -qw '_disappeared' $screen_mm; then
sed -i '' '1353i\
    _disappeared = NO;\
' $screen_mm
sed -i '' '1365i\
  _disappeared = NO;\
' $screen_mm
sed -i '' '1393i\
  _disappeared = NO;\
' $screen_mm
sed -i '' '1431i\
  _disappeared = NO;\
' $screen_mm
sed -i '' '1448i\
  _disappeared = YES;\
' $screen_mm
fi


if ! grep -qw $check $screen_stack_mm; then
    sed -i '' '680i\
      if(!((RNSScreen *)top).disappeared) {\
' $screen_stack_mm
sed -i '' '682i\
      }\
' $screen_stack_mm
fi

echo 'hook finished'

@wvq
Copy link
Copy Markdown
Author

wvq commented Apr 8, 2025

This bug is caused by asynchrony, I think some logic may need to be refactored, which is not something that a simple solution can handle.

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.

[iOS] Unexpected Navigation Behavior When Swiping Back Quickly

3 participants