I have a scrollview with a grid of images when I long press on an image I’d like to stop propagating the mouse events to the scrollview and just monitor the movements. With the intent to re-initialize propagation on press out. Anyone know how?
Just add the prop onStartShouldSetResponder={event => true} to the <View> you want to prevent bubbling up.
To stop an event from further propagation in the capturing and bubbling phases, you call the Event. stopPropation() method in the event handler. Note that the event. stopPropagation() method doesn't stop any default behaviors of the element e.g., link click, checkbox checked.
React Native touchableopacity provide a disabled attribute to disable touchableopacity, you have to just pass true in the disabled attribute like the below example.
Pressing the button will call the "onPress" function, which in this case displays an alert popup. If you like, you can specify a "color" prop to change the color of your button.
This might be new since the previous answers, but I find you can just gobble the event using another "touchable":
<TouchableOpacity onPress={this.onPressOuter}> <TouchableOpacity activeOpacity={1}> <Text>Content</Text> </TouchableOpacity> </TouchableOpacity>
In this example, touching the text does not trigger onPressOuter
I solved this issue by wrap my press event with class method that set inner variable to true, then did the original logic, and after it finished, set again the inner variable to false. Then, you can wrap your container component event handler to check if inner variable set to true or false. for example:
<TouchableOpacity onPress={this.doSomething1}> <TouchableOpacity onPress={this.doSomething2}> <Image ... /> </TouchableOpacity> </TouchableOpacity> doSomething1() { this.preventDefault = true; doSomeLogic(); this.preventDefault = false; } doSomething2() { if(!this.preventDefault) { } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With