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

IOS OnMapPress called when press the marker #1132

Closed
felangga opened this issue Mar 15, 2017 · 4 comments · Fixed by #2068
Closed

IOS OnMapPress called when press the marker #1132

felangga opened this issue Mar 15, 2017 · 4 comments · Fixed by #2068
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@felangga
Copy link

This problem using Google Maps and doesn't occurred on Android.

@ghost
Copy link

ghost commented Mar 21, 2017

In my case, that is same.
Who can help me?

@lelandrichardson lelandrichardson added bug Something isn't working Compatibility good first issue Good for newcomers labels Mar 27, 2017
hysan added a commit to hysan/react-native-maps that referenced this issue Mar 7, 2018
…s from being called when a marker is clicked. This makes the behavior of Apple Maps identical to that of the behavior of Google Maps on Android. This fixes react-native-maps#1132.
@hysan
Copy link
Contributor

hysan commented Mar 7, 2018

I dug into the code and after reading through a lot of issues, in particular #14 and #758, I understand what is going on with event bubbling and how to potentially fix this. However, before doing so, the larger question of what the proper behavior needs to be answered.

Note: All iOS behavior being described is for Apple Maps, not Google Maps, as that behaves differently on iOS and appears to be similar to Android.

Current Behavior of MapView

On Android, clicking on a Marker, regardless of defining onPress or not, will not trigger onPress for your MapView. This behavior is consistent with other children such as Polygon and PolyLine. Clicks on children never trigger the parent MapView's onPress. An easy way to visualize what's happening is that child objects are effectively covering that part of the map.

