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

fix: set VCs of views from recycling pool as UIAdaptivePresentationControllerDelegate #1535

Merged
merged 4 commits into from
Jul 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions ios/RNSScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,17 @@ - (void)prepareForRecycle
_dismissed = NO;
_state.reset();
_touchHandler = nil;

// We set this prop to default value here to workaround view-recycling.
// Let's assume the view has had _stackPresentation == <some modal stack presentation> set
// before below line was executed. Then, when instantiated again (with the same modal presentation)
// updateProps:oldProps: method would be called and setter for stack presentation would not be called.
// This is crucial as in that setter we register `self.controller` as a delegate
// (UIAdaptivePresentationControllerDelegate) to presentation controller and this leads to buggy modal behaviour as we
// rely on UIAdaptivePresentationControllerDelegate callbacks. Restoring the default value and then comparing against
// it in updateProps:oldProps: allows for setter to be called, however if there was some additional logic to execute
// when stackPresentation is set to "push" the setter would not be triggered.
_stackPresentation = RNSScreenStackPresentationPush;
}

- (void)updateProps:(facebook::react::Props::Shared const &)props
Expand Down Expand Up @@ -603,9 +614,12 @@ - (void)updateProps:(facebook::react::Props::Shared const &)props
}
#endif

if (newScreenProps.stackPresentation != oldScreenProps.stackPresentation) {
[self
setStackPresentation:[RNSConvert RNSScreenStackPresentationFromCppEquivalent:newScreenProps.stackPresentation]];
// Notice that we compare against _stackPresentation, not oldScreenProps.stackPresentation.
// See comment in prepareForRecycle method for explanation.
RNSScreenStackPresentation newStackPresentation =
[RNSConvert RNSScreenStackPresentationFromCppEquivalent:newScreenProps.stackPresentation];
if (newStackPresentation != _stackPresentation) {
[self setStackPresentation:newStackPresentation];
}

if (newScreenProps.stackAnimation != oldScreenProps.stackAnimation) {
Expand Down