-
-
Notifications
You must be signed in to change notification settings - Fork 530
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
WoLewicki
merged 4 commits into
main
from
@wolewicki/remove-unnecessary-snapshot-checks
Nov 14, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9177f24
fix: remove unnecessary checks for creating snapshot
WoLewicki e080014
Merge branch 'main' into @wolewicki/remove-unnecessary-snapshot-checks
WoLewicki 6c1a245
fix: make header subviews analogous to screen snapshotting
WoLewicki 4135b48
chore: merge current main
WoLewicki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -856,27 +856,29 @@ - (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childCompo | |
|
||
- (void)replaceNavigationBarViewsWithSnapshotOfSubview:(RNSScreenStackHeaderSubview *)childComponentView | ||
{ | ||
UINavigationItem *navitem = _screenView.controller.navigationItem; | ||
UIView *snapshot = [childComponentView snapshotViewAfterScreenUpdates:NO]; | ||
|
||
// This code should be kept in sync with analogous switch statement in | ||
// `+ [RNSScreenStackHeaderConfig updateViewController: withConfig: animated:]` method. | ||
switch (childComponentView.type) { | ||
case RNSScreenStackHeaderSubviewTypeLeft: | ||
navitem.leftBarButtonItem.customView = snapshot; | ||
break; | ||
case RNSScreenStackHeaderSubviewTypeCenter: | ||
case RNSScreenStackHeaderSubviewTypeTitle: | ||
navitem.titleView = snapshot; | ||
break; | ||
case RNSScreenStackHeaderSubviewTypeRight: | ||
navitem.rightBarButtonItem.customView = snapshot; | ||
break; | ||
case RNSScreenStackHeaderSubviewTypeSearchBar: | ||
case RNSScreenStackHeaderSubviewTypeBackButton: | ||
break; | ||
default: | ||
RCTLogError(@"[RNScreens] Unhandled subview type: %ld", childComponentView.type); | ||
if (childComponentView.window != nil) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
UINavigationItem *navitem = _screenView.controller.navigationItem; | ||
UIView *snapshot = [childComponentView snapshotViewAfterScreenUpdates:NO]; | ||
|
||
// This code should be kept in sync with analogous switch statement in | ||
// `+ [RNSScreenStackHeaderConfig updateViewController: withConfig: animated:]` method. | ||
switch (childComponentView.type) { | ||
case RNSScreenStackHeaderSubviewTypeLeft: | ||
navitem.leftBarButtonItem.customView = snapshot; | ||
break; | ||
case RNSScreenStackHeaderSubviewTypeCenter: | ||
case RNSScreenStackHeaderSubviewTypeTitle: | ||
navitem.titleView = snapshot; | ||
break; | ||
case RNSScreenStackHeaderSubviewTypeRight: | ||
navitem.rightBarButtonItem.customView = snapshot; | ||
break; | ||
case RNSScreenStackHeaderSubviewTypeSearchBar: | ||
case RNSScreenStackHeaderSubviewTypeBackButton: | ||
break; | ||
default: | ||
RCTLogError(@"[RNScreens] Unhandled subview type: %ld", childComponentView.type); | ||
} | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this code:
react-native-screens/ios/RNSScreen.mm
Line 1842 in 4614702
true
forB
? I think its view is not in the window since it is detached. Would have to check though.There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.