You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{Camera,MapView,MarkerView}from'@rnmapbox/maps';importReactfrom'react';import{TouchableOpacity}from'react-native';classBugReportExampleextendsReact.Component{handleMarkerPress=e=>{console.log('Marker pressed');e.stopPropagation();e.preventDefault();};handleMarkerLongPress=e=>{console.log('Marker long pressed');e.stopPropagation();e.preventDefault();};handleMapPress=()=>{console.log('Map pressed');};handleMapLongPress=()=>{console.log('Map long pressed');};render(){return(<MapViewstyle={{flex: 1}}onLongPress={this.handleMapLongPress}><CameracenterCoordinate={[-74.00597,40.71427]}zoomLevel={14}animationDuration={0}/><MarkerViewid="marker"coordinate={[-74.00597,40.71427]}><TouchableOpacityonPress={this.handleMarkerPress}onLongPress={this.handleMarkerLongPress}style={{backgroundColor: 'red',width: 20,height: 20,borderRadius: 10,}}/></MarkerView></MapView>);}}exportdefaultBugReportExample;
Observed behavior and steps to reproduce
When a MarkerView with a TouchableOpacity child is long-pressed within a MapView that also has an onLongPress event, both the onLongPress event of the TouchableOpacity and the onLongPress event of the MapView are triggered simultaneously, despite using event.stopPropagation() in the TouchableOpacity's onLongPress event handler. What would be the correct way to prevent this scenario? When I use onPress on both, it works as expected.
Expected behavior
The expected behavior is that only the onLongPress event of the TouchableOpacity should be triggered when the marker is long-pressed, preventing the onLongPress event of the MapView from being triggered.
Notes / preliminary analysis
Several approaches have been attempted to prevent the event from propagating to the parent, such as using event.stopPropagation(), event.preventDefault() and implementing custom event handling logic with View onTouchStart callback and the Pressable component from react-native. Still, none have successfully prevented the event's propagation to the parent MapView.
Additional links and references
No response
The text was updated successfully, but these errors were encountered:
Mapbox Implementation
Mapbox
Mapbox Version
default
Platform
iOS
@rnmapbox/maps
version10.0.4
Standalone component to reproduce
Observed behavior and steps to reproduce
When a
MarkerView
with aTouchableOpacity
child is long-pressed within aMapView
that also has anonLongPress
event, both theonLongPress
event of theTouchableOpacity
and theonLongPress
event of the MapView are triggered simultaneously, despite usingevent.stopPropagation()
in the TouchableOpacity's onLongPress event handler. What would be the correct way to prevent this scenario? When I useonPress
on both, it works as expected.Expected behavior
The expected behavior is that only the onLongPress event of the TouchableOpacity should be triggered when the marker is long-pressed, preventing the onLongPress event of the MapView from being triggered.
Notes / preliminary analysis
Several approaches have been attempted to prevent the event from propagating to the parent, such as using
event.stopPropagation()
,event.preventDefault()
and implementing custom event handling logic withView
onTouchStart callback and thePressable
component from react-native. Still, none have successfully prevented the event's propagation to the parentMapView
.Additional links and references
No response
The text was updated successfully, but these errors were encountered: