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(iOS): push and pop transitions change after full screen back swipe #2234

Merged
merged 1 commit into from
Jul 9, 2024

Conversation

maksg
Copy link
Contributor

@maksg maksg commented Jul 5, 2024

Description

Doing the swipe also caused programmatic push to use manual transition and have no shadow.
Fixes #2227.

Changes

Set _isFullWidthSwiping to NO when swipe gesture ends in handleSwipe: so programmatic push and pop can use OS logic by default.

Screenshots / GIFs

Before

Simulator.Screen.Recording.-.iPhone.15.Pro.Max.-.2024-07-05.at.16.43.46.mp4

After

Simulator.Screen.Recording.-.iPhone.15.Pro.Max.-.2024-07-05.at.16.44.34.mp4

Test code and steps to reproduce

  1. Run Test2227 in TestsExample app.
  2. Push screen with Go to Details.
  3. Swipe back with full screen swipe gesture.
  4. Push screen with Go to Details again.
  5. Before this fix there would be no shadow during transition after first full screen swipe back.

Checklist

@maksg maksg requested review from kkafar and WoLewicki July 5, 2024 14:56
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.

Left a tine remark, other than that - great job!

@@ -752,7 +752,7 @@ - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
[self cancelTouchesInParent];
return YES;
#else
// RNSPanGestureRecognizer will receive events iff topScreen.fullScreenSwipeEnabled == YES;
// RNSPanGestureRecognizer will receive events if topScreen.fullScreenSwipeEnabled == YES;
Copy link
Member

Choose a reason for hiding this comment

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

The iff is intentional - it is widely used, especially in mathematics & stands for if and only if (wtedy i tylko wtedy) 😄

Suggested change
// RNSPanGestureRecognizer will receive events if topScreen.fullScreenSwipeEnabled == YES;
// RNSPanGestureRecognizer will receive events iff topScreen.fullScreenSwipeEnabled == YES;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, haven't heard about that one before. That's good to know, thanks for enlightening me! 😃 I will revert that change

@@ -872,6 +872,7 @@ - (void)handleSwipe:(UIPanGestureRecognizer *)gestureRecognizer
[_interactionController cancelInteractiveTransition];
}
_interactionController = nil;
_isFullWidthSwiping = NO;
Copy link
Member

Choose a reason for hiding this comment

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

Okay, so the main issue (change of transition style after popping a screen with swipe for the very first time) was caused by not properly reset state. Great finding!

