@lugg/maps 1.0.0-beta.4 → 1.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/android/src/main/java/com/luggmaps/LuggCalloutView.kt +4 -2
  2. package/android/src/main/java/com/luggmaps/LuggCalloutViewManager.kt +4 -3
  3. package/android/src/main/java/com/luggmaps/LuggMapView.kt +40 -0
  4. package/android/src/main/java/com/luggmaps/LuggMapViewManager.kt +31 -0
  5. package/android/src/main/java/com/luggmaps/LuggMarkerView.kt +23 -0
  6. package/android/src/main/java/com/luggmaps/LuggMarkerViewManager.kt +13 -0
  7. package/android/src/main/java/com/luggmaps/core/GoogleMapProvider.kt +166 -21
  8. package/android/src/main/java/com/luggmaps/core/MapProviderDelegate.kt +5 -0
  9. package/android/src/main/java/com/luggmaps/extensions/ViewExtensions.kt +11 -0
  10. package/ios/LuggCalloutView.h +1 -1
  11. package/ios/LuggCalloutView.mm +21 -11
  12. package/ios/LuggMapView.mm +41 -2
  13. package/ios/LuggMarkerView.h +3 -0
  14. package/ios/LuggMarkerView.mm +23 -0
  15. package/ios/core/AppleMapProvider.mm +197 -16
  16. package/ios/core/GoogleMapProvider.mm +91 -18
  17. package/ios/core/MapProviderDelegate.h +8 -1
  18. package/lib/module/MapView.js +11 -0
  19. package/lib/module/MapView.js.map +1 -1
  20. package/lib/module/MapView.web.js +3 -0
  21. package/lib/module/MapView.web.js.map +1 -1
  22. package/lib/module/components/Marker.js +17 -3
  23. package/lib/module/components/Marker.js.map +1 -1
  24. package/lib/module/components/Marker.web.js +20 -7
  25. package/lib/module/components/Marker.web.js.map +1 -1
  26. package/lib/module/components/index.js.map +1 -1
  27. package/lib/module/fabric/LuggCalloutViewNativeComponent.ts +1 -1
  28. package/lib/module/fabric/LuggMapViewNativeComponent.ts +9 -1
  29. package/lib/module/fabric/LuggMarkerViewNativeComponent.ts +14 -2
  30. package/lib/module/index.js.map +1 -1
  31. package/lib/typescript/src/MapView.d.ts.map +1 -1
  32. package/lib/typescript/src/MapView.types.d.ts +36 -1
  33. package/lib/typescript/src/MapView.types.d.ts.map +1 -1
  34. package/lib/typescript/src/MapView.web.d.ts.map +1 -1
  35. package/lib/typescript/src/components/Marker.d.ts +6 -3
  36. package/lib/typescript/src/components/Marker.d.ts.map +1 -1
  37. package/lib/typescript/src/components/Marker.types.d.ts +14 -5
  38. package/lib/typescript/src/components/Marker.types.d.ts.map +1 -1
  39. package/lib/typescript/src/components/Marker.web.d.ts +3 -2
  40. package/lib/typescript/src/components/Marker.web.d.ts.map +1 -1
  41. package/lib/typescript/src/components/index.d.ts +1 -1
  42. package/lib/typescript/src/components/index.d.ts.map +1 -1
  43. package/lib/typescript/src/fabric/LuggCalloutViewNativeComponent.d.ts +1 -1
  44. package/lib/typescript/src/fabric/LuggMapViewNativeComponent.d.ts +6 -1
  45. package/lib/typescript/src/fabric/LuggMapViewNativeComponent.d.ts.map +1 -1
  46. package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts +8 -1
  47. package/lib/typescript/src/fabric/LuggMarkerViewNativeComponent.d.ts.map +1 -1
  48. package/lib/typescript/src/index.d.ts +3 -3
  49. package/lib/typescript/src/index.d.ts.map +1 -1
  50. package/lib/typescript/src/index.web.d.ts +1 -1
  51. package/lib/typescript/src/index.web.d.ts.map +1 -1
  52. package/lib/typescript/src/types.d.ts +0 -4
  53. package/lib/typescript/src/types.d.ts.map +1 -1
  54. package/package.json +1 -1
  55. package/src/MapView.tsx +11 -0
  56. package/src/MapView.types.ts +85 -1
  57. package/src/MapView.web.tsx +11 -0
  58. package/src/components/Marker.tsx +28 -5
  59. package/src/components/Marker.types.ts +15 -5
  60. package/src/components/Marker.web.tsx +191 -148
  61. package/src/components/index.ts +1 -0
  62. package/src/fabric/LuggCalloutViewNativeComponent.ts +1 -1
  63. package/src/fabric/LuggMapViewNativeComponent.ts +9 -1
  64. package/src/fabric/LuggMarkerViewNativeComponent.ts +14 -2
  65. package/src/index.ts +6 -1
  66. package/src/index.web.ts +3 -0
  67. package/src/types.ts +0 -5
@@ -1,7 +1,9 @@
1
1
  import React, {
2
+ forwardRef,
2
3
  isValidElement,
3
4
  useCallback,
4
5
  useEffect,
6
+ useImperativeHandle,
5
7
  useRef,
6
8
  useState,
7
9
  } from 'react';
@@ -11,7 +13,7 @@ import {
11
13
  useAdvancedMarkerRef,
12
14
  } from '@vis.gl/react-google-maps';
13
15
  import { useMapContext } from '../MapProvider.web';
14
- import type { MarkerProps } from './Marker.types';
16
+ import type { MarkerProps, MarkerRef } from './Marker.types';
15
17
 
16
18
  const CALLOUT_ARROW_HEIGHT = 12;
17
19
  const UNBUBBLED_CLASS = 'rnm-callout-unbubbled';
@@ -58,153 +60,194 @@ const createEvent = (
58
60
  },
59
61
  } as any);
60
62
 
61
- export const Marker = ({
62
- coordinate,
63
- title,
64
- description,
65
- anchor,
66
- zIndex,
67
- rotate,
68
- scale,
69
- draggable,
70
- onPress,
71
- onDragStart,
72
- onDragChange,
73
- onDragEnd,
74
- callout,
75
- calloutOptions,
76
- children,
77
- }: MarkerProps) => {
78
- const { moveCamera, onCalloutClose, closeCallouts } = useMapContext();
79
- const dragPositionRef = useRef<google.maps.LatLngLiteral | null>(null);
80
- const [markerRef, markerElement] = useAdvancedMarkerRef();
81
- const [infoWindowOpen, setInfoWindowOpen] = useState(false);
82
- const calloutBubbled = calloutOptions?.bubbled ?? true;
83
-
84
- const closeCallout = useCallback(() => setInfoWindowOpen(false), []);
85
-
86
- useEffect(() => onCalloutClose(closeCallout), [onCalloutClose, closeCallout]);
87
-
88
- useEffect(() => {
89
- if (!calloutBubbled) injectUnbubbledStyle();
90
- }, [calloutBubbled]);
91
-
92
- const hasCallout = !!(callout || title);
93
-
94
- const calloutContent = callout
95
- ? isValidElement(callout)
96
- ? callout
97
- : React.createElement(callout)
98
- : title
99
- ? React.createElement(
100
- 'div',
101
- { style: { fontSize: 14 } },
102
- React.createElement('div', { style: { fontWeight: 500 } }, title),
103
- description ? React.createElement('div', null, description) : null
104
- )
105
- : null;
106
-
107
- const transforms: string[] = [];
108
- if (rotate) transforms.push(`rotate(${rotate}deg)`);
109
- if (scale && scale !== 1) transforms.push(`scale(${scale})`);
110
-
111
- const handleClick = useCallback(
112
- (e: google.maps.MapMouseEvent) => {
113
- const pos = dragPositionRef.current;
114
- const coord = pos
115
- ? { latitude: pos.lat, longitude: pos.lng }
116
- : coordinate;
117
- moveCamera(coord);
118
- onPress?.(createEvent(e, coordinate));
119
- if (hasCallout) {
120
- closeCallouts(closeCallout);
121
- setInfoWindowOpen((prev) => !prev);
122
- }
63
+ export const Marker = forwardRef<MarkerRef, MarkerProps>(
64
+ (
65
+ {
66
+ coordinate,
67
+ title,
68
+ description,
69
+ anchor,
70
+ zIndex,
71
+ rotate,
72
+ scale,
73
+ centerOnPress = true,
74
+ draggable,
75
+ onPress,
76
+ onDragStart,
77
+ onDragChange,
78
+ onDragEnd,
79
+ callout,
80
+ calloutOptions,
81
+ children,
123
82
  },
124
- [moveCamera, onPress, coordinate, hasCallout, closeCallouts, closeCallout]
125
- );
126
-
127
- const handleDragStart = useCallback(
128
- (e: google.maps.MapMouseEvent) => {
129
- const latLng = e.latLng;
130
- if (latLng) {
131
- dragPositionRef.current = { lat: latLng.lat(), lng: latLng.lng() };
132
- }
133
- onDragStart?.(createEvent(e, coordinate));
134
- },
135
- [onDragStart, coordinate]
136
- );
137
-
138
- const handleDrag = useCallback(
139
- (e: google.maps.MapMouseEvent) => {
140
- const latLng = e.latLng;
141
- if (latLng) {
142
- dragPositionRef.current = { lat: latLng.lat(), lng: latLng.lng() };
143
- }
144
- onDragChange?.(createEvent(e, coordinate));
145
- },
146
- [onDragChange, coordinate]
147
- );
148
-
149
- const handleDragEnd = useCallback(
150
- (e: google.maps.MapMouseEvent) => {
151
- const latLng = e.latLng;
152
- if (latLng) {
153
- dragPositionRef.current = { lat: latLng.lat(), lng: latLng.lng() };
154
- }
155
- onDragEnd?.(createEvent(e, coordinate));
156
- },
157
- [onDragEnd, coordinate]
158
- );
159
-
160
- useEffect(() => {
161
- dragPositionRef.current = null;
162
- }, [coordinate.latitude, coordinate.longitude]);
163
-
164
- const latLngPosition = {
165
- lat: coordinate.latitude,
166
- lng: coordinate.longitude,
167
- };
168
-
169
- const position = dragPositionRef.current ?? latLngPosition;
170
-
171
- return (
172
- <>
173
- <AdvancedMarker
174
- ref={markerRef}
175
- position={position}
176
- title={title}
177
- zIndex={zIndex}
178
- anchorLeft={anchor ? toWebAnchor(anchor.x) : undefined}
179
- anchorTop={anchor ? toWebAnchor(anchor.y) : undefined}
180
- clickable
181
- draggable={draggable}
182
- onClick={handleClick}
183
- onDragStart={handleDragStart}
184
- onDrag={handleDrag}
185
- onDragEnd={handleDragEnd}
186
- style={
187
- transforms.length > 0
188
- ? { transform: transforms.join(' ') }
189
- : undefined
83
+ ref
84
+ ) => {
85
+ const { moveCamera, onCalloutClose, closeCallouts } = useMapContext();
86
+ const dragPositionRef = useRef<google.maps.LatLngLiteral | null>(null);
87
+ const [markerRef, markerElement] = useAdvancedMarkerRef();
88
+ const [infoWindowOpen, setInfoWindowOpen] = useState(false);
89
+ const calloutBubbled = calloutOptions?.bubbled ?? true;
90
+ const calloutOffset = calloutOptions?.offset;
91
+
92
+ const closeCallout = useCallback(() => setInfoWindowOpen(false), []);
93
+
94
+ useEffect(
95
+ () => onCalloutClose(closeCallout),
96
+ [onCalloutClose, closeCallout]
97
+ );
98
+
99
+ useEffect(() => {
100
+ if (!calloutBubbled) injectUnbubbledStyle();
101
+ }, [calloutBubbled]);
102
+
103
+ const hasCallout = !!(callout || title);
104
+
105
+ useImperativeHandle(
106
+ ref,
107
+ () => ({
108
+ showCallout() {
109
+ if (hasCallout) {
110
+ closeCallouts(closeCallout);
111
+ setInfoWindowOpen(true);
112
+ }
113
+ },
114
+ hideCallout() {
115
+ setInfoWindowOpen(false);
116
+ },
117
+ }),
118
+ [hasCallout, closeCallouts, closeCallout]
119
+ );
120
+
121
+ const calloutContent = callout
122
+ ? isValidElement(callout)
123
+ ? callout
124
+ : React.createElement(callout)
125
+ : title
126
+ ? React.createElement(
127
+ 'div',
128
+ { style: { fontSize: 14 } },
129
+ React.createElement('div', { style: { fontWeight: 500 } }, title),
130
+ description ? React.createElement('div', null, description) : null
131
+ )
132
+ : null;
133
+
134
+ const transforms: string[] = [];
135
+ if (rotate) transforms.push(`rotate(${rotate}deg)`);
136
+ if (scale && scale !== 1) transforms.push(`scale(${scale})`);
137
+
138
+ const handleClick = useCallback(
139
+ (e: google.maps.MapMouseEvent) => {
140
+ const pos = dragPositionRef.current;
141
+ const coord = pos
142
+ ? { latitude: pos.lat, longitude: pos.lng }
143
+ : coordinate;
144
+ if (centerOnPress) moveCamera(coord);
145
+ onPress?.(createEvent(e, coordinate));
146
+ if (hasCallout) {
147
+ closeCallouts(closeCallout);
148
+ setInfoWindowOpen((prev) => !prev);
149
+ }
150
+ },
151
+ [
152
+ centerOnPress,
153
+ moveCamera,
154
+ onPress,
155
+ coordinate,
156
+ hasCallout,
157
+ closeCallouts,
158
+ closeCallout,
159
+ ]
160
+ );
161
+
162
+ const handleDragStart = useCallback(
163
+ (e: google.maps.MapMouseEvent) => {
164
+ const latLng = e.latLng;
165
+ if (latLng) {
166
+ dragPositionRef.current = { lat: latLng.lat(), lng: latLng.lng() };
190
167
  }
191
- >
192
- {children}
193
- </AdvancedMarker>
194
- {calloutContent && infoWindowOpen && markerElement && (
195
- <InfoWindow
196
- anchor={markerElement}
197
- pixelOffset={!calloutBubbled ? [0, CALLOUT_ARROW_HEIGHT] : undefined}
198
- headerDisabled
199
- onClose={() => setInfoWindowOpen(false)}
168
+ onDragStart?.(createEvent(e, coordinate));
169
+ },
170
+ [onDragStart, coordinate]
171
+ );
172
+
173
+ const handleDrag = useCallback(
174
+ (e: google.maps.MapMouseEvent) => {
175
+ const latLng = e.latLng;
176
+ if (latLng) {
177
+ dragPositionRef.current = { lat: latLng.lat(), lng: latLng.lng() };
178
+ }
179
+ onDragChange?.(createEvent(e, coordinate));
180
+ },
181
+ [onDragChange, coordinate]
182
+ );
183
+
184
+ const handleDragEnd = useCallback(
185
+ (e: google.maps.MapMouseEvent) => {
186
+ const latLng = e.latLng;
187
+ if (latLng) {
188
+ dragPositionRef.current = { lat: latLng.lat(), lng: latLng.lng() };
189
+ }
190
+ onDragEnd?.(createEvent(e, coordinate));
191
+ },
192
+ [onDragEnd, coordinate]
193
+ );
194
+
195
+ useEffect(() => {
196
+ dragPositionRef.current = null;
197
+ }, [coordinate.latitude, coordinate.longitude]);
198
+
199
+ const latLngPosition = {
200
+ lat: coordinate.latitude,
201
+ lng: coordinate.longitude,
202
+ };
203
+
204
+ const position = dragPositionRef.current ?? latLngPosition;
205
+
206
+ return (
207
+ <>
208
+ <AdvancedMarker
209
+ ref={markerRef}
210
+ position={position}
211
+ title={title}
212
+ zIndex={zIndex}
213
+ anchorLeft={anchor ? toWebAnchor(anchor.x) : undefined}
214
+ anchorTop={anchor ? toWebAnchor(anchor.y) : undefined}
215
+ clickable
216
+ draggable={draggable}
217
+ onClick={handleClick}
218
+ onDragStart={handleDragStart}
219
+ onDrag={handleDrag}
220
+ onDragEnd={handleDragEnd}
221
+ style={
222
+ transforms.length > 0
223
+ ? { transform: transforms.join(' ') }
224
+ : undefined
225
+ }
200
226
  >
201
- {!calloutBubbled ? (
202
- <div className={UNBUBBLED_CLASS}>{calloutContent}</div>
203
- ) : (
204
- calloutContent
205
- )}
206
- </InfoWindow>
207
- )}
208
- </>
209
- );
210
- };
227
+ {children}
228
+ </AdvancedMarker>
229
+ {calloutContent && infoWindowOpen && markerElement && (
230
+ <InfoWindow
231
+ anchor={markerElement}
232
+ pixelOffset={
233
+ !calloutBubbled
234
+ ? [
235
+ calloutOffset?.x ?? 0,
236
+ CALLOUT_ARROW_HEIGHT + (calloutOffset?.y ?? 0),
237
+ ]
238
+ : undefined
239
+ }
240
+ headerDisabled
241
+ onClose={() => setInfoWindowOpen(false)}
242
+ >
243
+ {!calloutBubbled ? (
244
+ <div className={UNBUBBLED_CLASS}>{calloutContent}</div>
245
+ ) : (
246
+ calloutContent
247
+ )}
248
+ </InfoWindow>
249
+ )}
250
+ </>
251
+ );
252
+ }
253
+ );
@@ -1,6 +1,7 @@
1
1
  export { Marker } from './Marker';
2
2
  export type {
3
3
  CalloutOptions,
4
+ MarkerRef,
4
5
  MarkerProps,
5
6
  MarkerPressEvent,
6
7
  MarkerDragEvent,
@@ -12,7 +12,7 @@ export interface Point {
12
12
 
13
13
  export interface NativeProps extends ViewProps {
14
14
  bubbled?: WithDefault<boolean, true>;
15
- anchor?: Point;
15
+ offset?: Point;
16
16
  }
17
17
 
18
18
  export default codegenNativeComponent<NativeProps>(
@@ -62,6 +62,10 @@ export interface ReadyEvent {}
62
62
 
63
63
  export interface NativeProps extends ViewProps {
64
64
  provider?: WithDefault<'google' | 'apple', 'google'>;
65
+ mapType?: WithDefault<
66
+ 'standard' | 'satellite' | 'terrain' | 'hybrid' | 'muted-standard',
67
+ 'standard'
68
+ >;
65
69
  mapId?: string;
66
70
  initialCoordinate?: Coordinate;
67
71
  initialZoom?: Double;
@@ -74,7 +78,11 @@ export interface NativeProps extends ViewProps {
74
78
  edgeInsets?: EdgeInsets;
75
79
  userLocationEnabled?: boolean;
76
80
  userLocationButtonEnabled?: boolean;
77
- theme?: WithDefault<'light' | 'dark' | 'system', 'system'>;
81
+ poiEnabled?: boolean;
82
+ poiFilterMode?: WithDefault<'including' | 'excluding', 'including'>;
83
+ poiFilterCategories?: ReadonlyArray<string>;
84
+ theme?: WithDefault<'system' | 'light' | 'dark', 'system'>;
85
+ insetAdjustment?: WithDefault<'never' | 'automatic', 'never'>;
78
86
  onMapPress?: DirectEventHandler<PressEvent>;
79
87
  onMapLongPress?: DirectEventHandler<LongPressEvent>;
80
88
  onCameraMove?: DirectEventHandler<CameraMoveEvent>;
@@ -1,4 +1,4 @@
1
- import { codegenNativeComponent } from 'react-native';
1
+ import { codegenNativeComponent, codegenNativeCommands } from 'react-native';
2
2
  import type { ViewProps, HostComponent } from 'react-native';
3
3
  import type {
4
4
  Double,
@@ -25,6 +25,7 @@ export interface NativeProps extends ViewProps {
25
25
  rotate?: WithDefault<Double, 0>;
26
26
  scale?: WithDefault<Double, 1>;
27
27
  rasterize?: WithDefault<boolean, true>;
28
+ centerOnPress?: WithDefault<boolean, true>;
28
29
  draggable?: WithDefault<boolean, false>;
29
30
  onMarkerPress?: DirectEventHandler<{
30
31
  coordinate: {
@@ -68,6 +69,17 @@ export interface NativeProps extends ViewProps {
68
69
  }>;
69
70
  }
70
71
 
72
+ type ComponentType = HostComponent<NativeProps>;
73
+
74
+ interface NativeCommands {
75
+ showCallout: (viewRef: React.ElementRef<ComponentType>) => void;
76
+ hideCallout: (viewRef: React.ElementRef<ComponentType>) => void;
77
+ }
78
+
79
+ export const Commands = codegenNativeCommands<NativeCommands>({
80
+ supportedCommands: ['showCallout', 'hideCallout'],
81
+ });
82
+
71
83
  export default codegenNativeComponent<NativeProps>(
72
84
  'LuggMarkerView'
73
- ) as HostComponent<NativeProps>;
85
+ ) as ComponentType;
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@ export type { MapProviderProps } from './MapProvider.types';
4
4
  export { Marker } from './components';
5
5
  export type {
6
6
  CalloutOptions,
7
+ MarkerRef,
7
8
  MarkerProps,
8
9
  MarkerPressEvent,
9
10
  MarkerDragEvent,
@@ -33,10 +34,14 @@ export type {
33
34
  CameraEventPayload,
34
35
  MapCameraEvent,
35
36
  MapPressEvent,
37
+ MapType,
38
+ MapTheme,
39
+ InsetAdjustment,
40
+ PoiCategory,
41
+ PoiFilter,
36
42
  } from './MapView.types';
37
43
  export type {
38
44
  MapProvider as MapProviderType,
39
- MapTheme,
40
45
  Coordinate,
41
46
  Point,
42
47
  EdgeInsets,
package/src/index.web.ts CHANGED
@@ -27,6 +27,9 @@ export type {
27
27
  MoveCameraOptions,
28
28
  FitCoordinatesOptions,
29
29
  CameraEventPayload,
30
+ MapType,
31
+ PoiCategory,
32
+ PoiFilter,
30
33
  } from './MapView.types';
31
34
  export type {
32
35
  MapProvider as MapProviderType,
package/src/types.ts CHANGED
@@ -29,11 +29,6 @@ export interface EdgeInsets {
29
29
  right: number;
30
30
  }
31
31
 
32
- /**
33
- * Map theme
34
- */
35
- export type MapTheme = 'light' | 'dark' | 'system';
36
-
37
32
  /**
38
33
  * Press event payload
39
34
  */