From bc2bb2fc8bd0b8e918dcde5a4b4ca164170231c3 Mon Sep 17 00:00:00 2001 From: Amos Date: Wed, 14 Aug 2024 19:57:48 +0800 Subject: [PATCH 1/2] Fix: Tilt.disable: true still prevents scrolling --- CHANGELOG.md | 6 +++ lib/src/tilt.dart | 1 + lib/src/widget/gestures_listener.dart | 7 +++ pubspec.yaml | 2 +- test/tilt_widget/tilt_config_test.dart | 55 ++++++++++++++++----- test/tilt_widget/tilt_config_tilt_test.dart | 51 ++++++++++++++++++- 6 files changed, 108 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8dcb1d..3341e9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ > [!IMPORTANT] > See the [Migration Guide](guides/migration_guide.md) for the details of breaking changes between versions. +## 3.0.5 + +### Fixes + +- Fix `Tilt.disable: true` still prevents scrolling. + ## 3.0.4 ### Fixes diff --git a/lib/src/tilt.dart b/lib/src/tilt.dart index 88c312d..c6258c3 100644 --- a/lib/src/tilt.dart +++ b/lib/src/tilt.dart @@ -176,6 +176,7 @@ class _TiltState extends State { _tiltStreamController ?? defaultTiltStreamController; return GesturesListener( + disable: _disable, tiltStreamController: tiltStreamController, tiltConfig: _tiltConfig, child: TiltStreamBuilder( diff --git a/lib/src/widget/gestures_listener.dart b/lib/src/widget/gestures_listener.dart index 6d5b747..5fbe262 100644 --- a/lib/src/widget/gestures_listener.dart +++ b/lib/src/widget/gestures_listener.dart @@ -15,12 +15,16 @@ class GesturesListener extends StatefulWidget { const GesturesListener({ super.key, required this.child, + required this.disable, required this.tiltStreamController, required this.tiltConfig, }); final Widget child; + /// 是否禁用 + final bool disable; + /// TiltStreamController final async.StreamController tiltStreamController; @@ -32,6 +36,7 @@ class GesturesListener extends StatefulWidget { class _GesturesListenerState extends State { Widget get _child => widget.child; + bool get _disable => widget.disable; async.StreamController get _tiltStreamController => widget.tiltStreamController; TiltConfig get _tiltConfig => widget.tiltConfig; @@ -44,6 +49,8 @@ class _GesturesListenerState extends State { @override Widget build(BuildContext context) { + if (_disable) return _child; + /// 不受滑动影响 return GestureDetector( onVerticalDragUpdate: _tiltConfig.enableGestureTouch ? (_) {} : null, diff --git a/pubspec.yaml b/pubspec.yaml index 427669f..81a40b8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,7 +8,7 @@ description: Easily apply tilt parallax hover effects for Flutter, which support # https://semver.org/spec/v2.0.0-rc.1.html # https://dart.dev/tools/pub/versioning#semantic-versions # https://dart.dev/tools/pub/dependencies#version-constraints -version: 3.0.4 +version: 3.0.5 homepage: https://amoshuke.github.io/flutter_tilt_book repository: https://github.com/fluttercandies/flutter_tilt issue_tracker: https://github.com/fluttercandies/flutter_tilt/issues diff --git a/test/tilt_widget/tilt_config_test.dart b/test/tilt_widget/tilt_config_test.dart index c9c516b..fe8748b 100644 --- a/test/tilt_widget/tilt_config_test.dart +++ b/test/tilt_widget/tilt_config_test.dart @@ -1,4 +1,4 @@ -import 'package:flutter/widgets.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_tilt/flutter_tilt.dart'; import 'tilt_widget.dart'; @@ -13,21 +13,52 @@ void main() { expect(childFinder, findsOneWidget); }); testWidgets('disable true', (WidgetTester tester) async { - TiltDataModel? tiltData; - GesturesType? gesturesType; + final ScrollController scrollController = ScrollController(); + + TiltDataModel? tiltDataTest; + GesturesType? gesturesTypeTest; + await tester.pumpWidget( - TiltWidget( - disable: true, - onGestureMove: (TiltDataModel tiltData, GesturesType gesturesType) { - tiltData = tiltData; - gesturesType = gesturesType; - }, + MaterialApp( + home: Scaffold( + body: ListView( + controller: scrollController, + children: [ + Tilt( + key: const Key('tilt_widget'), + disable: true, + child: const SizedBox( + width: 100, + height: 100, + child: Text('Tilt'), + ), + onGestureMove: ( + TiltDataModel tiltData, + GesturesType gesturesType, + ) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + ), + const SizedBox(key: Key('scroll'), height: 100, width: 100), + const SizedBox(height: 1000), + ], + ), + ), ), ); - await tester.fling(tiltWidgetFinder, const Offset(0.0, -5.0), 0.1); + + /// onVerticalDragUpdate + await tester.timedDrag( + childFinder, + const Offset(0.0, -50.0), + const Duration(milliseconds: 1000), + ); + await tester.pumpAndSettle(); expect(childFinder, findsOneWidget); - expect(gesturesType, null); - expect(tiltData, null); + expect(scrollController.offset, 50.0); + expect(gesturesTypeTest, null); + expect(tiltDataTest, null); }); testWidgets('fps', (WidgetTester tester) async { int count = 0; diff --git a/test/tilt_widget/tilt_config_tilt_test.dart b/test/tilt_widget/tilt_config_tilt_test.dart index 94a0d42..ee913a6 100644 --- a/test/tilt_widget/tilt_config_tilt_test.dart +++ b/test/tilt_widget/tilt_config_tilt_test.dart @@ -1,5 +1,5 @@ import 'package:flutter/gestures.dart'; -import 'package:flutter/widgets.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_tilt/flutter_tilt.dart'; import 'tilt_widget.dart'; @@ -578,6 +578,55 @@ void main() { await tester.sendEventToBinding(testPointer.removePointer()); }); + testWidgets('enableGestureTouch false - scrolling', + (WidgetTester tester) async { + final ScrollController scrollController = ScrollController(); + + TiltDataModel? tiltDataTest; + GesturesType? gesturesTypeTest; + + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: ListView( + controller: scrollController, + children: [ + Tilt( + key: const Key('tilt_widget'), + tiltConfig: const TiltConfig(enableGestureTouch: false), + child: const SizedBox( + width: 100, + height: 100, + child: Text('Tilt'), + ), + onGestureMove: ( + TiltDataModel tiltData, + GesturesType gesturesType, + ) { + tiltDataTest = tiltData; + gesturesTypeTest = gesturesType; + }, + ), + const SizedBox(key: Key('scroll'), height: 100, width: 100), + const SizedBox(height: 1000), + ], + ), + ), + ), + ); + + /// onVerticalDragUpdate + await tester.timedDrag( + childFinder, + const Offset(0.0, -50.0), + const Duration(milliseconds: 1000), + ); + await tester.pumpAndSettle(); + expect(childFinder, findsOneWidget); + expect(scrollController.offset, 50.0); + expect(gesturesTypeTest, null); + expect(tiltDataTest, null); + }); testWidgets('enableGestureHover false', (WidgetTester tester) async { TiltDataModel? tiltDataTest; GesturesType? gesturesTypeTest; From 25c00beabcaa1a6232af0f59fcb2681718092433 Mon Sep 17 00:00:00 2001 From: Amos Date: Wed, 14 Aug 2024 20:02:42 +0800 Subject: [PATCH 2/2] Update: CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3341e9e..955e0f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ ### Fixes -- Fix `Tilt.disable: true` still prevents scrolling. +- Fix `Tilt.disable: true` still prevents scrolling. ([#16](https://github.com/fluttercandies/flutter_tilt/pull/16)) ## 3.0.4