Comments (7)
I will try to look at it! Seems like using doubleTap
in multiple detectors wasn't the only problem. I've manged to find out what caused ConcurrentModificationException
and I've already prepared PR to fix that.
Even though it no longer crashes it doesn't seem to work correctly. I've checked that on a commit before we made changes in Orchestrator
and it seems like this bug was there for a long time.
I'll get back to you as soon as we find a solution!
from react-native-gesture-handler.
Hi, I tried to run your Modified code with requireExternalGestureToFail
with the PR installed. It seems to work! 😄
Compared to the original, I guess I'll just have to bubble up the different doubletap gestures, but that should not be too much of an issue. Thanks!
from react-native-gesture-handler.
HI @jacobmolby! Indeed, the app does crash, but it is expected behavior.
One of the assumptions of Gesture Handler is that no Gesture will be used in more than one gesture detector, since it leads to strange behaviors. The problem is that check for this specific case was present only on web, therefore a while ago we decided to unify it across all platforms.
As I can see, your doubleTapGesture
is used across 3 different GestureDetectors
, violating mentioned principle.
Note that PR that I've mentioned has not been released yet - that's why I got a bit confused at the beginning.
This is how your example looks on current main:
from react-native-gesture-handler.
Okay, makes sense. Can you tell me how I can achieve the desired gestures then? Is it possible to do with RNGH?
from react-native-gesture-handler.
I went through your example once more, this time focusing more on how it actually works. I believe the thing that you want to use is requireExternalGestureToFail. I've done some changes and double taps seem to work. The only issue that we have to deal with is that both, orange and blue tap, activate when you tap on orange rectangle.
Modified code with requireExternalGestureToFail
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
import Animated from 'react-native-reanimated';
const orangeTapGesture = Gesture.Tap()
.onStart(() => {
console.log('Orange: Tap');
})
.runOnJS(true);
const orangeDoubleTapGesture = Gesture.Tap()
.numberOfTaps(2)
.onStart(() => {
console.log('Orange: Double tap');
})
.runOnJS(true);
const blueTapGesture = Gesture.Tap()
.onStart(() => {
console.log('Blue: Tap');
})
.runOnJS(true)
.requireExternalGestureToFail(orangeTapGesture, orangeDoubleTapGesture);
const blueDoubleTapGesture = Gesture.Tap()
.numberOfTaps(2)
.onStart(() => {
console.log('Blue: Double tap');
})
.runOnJS(true);
const redLongPressGesture = Gesture.LongPress()
.onStart(() => {
console.log('Red: Long press');
})
.runOnJS(true);
const redDoubleTapGesture = Gesture.Tap()
.numberOfTaps(2)
.onStart(() => {
console.log('Red: Double tap');
})
.runOnJS(true);
const Showcase = () => {
const gesture = Gesture.Race(redDoubleTapGesture, redLongPressGesture);
return (
<View
style={{
flex: 1,
backgroundColor: 'white',
marginHorizontal: 20,
marginVertical: 60,
}}>
<GestureDetector gesture={gesture}>
<Animated.View style={styles.outer}>
<Blue />
</Animated.View>
</GestureDetector>
</View>
);
};
export default Showcase;
const Blue = () => {
const composedGesture = Gesture.Exclusive(
blueDoubleTapGesture,
blueTapGesture
);
return (
<GestureDetector gesture={composedGesture}>
<Animated.View style={styles.blue}>
<Orange />
</Animated.View>
</GestureDetector>
);
};
const Orange = () => {
const composedGesture = Gesture.Exclusive(
orangeDoubleTapGesture,
orangeTapGesture
);
return (
<GestureDetector gesture={composedGesture}>
<Animated.View style={styles.orange}></Animated.View>
</GestureDetector>
);
};
const styles = StyleSheet.create({
outer: {
padding: 20,
backgroundColor: 'red',
width: 300,
height: 200,
},
blue: {
width: '80%',
height: '80%',
backgroundColor: 'blue',
flexDirection: 'row',
flexWrap: 'wrap',
},
orange: {
margin: 5,
width: '50%',
height: '50%',
backgroundColor: 'orange',
},
});
from react-native-gesture-handler.
Hi @jacobmolby! I've created this PR that should fix taps
activation. Could you please check if it works? It is still a draft so it is possible that something will change, but I'd like to know if it does help in your case.
from react-native-gesture-handler.
That's great! Thanks for submitting this issue, it uncovered some flaws in our logic that we were not aware of!
I will try to merge this PR asap, but we have to discuss something before doing it (i.e. should we do it for all discrete gestures and if so, then how to do it correctly).
from react-native-gesture-handler.
Related Issues (20)
- 'RNGestureHandlerModule' could not be found. HOT 20
- ReanimatedSwipeable > Jest > getByGestureTestId fails to find component. HOT 3
- Long press is getting cancelled in Expo HOT 24
- Warning when closing Reanimated Swipeable HOT 5
- [Android] [Talkback] [Accessible] Cannot select other components on screen after moving the Bottomsheet HOT 4
- Gesture.Tap() behaving weirdly, one finger needs to be on screen to receive onStart and onEnd events HOT 3
- Pan gesture doesn't activate for some time after scrolling the parent scrollable HOT 5
- Error export 'PressableProps' (reexported as 'PressableProps') was not found in './PressableProps' (module has no exports) HOT 12
- `Hover` nested in `ScrollView` and scrolling `ScrollView` not working simultanously on Android
- onTouchesMove reports invalid absolute position values during pinch gesture HOT 4
- [web] Gesture.Pan() fires `onStart` when toggling `enabled` HOT 1
- NullPointerException android.widget.ScrollView in onTouchEvent HOT 2
- ReanimatedSwipeable Error: Tried to modify key `velocity` of an object which has already passed to a worklet HOT 3
- Crash on iOS when setting cursor style HOT 1
- [2.19.0] Pressable now interferes with parent's dimensions HOT 2
- [2.19.0] The latest version causes a react-native build issue error Failed to build the app: No package name found. Found errors in <project_path>/node_modules/react-native-gesture-handler/android/src/main/AndroidManifest.xml. HOT 3
- Transparent background removes border for touchables HOT 1
- react-native-tvOS not building HOT 3
- Android Brownfield app can't find buildDir when using new archtecture HOT 2
- Button components have incorrect layout when given padding on iOS new arch HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-gesture-handler.