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

Extra page shown when swiping back in Safari on iOS #114324

Open
MarcBritton opened this issue Oct 30, 2022 · 26 comments
Open

Extra page shown when swiping back in Safari on iOS #114324

MarcBritton opened this issue Oct 30, 2022 · 26 comments
Labels
browser: safari-ios only manifests in Safari on iOS f: routes Navigator, Router, and related APIs. found in release: 3.3 Found to occur in 3.3 found in release: 3.5 Found to occur in 3.5 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list platform-web Web applications specifically team-web Owned by Web platform team triaged-web Triaged by Web platform team

Comments

@MarcBritton
Copy link

Tested using the Navigation and Routing application from the Flutter samples.
https://github.com/flutter/samples/tree/main/navigation_and_routing
I built this application for the web (flutter build web), then ran a local webserver on MacOS in build/web and connected to it with Safari from my iPhone.

When you swipe from outside the left edge of the screen across to the right on a Flutter Web app running in Safari on an iOS device, an 'extra' page is shown in the slide transition animation that shouldn't be there.

The bug only occurs if you begin your swipe from outside the left edge of the display and then swipe across. If you begin from slightly inside the left edge of the screen, only 2 screens are displayed in the transition and it looks correct.

I tested this swiping behaviour in other web pages/apps and it doesn't occur, so it seems to be specific to Flutter.

I also tested in the Chrome browser from my iOS device and the same problem occurs, so it seems the problem is not specific to Safari.

The video shows alternating swipes first from the outside the left edge, then inside.

swipe_bug.mov
@danagbemava-nc
Copy link
Member

Hi @MarcBritton, kindly reduce the code sample to only the relevant parts required to reproduce the bug. Ideally, it should be a single main.dart file.

Please also provide the output of flutter doctor -v.

Thank you

@danagbemava-nc danagbemava-nc added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Oct 31, 2022
@MarcBritton
Copy link
Author

flutter doctor -v output:

[✓] Flutter (Channel stable, 3.3.4, on macOS 12.6 21G115 darwin-x64, locale en-AU)
    • Flutter version 3.3.4 on channel stable at /Users/marcbritton/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision eb6d86ee27 (4 weeks ago), 2022-10-04 22:31:45 -0700
    • Engine revision c08d7d5efc
    • Dart version 2.18.2
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/marcbritton/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A400
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

[✓] VS Code (version 1.72.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.50.0

[✓] Connected device (3 available)
    • iPhone SE (3rd generation) (mobile) • DA519C0F-2A9B-4FCF-8D50-19B40949E138 • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-16-0 (simulator)
    • macOS (desktop)                     • macos                                • darwin-x64     • macOS 12.6 21G115
      darwin-x64
    • Chrome (web)                        • chrome                               • web-javascript • Google Chrome
      107.0.5304.87

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Nov 1, 2022
@MarcBritton
Copy link
Author

MarcBritton commented Nov 1, 2022

Reproducible with this sample code:

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const FirstScreen(),
    );
  }
}

class FirstScreen extends StatelessWidget {
  const FirstScreen({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('First Page'),
      ),
      body: Center(
        child: TextButton(
          child: const Text('Go To Second Page'),
          onPressed: () => Navigator.push(
            context,
            MaterialPageRoute(
              builder: (context) => const SecondScreen(),
            ),
          ),
        ),
      ),
    );
  }
}

class SecondScreen extends StatelessWidget {
  const SecondScreen({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Second Page'),
      ),
      body: Center(
        child: TextButton(
          child: const Text('Go To Third Page'),
          onPressed: () => Navigator.push(
            context,
            MaterialPageRoute(
              builder: (context) => const ThirdScreen(),
            ),
          ),
        ),
      ),
    );
  }
}

class ThirdScreen extends StatelessWidget {
  const ThirdScreen({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Third Page'),
      ),
      body: const Center(child: Text('Third Page')),
    );
  }
}
slide.from.outside.screen.extra.page.MP4
slide.from.inside.screen.no.extra.page.MP4

