How to disable scroll while selecting text?
markusait opened this issue · 2 comments
I found the solution: Set the Duration of the LongPressGestureRecognizer to < 1 milliseconds [here](https://github.com/Mantano/iridium/blob/fcc2e2e690276e2a1ce412d3c15ee813b7c13354/components/navigator/lib/src/epub/widget/webview_screen_state.dart#L209)
It can be done like this LongPressGestureRecognizer(duration: Duration(milliseconds: 1));
My guess is that when text is selected in a Flutter app, a LongPressGestureRecognizer is used to start the text selection process. If the user moves their finger while the long press gesture is being recognized, the gesture recognizer will interpret this as a scroll gesture and scroll the page.
By setting the duration property to Duration(milliseconds: 1)
, you're preventing the LongPressGestureRecognizer from interpreting the finger movement as a scroll gesture. This is because the long press gesture is recognized almost immediately, and the text selection process starts before the user has a chance to move their finger.
This makes it easier to select text, but it also changes the behavior of the long press gesture. If you want to use a long press gesture for other purposes in your app, you might need to adjust the duration to a longer value.
Setting the Duration to < 1 second can actually lead to issues with scrolling. Instead I added a VerticalDragGestureRecognizer and it worked as intented:
gestureRecognizers: {
Factory<WebViewHorizontalGestureRecognizer>(
() => webViewHorizontalGestureRecognizer),
Factory<VerticalDragGestureRecognizer>(
() => VerticalDragGestureRecognizer()),
Factory<LongPressGestureRecognizer>(() {
return LongPressGestureRecognizer();
}),
},