[英]iOS app freeze for ~0.5 second on swipe back gesture
I am using Flutter to develop our mobile app.我正在使用 Flutter 来开发我们的移动应用程序。 When I open new screen like this:当我像这样打开新屏幕时:
Navigator.push(
context,
MaterialPageRoute/CupertinoPageRoute(
builder: (context) => NewScreen(....),
));
and I swipe back using swipe gesture, the UI is not clickable for like 0.5 - 1 seconds afterwards.我使用滑动手势向后滑动,用户界面在 0.5 - 1 秒后不可点击。 It makes the app feel unresponsive and slow.它使应用程序感觉反应迟钝和缓慢。 What is causing this "freezing"?是什么导致了这种“冻结”? Is something eating the touch events?有什么东西在吃触摸事件吗?
Similar issue: https://github.com/flutter/flutter/issues/48225类似问题: https://github.com/flutter/flutter/issues/48225
I tried investigating this issue using the sample code provided by @edwardez and found out that this is due to...我尝试使用@edwardez 提供的示例代码调查此问题,发现这是由于...
File: routes.dart Class: _ModalScopeState Function: build(...) Lines:文件:routes.dart Class:_ModalScopeState Function:构建(...)行:
AnimatedBuilder(
// !!!!!!!!!!!!!!!!!!!!!!!!! userGestureInProgressNotifier becomes true
animation: widget.route.navigator?.userGestureInProgressNotifier ?? ValueNotifier<bool>(false),
builder: (BuildContext context, Widget child) {
final bool ignoreEvents = _shouldIgnoreFocusRequest;
focusScopeNode.canRequestFocus = !ignoreEvents;
return IgnorePointer(
ignoring: false,//ignoreEvents, // <<<<<<<<<<<<<< Tried setting it to FALSE, resolves the issue.
child: child,
);
},
child: child,
),
Setting the IgnorePointer
's ignoring
property to false retains the First screen's animation and resolves the issue.将IgnorePointer
的ignoring
属性设置为 false 会保留第一个屏幕的 animation 并解决问题。
When I tried setting the userGestureInProgressNotifier
to always return to false, and reverting my changes in IgnorePointer...当我尝试将userGestureInProgressNotifier
设置为始终返回 false 并恢复我在 IgnorePointer 中的更改时...
File: navigator.dart Function: set _userGesturesInProgress Lines:文件:navigator.dart Function:设置_userGesturesInProgress 行:
set _userGesturesInProgress(int value) {
_userGesturesInProgressCount = value;
//userGestureInProgressNotifier.value = _userGesturesInProgress > 0; // <<<<<< Commented
}
This also resolves the issue but there's no animation for the First screen.这也解决了问题,但第一个屏幕没有 animation。 (same as pressing back button in AppBar). (与在 AppBar 中按下后退按钮相同)。
My Flutter doctor...我的Flutter博士...
[✓] Flutter (Channel stable, 1.22.5, on macOS 11.1 20C69 darwin-x64, locale en-US)
• Flutter version 1.22.5 at /Users/rickkystiannelim/Documents/sdk/flutter
• Framework revision 7891006299 (5 weeks ago), 2020-12-10 11:54:40 -0800
• Engine revision ae90085a84
• Dart version 2.10.4
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /Users/rickkystiannelim/Library/Android/sdk
• Platform android-30, build-tools 30.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 12.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.2, Build version 12B45b
• CocoaPods version 1.9.3
[!] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
[✓] VS Code (version 1.52.1) // <<<<<<<<<<<<<< IDE used
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.18.1
[✓] Connected device (1 available)
• ASUS Z012DA (mobile) • G8AZCY00Z1714K5 • android-arm64 • Android 8.0.0 (API 26) // <<<<<< Device used
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.