Unverified Commit 26548503 authored by jslavitz's avatar jslavitz Committed by GitHub

Fixes navigation page back drag area for iPhone X (#24375)

* nav fix and test
parent b3d9fb4d
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:math';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
......@@ -518,13 +519,19 @@ class _CupertinoBackGestureDetectorState<T> extends State<_CupertinoBackGestureD
@override
Widget build(BuildContext context) {
assert(debugCheckHasDirectionality(context));
// For devices with notches, the drag area needs to be larger on the side
// that has the notch.
double dragAreaWidth = Directionality.of(context) == TextDirection.ltr ?
MediaQuery.of(context).padding.left :
MediaQuery.of(context).padding.right;
dragAreaWidth = max(dragAreaWidth, _kBackGestureWidth);
return Stack(
fit: StackFit.passthrough,
children: <Widget>[
widget.child,
PositionedDirectional(
start: 0.0,
width: _kBackGestureWidth,
width: dragAreaWidth,
top: 0.0,
bottom: 0.0,
child: Listener(
......
......@@ -265,6 +265,98 @@ void main() {
expect(find.text('Page 2'), isOnstage);
});
testWidgets('test edge swipes work with media query padding (LTR)', (WidgetTester tester) async {
await tester.pumpWidget(
CupertinoApp(
builder: (BuildContext context, Widget navigator) {
return MediaQuery(
data: const MediaQueryData(padding: EdgeInsets.only(left: 40)),
child: navigator,
);
},
home: const Placeholder(),
),
);
tester.state<NavigatorState>(find.byType(Navigator)).push(
CupertinoPageRoute<void>(
builder: (BuildContext context) => const Center(child: Text('Page 1')),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
tester.state<NavigatorState>(find.byType(Navigator)).push(
CupertinoPageRoute<void>(
builder: (BuildContext context) => const Center(child: Text('Page 2')),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
expect(find.text('Page 1'), findsNothing);
expect(find.text('Page 2'), isOnstage);
// Now drag from the left edge.
final TestGesture gesture = await tester.startGesture(const Offset(35.0, 200.0));
await gesture.moveBy(const Offset(300.0, 0.0));
await tester.pump();
await tester.pumpAndSettle();
// Page 1 is now visible.
expect(find.text('Page 1'), isOnstage);
expect(find.text('Page 2'), isOnstage);
});
testWidgets('test edge swipes work with media query padding (RLT)', (WidgetTester tester) async {
await tester.pumpWidget(
CupertinoApp(
builder: (BuildContext context, Widget navigator) {
return Directionality(
textDirection: TextDirection.rtl,
child: MediaQuery(
data: const MediaQueryData(padding: EdgeInsets.only(right: 40)),
child: navigator,
),
);
},
home: const Placeholder(),
),
);
tester.state<NavigatorState>(find.byType(Navigator)).push(
CupertinoPageRoute<void>(
builder: (BuildContext context) => const Center(child: Text('Page 1')),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
tester.state<NavigatorState>(find.byType(Navigator)).push(
CupertinoPageRoute<void>(
builder: (BuildContext context) => const Center(child: Text('Page 2')),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
expect(find.text('Page 1'), findsNothing);
expect(find.text('Page 2'), isOnstage);
// Now drag from the left edge.
final TestGesture gesture = await tester.startGesture(const Offset(765.0, 200.0));
await gesture.moveBy(const Offset(-300.0, 0.0));
await tester.pump();
await tester.pumpAndSettle();
// Page 1 is now visible.
expect(find.text('Page 1'), isOnstage);
expect(find.text('Page 2'), isOnstage);
});
testWidgets('test only edge swipes work (RTL)', (WidgetTester tester) async {
await tester.pumpWidget(
CupertinoApp(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment