Skip to content

Commit 684165c

Browse files
committed
chore: port to new arch
1 parent 51a6a72 commit 684165c

33 files changed

+862
-27
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ This project follows
4242
follow [GitHub's directions](https://help.github.com/articles/generating-ssh-keys/)
4343
to generate an SSH key.
4444
- `git clone git@github.com:<your_name_here>/googlemaps/react-native-navigation-sdk.git`
45-
- `git remote add upstream git@github.com:googlemaps/react-native-sdk.git` (So that you
45+
- `git remote add upstream git@github.com:googlemaps/react-native-navigation-sdk.git` (So that you
4646
fetch from the master repository, not your clone, when running `git fetch`
4747
et al.)
4848

4949
#### Create branch
5050

5151
1. `git fetch upstream`
52-
2. `git checkout upstream/master -b <name_of_your_branch>`
52+
2. `git checkout upstream/main -b <name_of_your_branch>`
5353
3. Start coding!
5454

5555
#### Commit changes

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,8 @@ Both `NavigationView` and `MapView` support the following props. Props marked wi
542542
| ----------------------------------- | ------------------------------------------------ | :---: | ------------------------------------------------ |
543543
| `onMapReady` | `() => void` | | Called when the map is ready to use |
544544
| `onMapClick` | `(latLng: LatLng) => void` | | Called when the map is clicked |
545+
| `onMapDrag` | `(result: DragResult) => void` | | Called when the map is dragged |
546+
| `onMapDragEnd` | `(result: DragResult) => void` | | Called when the map dragging stops |
545547
| `onMarkerClick` | `(marker: Marker) => void` | | Called when a marker is clicked |
546548
| `onPolylineClick` | `(polyline: Polyline) => void` | | Called when a polyline is clicked |
547549
| `onPolygonClick` | `(polygon: Polygon) => void` | | Called when a polygon is clicked |
@@ -564,6 +566,10 @@ The `MapViewController` is provided via the `onMapViewControllerCreated` callbac
564566
| `addPolyline(options: PolylineOptions)` | `Promise<Polyline>` | Add or update a polyline. If `options.id` matches an existing polyline, it is updated |
565567
| `addPolygon(options: PolygonOptions)` | `Promise<Polygon>` | Add or update a polygon. If `options.id` matches an existing polygon, it is updated |
566568
| `addCircle(options: CircleOptions)` | `Promise<Circle>` | Add or update a circle. If `options.id` matches an existing circle, it is updated |
569+
| `coordinateForPoint(point: Point)` | `Promise<LatLng>` | Maps a point coordinate in the map’s view to an Earth coordinate |
570+
| `pointForCoordinate(coordinate: LatLng)` | `Promise<Point>` | Maps an Earth coordinate to a point coordinate in the map’s view |
571+
| `fitBounds(boundsOptions: BoundsOptions)` | `Promise<void>` | Transforms the camera such that the specified bounds are centered on screen |
572+
| `getBounds()` | `Promise<Bounds>` | Retrieves the rectangular bounds of the map view |
567573
| `addGroundOverlay(options: GroundOverlayOptions)` | `Promise<GroundOverlay>` | Add or update a ground overlay. If `options.id` matches an existing overlay, it is updated |
568574
| `removeMarker(id: string)` | `void` | Remove a marker by its ID |
569575
| `removePolyline(id: string)` | `void` | Remove a polyline by its ID |

android/src/main/java/com/google/android/react/navsdk/Constants.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,15 @@
1616
public class Constants {
1717
public static final String LAT_FIELD_KEY = "lat";
1818
public static final String LNG_FIELD_KEY = "lng";
19+
20+
public static final String URI_KEY = "uri";
21+
22+
public static final String X_KEY = "x";
23+
public static final String Y_KEY = "y";
24+
25+
public static final String CAMERA_POSITION_KEY = "cameraPosition";
26+
public static final String TARGET_KEY = "target";
27+
public static final String BEARING_KEY = "bearing";
28+
public static final String TILT_KEY = "tilt";
29+
public static final String ZOOM_KEY = "zoom";
1930
}

android/src/main/java/com/google/android/react/navsdk/INavigationViewCallback.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
package com.google.android.react.navsdk;
1515

16+
import com.google.android.gms.maps.model.CameraPosition;
1617
import com.google.android.gms.maps.model.Circle;
1718
import com.google.android.gms.maps.model.GroundOverlay;
1819
import com.google.android.gms.maps.model.LatLng;
@@ -36,4 +37,8 @@ public interface INavigationViewCallback {
3637
void onMarkerInfoWindowTapped(Marker marker);
3738

3839
void onMapClick(LatLng latLng);
40+
41+
void onMapDrag(CameraPosition cameraPosition);
42+
43+
void onMapDragEnd(CameraPosition cameraPosition);
3944
}

android/src/main/java/com/google/android/react/navsdk/MapViewController.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ public void setupMapListeners(INavigationViewCallback navigationViewCallback) {
9898
mGoogleMap.setOnInfoWindowClickListener(
9999
marker -> mNavigationViewCallback.onMarkerInfoWindowTapped(marker));
100100
mGoogleMap.setOnMapClickListener(latLng -> mNavigationViewCallback.onMapClick(latLng));
101+
mGoogleMap.setOnCameraMoveListener(
102+
() -> mNavigationViewCallback.onMapDrag(mGoogleMap.getCameraPosition()));
103+
mGoogleMap.setOnCameraIdleListener(
104+
() -> mNavigationViewCallback.onMapDragEnd(mGoogleMap.getCameraPosition()));
101105
}
102106

103107
public GoogleMap getGoogleMap() {

android/src/main/java/com/google/android/react/navsdk/MapViewFragment.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.google.android.gms.maps.GoogleMap;
2828
import com.google.android.gms.maps.GoogleMapOptions;
2929
import com.google.android.gms.maps.SupportMapFragment;
30+
import com.google.android.gms.maps.model.CameraPosition;
3031
import com.google.android.gms.maps.model.Circle;
3132
import com.google.android.gms.maps.model.GroundOverlay;
3233
import com.google.android.gms.maps.model.LatLng;
@@ -137,6 +138,24 @@ public void onMapClick(LatLng latLng) {
137138
emitEvent("onMapClick", ObjectTranslationUtil.getMapFromLatLng(latLng));
138139
}
139140

141+
@Override
142+
public void onMapDrag(CameraPosition cameraPosition) {
143+
WritableMap map = Arguments.createMap();
144+
map.putMap(
145+
Constants.CAMERA_POSITION_KEY,
146+
ObjectTranslationUtil.getMapFromCameraPosition(cameraPosition));
147+
emitEvent("onMapDrag", map);
148+
}
149+
150+
@Override
151+
public void onMapDragEnd(CameraPosition cameraPosition) {
152+
WritableMap map = Arguments.createMap();
153+
map.putMap(
154+
Constants.CAMERA_POSITION_KEY,
155+
ObjectTranslationUtil.getMapFromCameraPosition(cameraPosition));
156+
emitEvent("onMapDragEnd", map);
157+
}
158+
140159
public MapViewController getMapController() {
141160
return mMapViewController;
142161
}

android/src/main/java/com/google/android/react/navsdk/NavAutoModule.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,52 @@ public void addCircle(ReadableMap options, final Promise promise) {
163163
});
164164
}
165165

166+
@Override
167+
public void coordinateForPoint(String nativeID, ReadableMap point, Promise promise) {
168+
UiThreadUtil.runOnUiThread(
169+
() -> {
170+
if (mMapViewController == null) {
171+
promise.reject(JsErrors.NO_MAP_ERROR_CODE, JsErrors.NO_MAP_ERROR_MESSAGE);
172+
return;
173+
}
174+
175+
NavViewModule.resolveCoordinateForPoint(
176+
getReactApplicationContext(), mMapViewController.getGoogleMap(), point, promise);
177+
});
178+
}
179+
180+
@Override
181+
public void pointForCoordinate(String nativeID, ReadableMap coordinate, Promise promise) {
182+
if (mMapViewController == null) {
183+
promise.reject(JsErrors.NO_MAP_ERROR_CODE, JsErrors.NO_MAP_ERROR_MESSAGE);
184+
return;
185+
}
186+
187+
NavViewModule.resolvePointForCoordinate(
188+
getReactApplicationContext(), mMapViewController.getGoogleMap(), coordinate, promise);
189+
}
190+
191+
@Override
192+
public void fitBounds(String nativeID, ReadableMap boundsOptions, Promise promise) {
193+
if (mMapViewController == null) {
194+
promise.reject(JsErrors.NO_MAP_ERROR_CODE, JsErrors.NO_MAP_ERROR_MESSAGE);
195+
return;
196+
}
197+
198+
NavViewModule.resolveFitBounds(
199+
getReactApplicationContext(), mMapViewController.getGoogleMap(), boundsOptions, promise);
200+
}
201+
202+
@Override
203+
public void getBounds(String nativeID, Promise promise) {
204+
if (mMapViewController == null) {
205+
promise.reject(JsErrors.NO_MAP_ERROR_CODE, JsErrors.NO_MAP_ERROR_MESSAGE);
206+
return;
207+
}
208+
209+
NavViewModule.resolveGetBounds(mMapViewController.getGoogleMap(), promise);
210+
}
211+
166212
@Override
167213
public void addMarker(ReadableMap options, final Promise promise) {
168214
ReadableMap markerOptionsMap = options;

android/src/main/java/com/google/android/react/navsdk/NavViewFragment.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.facebook.react.uimanager.events.EventDispatcher;
2727
import com.google.android.gms.maps.GoogleMap;
2828
import com.google.android.gms.maps.GoogleMapOptions;
29+
import com.google.android.gms.maps.model.CameraPosition;
2930
import com.google.android.gms.maps.model.Circle;
3031
import com.google.android.gms.maps.model.GroundOverlay;
3132
import com.google.android.gms.maps.model.LatLng;
@@ -242,6 +243,24 @@ public void onMapClick(LatLng latLng) {
242243
emitEvent("onMapClick", ObjectTranslationUtil.getMapFromLatLng(latLng));
243244
}
244245

246+
@Override
247+
public void onMapDrag(CameraPosition cameraPosition) {
248+
WritableMap map = Arguments.createMap();
249+
map.putMap(
250+
Constants.CAMERA_POSITION_KEY,
251+
ObjectTranslationUtil.getMapFromCameraPosition(cameraPosition));
252+
emitEvent("onMapDrag", map);
253+
}
254+
255+
@Override
256+
public void onMapDragEnd(CameraPosition cameraPosition) {
257+
WritableMap map = Arguments.createMap();
258+
map.putMap(
259+
Constants.CAMERA_POSITION_KEY,
260+
ObjectTranslationUtil.getMapFromCameraPosition(cameraPosition));
261+
emitEvent("onMapDragEnd", map);
262+
}
263+
245264
@Override
246265
public void onDestroy() {
247266
super.onDestroy();

android/src/main/java/com/google/android/react/navsdk/NavViewManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,8 @@ public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
655655
MapBuilder.of("registrationName", "onPromptVisibilityChanged"))
656656
.put("onMapReady", MapBuilder.of("registrationName", "onMapReady"))
657657
.put("onMapClick", MapBuilder.of("registrationName", "onMapClick"))
658+
.put("onMapDrag", MapBuilder.of("registrationName", "onMapDrag"))
659+
.put("onMapDragEnd", MapBuilder.of("registrationName", "onMapDragEnd"))
658660
.put("onMarkerClick", MapBuilder.of("registrationName", "onMarkerClick"))
659661
.put("onPolylineClick", MapBuilder.of("registrationName", "onPolylineClick"))
660662
.put("onPolygonClick", MapBuilder.of("registrationName", "onPolygonClick"))

0 commit comments

Comments
 (0)