On iOS, onPress events for children such as Marker and Polygon (see #1713) will always trigger the onPress prop for MapView. The reasons are different for each, such as Markers bubbling up events (this occurs in AIRMapMarker.m line 223), but the end result is the same - MapView's onPress will be triggered. This is the opposite of Android; child objects don't cover up the map - they let clicks pass through.

Current Behavior of Markers, Polygons, PolyLines, possibly others

On Android, these components appear to have a set hierarchy in how they are layered:

Marker > PolyLine > Polygon

They do not propagate click events down even if onPress is not defined. For example, PolyLine with no onPress will prevent the onPress of a Polygon underneath it to be triggered. The order of the components in render does not matter which also means that zIndex does not matter.

I haven't tested the other components like Circle, but there's probably similar behavior there as well.

On iOS, the logic makes less sense:

  • Markers that are positioned on top of Polygons or PolyLines do not pass onPress events pass down to the Polygon or PolyLine.

  • PolyLines pass through clicks to Polygon if they are on top of each other.

  • PolyLines also have an undocumented threshold that allows them to trigger their onPress event if you click close enough to them. So clearly clicking on a Polygon can cause a nearby PolyLine to be clicked (AirMapManager.m line 410 and line 481):

    #define MAX_DISTANCE_PX 10.0f

What's the "correct" behavior?

On iOS Apple Maps, the onPress behavior is a mess. There's no consistent paradigm for understanding how the onPress events of the various components interact with each other.

On Android, it's more consistent but there are still some gotchas such as they ignoring of render order for children.

Do we attempt to bring iOS behavior more in line with Android?

Workarounds and Fixes for Markers

Solution 1 is a documentation fix. Right now, users can stop this behavior by stopping propagation with:

event.stopPropagation();

in their onPress function.

All we have to do is update the documentation to explain the different behavior and add examples of how to stop the event propagation.

Caveat: While this does give iOS greater fine grain control over click behavior, it also means that users have to add code to all marker onPresses if they want iOS behavior to be identical to Android.

Solution 2 is to push this fix downward into react-native-maps.

Caveat: This would be a breaking change. Anyone who is relying on this difference in behavior would be forced to not upgrade or fork.

Solution 3 is to push this fix downward into react-native-maps and add a new prop (probably to Marker) that is iOS-only and controls whether or not propagation occurs. The default would be false in order to align iOS behavior with Android behavior.

It's the same breaking change, but it would give users relying on this behavior a fallback.

Polygons, PolyLines, and others

TODO: I still need to investigate how to "fix" these use cases, but I would still have the same question about "proper" behavior here. It's also out of scope for this particular issue.

Thoughts?

@lelandrichardson Not sure who else to ping for this issue.

I'll submit a PR for the fix I explained in Solution 2 with a fix via Solution 3 being trivially easy to do. However, I'm not sure if it should be accepted until the question of overall behavior is answered. How should onPress behave and how should the various components interact with each other? Should iOS behave exactly like Android in all cases? Or maybe it should be the reverse?

rborn pushed a commit that referenced this issue Mar 10, 2018
#2068)

* Stop marker event propagation in order to prevent onPress for MapViews from being called when a marker is clicked. This makes the behavior of Apple Maps identical to that of the behavior of Google Maps on Android. This fixes #1132.

* Added a new Marker prop called stopPropagation. This allows the user to control whether or not onPress events from Markers propagate up and trigger MapView onPress events. This is iOS only. The default behavior is disabled (false) to prevent a breaking change from the current behavior.
@saadmutahar
Copy link

saadmutahar commented Aug 4, 2019

@hysan
The same error is occurred in latest version of maps.
When I press the marker, it triggers the onPress of parent Maps also. Can you please have a look for this.

I am using these versions.

"react-native": "0.59.8",
"react-native-maps": "0.25.0"

Thanks

@saadmutahar
Copy link

It's fixed the issue for me, As I forgot to add the stopPropagation event on marker click.

Thanks.

markdgo pushed a commit to markdgo/react-native-maps that referenced this issue Mar 15, 2021
…… (#2068)

* Stop marker event propagation in order to prevent onPress for MapViews from being called when a marker is clicked. This makes the behavior of Apple Maps identical to that of the behavior of Google Maps on Android. This fixes react-native-maps/react-native-maps#1132.

* Added a new Marker prop called stopPropagation. This allows the user to control whether or not onPress events from Markers propagate up and trigger MapView onPress events. This is iOS only. The default behavior is disabled (false) to prevent a breaking change from the current behavior.
MarcoAntonioAG pushed a commit to MarcoAntonioAG/React-map that referenced this issue Mar 31, 2022
…… (#2068)

* Stop marker event propagation in order to prevent onPress for MapViews from being called when a marker is clicked. This makes the behavior of Apple Maps identical to that of the behavior of Google Maps on Android. This fixes react-native-maps/react-native-maps#1132.

* Added a new Marker prop called stopPropagation. This allows the user to control whether or not onPress events from Markers propagate up and trigger MapView onPress events. This is iOS only. The default behavior is disabled (false) to prevent a breaking change from the current behavior.
joshpeterson30489 added a commit to joshpeterson30489/maps-develop-with-react-native that referenced this issue Sep 30, 2022
…… (#2068)

* Stop marker event propagation in order to prevent onPress for MapViews from being called when a marker is clicked. This makes the behavior of Apple Maps identical to that of the behavior of Google Maps on Android. This fixes react-native-maps/react-native-maps#1132.

* Added a new Marker prop called stopPropagation. This allows the user to control whether or not onPress events from Markers propagate up and trigger MapView onPress events. This is iOS only. The default behavior is disabled (false) to prevent a breaking change from the current behavior.
superstar1205 added a commit to superstar1205/Map-ReactNative that referenced this issue Dec 26, 2022
…… (#2068)

* Stop marker event propagation in order to prevent onPress for MapViews from being called when a marker is clicked. This makes the behavior of Apple Maps identical to that of the behavior of Google Maps on Android. This fixes react-native-maps/react-native-maps#1132.

* Added a new Marker prop called stopPropagation. This allows the user to control whether or not onPress events from Markers propagate up and trigger MapView onPress events. This is iOS only. The default behavior is disabled (false) to prevent a breaking change from the current behavior.
anthony0506 added a commit to anthony0506/react-native-maps that referenced this issue Mar 19, 2023
…… (#2068)

* Stop marker event propagation in order to prevent onPress for MapViews from being called when a marker is clicked. This makes the behavior of Apple Maps identical to that of the behavior of Google Maps on Android. This fixes react-native-maps/react-native-maps#1132.

* Added a new Marker prop called stopPropagation. This allows the user to control whether or not onPress events from Markers propagate up and trigger MapView onPress events. This is iOS only. The default behavior is disabled (false) to prevent a breaking change from the current behavior.
johney6767 pushed a commit to johney6767/Map-ReactNative that referenced this issue May 31, 2023
…… (#2068)

* Stop marker event propagation in order to prevent onPress for MapViews from being called when a marker is clicked. This makes the behavior of Apple Maps identical to that of the behavior of Google Maps on Android. This fixes react-native-maps/react-native-maps#1132.

* Added a new Marker prop called stopPropagation. This allows the user to control whether or not onPress events from Markers propagate up and trigger MapView onPress events. This is iOS only. The default behavior is disabled (false) to prevent a breaking change from the current behavior.
PainStaker0331 pushed a commit to PainStaker0331/react-native-maps that referenced this issue Mar 3, 2024
…… (#2068)

* Stop marker event propagation in order to prevent onPress for MapViews from being called when a marker is clicked. This makes the behavior of Apple Maps identical to that of the behavior of Google Maps on Android. This fixes react-native-maps/react-native-maps#1132.

* Added a new Marker prop called stopPropagation. This allows the user to control whether or not onPress events from Markers propagate up and trigger MapView onPress events. This is iOS only. The default behavior is disabled (false) to prevent a breaking change from the current behavior.
Super-CodeKing added a commit to Super-CodeKing/react_native_map that referenced this issue Apr 26, 2024
…… (#2068)

* Stop marker event propagation in order to prevent onPress for MapViews from being called when a marker is clicked. This makes the behavior of Apple Maps identical to that of the behavior of Google Maps on Android. This fixes react-native-maps/react-native-maps#1132.

* Added a new Marker prop called stopPropagation. This allows the user to control whether or not onPress events from Markers propagate up and trigger MapView onPress events. This is iOS only. The default behavior is disabled (false) to prevent a breaking change from the current behavior.
fairskyDev0201 pushed a commit to fairskyDev0201/react-native-maps that referenced this issue Apr 29, 2024
…… (#2068)

* Stop marker event propagation in order to prevent onPress for MapViews from being called when a marker is clicked. This makes the behavior of Apple Maps identical to that of the behavior of Google Maps on Android. This fixes react-native-maps/react-native-maps#1132.

* Added a new Marker prop called stopPropagation. This allows the user to control whether or not onPress events from Markers propagate up and trigger MapView onPress events. This is iOS only. The default behavior is disabled (false) to prevent a breaking change from the current behavior.
DavidLee0501 added a commit to DavidLee0501/React-Native-Map that referenced this issue Aug 12, 2024
…… (#2068)

* Stop marker event propagation in order to prevent onPress for MapViews from being called when a marker is clicked. This makes the behavior of Apple Maps identical to that of the behavior of Google Maps on Android. This fixes react-native-maps/react-native-maps#1132.

* Added a new Marker prop called stopPropagation. This allows the user to control whether or not onPress events from Markers propagate up and trigger MapView onPress events. This is iOS only. The default behavior is disabled (false) to prevent a breaking change from the current behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants