Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop marker event propagation in order to prevent onPress for MapView… #2068

Merged
merged 2 commits into from
Mar 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/marker.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
| `draggable` | `<null>` | | This is a non-value based prop. Adding this allows the marker to be draggable (re-positioned).
| `tracksViewChanges` | `Boolean` | true | Sets whether this marker should track view changes. It's recommended to turn it off whenever it's possible to improve custom marker performance. **Note**: iOS Google Maps only.
| `tracksInfoWindowChanges` | `Boolean` | false | Sets whether this marker should track view changes in info window. Enabling it will let marker change content of info window after first render pass, but will lead to decreased performance, so it's recommended to disable it whenever you don't need it. **Note**: iOS Google Maps only.
| `stopPropagation` | `Boolean` | false | Sets whether this marker should propagate `onPress` events. Enabling it will stop the parent `MapView`'s `onPress` from being called. **Note**: iOS only. Android does not propagate `onPress` events. See [#1132](https://github.com/react-community/react-native-maps/issues/1132) for more information.

## Events

Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ declare module "react-native-maps" {
rotation?: number;
tracksViewChanges?: boolean
tracksInfoWindowChanges?: boolean
stopPropagation?: boolean
}

export interface MapPolylineProps {
Expand Down
18 changes: 17 additions & 1 deletion lib/components/MapMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ const propTypes = {

tracksInfoWindowChanges: PropTypes.bool,

/**
* Stops Marker onPress events from propagating to and triggering MapView onPress events.
*
* @platform ios
*/

stopPropagation: PropTypes.bool,

/**
* Callback that is called when the user presses on the marker
*/
Expand Down Expand Up @@ -227,7 +235,7 @@ const propTypes = {
};

const defaultProps = {
onPress() {},
stopPropagation: false,
};

class MapMarker extends React.Component {
Expand Down Expand Up @@ -295,6 +303,14 @@ class MapMarker extends React.Component {
{...this.props}
image={image}
style={[styles.marker, this.props.style]}
onPress={event => {
if (this.props.stopPropagation) {
event.stopPropagation();
}
if (this.props.onPress) {
this.props.onPress(event);
}
}}
/>
);
}
Expand Down