Compare commits

...

2 commits

Author SHA1 Message Date
EpicKiwi 305aba510f Added some comments 2025-01-02 10:16:25 +01:00
EpicKiwi 3ae1548ba0
Ignore swipes initiated from inside system gesture 2025-01-02 00:18:26 +01:00

View file

@ -204,6 +204,11 @@ class _SwipeableState extends State<Swipeable> with TickerProviderStateMixin, Au
bool _isTouch = true;
// Minimum global X where swipe is allowed to start
double? _minX;
// Maximum global X where swipe is allowed to start
double? _maxX;
@override
bool get wantKeepAlive => _moveController.isAnimating == true;
@ -237,8 +242,22 @@ class _SwipeableState extends State<Swipeable> with TickerProviderStateMixin, Au
}
void _handlePointerDown(PointerDownEvent event) {
final xPos = event.position.dx;
var validTouch = widget.allowedPointerKinds.contains(event.kind);
// Check if touch was performed after minX and before maxX to avoid system
// gesture insets
if(validTouch && _minX != null){
validTouch = xPos > _minX!;
}
if(validTouch && _maxX != null){
validTouch = xPos < _maxX!;
}
setState(() {
_isTouch = widget.allowedPointerKinds.contains(event.kind);
_isTouch = validTouch;
});
}
@ -429,6 +448,20 @@ class _SwipeableState extends State<Swipeable> with TickerProviderStateMixin, Au
}
}
// Get system screen size and system gesture insets
// to avoid starting a swipe in this areas
MediaQueryData? mediaQuery = MediaQuery.maybeOf(context);
if (mediaQuery != null) {
if(_minX == null || _maxX == null){
WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {
_minX = mediaQuery.systemGestureInsets.left;
_maxX = mediaQuery.size.width - mediaQuery.systemGestureInsets.right;
});
});
}
}
Widget content = SlideTransition(
position: _moveAnimation,
child: widget.child,