Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/widgets/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,11 @@ class _AnimatedScaleOnTapState extends State<AnimatedScaleOnTap> {

@override
Widget build(BuildContext context) {
return GestureDetector(
return Listener(
behavior: HitTestBehavior.translucent,
onTapDown: (_) => _changeScale(widget.scaleEnd),
onTapUp: (_) => _changeScale(1),
onTapCancel: () => _changeScale(1),
onPointerDown: (_) => _changeScale(widget.scaleEnd),
onPointerUp: (_) => _changeScale(1),
onPointerCancel: (_) => _changeScale(1),
child: AnimatedScale(
scale: _scale,
duration: widget.duration,
Expand Down
33 changes: 33 additions & 0 deletions test/widgets/button_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,39 @@ void main() {
check(renderObject).size.equals(Size.square(40));
});

group('AnimatedScaleOnTap', () {
void checkScale(WidgetTester tester, Finder finder, double expectedScale) {
final scale = tester.widget<AnimatedScale>(finder).scale;
check(scale).equals(expectedScale);
}

testWidgets('Animation happen instantly when tap down', (tester) async {
addTearDown(testBinding.reset);

await tester.pumpWidget(TestZulipApp(
child: AnimatedScaleOnTap(
scaleEnd: 0.95,
duration: Duration(milliseconds: 100),
child: UnconstrainedBox(
child: ZulipIconButton(
icon: ZulipIcons.follow,
onPressed: () {})))));
await tester.pump();

final animatedScaleFinder = find.byType(AnimatedScale);

// Now that the widget is being held down, its scale should be at the target scaleEnd i.e 0.95.
final gesture = await tester.startGesture(tester.getCenter(find.byType(ZulipIconButton)));
await tester.pumpAndSettle();
checkScale(tester, animatedScaleFinder, 0.95);

// After releasing, the scale must return to 1.0.
await gesture.up();
await tester.pumpAndSettle();
checkScale(tester, animatedScaleFinder, 1.0);
});
});

// TODO test that the touch feedback fills the whole square
});
}