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: remove unnecessary checks for creating snapshot #2485

Merged
merged 4 commits into from
Nov 14, 2024

Conversation

WoLewicki
Copy link
Member

Description

Based on Expensify/App#49937 (comment) and the comments above, PR fixes the unnecessary checks for creating snapshot on the view on dismiss. It was refactored already in #2134 and #2261 (👏 to @kkafar). Those checks do nothing now since each screen is responsible for making its own snapshot. Having those checks can only lead to problems.

Copy link
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.

I think we need to work on improving this code 👇🏻

screenChildComponent == [_presentedModals.lastObject view])) {
[screenChildComponent.controller setViewToSnapshot];
}
[screenChildComponent.controller setViewToSnapshot];
Copy link
Member

Choose a reason for hiding this comment

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

I see that this simplifies the logic, but I don't think this is quite right.

Imagine you have Stack with three screens: "A, B, C". You pop from C to top, thus resulting stack is "A". This code would do snapshots of both C and B, while we only want to do a snapshot of C.

If you describe what problem exactly you intend to solve we might be able to figure out better solution.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will this code:

if (self.view.window != nil) {
return true for B? I think its view is not in the window since it is detached. Would have to check though.

Copy link
Member Author

Choose a reason for hiding this comment

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

I checked. It is nil then so it should work correctly.

Copy link
Member

Choose a reason for hiding this comment

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

+1, I've forgotten that UINavigationController will keep all the controllers lower in the stack in detached state and that's it why it will work correctly.

break;
default:
RCTLogError(@"[RNScreens] Unhandled subview type: %ld", childComponentView.type);
if (childComponentView.window != nil) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Also added this check since we got many warning of snapshotting a view that is not in hierarchy when dismissing many screens with header items at once.

Copy link
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.

We're good then. Thanks for answering my concerns.

screenChildComponent == [_presentedModals.lastObject view])) {
[screenChildComponent.controller setViewToSnapshot];
}
[screenChildComponent.controller setViewToSnapshot];
Copy link
Member

Choose a reason for hiding this comment

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

+1, I've forgotten that UINavigationController will keep all the controllers lower in the stack in detached state and that's it why it will work correctly.

@kkafar
Copy link
Member

kkafar commented Nov 14, 2024

I've restarted the CI & we need to update the podfile lock.

@WoLewicki WoLewicki merged commit 7549b19 into main Nov 14, 2024
5 checks passed
@WoLewicki WoLewicki deleted the @wolewicki/remove-unnecessary-snapshot-checks branch November 14, 2024 13:28
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.

2 participants