Open matis-dk opened 1 year ago
Demo showcasing scroll and panning simultaneously.
Dragging a list item from iOS's "Reminders" app: https://github.com/software-mansion/react-native-gesture-handler/assets/32526593/d42a6357-e316-4241-8cfd-4b6e2a65ee51
Dragging a iOS widget between the different homescreen: https://github.com/software-mansion/react-native-gesture-handler/assets/32526593/3cffb182-9b4c-414c-9e61-af83db2db570
@j-piasecki can you by any chance confirm that this is in fact currently not possible with the primitives provided by RNGH?
Here is a snippet i used with to handle simulatneously multiple gestures with native elements, the key is to have the native element as direct child to your gesture detector
You can do something like this,
const nativeGesture = Gesture.Native();
const composedGestures = Gesture.Simultaneous(myPanGesture, nativeGesture);
const ScrollComponent = (props: any) => {
return (
<GestureDetector gesture={composedGestures}>
<ScrollView {...props} />
</GestureDetector>
);
};
return (
<Flashlist
renderScrollComponent={ScrollComponent}
{...otherProps}
/>
);
This will handle both gestures simultaneously, I am just using translationX in my myPanGesture gesture so i havent tried yet with others.
Hi @matis-dk
The end result you described is as far as i know only possible to achieve on Android
phones for now.
The code snippet sent by @zebriot is a good example of how you can achieve these results, the key is to wrap your scroll component with Gesture.Native()
.
Here's another example which works well on Android
:
But please keep in mind, as this feature works only on Android.
as of the following PR: #3095, the Gesture.Pan()
will require .simultaneousWithExternalGesture(scroll)
to be added to it.
Description
I’m trying to implement something similar to the gesture behaviour on the default list view on iOS. Eg. the “Reminders” app inside iOS.
It consist of a scrollable view with some list item's inside. When you long-press a list item, it lets you rearrange where the item belong. At the surface, this implementation seems quite simple - a ScrollView wrapping around multiple ListItem component's that is using the
Gesture.Pan().activateAfterLongPress(250)
.The code could look something like this
``` import { useRef } from "react"; import { Dimensions, View } from "react-native"; import { Gesture, GestureDetector, ScrollView, } from "react-native-gesture-handler"; import Animated, { useAnimatedStyle, useSharedValue, withSpring, } from "react-native-reanimated"; import { Text } from "../restyled/Text"; const items = [ { id: "id_John", name: "John" }, { id: "id_Jane", name: "Jane" }, { id: "id_Jack", name: "Jack" }, { id: "id_Jill", name: "Jill" }, { id: "id_Joe", name: "Joe" }, { id: "id_Jim", name: "Jim" }, { id: "id_Joy", name: "Joy" }, ]; const listItemHeight = 75; const listItemWidth = Dimensions.get("window").width; type Position = { x: number; y: number }; export function List() { return (The problem arise when the scrollable list is expanding beyond the device height dimensions. Because if you would like to drag a ListItem to the bottom of the list, then you need to be able to support scrolling while panning (dragging the item around). To support this, iOS implement 2 different scroll behaviors.
I think that bullet 1. is possible by keeping track of the fingers absolute position on the screen, and activate scroll imperatively, when the primary finger is entering hot areas in the top or bottom of the screen.
But bullet 2. doesn't seem to be possible by the primitive provider by RNGH currently. By default, ScrollView's seems to be dismissed when a pan-gesture is active. The
simultaneousHandlers
prop allow the ScrollView gesture, andGesture.Pan
, to be active simultaneously - but this let the primary finger, pan and scroll at the same time.What seems to be the crux of the problem, is that when a
Gesture.Pan
is active, RNGH is disabling ScrollView gestures globally, and not locally to the current gesture in action. If theGesture.Pan
instead recognized and ignored the scrollview events, for the local pan-gesture in action, it would allow the secondary finger to scroll. What seems to be missing is a way to distingquish between disabling and ignoring ScrollView events for a given gesture.The multi-touch behavior combining pan with the primary finger, and scrolling with secondary finger, is used multiple places inside iOS. E.g when.
I noticed that
Gesture.Native
is able to wrap and listen to events on the ScrollView, but I'm unable to figure out how this can be composed with behavior im describing above.Steps to reproduce
The code could look something like this
``` import { useRef } from "react"; import { Dimensions, View } from "react-native"; import { Gesture, GestureDetector, ScrollView, } from "react-native-gesture-handler"; import Animated, { useAnimatedStyle, useSharedValue, withSpring, } from "react-native-reanimated"; import { Text } from "../restyled/Text"; const items = [ { id: "id_John", name: "John" }, { id: "id_Jane", name: "Jane" }, { id: "id_Jack", name: "Jack" }, { id: "id_Jill", name: "Jill" }, { id: "id_Joe", name: "Joe" }, { id: "id_Jim", name: "Jim" }, { id: "id_Joy", name: "Joy" }, ]; const listItemHeight = 75; const listItemWidth = Dimensions.get("window").width; type Position = { x: number; y: number }; export function List() { return (