diff --git a/android/src/main/java/com/luggmaps/LuggMapView.kt b/android/src/main/java/com/luggmaps/LuggMapView.kt index 777c98e..d6a0150 100644 --- a/android/src/main/java/com/luggmaps/LuggMapView.kt +++ b/android/src/main/java/com/luggmaps/LuggMapView.kt @@ -28,6 +28,8 @@ interface LuggMapViewEventDelegate { gesture: Boolean ) fun onReady(view: LuggMapView) + fun onPress(view: LuggMapView, latitude: Double, longitude: Double, x: Float, y: Float) + fun onLongPress(view: LuggMapView, latitude: Double, longitude: Double, x: Float, y: Float) } @SuppressLint("ViewConstructor") @@ -141,6 +143,14 @@ class LuggMapView(private val reactContext: ThemedReactContext) : eventDelegate?.onCameraIdle(this, latitude, longitude, zoom, gesture) } + override fun mapProviderDidPress(latitude: Double, longitude: Double, x: Float, y: Float) { + eventDelegate?.onPress(this, latitude, longitude, x, y) + } + + override fun mapProviderDidLongPress(latitude: Double, longitude: Double, x: Float, y: Float) { + eventDelegate?.onLongPress(this, latitude, longitude, x, y) + } + // endregion // region Property Setters diff --git a/android/src/main/java/com/luggmaps/LuggMapViewManager.kt b/android/src/main/java/com/luggmaps/LuggMapViewManager.kt index 4a4a0e8..e464a36 100644 --- a/android/src/main/java/com/luggmaps/LuggMapViewManager.kt +++ b/android/src/main/java/com/luggmaps/LuggMapViewManager.kt @@ -13,6 +13,8 @@ import com.facebook.react.viewmanagers.LuggMapViewManagerInterface import com.google.android.gms.maps.model.LatLng import com.luggmaps.events.CameraIdleEvent import com.luggmaps.events.CameraMoveEvent +import com.luggmaps.events.LongPressEvent +import com.luggmaps.events.PressEvent import com.luggmaps.events.ReadyEvent import com.luggmaps.extensions.dispatchEvent @@ -35,6 +37,8 @@ class LuggMapViewManager : override fun getExportedCustomDirectEventTypeConstants(): Map = mapOf( + "topMapPress" to mapOf("registrationName" to "onMapPress"), + "topMapLongPress" to mapOf("registrationName" to "onMapLongPress"), "topCameraMove" to mapOf("registrationName" to "onCameraMove"), "topCameraIdle" to mapOf("registrationName" to "onCameraIdle"), "topReady" to mapOf("registrationName" to "onReady") @@ -64,6 +68,14 @@ class LuggMapViewManager : view.dispatchEvent(ReadyEvent(view)) } + override fun onPress(view: LuggMapView, latitude: Double, longitude: Double, x: Float, y: Float) { + view.dispatchEvent(PressEvent(view, latitude, longitude, x, y)) + } + + override fun onLongPress(view: LuggMapView, latitude: Double, longitude: Double, x: Float, y: Float) { + view.dispatchEvent(LongPressEvent(view, latitude, longitude, x, y)) + } + @ReactProp(name = "provider") override fun setProvider(view: LuggMapView, value: String?) { view.setProvider(value) diff --git a/android/src/main/java/com/luggmaps/LuggPolygonViewManager.kt b/android/src/main/java/com/luggmaps/LuggPolygonViewManager.kt index baf19a6..ed66a8c 100644 --- a/android/src/main/java/com/luggmaps/LuggPolygonViewManager.kt +++ b/android/src/main/java/com/luggmaps/LuggPolygonViewManager.kt @@ -20,6 +20,9 @@ class LuggPolygonViewManager : override fun getName(): String = NAME override fun createViewInstance(context: ThemedReactContext): LuggPolygonView = LuggPolygonView(context) + override fun getExportedCustomDirectEventTypeConstants(): Map = + mapOf("topPolygonPress" to mapOf("registrationName" to "onPolygonPress")) + override fun onDropViewInstance(view: LuggPolygonView) { super.onDropViewInstance(view) view.onDropViewInstance() diff --git a/android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt b/android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt index 2f796df..9a0f3d1 100644 --- a/android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt +++ b/android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt @@ -33,6 +33,8 @@ class GoogleMapProvider(private val context: Context) : GoogleMap.OnCameraMoveStartedListener, GoogleMap.OnCameraMoveListener, GoogleMap.OnCameraIdleListener, + GoogleMap.OnMapClickListener, + GoogleMap.OnMapLongClickListener, GoogleMap.OnPolygonClickListener { override var delegate: MapProviderDelegate? = null @@ -50,6 +52,7 @@ class GoogleMapProvider(private val context: Context) : private val pendingPolygonViews = mutableSetOf() private val polylineAnimators = mutableMapOf() private val polygonToViewMap = mutableMapOf() + private var tapLocation: LatLng? = null // Initial camera settings private var initialLatitude: Double = 0.0 @@ -107,6 +110,8 @@ class GoogleMapProvider(private val context: Context) : googleMap?.setOnCameraMoveStartedListener(null) googleMap?.setOnCameraMoveListener(null) googleMap?.setOnCameraIdleListener(null) + googleMap?.setOnMapClickListener(null) + googleMap?.setOnMapLongClickListener(null) googleMap?.setOnPolygonClickListener(null) googleMap?.clear() googleMap = null @@ -126,8 +131,16 @@ class GoogleMapProvider(private val context: Context) : map.setOnCameraMoveStartedListener(this) map.setOnCameraMoveListener(this) map.setOnCameraIdleListener(this) + map.setOnMapClickListener(this) + map.setOnMapLongClickListener(this) map.setOnPolygonClickListener(this) + wrapperView?.touchEventHandler = { event -> + if (event.action == android.view.MotionEvent.ACTION_DOWN) { + tapLocation = map.projection.fromScreenLocation(android.graphics.Point(event.x.toInt(), event.y.toInt())) + } + } + applyUiSettings() applyZoomLimits() applyEdgeInsets() @@ -167,8 +180,25 @@ class GoogleMapProvider(private val context: Context) : isDragging = false } + override fun onMapClick(latLng: LatLng) { + val map = googleMap ?: return + val point = map.projection.toScreenLocation(latLng) + delegate?.mapProviderDidPress(latLng.latitude, latLng.longitude, point.x.toFloat(), point.y.toFloat()) + } + + override fun onMapLongClick(latLng: LatLng) { + val map = googleMap ?: return + val point = map.projection.toScreenLocation(latLng) + delegate?.mapProviderDidLongPress(latLng.latitude, latLng.longitude, point.x.toFloat(), point.y.toFloat()) + } + override fun onPolygonClick(polygon: Polygon) { - polygonToViewMap[polygon]?.emitPressEvent() + val polygonView = polygonToViewMap[polygon] + if (polygonView?.tappable == true) { + polygonView.emitPressEvent() + } else { + onMapClick(tapLocation ?: return) + } } // endregion @@ -465,7 +495,7 @@ class GoogleMapProvider(private val context: Context) : strokeColor = polygonView.strokeColor strokeWidth = polygonView.strokeWidth.dpToPx() zIndex = polygonView.zIndex - isClickable = polygonView.tappable + isClickable = true } } @@ -484,9 +514,9 @@ class GoogleMapProvider(private val context: Context) : .strokeColor(polygonView.strokeColor) .strokeWidth(polygonView.strokeWidth.dpToPx()) .zIndex(polygonView.zIndex) + .clickable(true) val polygon = map.addPolygon(options) - polygon.isClickable = polygonView.tappable polygonView.polygon = polygon polygonToViewMap[polygon] = polygonView } diff --git a/android/src/main/java/com/luggmaps/core/MapProviderDelegate.kt b/android/src/main/java/com/luggmaps/core/MapProviderDelegate.kt index 17af711..26a754c 100644 --- a/android/src/main/java/com/luggmaps/core/MapProviderDelegate.kt +++ b/android/src/main/java/com/luggmaps/core/MapProviderDelegate.kt @@ -11,6 +11,8 @@ interface MapProviderDelegate { fun mapProviderDidReady() fun mapProviderDidMoveCamera(latitude: Double, longitude: Double, zoom: Float, gesture: Boolean) fun mapProviderDidIdleCamera(latitude: Double, longitude: Double, zoom: Float, gesture: Boolean) + fun mapProviderDidPress(latitude: Double, longitude: Double, x: Float, y: Float) + fun mapProviderDidLongPress(latitude: Double, longitude: Double, x: Float, y: Float) } interface MapProvider { diff --git a/android/src/main/java/com/luggmaps/events/LongPressEvent.kt b/android/src/main/java/com/luggmaps/events/LongPressEvent.kt new file mode 100644 index 0000000..cdbf16c --- /dev/null +++ b/android/src/main/java/com/luggmaps/events/LongPressEvent.kt @@ -0,0 +1,34 @@ +package com.luggmaps.events + +import android.view.View +import com.facebook.react.bridge.Arguments +import com.facebook.react.uimanager.UIManagerHelper +import com.facebook.react.uimanager.events.Event + +class LongPressEvent( + view: View, + private val latitude: Double, + private val longitude: Double, + private val x: Float, + private val y: Float +) : Event(UIManagerHelper.getSurfaceId(view), view.id) { + override fun getEventName() = "topMapLongPress" + + override fun getEventData() = + Arguments.createMap().apply { + putMap( + "coordinate", + Arguments.createMap().apply { + putDouble("latitude", latitude) + putDouble("longitude", longitude) + } + ) + putMap( + "point", + Arguments.createMap().apply { + putDouble("x", x.toDouble()) + putDouble("y", y.toDouble()) + } + ) + } +} diff --git a/android/src/main/java/com/luggmaps/events/PolygonPressEvent.kt b/android/src/main/java/com/luggmaps/events/PolygonPressEvent.kt index f68882d..c3882a2 100644 --- a/android/src/main/java/com/luggmaps/events/PolygonPressEvent.kt +++ b/android/src/main/java/com/luggmaps/events/PolygonPressEvent.kt @@ -6,7 +6,7 @@ import com.facebook.react.uimanager.UIManagerHelper import com.facebook.react.uimanager.events.Event class PolygonPressEvent(view: View) : Event(UIManagerHelper.getSurfaceId(view), view.id) { - override fun getEventName() = "topPress" + override fun getEventName() = "topPolygonPress" override fun getEventData() = Arguments.createMap() } diff --git a/android/src/main/java/com/luggmaps/events/PressEvent.kt b/android/src/main/java/com/luggmaps/events/PressEvent.kt new file mode 100644 index 0000000..1435023 --- /dev/null +++ b/android/src/main/java/com/luggmaps/events/PressEvent.kt @@ -0,0 +1,34 @@ +package com.luggmaps.events + +import android.view.View +import com.facebook.react.bridge.Arguments +import com.facebook.react.uimanager.UIManagerHelper +import com.facebook.react.uimanager.events.Event + +class PressEvent( + view: View, + private val latitude: Double, + private val longitude: Double, + private val x: Float, + private val y: Float +) : Event(UIManagerHelper.getSurfaceId(view), view.id) { + override fun getEventName() = "topMapPress" + + override fun getEventData() = + Arguments.createMap().apply { + putMap( + "coordinate", + Arguments.createMap().apply { + putDouble("latitude", latitude) + putDouble("longitude", longitude) + } + ) + putMap( + "point", + Arguments.createMap().apply { + putDouble("x", x.toDouble()) + putDouble("y", y.toDouble()) + } + ) + } +} diff --git a/example/shared/src/Home.tsx b/example/shared/src/Home.tsx index ec1a282..2343f4e 100644 --- a/example/shared/src/Home.tsx +++ b/example/shared/src/Home.tsx @@ -11,6 +11,7 @@ import { MapProvider, type MapProviderType, type MapCameraEvent, + type MapPressEvent, } from '@lugg/maps'; import { TrueSheet, @@ -94,6 +95,18 @@ function HomeContent() { [getSheetBottom] ); + const formatPressEvent = useCallback( + (event: MapPressEvent, label: string) => { + const { coordinate, point } = event.nativeEvent; + const lat = coordinate.latitude.toFixed(5); + const lng = coordinate.longitude.toFixed(5); + const px = point.x.toFixed(0); + const py = point.y.toFixed(0); + setStatusText(`${label}: ${lat}, ${lng} (${px}, ${py})`); + }, + [] + ); + const formatCameraEvent = useCallback( (event: MapCameraEvent, idle: boolean) => { const { coordinate, zoom, gesture } = event.nativeEvent; @@ -166,6 +179,8 @@ function HomeContent() { animatedPosition={animatedPosition} userLocationEnabled={locationPermission} onReady={handleMapReady} + onPress={(e) => formatPressEvent(e, 'Press')} + onLongPress={(e) => formatPressEvent(e, 'Long press')} onCameraMove={(e) => formatCameraEvent(e, false)} onCameraIdle={(e) => formatCameraEvent(e, true)} onPolygonPress={() => setStatusText('Polygon pressed')} diff --git a/example/shared/src/components/Map.tsx b/example/shared/src/components/Map.tsx index b8c5805..b65ecca 100644 --- a/example/shared/src/components/Map.tsx +++ b/example/shared/src/components/Map.tsx @@ -105,6 +105,8 @@ export const Map = forwardRef( animatedPosition, onCameraIdle, onCameraMove, + onPress, + onLongPress, onPolygonPress, ...props }, @@ -148,6 +150,8 @@ export const Map = forwardRef( initialZoom={INITIAL_ZOOM} userLocationEnabled edgeInsets={edgeInsets} + onPress={onPress} + onLongPress={onLongPress} onCameraMove={handleCameraMove} onCameraIdle={handleCameraIdle} {...props} diff --git a/ios/LuggMapView.mm b/ios/LuggMapView.mm index 108315b..6f8a15b 100644 --- a/ios/LuggMapView.mm +++ b/ios/LuggMapView.mm @@ -8,6 +8,8 @@ #import "core/MapProviderDelegate.h" #import "events/CameraIdleEvent.h" #import "events/CameraMoveEvent.h" +#import "events/LongPressEvent.h" +#import "events/PressEvent.h" #import "events/ReadyEvent.h" #import @@ -203,6 +205,22 @@ - (void)mapProviderDidIdleCamera:(double)latitude .emit(_eventEmitter); } +- (void)mapProviderDidPress:(double)latitude + longitude:(double)longitude + x:(double)x + y:(double)y { + PressEvent{latitude, longitude, x, y} + .emit(_eventEmitter); +} + +- (void)mapProviderDidLongPress:(double)latitude + longitude:(double)longitude + x:(double)x + y:(double)y { + LongPressEvent{latitude, longitude, x, y} + .emit(_eventEmitter); +} + #pragma mark - Property Setters - (void)applyProps { diff --git a/ios/core/AppleMapProvider.mm b/ios/core/AppleMapProvider.mm index febb824..6b14a0d 100644 --- a/ios/core/AppleMapProvider.mm +++ b/ios/core/AppleMapProvider.mm @@ -32,7 +32,8 @@ @implementation AppleMapProvider { double _maxZoom; NSMapTable, LuggPolylineView *> *_overlayToPolylineMap; NSMapTable, LuggPolygonView *> *_overlayToPolygonMap; - UITapGestureRecognizer *_polygonPressGesture; + UITapGestureRecognizer *_tapGesture; + UILongPressGestureRecognizer *_longPressGesture; // Edge insets animation CADisplayLink *_edgeInsetsDisplayLink; @@ -76,12 +77,20 @@ - (void)initializeMapInView:(UIView *)wrapperView [self applyZoomRange]; - _polygonPressGesture = [[UITapGestureRecognizer alloc] + _tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self - action:@selector(handlePolygonPress:)]; - _polygonPressGesture.cancelsTouchesInView = NO; - _polygonPressGesture.delegate = self; - [_mapView addGestureRecognizer:_polygonPressGesture]; + action:@selector(handleTap:)]; + _tapGesture.cancelsTouchesInView = NO; + _tapGesture.delegate = self; + [_mapView addGestureRecognizer:_tapGesture]; + + _longPressGesture = [[UILongPressGestureRecognizer alloc] + initWithTarget:self + action:@selector(handleLongPress:)]; + _longPressGesture.delegate = self; + [_mapView addGestureRecognizer:_longPressGesture]; + + [_tapGesture requireGestureRecognizerToFail:_longPressGesture]; [wrapperView addSubview:_mapView]; @@ -96,9 +105,13 @@ - (void)initializeMapInView:(UIView *)wrapperView - (void)destroy { [self stopEdgeInsetsAnimation]; - if (_polygonPressGesture) { - [_mapView removeGestureRecognizer:_polygonPressGesture]; - _polygonPressGesture = nil; + if (_tapGesture) { + [_mapView removeGestureRecognizer:_tapGesture]; + _tapGesture = nil; + } + if (_longPressGesture) { + [_mapView removeGestureRecognizer:_longPressGesture]; + _longPressGesture = nil; } [_mapView removeFromSuperview]; _mapView = nil; @@ -283,13 +296,35 @@ - (LuggPolygonView *)hitTestPolygonAtPoint:(CGPoint)point { return nil; } -- (void)handlePolygonPress:(UITapGestureRecognizer *)gesture { +- (void)handleTap:(UITapGestureRecognizer *)gesture { if (gesture.state != UIGestureRecognizerStateEnded) return; CGPoint point = [gesture locationInView:_mapView]; LuggPolygonView *polygonView = [self hitTestPolygonAtPoint:point]; - [polygonView emitPressEvent]; + if (polygonView) { + [polygonView emitPressEvent]; + } else { + CLLocationCoordinate2D coordinate = [_mapView convertPoint:point + toCoordinateFromView:_mapView]; + [_delegate mapProviderDidPress:coordinate.latitude + longitude:coordinate.longitude + x:point.x + y:point.y]; + } +} + +- (void)handleLongPress:(UILongPressGestureRecognizer *)gesture { + if (gesture.state != UIGestureRecognizerStateBegan) + return; + + CGPoint point = [gesture locationInView:_mapView]; + CLLocationCoordinate2D coordinate = [_mapView convertPoint:point + toCoordinateFromView:_mapView]; + [_delegate mapProviderDidLongPress:coordinate.latitude + longitude:coordinate.longitude + x:point.x + y:point.y]; } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer diff --git a/ios/core/GoogleMapProvider.mm b/ios/core/GoogleMapProvider.mm index 48d42b4..5ac252c 100644 --- a/ios/core/GoogleMapProvider.mm +++ b/ios/core/GoogleMapProvider.mm @@ -262,6 +262,24 @@ - (void)mapView:(GMSMapView *)mapView gesture:wasDragging]; } +- (void)mapView:(GMSMapView *)mapView + didTapAtCoordinate:(CLLocationCoordinate2D)coordinate { + CGPoint point = [mapView.projection pointForCoordinate:coordinate]; + [_delegate mapProviderDidPress:coordinate.latitude + longitude:coordinate.longitude + x:point.x + y:point.y]; +} + +- (void)mapView:(GMSMapView *)mapView + didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate { + CGPoint point = [mapView.projection pointForCoordinate:coordinate]; + [_delegate mapProviderDidLongPress:coordinate.latitude + longitude:coordinate.longitude + x:point.x + y:point.y]; +} + - (void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSOverlay *)overlay { if (![overlay isKindOfClass:[GMSPolygon class]]) return; diff --git a/ios/core/MapProviderDelegate.h b/ios/core/MapProviderDelegate.h index 3897f90..7736220 100644 --- a/ios/core/MapProviderDelegate.h +++ b/ios/core/MapProviderDelegate.h @@ -17,6 +17,14 @@ NS_ASSUME_NONNULL_BEGIN longitude:(double)longitude zoom:(double)zoom gesture:(BOOL)gesture; +- (void)mapProviderDidPress:(double)latitude + longitude:(double)longitude + x:(double)x + y:(double)y; +- (void)mapProviderDidLongPress:(double)latitude + longitude:(double)longitude + x:(double)x + y:(double)y; @end @protocol MapProvider diff --git a/ios/events/LongPressEvent.h b/ios/events/LongPressEvent.h new file mode 100644 index 0000000..d40b2f3 --- /dev/null +++ b/ios/events/LongPressEvent.h @@ -0,0 +1,29 @@ +#pragma once + +#import + +namespace luggmaps { +namespace events { + +struct LongPressEvent { + double latitude; + double longitude; + double x; + double y; + + template + void emit(const facebook::react::SharedEventEmitter &eventEmitter) const { + if (!eventEmitter) + return; + auto emitter = std::static_pointer_cast(eventEmitter); + typename Emitter::OnMapLongPress event; + event.coordinate.latitude = latitude; + event.coordinate.longitude = longitude; + event.point.x = x; + event.point.y = y; + emitter->onMapLongPress(event); + } +}; + +} // namespace events +} // namespace luggmaps diff --git a/ios/events/PolygonPressEvent.h b/ios/events/PolygonPressEvent.h index 9afacc4..ee08cac 100644 --- a/ios/events/PolygonPressEvent.h +++ b/ios/events/PolygonPressEvent.h @@ -11,8 +11,8 @@ struct PolygonPressEvent { if (!eventEmitter) return; auto emitter = std::static_pointer_cast(eventEmitter); - typename Emitter::OnPress event; - emitter->onPress(event); + typename Emitter::OnPolygonPress event; + emitter->onPolygonPress(event); } }; diff --git a/ios/events/PressEvent.h b/ios/events/PressEvent.h new file mode 100644 index 0000000..08fe6a7 --- /dev/null +++ b/ios/events/PressEvent.h @@ -0,0 +1,29 @@ +#pragma once + +#import + +namespace luggmaps { +namespace events { + +struct PressEvent { + double latitude; + double longitude; + double x; + double y; + + template + void emit(const facebook::react::SharedEventEmitter &eventEmitter) const { + if (!eventEmitter) + return; + auto emitter = std::static_pointer_cast(eventEmitter); + typename Emitter::OnMapPress event; + event.coordinate.latitude = latitude; + event.coordinate.longitude = longitude; + event.point.x = x; + event.point.y = y; + emitter->onMapPress(event); + } +}; + +} // namespace events +} // namespace luggmaps diff --git a/src/MapView.tsx b/src/MapView.tsx index 1931916..823eb3b 100644 --- a/src/MapView.tsx +++ b/src/MapView.tsx @@ -93,6 +93,8 @@ export class MapView userLocationEnabled, userLocationButtonEnabled, theme, + onPress, + onLongPress, onCameraMove, onCameraIdle, onReady, @@ -118,6 +120,8 @@ export class MapView userLocationEnabled={userLocationEnabled} userLocationButtonEnabled={userLocationButtonEnabled} theme={theme} + onMapPress={onPress} + onMapLongPress={onLongPress} onCameraMove={onCameraMove} onCameraIdle={onCameraIdle} onReady={onReady} diff --git a/src/MapView.types.ts b/src/MapView.types.ts index 5622838..631d8bf 100644 --- a/src/MapView.types.ts +++ b/src/MapView.types.ts @@ -1,6 +1,12 @@ import type { ReactNode } from 'react'; import type { NativeSyntheticEvent, ViewProps } from 'react-native'; -import type { MapProvider, Coordinate, EdgeInsets, MapTheme } from './types'; +import type { + MapProvider, + Coordinate, + EdgeInsets, + MapTheme, + PressEventPayload, +} from './types'; /** * Options for moving the camera @@ -47,6 +53,7 @@ export interface CameraEventPayload { } export type MapCameraEvent = NativeSyntheticEvent; +export type MapPressEvent = NativeSyntheticEvent; /** * MapView component props @@ -119,6 +126,14 @@ export interface MapViewProps extends ViewProps { * @default 'system' */ theme?: MapTheme; + /** + * Called when the map is pressed + */ + onPress?: (event: MapPressEvent) => void; + /** + * Called when the map is long pressed + */ + onLongPress?: (event: MapPressEvent) => void; /** * Called when camera moves */ diff --git a/src/components/Polygon.tsx b/src/components/Polygon.tsx index 16bc2e0..80fb426 100644 --- a/src/components/Polygon.tsx +++ b/src/components/Polygon.tsx @@ -62,7 +62,7 @@ export class Polygon extends React.PureComponent { strokeWidth={strokeWidth} fillColor={fillColor} tappable={!!onPress} - onPress={onPress} + onPolygonPress={onPress} /> ); } diff --git a/src/fabric/LuggMapViewNativeComponent.ts b/src/fabric/LuggMapViewNativeComponent.ts index 0c98287..9d0042e 100644 --- a/src/fabric/LuggMapViewNativeComponent.ts +++ b/src/fabric/LuggMapViewNativeComponent.ts @@ -36,6 +36,28 @@ export interface CameraIdleEvent { gesture: boolean; } +export interface PressEvent { + coordinate: { + latitude: Double; + longitude: Double; + }; + point: { + x: Double; + y: Double; + }; +} + +export interface LongPressEvent { + coordinate: { + latitude: Double; + longitude: Double; + }; + point: { + x: Double; + y: Double; + }; +} + export interface ReadyEvent {} export interface NativeProps extends ViewProps { @@ -53,6 +75,8 @@ export interface NativeProps extends ViewProps { userLocationEnabled?: boolean; userLocationButtonEnabled?: boolean; theme?: WithDefault<'light' | 'dark' | 'system', 'system'>; + onMapPress?: DirectEventHandler; + onMapLongPress?: DirectEventHandler; onCameraMove?: DirectEventHandler; onCameraIdle?: DirectEventHandler; onReady?: DirectEventHandler; diff --git a/src/fabric/LuggPolygonViewNativeComponent.ts b/src/fabric/LuggPolygonViewNativeComponent.ts index da93484..38cad6a 100644 --- a/src/fabric/LuggPolygonViewNativeComponent.ts +++ b/src/fabric/LuggPolygonViewNativeComponent.ts @@ -2,7 +2,7 @@ import { codegenNativeComponent } from 'react-native'; import type { ViewProps, HostComponent, ColorValue } from 'react-native'; import type { Double, - BubblingEventHandler, + DirectEventHandler, } from 'react-native/Libraries/Types/CodegenTypes'; export interface Coordinate { @@ -16,7 +16,7 @@ export interface NativeProps extends ViewProps { strokeWidth?: Double; fillColor?: ColorValue; tappable?: boolean; - onPress?: BubblingEventHandler; + onPolygonPress?: DirectEventHandler; } export default codegenNativeComponent( diff --git a/src/index.ts b/src/index.ts index 55522f4..3d1f0f6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,6 +19,7 @@ export type { SetEdgeInsetsOptions, CameraEventPayload, MapCameraEvent, + MapPressEvent, } from './MapView.types'; export type { MapProvider as MapProviderType,