When the marker is connected I want to press it 3 times

There's a problem with map markers on Android and no one seems to be able to fix it. The workaround is to click the map marker 3 times and it will open the callout / annotation correctly with the image inside.

How can I do this programmatically? I want to hit the marker 3 times every time the user touches.

<MapView.Marker
  key={marker.key}
  coordinate={marker.latlng}
  title={marker.title}
  description={marker.description}
>
  <MapView.Callout style={styles.annotation}>
    <Image
      key={marker.key}
      source={{ uri: marker.image }}
      style={styles.thumbnail}
    />
  </MapView.Callout>
</MapView.Marker>

      

+3


source to share


1 answer


tl; dr: This is not possible for security reasons. If the user application could create "synthetic" strokes, this feature can be used by malicious applications to force the user device to act "on its own". Read on if you would like to read my research on the topic.

You cannot do this on the JavaScript React Native side as far as I can tell. You need to set up some custom logic to emit your own events from the inside.

The reason for this is that the JS React Native side can only handle native events (like touches) that it receives via its own bridge. These events then trigger event-handling code such as code provided by components Touchable*

(eg TouchableHighlight

, TouchableOpacity

and others). As far as I can tell, there is no way to emit native events from the JS side according to one way data flow principles.

On the other hand, while you can emit arbitrary custom events from the native side, you won't be able to find out what the JavaScript side is doing unless you somehow check to send data to the render methods on the native side, which would probably be pretty harsh. if not impossible.

Thus, the best way to do this is to create your own view class in your own code that fires multiple touch events whenever it touches and transfers it to a React Native component as described in iOS and Android . However, this raises problems:



There is no publicly available way in iOS for user code to create objects UITouch

and submit them to the UI. To do this, you need to use undisclosed API methods that can change at any time and will reject your app if you try to submit it to the App Store. There is one way to do this, documented here , but it is probably out of date as Apple does not guarantee that undisclosed APIs remain stable. There are several answers on SO already on why simulating touch events on iOS is not a good idea and your app will be rejected.

On Android, this is detailed on the android-platform mailing list , with a general consensus that it should not be possible to trigger random touch events from user code. Attempting to send programmatically MotionEvent

appears to result in strange and unreliable behavior, as seen in the second answer to this question , the subsequent comments on this answer, and the answer to this question .

Even React Native doesn't create its own touch events - it just receives touch events generated by its own views. All React Native Gesture Responder Systems just wrap the public APIs available on the native side - the API for creating touch events doesn't seem to be public.

All of this together makes me believe that what you want to do is not possible at all without using the private iOS / Android APIs, most likely due to security concerns .

+5


source







All Articles