@danagbemava-nc
Copy link
Member

Issue is reproducible using the code sample provided in #114324 (comment).

recording
RPReplay_Final1667284945.MP4
flutter doctor -v
[✓] Flutter (Channel stable, 3.3.6, on macOS 13.0 22A380 darwin-arm, locale en-GB)
    • Flutter version 3.3.6 on channel stable at /Users/nexus/dev/sdks/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 6928314d50 (6 days ago), 2022-10-25 16:34:41 -0400
    • Engine revision 3ad69d7be3
    • Dart version 2.18.2
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/nexus/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A309
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio
    • Android Studio at /Applications/Android Studio Preview.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[!] Android Studio
    • Android Studio at /Applications/Android Studio Preview 2.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] Android Studio (version 2021.3)
    • Android Studio at /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] Android Studio (version 2021.3)
    • Android Studio at /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9014738/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.72.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.50.0

[✓] Connected device (3 available)
    • iPhone 14 Pro (mobile) • 5B802496-18C0-4AF6-84C2-57E11359A79B • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-0 (simulator)
    • macOS (desktop)        • macos                                • darwin-arm64   • macOS 13.0 22A380 darwin-arm
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 107.0.5304.87

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 2 categories.
[!] Flutter (Channel master, 3.5.0-12.0.pre.46, on macOS 13.0 22A380 darwin-arm64, locale en-GB)
    • Flutter version 3.5.0-12.0.pre.46 on channel master at /Users/nexus/dev/sdks/flutters
    ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 0f1d0e39e9 (70 minutes ago), 2022-11-01 13:33:33 +0800
    • Engine revision f721db653d
    • Dart version 2.19.0 (build 2.19.0-356.0.dev)
    • DevTools version 2.18.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/nexus/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A309
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio
    • Android Studio at /Applications/Android Studio Preview.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[!] Android Studio
    • Android Studio at /Applications/Android Studio Preview 2.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] Android Studio (version 2021.3)
    • Android Studio at /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] Android Studio (version 2021.3)
    • Android Studio at /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9014738/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.72.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.50.0

[✓] Connected device (3 available)
    • iPhone 14 Pro (mobile) • 5B802496-18C0-4AF6-84C2-57E11359A79B • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-0 (simulator)
    • macOS (desktop)        • macos                                • darwin-arm64   • macOS 13.0 22A380 darwin-arm64
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 107.0.5304.87

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 3 categories.

@danagbemava-nc danagbemava-nc added framework flutter/packages/flutter repository. See also f: labels. f: routes Navigator, Router, and related APIs. platform-web Web applications specifically has reproducible steps The issue has been confirmed reproducible and is ready to work on browser: safari-ios only manifests in Safari on iOS found in release: 3.3 Found to occur in 3.3 found in release: 3.5 Found to occur in 3.5 and removed in triage Presently being triaged by the triage team labels Nov 1, 2022
@yjbanov yjbanov added the P2 Important issues not at the top of the work list label Nov 4, 2022
@kraa
Copy link

kraa commented Dec 1, 2022

RPReplay_Final1669904974.MP4

I have the same problem

@Bylinkk

This comment was marked as duplicate.

@Bylinkk
Copy link

Bylinkk commented Jan 28, 2023

I reproduced the issue with a new project and simple code. Does anyone know where the problem could come from ?
I try with RouteGenerator and goRoute package, is same issues.
The issues appears in real device iOS, not on virtual device.

WhatsApp.Video.2023-01-28.at.13.38.52.mp4
import` 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    // With Package RouteGenerator
    return MaterialApp(
      title: 'Flutter Demo Page Transition issues',
      home: const MyHomePage(),
      onGenerateRoute: (settings) => RouteGenerator.generateRoute(settings),
    );
    // With package GoRouter
    /*return MaterialApp.router(
      title: 'Flutter Demo Page Transition issues',
      routerConfig: router,
    );*/
  }
}

class RouteGenerator {
  static Route<dynamic> generateRoute(RouteSettings settings) {
    switch (settings.name) {
      case '/secondPage':
        return MaterialPageRoute(builder: (context) => const SecondPage());
      default:
        return MaterialPageRoute(
            builder: (context) => Scaffold(
                  appBar: AppBar(
                      title: const Text("Flutter Demo Page Transition issues")),
                  body: const Center(
                    child: Text("Page not found"),
                  ),
                ));
    }
  }
}

final GoRouter router = GoRouter(
  routes: <GoRoute>[
    GoRoute(
        path: '/',
        builder: (BuildContext context, GoRouterState state) =>
            const MyHomePage()),
    GoRoute(
        path: '/secondPage',
        builder: (BuildContext context, GoRouterState state) =>
            const SecondPage())
  ],
);

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('My First Page'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'This is my First Page',
            ),
            ElevatedButton(
                onPressed: () {
                  // With package RouteGenerator
                  Navigator.pushNamed(context, '/secondPage');
                  // With package GoRouter
                  //GoRouter.of(context).push("/secondPage");
                },
                child: const Text('Go to Second Page'))
          ],
        ),
      ),
    );
  }
}

class SecondPage extends StatelessWidget {
  const SecondPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('My Second Page'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: const <Widget>[
            Text('This is my Second Page'),
          ],
        ),
      ),
    );
  }
}
```

@kraa

This comment was marked as off-topic.

@Bylinkk

This comment was marked as off-topic.

@Bylinkk
Copy link

Bylinkk commented Jan 28, 2023

By using WillPopScope and recreating the back button with the leading argument, we manage to make the page split disappear but the return is still not logical!

return WillPopScope(
      onWillPop: () async => false,
      child: Scaffold(
        appBar: AppBar(
            title: const Text('My Second Page'),
            leading: IconButton(
                icon: const Icon(Icons.keyboard_arrow_left_outlined),
                onPressed: () {
                  Navigator.pop(context);
                })),
WhatsApp.Video.2023-01-28.at.16.11.22.mp4

@Bylinkk

This comment was marked as duplicate.

@MarcBritton

This comment was marked as duplicate.

@mchesnokov

This comment was marked as duplicate.

@JDongKhan

This comment was marked as duplicate.

@mchesnokov
Copy link

Interesting to notice that on iOS Simulator it works perfectly.

@sjohnsonaz

This comment was marked as duplicate.

@flutter-triage-bot flutter-triage-bot bot added multiteam-retriage-candidate team-web Owned by Web platform team triaged-web Triaged by Web platform team labels Jul 8, 2023
@birros
Copy link

birros commented Aug 25, 2023

I use the following workaround to prevent the first call to pushState made by Flutter during its initialization.
Unfortunately, I couldn't find the origin of this "first" call in the Flutter source code.
I hope this will be helpful.

import 'dart:js';

/// Prevents first unnecessary [pushState] call made by the Flutter web engine
/// during its initialization.
///
/// This removes the extra page shown when swiping back in Safari on iOS.
void preventFirstPushState() {
  final history = context["history"] as JsObject;

  /// Store original pushState callback.
  final originalCallback = history["pushState"] as JsFunction;

  /// Define a temporary callback to catch first call.
  /// Optionnal arguments are used to catch var args call.
  void temporaryCallback([a1, a2, a3, a4, a5, a6]) {
    /// Restore original pushState callback.
    history["pushState"] = originalCallback;
  }

  /// Replace current callback.
  history["pushState"] = temporaryCallback;
}

@hlynurl
Copy link

hlynurl commented Aug 30, 2023

I use the following workaround to prevent the first call to pushState made by Flutter during its initialization. Unfortunately, I couldn't find the origin of this "first" call in the Flutter source code. I hope this will be helpful.

import 'dart:js';

/// Prevents first unnecessary [pushState] call made by the Flutter web engine
/// during its initialization.
///
/// This removes the extra page shown when swiping back in Safari on iOS.
void preventFirstPushState() {
  final history = context["history"] as JsObject;

  /// Store original pushState callback.
  final originalCallback = history["pushState"] as JsFunction;

  /// Define a temporary callback to catch first call.
  /// Optionnal arguments are used to catch var args call.
  void temporaryCallback([a1, a2, a3, a4, a5, a6]) {
    /// Restore original pushState callback.
    history["pushState"] = originalCallback;
  }

  /// Replace current callback.
  history["pushState"] = temporaryCallback;
}

This does not solve the issue. 😿

@NikitaPolyakov11
Copy link

NikitaPolyakov11 commented Sep 19, 2023

This helped me solve the same problem

function handleTouchMove(event, xStart, yStart) {
  var xDiff = xStart - event.touches[0].pageX;
  var yDiff = yStart - event.touches[0].pageY;

  // Prevent horizontal swipe
  if (xDiff > 20 && Math.abs(xDiff) > Math.abs(yDiff)) {
    event.preventDefault();
  }
}

var newHandleTouchMove = function (xStart, yStart) {
  return function (event) {
    handleTouchMove(event, xStart, yStart);
  };
}

document.addEventListener('touchstart', function (startEvent) {
  // Ignore multi-touch gestures
  if (startEvent.touches.length > 1) {
    return;
  }

  var xStart = startEvent.touches[0].pageX;
  var yStart = startEvent.touches[0].pageY;


  // Attach the touchmove event listener
  document.addEventListener('touchmove', newHandleTouchMove(xStart, yStart), { passive: false });
}, { passive: false });

And add this script to index.html
<script defer src="src/swipe_back.js"></script>

@danielRi
Copy link

Interesting to notice that on iOS Simulator it works perfectly.

I thought the same thing too, but I figured on the emulator it does not appear as often because we tend to swipe from the left side within the screen. The error described above only occurs when you swipe from outside the screen, whiche happens more easy when using a real device.

The problem also exists with go_router, if someone comes across this. Here is a minimal working example to reproduce the bug:

https://github.com/danielRi/gorouter_bug

@Bylinkk
Copy link

Bylinkk commented Oct 28, 2023

@NikitaPolyakov11 thank you for your work and your feedback. But this solution does not work. We are still waiting flutter to find a solution for this problem.
WhatsApp Image 2023-10-28 at 11 41 28

@danielRi
Copy link

bumping because it´s still occuring in Flutter 3.16.0

See #136455 for example project and video.

@kafukaxxx
Copy link

i have the same problem at 3.16.5

@demetrio812
Copy link

I have the same issue also with a drawer

@MarsMan13
Copy link

This helped me solve the same problem

function handleTouchMove(event, xStart, yStart) {
  var xDiff = xStart - event.touches[0].pageX;
  var yDiff = yStart - event.touches[0].pageY;

  // Prevent horizontal swipe
  if (xDiff > 20 && Math.abs(xDiff) > Math.abs(yDiff)) {
    event.preventDefault();
  }
}

var newHandleTouchMove = function (xStart, yStart) {
  return function (event) {
    handleTouchMove(event, xStart, yStart);
  };
}

document.addEventListener('touchstart', function (startEvent) {
  // Ignore multi-touch gestures
  if (startEvent.touches.length > 1) {
    return;
  }

  var xStart = startEvent.touches[0].pageX;
  var yStart = startEvent.touches[0].pageY;


  // Attach the touchmove event listener
  document.addEventListener('touchmove', newHandleTouchMove(xStart, yStart), { passive: false });
}, { passive: false });

And add this script to index.html <script defer src="src/swipe_back.js"></script>

I love U.

@liqping
Copy link

liqping commented Apr 3, 2024

document.addEventListener('touchstart', function (startEvent) { // Ignore multi-touch gestures if (startEvent.touches.length > 1) { return; } startEvent.preventDefault(); }, { passive: false });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
browser: safari-ios only manifests in Safari on iOS f: routes Navigator, Router, and related APIs. found in release: 3.3 Found to occur in 3.3 found in release: 3.5 Found to occur in 3.5 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list platform-web Web applications specifically team-web Owned by Web platform team triaged-web Triaged by Web platform team
Projects
None yet
Development

No branches or pull requests