Use native image reset controls on each host
This commit is contained in:
@@ -219,12 +219,24 @@ class _ZoomableImageState extends State<_ZoomableImage> {
|
|||||||
PositionedDirectional(
|
PositionedDirectional(
|
||||||
top: 8,
|
top: 8,
|
||||||
end: 8,
|
end: 8,
|
||||||
child: IconButton(
|
child: usesCupertinoHost(context)
|
||||||
key: const Key('artifact-image-reset-zoom'),
|
? Tooltip(
|
||||||
tooltip: 'Reset image zoom',
|
message: 'Reset image zoom',
|
||||||
onPressed: _reset,
|
child: CupertinoButton(
|
||||||
icon: const Icon(Icons.zoom_out_map),
|
key: const Key('artifact-image-reset-zoom'),
|
||||||
),
|
sizeStyle: CupertinoButtonSize.small,
|
||||||
|
onPressed: _reset,
|
||||||
|
child: const Icon(
|
||||||
|
CupertinoIcons.arrow_down_right_arrow_up_left,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: IconButton(
|
||||||
|
key: const Key('artifact-image-reset-zoom'),
|
||||||
|
tooltip: 'Reset image zoom',
|
||||||
|
onPressed: _reset,
|
||||||
|
icon: const Icon(Icons.zoom_out_map),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -651,69 +651,83 @@ void main() {
|
|||||||
expect(find.textContaining('1 of 2'), findsWidgets);
|
expect(find.textContaining('1 of 2'), findsWidgets);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('pinch owns the image gesture, pans while zoomed, and resets', (
|
for (final cupertino in [false, true]) {
|
||||||
tester,
|
testWidgets(
|
||||||
) async {
|
'pinch owns image pan and native reset (Cupertino=$cupertino)',
|
||||||
final first = recordedArtifact(
|
(tester) async {
|
||||||
'a.png',
|
final first = recordedArtifact(
|
||||||
url: '/artifacts/1/1/a.png',
|
'a.png',
|
||||||
contentType: 'image/png',
|
url: '/artifacts/1/1/a.png',
|
||||||
);
|
contentType: 'image/png',
|
||||||
final second = recordedArtifact(
|
);
|
||||||
'b.png',
|
final second = recordedArtifact(
|
||||||
url: '/artifacts/1/2/b.png',
|
'b.png',
|
||||||
contentType: 'image/png',
|
url: '/artifacts/1/2/b.png',
|
||||||
);
|
contentType: 'image/png',
|
||||||
final groups = [
|
);
|
||||||
_group([first], visit: 1),
|
final groups = [
|
||||||
_group([second], visit: 2),
|
_group([first], visit: 1),
|
||||||
];
|
_group([second], visit: 2),
|
||||||
await _pumpViewer(
|
];
|
||||||
tester,
|
await _pumpViewer(
|
||||||
groups: groups,
|
tester,
|
||||||
selected: artifactVisitIdentity(groups[0], first),
|
groups: groups,
|
||||||
);
|
cupertino: cupertino,
|
||||||
|
selected: artifactVisitIdentity(groups[0], first),
|
||||||
|
);
|
||||||
|
|
||||||
final viewport = tester.getRect(
|
final viewport = tester.getRect(
|
||||||
find.byKey(const Key('artifact-image-zoom')),
|
find.byKey(const Key('artifact-image-zoom')),
|
||||||
);
|
);
|
||||||
final center = viewport.center;
|
final center = viewport.center;
|
||||||
final one = await tester.startGesture(
|
final one = await tester.startGesture(
|
||||||
center + const Offset(-30, 0),
|
center + const Offset(-30, 0),
|
||||||
pointer: 1,
|
pointer: 1,
|
||||||
);
|
);
|
||||||
final two = await tester.startGesture(
|
final two = await tester.startGesture(
|
||||||
center + const Offset(30, 0),
|
center + const Offset(30, 0),
|
||||||
pointer: 2,
|
pointer: 2,
|
||||||
);
|
);
|
||||||
await one.moveTo(center + const Offset(-110, 0));
|
await one.moveTo(center + const Offset(-110, 0));
|
||||||
await two.moveTo(center + const Offset(110, 0));
|
await two.moveTo(center + const Offset(110, 0));
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
await one.up();
|
await one.up();
|
||||||
await two.up();
|
await two.up();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(find.byKey(const Key('artifact-image-reset-zoom')), findsOneWidget);
|
expect(
|
||||||
// A one-finger drag now belongs to the zoomed image, not the gallery.
|
find.byKey(const Key('artifact-image-reset-zoom')),
|
||||||
await tester.fling(
|
findsOneWidget,
|
||||||
find.byKey(const Key('artifact-image-zoom')),
|
);
|
||||||
const Offset(-300, 0),
|
expect(
|
||||||
1000,
|
tester.widget(find.byKey(const Key('artifact-image-reset-zoom'))),
|
||||||
);
|
cupertino ? isA<CupertinoButton>() : isA<IconButton>(),
|
||||||
await tester.pumpAndSettle();
|
);
|
||||||
expect(find.textContaining('1 of 2'), findsWidgets);
|
// A one-finger drag now belongs to the zoomed image, not the gallery.
|
||||||
|
await tester.fling(
|
||||||
|
find.byKey(const Key('artifact-image-zoom')),
|
||||||
|
const Offset(-300, 0),
|
||||||
|
1000,
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.textContaining('1 of 2'), findsWidgets);
|
||||||
|
|
||||||
await tester.tap(find.byKey(const Key('artifact-image-reset-zoom')));
|
await tester.tap(find.byKey(const Key('artifact-image-reset-zoom')));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(find.byKey(const Key('artifact-image-reset-zoom')), findsNothing);
|
expect(
|
||||||
await tester.fling(
|
find.byKey(const Key('artifact-image-reset-zoom')),
|
||||||
find.byKey(const Key('artifact-viewer-swipe')),
|
findsNothing,
|
||||||
const Offset(-300, 0),
|
);
|
||||||
1000,
|
await tester.fling(
|
||||||
|
find.byKey(const Key('artifact-viewer-swipe')),
|
||||||
|
const Offset(-300, 0),
|
||||||
|
1000,
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.textContaining('2 of 2'), findsWidgets);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
await tester.pumpAndSettle();
|
}
|
||||||
expect(find.textContaining('2 of 2'), findsWidgets);
|
|
||||||
});
|
|
||||||
|
|
||||||
testWidgets('Material paging stays inside 320px at 2x text', (tester) async {
|
testWidgets('Material paging stays inside 320px at 2x text', (tester) async {
|
||||||
tester.view.physicalSize = const Size(640, 1200);
|
tester.view.physicalSize = const Size(640, 1200);
|
||||||
|
|||||||
Reference in New Issue
Block a user