rnmapbox / rnmapbox/maps

[Bug]: PointAnnotation need to click 2x same item to open

Open
#3,322 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug 🪲
Dominant language
Kotlin
Stars
2.9k
Forks
947
Avg merge
6d 37m
Merged PRs (30d)
1

Description

Mapbox Implementation

Mapbox

Mapbox Version

10.12.0

Platform

iOS

@rnmapbox/maps version

10.1.6

Standalone component to reproduce
import React, { Camera, MapView, PointAnnotation, StyleURL } from '@rnmapbox/maps';
import { useRef } from 'react';
import { StyleSheet, TouchableOpacity, View } from 'react-native';

const BASE_COORDINATES = {
  centerCoordinate: [98.34, 7.96],
  zoomLevel: 10.1,
};

const Mapbox = (p) => {
  const cameraRef = useRef(null);
  const pointAnnotationRef = useRef(null);

  return (
    <View style={css.container}>
      <MapView
        attributionEnabled={false}
        attributionPosition={{ bottom: 100, right: 0 }}
        logoEnabled={false}
        pitchEnabled={false}
        rotateEnabled={false}
        scaleBarEnabled={false}
        style={css.map}
        styleURL={StyleURL.Dark}
      >
        <Camera
          ref={cameraRef}
          animationDuration={0}
          animationMode="flyTo"
          centerCoordinate={BASE_COORDINATES.centerCoordinate}
          zoomLevel={BASE_COORDINATES.zoomLevel}
        />

        {p.markers.map((item) => {
          return (
            <TouchableOpacity
              key={item.id.toString()}
              onPress={() => {
                pointAnnotationRef.current?.setState({ selected: true });
                console.log('onSelected');
              }}
              style={{ height: 20, width: 20, zIndex: 9999 }}
            >
              <PointAnnotation
                id="marker"
                ref={pointAnnotationRef}
                coordinate={item.coordinates}
                onSelected={() => {
                  console.log('onSelected');
                }}
              >
                <View>
                  <View />
                </View>
              </PointAnnotation>
            </TouchableOpacity>
          );
        })}
      </MapView>
    </View>
  );
};

export default Mapbox;

const css = StyleSheet.create({
  container: {
    height: '100%',
    width: '100%',
  },
  map: {
    flex: 1,
  },
});
Observed behavior and steps to reproduce

When i click PointAnnotation for first time its ok onSelected is being called but if i click again then its not, then i need to click again to onSelected register.

If i click different PointAnnotation all ok, clicks are being registered from 1st time. But as soon as i click again same marker then i need to click twice for onSelected to register

Expected behavior

I should not need to click PointAnnotation twice if being clicked before to register click

Notes / preliminary analysis

No response

Additional links and references

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the standalone TypeScript reproduction using PointAnnotation, TouchableOpacity, and the onSelected callback. Compare the first and repeated taps on the same marker with taps on different markers. Done means onSelected registers on every tap without requiring a second click.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, react-native, typescript
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.