[UIView animateWithDuration:[self transitionDuration:transitionContext]
animations:^{
fromViewController.view.transform = leftTransform;
toViewController.view.transform = CGAffineTransformIdentity;
shadowView.alpha = 0.1;
Copy link
Member

Choose a reason for hiding this comment

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

My only suggestion here would be to extract this target alpha value to a constant, see the top of the RNSScreenStackAnimator.mm file (maybe use constexpr instead of static const) & if there is any reasoning behind this value (e.g. "Looked best in experimentation") - leave a comment behind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, I'll extract it and I'll add a comment a comment with explanation

@tboba tboba self-requested a review July 8, 2024 10:00
@maksg maksg force-pushed the @maksg/shadow-during-custom-push-pop-fix branch from 6a729b4 to 34420b2 Compare July 8, 2024 10:26
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.

One last thing, and we're good to go.

@@ -9,6 +9,9 @@
static const float RNSSlideCloseTransitionDurationProportion = 0.25 / 0.35;
static const float RNSFadeCloseTransitionDurationProportion = 0.15 / 0.35;
static const float RNSFadeCloseDelayTransitionDurationProportion = 0.1 / 0.35;
// same value is used in other projects using similar approach for transistions
// and it looks the most similar to the value used by Apple
constexpr float RNSShadowViewMaxAlpha = 0.1;
Copy link
Member

Choose a reason for hiding this comment

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

Idk why I suggested sole constexpr here, let's make it static also, so that the definition is visible only in this translation unit.

Suggested change
constexpr float RNSShadowViewMaxAlpha = 0.1;
static constexpr float RNSShadowViewMaxAlpha = 0.1;

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.

I am afraid doing it like this is a breaking change. When people use fullScreenSwipe right now, they don't have the shadow included. With those changes, it will appear which can be not expected by the users. Shouldn't we make this an optional prop of screen/navigator instead?

@maksg maksg force-pushed the @maksg/shadow-during-custom-push-pop-fix branch from 34420b2 to c30c7d3 Compare July 8, 2024 12:02
@kkafar
Copy link
Member

kkafar commented Jul 8, 2024

I considered it rather a fix, than breaking the behaviour. Although I can see your point.

One thing for sure: the change responsible for using default animation for programming push / pop after popping a screen with a gesture is a fix & it should be merged as is.

The code responsible for adding a dimming view for swipe-transition might be hidden behind a prop, as opt-in.

@maksg @WoLewicki Let's split this PR into two separate ones. Does that sound right?

@maksg maksg force-pushed the @maksg/shadow-during-custom-push-pop-fix branch from c30c7d3 to 37d59ba Compare July 8, 2024 13:57
@maksg maksg changed the title fix(iOS): shadow does not appear on manual transition during push and pop fix(iOS): push and pop transitions change after full screen back swipe Jul 8, 2024
@maksg
Copy link
Contributor Author

maksg commented Jul 8, 2024

I moved shadow view implementation to #2239

@jwoodmansey
Copy link

I have just played around with this branch and it seems that this issue shows up again randomly. As in, every so often navigation still uses the incorrect transition, it is now very rare. Are there more cases where _isFullWidthSwiping does not get properly reset?

Sorry I know that's not particularly helpful, I was swiping around a lot in a large app and have seen it a few times.

@kkafar
Copy link
Member

kkafar commented Jul 9, 2024

@jwoodmansey Can you post a video where you trigger the buggy behaviour? Maybe we can figure out the scenario in which in happens together somehow.

Despite the fact, this PR improves the situation. We should proceed @maksg.

@maksg maksg merged commit 8a13075 into main Jul 9, 2024
5 checks passed
@maksg maksg deleted the @maksg/shadow-during-custom-push-pop-fix branch July 9, 2024 09:26
maksg added a commit that referenced this pull request Jul 23, 2024
…adow during swipe gesture (#2239)

## Description

When using full screen swipe back there was no shadow under the view.
Related PR #2234 with discussion about this change.

Corresponding PR in `react-navigation`:

* react-navigation/react-navigation#12053

## Changes

Added shadow to transition in
animateSimplePushWithTransitionContext:toVC:fromVC:.

## Test code and steps to reproduce

1. Run `Test2227` in TestsExample app.
2. Push screen with Go to Details.
3. Swipe back with full screen swipe gesture.
5. Before this fix there would be no shadow during transition with full
screen swipe back.

## Checklist

- [x] Included code example that can be used to test this change
- [ ] Updated TS types
- [x] Updated documentation: <!-- For adding new props to native-stack
-->
- [x]
https://github.com/software-mansion/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md
- [x]
https://github.com/software-mansion/react-native-screens/blob/main/native-stack/README.md
- [x]
https://github.com/software-mansion/react-native-screens/blob/main/src/types.tsx
- [x]
https://github.com/software-mansion/react-native-screens/blob/main/src/native-stack/types.tsx
- [ ] Ensured that CI passes
ja1ns pushed a commit to WiseOwlTech/react-native-screens that referenced this pull request Oct 9, 2024
software-mansion#2234)

## Description

Doing the swipe also caused programmatic push to use manual transition
and have no shadow.
Fixes software-mansion#2227.

## Changes

Set `_isFullWidthSwiping` to `NO` when swipe gesture ends in
`handleSwipe:` so programmatic push and pop can use OS logic by default.

## Screenshots / GIFs

### Before

https://github.com/software-mansion/react-native-screens/assets/11507974/0f710aec-c8f0-4a3a-82df-d3edb5f0fb19

### After

https://github.com/software-mansion/react-native-screens/assets/11507974/51119c74-b2c3-4c32-9202-6954c3c70218

## Test code and steps to reproduce

1. Run `Test2227` in TestsExample app.
2. Push screen with `Go to Details`.
3. Swipe back with full screen swipe gesture.
4. Push screen with `Go to Details` again.
7. Before this fix there would be no shadow during transition after
first full screen swipe back.

## Checklist

- [x] Included code example that can be used to test this change
- [ ] Updated TS types
- [ ] Updated documentation: <!-- For adding new props to native-stack
-->
- [ ]
https://github.com/software-mansion/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md
- [ ]
https://github.com/software-mansion/react-native-screens/blob/main/native-stack/README.md
- [ ]
https://github.com/software-mansion/react-native-screens/blob/main/src/types.tsx
- [ ]
https://github.com/software-mansion/react-native-screens/blob/main/src/native-stack/types.tsx
- [ ] Ensured that CI passes
ja1ns pushed a commit to WiseOwlTech/react-native-screens that referenced this pull request Oct 9, 2024
…adow during swipe gesture (software-mansion#2239)

## Description

When using full screen swipe back there was no shadow under the view.
Related PR software-mansion#2234 with discussion about this change.

Corresponding PR in `react-navigation`:

* react-navigation/react-navigation#12053

## Changes

Added shadow to transition in
animateSimplePushWithTransitionContext:toVC:fromVC:.

## Test code and steps to reproduce

1. Run `Test2227` in TestsExample app.
2. Push screen with Go to Details.
3. Swipe back with full screen swipe gesture.
5. Before this fix there would be no shadow during transition with full
screen swipe back.

## Checklist

- [x] Included code example that can be used to test this change
- [ ] Updated TS types
- [x] Updated documentation: <!-- For adding new props to native-stack
-->
- [x]
https://github.com/software-mansion/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md
- [x]
https://github.com/software-mansion/react-native-screens/blob/main/native-stack/README.md
- [x]
https://github.com/software-mansion/react-native-screens/blob/main/src/types.tsx
- [x]
https://github.com/software-mansion/react-native-screens/blob/main/src/native-stack/types.tsx
- [ ] Ensured that CI passes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants