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

Conversation

kkafar
Copy link
Member

@kkafar kkafar commented Jul 18, 2022

Description

Fixes #1299 on Fabric. I was not able to reproduce this issue on Paper -> changes introduced in this PR do not change behaviour on Paper.

View recycling caused behaviour such that VCs of views that returned from recycle pool were not set as delegates for presentation controller. This caused presentationControllerDidDismiss: method not to be called and in consequence we did not receive information that modal transition had finished -> we did not allow for another one to start.

Changes

Set stackPresentation to default value in prepareForRecycle method to workaround view-recycling & check incoming new prop value (in updateProps:oldProps:) against actual state not old props. I pasted just below (a little bit paraphased) comment I placed in code in prepareForRecycle method with better explanation how the bug worked.

Let's assume the view has had _stackPresentation == <some modal stack presentation> set
before below line was executed.

_stackPresentation = RNSScreenStackPresentationPush

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.

Test code and steps to reproduce

See Test1299 in FabricTestExample & description of #1299 to see what & how to test.

Checklist

  • Ensured that CI passes

method

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` 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.
@kkafar kkafar changed the title bookmark: @kkafar/fix-1299 INIT fix: set UIAdaptivePresentationControllerDelegate for views from recycling pool Jul 19, 2022
@kkafar kkafar changed the title fix: set UIAdaptivePresentationControllerDelegate for views from recycling pool fix: set views from recycling pool as UIAdaptivePresentationControllerDelegate Jul 19, 2022
@kkafar kkafar changed the title fix: set views from recycling pool as UIAdaptivePresentationControllerDelegate fix: set VCs of views from recycling pool as UIAdaptivePresentationControllerDelegate Jul 19, 2022
@kkafar kkafar marked this pull request as ready for review July 19, 2022 13:03
@kkafar kkafar requested a review from WoLewicki July 19, 2022 13:03
Copy link
Member

@WoLewicki WoLewicki left a comment

Choose a reason for hiding this comment

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

We have to remember that it may trigger problems and maybe find a more generic solution to the problem, but for now it seems good enough 🚀

@kkafar kkafar merged commit dcc5ebd into main Jul 25, 2022
@kkafar kkafar deleted the @kkafar/fix-1299 branch July 25, 2022 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants