App icon indicating copy to clipboard operation
App copied to clipboard

[$250] Gesture - Safari on iPhone flickers previous screen on swipe-back gesture

Open lanitochka17 opened this issue 1 year ago • 185 comments

If you haven't already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: 9.2.62-5 Reproducible in staging?: Y Reproducible in production?: Y If this was caught during regression testing, add the test name, ID and link from TestRail: Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause - Internal Team

Action Performed:

  1. Open app and login
  2. Navigate to Account > Profile > Display name
  3. Perform swipe-back gesture

Expected Result:

When performing the swipe-back gesture in Safari on iPhone, the previous screen should not appear. Navigation to the previous screen occurs smoothly, without flickering or momentary display of previous content

Actual Result:

When performing the swipe-back gesture in Safari on iPhone, the previous screen briefly flickers upon returning. This occurs on any screen of the app

Workaround:

Unknown

Platforms:

Select the officially supported platforms where the issue was reproduced:

  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [ ] iOS: App
  • [x] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [ ] Windows: Chrome
  • [ ] MacOS: Chrome / Safari
  • [ ] MacOS: Desktop
Platforms Tested: On which of our officially supported platforms was this issue tested:
  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [ ] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [ ] Windows: Chrome
  • [ ] MacOS: Chrome / Safari
  • [ ] MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

https://github.com/user-attachments/assets/58d74c00-86b6-46ae-941e-a808dfda8139

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021993123218832684990
  • Upwork Job ID: 1993123218832684990
  • Last Price Increase: 2025-12-02
  • Automatic offers:
    • aimane-chnaif | Reviewer | 109688488
    • LorenzoBloedow | Contributor | 109688489
Issue OwnerCurrent Issue Owner: @eh2077

lanitochka17 avatar Nov 24 '25 17:11 lanitochka17

Triggered auto assignment to @jliexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

melvin-bot[bot] avatar Nov 24 '25 17:11 melvin-bot[bot]

Android <> iOS swapsies, as Kadie has a physical iPhone to test

jliexpensify avatar Nov 24 '25 21:11 jliexpensify

Job added to Upwork: https://www.upwork.com/jobs/~021993123218832684990

melvin-bot[bot] avatar Nov 25 '25 01:11 melvin-bot[bot]

Triggered auto assignment to Contributor-plus team member for initial proposal review - @aimane-chnaif (External)

melvin-bot[bot] avatar Nov 25 '25 01:11 melvin-bot[bot]

🚨 Edited by proposal-police: This proposal was edited at 2025-12-02 16:52:08 UTC.

Proposal

Please re-state the problem that we are trying to solve in this issue.

When doing the swipe-back gesture on iOS Safari, the previous screen flickers.

What is the root cause of that problem?

This bug has actually already happened before, and this PR fixed it. However, as predicted in the PR linked above:

Gestures that would trigger navigation in the browser history generate broken touch events so this solution is based on this broken behavior. This will need a rework if the bugs with events in the iOS safari will be fixed.

From my tests, It seems the bug has indeed been fixed upstream. However, this also means the patch from the PR above is now outdated.

Along with the bug being fixed on Safari, that PR is somewhat old, so probably because of changes in React Navigation (we've updated React Navigation to several releases since then, including a major one) and/or in Expensify, when the animation happens it's using a spring animation, which doesn't seem to fully support duration (from testing).

So, because we were using duration set to 0 to prevent the animation from flickering, and now we/RNN are using an animation type that doesn't support duration, along with the Safari bug being fixed which means the fix in that PR is outdated, the old fix just doesn't work anymore.

What changes do you think we should make in order to solve the problem?

  1. Delete patches/react-navigation/@react-navigation+stack+7.3.3+001+edge-drag-gesture.patch (we'll build upon this patch).
  2. Add the following patch:
diff --git a/node_modules/@react-navigation/stack/lib/module/utils/edgeDragGestureMonitor.js b/node_modules/@react-navigation/stack/lib/module/utils/edgeDragGestureMonitor.js
new file mode 100644
index 0000000..014d643
--- /dev/null
+++ b/node_modules/@react-navigation/stack/lib/module/utils/edgeDragGestureMonitor.js
@@ -0,0 +1,40 @@
+"use strict";
+
+let isInitialized = false;
+let justFinishedEdgeGestureFromLeft = false;
+let touchStartPositionX = 0;
+
+/// This returns information if the user just performed edge gesture on iOS safari to navigate in the browser history.
+export const getIsEdgeDragGesture = () => {
+  return justFinishedEdgeGestureFromLeft;
+};
+
+export const maybeInitializeEdgeDragGestureMonitor = () => {
+  if (isInitialized) {
+    return;
+  }
+  isInitialized = true;
+  let timer;
+
+  // Gestures that would trigger navigation forward are broken on iOS safari.
+  // They don't have touchend event fired so we can look at expectingTouchEnd flag to detect if we should run animation.
+  const handleTouchStart = (e) => {
+    touchStartPositionX = e.changedTouches[0].pageX;
+  };
+  const handleTouchEnd = e => {
+    let changedTouches;
+    const pageX = (changedTouches = e.changedTouches[0]) === null || changedTouches === void 0 ? void 0 : changedTouches.pageX;
+    console.log(202020220, pageX, touchStartPositionX, e);
+    // PageX for gesture that would trigger navigation back is negative.
+    if ((pageX - touchStartPositionX) > 20) {
+      if (timer) {
+        clearTimeout(timer);
+      }
+      justFinishedEdgeGestureFromLeft = true;
+      timer = setTimeout(() => justFinishedEdgeGestureFromLeft = false, 100);
+    }
+  };
+  document.addEventListener('touchstart', handleTouchStart);
+  document.addEventListener('touchend', handleTouchEnd);
+};
+//# sourceMappingURL=edgeDragGestureMonitor.js.map
\ No newline at end of file
diff --git a/node_modules/@react-navigation/stack/lib/module/utils/edgeDragGestureMonitor.native.js b/node_modules/@react-navigation/stack/lib/module/utils/edgeDragGestureMonitor.native.js
new file mode 100644
index 0000000..9c7b703
--- /dev/null
+++ b/node_modules/@react-navigation/stack/lib/module/utils/edgeDragGestureMonitor.native.js
@@ -0,0 +1,8 @@
+"use strict";
+
+// We don't need edgeDragGestureMonitor for native platforms.
+
+export const getIsEdgeDragGesture = () => false;
+export const resetExpectingTouchendWithDelay = () => {};
+export const maybeInitializeEdgeDragGestureMonitor = () => {};
+//# sourceMappingURL=edgeDragGestureMonitor.native.js.map
\ No newline at end of file
diff --git a/node_modules/@react-navigation/stack/lib/module/views/Stack/Card.js b/node_modules/@react-navigation/stack/lib/module/views/Stack/Card.js
index b680e64..52a001a 100644
--- a/node_modules/@react-navigation/stack/lib/module/views/Stack/Card.js
+++ b/node_modules/@react-navigation/stack/lib/module/views/Stack/Card.js
@@ -12,6 +12,8 @@ import { getShadowStyle } from "../../utils/getShadowStyle.js";
 import { GestureState, PanGestureHandler } from '../GestureHandler';
 import { CardContent } from "./CardContent.js";
 import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
+import { getIsEdgeDragGesture } from '../../utils/edgeDragGestureMonitor.js';
+
 const GESTURE_VELOCITY_IMPACT = 0.3;
 const TRUE = 1;
 const FALSE = 0;
@@ -111,7 +113,8 @@ function Card({
     lastToValueRef.current = toValue;
     isClosing.setValue(isClosingParam ? TRUE : FALSE);
     const spec = isClosingParam ? transitionSpec.close : transitionSpec.open;
-    const animation = spec.animation === 'spring' ? Animated.spring : Animated.timing;
+    const isEdgeDragGesture = getIsEdgeDragGesture();
+    const animation = spec.animation === 'spring' && !isEdgeDragGesture ? Animated.spring : Animated.timing;
     clearTimeout(pendingGestureCallbackRef.current);
     if (animationHandleRef.current !== undefined) {
       cancelAnimationFrame(animationHandleRef.current);
@@ -133,10 +136,12 @@ function Card({
         }
       });
     };
+    console.log(10101010110, animated, isEdgeDragGesture, spec);
     if (animated) {
       onStartInteraction();
       animation(gesture, {
         ...spec.config,
+        duration: isEdgeDragGesture ? 0 : spec.config && 'duration' in spec.config ? spec.config.duration : undefined,
         velocity,
         toValue,
         useNativeDriver,
diff --git a/node_modules/@react-navigation/stack/lib/module/views/Stack/CardStack.js b/node_modules/@react-navigation/stack/lib/module/views/Stack/CardStack.js
index 2f9a4a9..121b6fe 100644
--- a/node_modules/@react-navigation/stack/lib/module/views/Stack/CardStack.js
+++ b/node_modules/@react-navigation/stack/lib/module/views/Stack/CardStack.js
@@ -5,6 +5,7 @@ import * as React from 'react';
 import { Animated, Platform, StyleSheet, View } from 'react-native';
 import { forModalPresentationIOS, forNoAnimation as forNoAnimationCard } from "../../TransitionConfigs/CardStyleInterpolators.js";
 import { BottomSheetAndroid, DefaultTransition, FadeFromBottomAndroid, FadeFromRightAndroid, ModalFadeTransition, ModalSlideFromBottomIOS, ModalTransition, RevealFromBottomAndroid, ScaleFromCenterAndroid, SlideFromLeftIOS, SlideFromRightIOS } from "../../TransitionConfigs/TransitionPresets.js";
+import { maybeInitializeEdgeDragGestureMonitor } from '../../utils/edgeDragGestureMonitor';
 import { findLastIndex } from "../../utils/findLastIndex.js";
 import { getDistanceForDirection } from "../../utils/getDistanceForDirection.js";
 import { getModalRouteKeys } from "../../utils/getModalRoutesKeys.js";
@@ -262,6 +263,7 @@ export class CardStack extends React.Component {
   }
   constructor(props) {
     super(props);
+    maybeInitializeEdgeDragGestureMonitor();
     this.state = {
       routes: [],
       scenes: [],

As you can see above, since the touch gestures are now working (Safari bug fixed), we can compare the start of the touch with the end to detect if it's a left-to-right swipe gesture. Then, we can force the animation to Timing which does work with duration set to 0.

What alternative solutions did you explore? (Optional)

N/A

Result:

https://github.com/user-attachments/assets/9a8f7135-753a-49c7-8003-10177793fd0f

LorenzoBloedow avatar Nov 25 '25 12:11 LorenzoBloedow

@aimane-chnaif Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

melvin-bot[bot] avatar Nov 29 '25 00:11 melvin-bot[bot]

reviewing

aimane-chnaif avatar Dec 02 '25 14:12 aimane-chnaif

@LorenzoBloedow How were you able to use swipe-back gesture on simulator? Not working for me. I am only able to test on my iPhone.

https://github.com/user-attachments/assets/efb58dab-8116-4e02-aaa7-c872898706ec


From my tests, It seems the bug has indeed been fixed upstream.

Which repo exactly? So you mean that if we bump @react-navigation/stack to the latest version, bug will be gone?

aimane-chnaif avatar Dec 02 '25 15:12 aimane-chnaif

@aimane-chnaif To repro on the simulator you have to start dragging from the left edge outside the screen (the black frame). You're dragging from the inside, that's why it doesn't work.

Which repo exactly? So you mean that if we bump @react-navigation/stack to the latest version, bug will be gone?

No, I just meant that this bug has happened before, and we had made a workaround based on the previous (buggy) Safari behavior. And as predicted in the workaround PR, we'll have to rewrite the workaround now that the bug we've based our logic on has been fixed in Safari.

Basically the logic in Safari changed, so the workaround for this same bug that happened before doesn't work anymore so we have to rewrite it for the new Safari versions.

LorenzoBloedow avatar Dec 02 '25 15:12 LorenzoBloedow

@LorenzoBloedow we're going to update react-navigation packages soon - #75700 Can you please update your proposal to patch against latest version (maybe 7.6.9) of @react-navigation/stack?

aimane-chnaif avatar Dec 02 '25 15:12 aimane-chnaif

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

melvin-bot[bot] avatar Dec 02 '25 16:12 melvin-bot[bot]

@aimane-chnaif Updated my proposal and tested with react-navigation 7.6.9 (by removing some patches since we don't have the PR that updates @react-navigation/stack ready yet):

https://github.com/user-attachments/assets/90cfa4d4-4ebc-429c-847c-d72ac3453507

LorenzoBloedow avatar Dec 02 '25 16:12 LorenzoBloedow

I also updated my proposal to delete the previous patch instead of patching the patch, this way we just have to put the initial PR in details.md and it'll be cleaner.

LorenzoBloedow avatar Dec 02 '25 16:12 LorenzoBloedow

@LorenzoBloedow's proposal looks good. We need to hold this for https://github.com/Expensify/App/issues/75700 so that patch would be based on latest version of @react-navigation/stack. 🎀 👀 🎀 C+ reviewed

aimane-chnaif avatar Dec 02 '25 17:12 aimane-chnaif

Triggered auto assignment to @Beamanator, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

melvin-bot[bot] avatar Dec 02 '25 17:12 melvin-bot[bot]

📣 @aimane-chnaif 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link Upwork job

melvin-bot[bot] avatar Dec 03 '25 07:12 melvin-bot[bot]

📣 @LorenzoBloedow 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link Upwork job Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻 Keep in mind: Code of Conduct | Contributing 📖

melvin-bot[bot] avatar Dec 03 '25 07:12 melvin-bot[bot]

Assigned & put on hold as you recommended! :D

Beamanator avatar Dec 03 '25 08:12 Beamanator

Just to confirm, does this mean I should wait until #75700 is closed to open the PR?

LorenzoBloedow avatar Dec 03 '25 13:12 LorenzoBloedow

Just to confirm, does this mean I should wait until #75700 is closed to open the PR?

yes correct

aimane-chnaif avatar Dec 03 '25 13:12 aimane-chnaif