Skip to content

Commit

Permalink
feat(MapView): remove setCamera
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `setCamera` removed. Use `animateCamera` with `duration: 0` instead.
  • Loading branch information
monholm committed May 4, 2023
1 parent 854e5df commit aef8148
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 89 deletions.
10 changes: 0 additions & 10 deletions android/src/main/java/com/rnmaps/maps/MapManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,17 +281,7 @@ public void setBoundary(MapView view, ReadableMap boundary) {

@Override
public void receiveCommand(@NonNull MapView view, String commandId, @Nullable ReadableArray args) {
ReadableMap camera;

switch (commandId) {
case "setCamera":
if(args == null) {
break;
}
camera = args.getMap(0);
view.animateToCamera(camera, 0);
break;

case "setIndoorActiveLevelIndex":
if(args == null) {
break;
Expand Down
13 changes: 0 additions & 13 deletions android/src/main/java/com/rnmaps/maps/MapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -886,19 +886,6 @@ public CameraUpdate buildCameraUpdate(ReadableMap camera) {
return CameraUpdateFactory.newCameraPosition(builder.build());
}

public void animateToCamera(ReadableMap camera, int duration) {
if (map == null) return;

CameraUpdate update = buildCameraUpdate(camera);

if (duration <= 0) {
map.moveCamera(update);
}
else {
map.animateCamera(update, duration, null);
}
}

public int baseLeftMapPadding;
public int baseRightMapPadding;
public int baseTopMapPadding;
Expand Down
1 change: 0 additions & 1 deletion docs/mapview.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ To access event data, you will need to use `e.nativeEvent`. For example, `onPres
| `getMapBoundaries` | | `Promise<{northEast: LatLng, southWest: LatLng}>` |
| `getMarkersFrames` | `onlyVisible: Boolean` | Get markers' centers and frames in view coordinates. Returns a `Promise<{ "markerID" : { point: Point, frame: Frame } }>`. **Note**: iOS only. |
| `pointForCoordinate` | `coordinate: LatLng` | Converts a map coordinate to a view coordinate (`Point`). Returns a `Promise<Point>`. |
| `setCamera` | `camera: Camera` | Like `animateCamera`, but sets the new view instantly, without an animation. |
| `setIndoorActiveLevelIndex` | `levelIndex: Number` |

## Types
Expand Down
15 changes: 0 additions & 15 deletions ios/GoogleMaps/RNMGoogleMapManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,6 @@ - (UIView *)view
RCT_REMAP_VIEW_PROPERTY(paddingAdjustmentBehavior, paddingAdjustmentBehaviorString, NSString)
RCT_REMAP_VIEW_PROPERTY(testID, accessibilityIdentifier, NSString)

RCT_EXPORT_METHOD(setCamera:(nonnull NSNumber *)reactTag
camera:(id)json)
{
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
id view = viewRegistry[reactTag];
if (![view isKindOfClass:[RNMGoogleMap class]]) {
RCTLogError(@"Invalid view returned from registry, expecting RNMGoogleMap, got: %@", view);
} else {
RNMGoogleMap *mapView = (RNMGoogleMap *)view;
GMSCameraPosition *camera = [RCTConvert GMSCameraPositionWithDefaults:json existingCamera:[mapView camera]];
[mapView setCamera:camera];
}
}];
}

RCT_EXPORT_METHOD(setIndoorActiveLevelIndex:(nonnull NSNumber *)reactTag
levelIndex:(NSInteger) levelIndex)
{
Expand Down
19 changes: 12 additions & 7 deletions ios/GoogleMaps/RNMGoogleMapViewModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,18 @@ - (dispatch_queue_t)methodQueue
RNMGoogleMap *mapView = (RNMGoogleMap *)view;
GMSCameraPosition *camera = [RCTConvert GMSCameraPositionWithDefaults:json existingCamera:[mapView camera]];

[CATransaction begin];
[CATransaction setCompletionBlock:^{
resolve(nil);
}];
[CATransaction setAnimationDuration:duration/1000];
[mapView animateToCameraPosition:camera];
[CATransaction commit];
if(duration > 0.0f) {
[CATransaction begin];
[CATransaction setCompletionBlock:^{
resolve(nil);
}];
[CATransaction setAnimationDuration:duration/1000];
[mapView animateToCameraPosition:camera];
[CATransaction commit];
} else {
[mapView moveCamera:camera];
resolve(nil);
}
}
}];
}
Expand Down
24 changes: 0 additions & 24 deletions ios/Maps/RNMMapManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -170,30 +170,6 @@ - (UIView *)view
view.ignoreRegionChanges = originalIgnore;
}

#pragma mark exported MapView methods

RCT_EXPORT_METHOD(setCamera:(nonnull NSNumber *)reactTag
camera:(id)json)
{
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
id view = viewRegistry[reactTag];
if (![view isKindOfClass:[RNMMap class]]) {
RCTLogError(@"Invalid view returned from registry, expecting RNMMap, got: %@", view);
} else {
RNMMap *mapView = (RNMMap *)view;

// Merge the changes given with the current camera
MKMapCamera *camera = [RCTConvert MKMapCameraWithDefaults:json existingCamera:[mapView camera]];

// don't emit region change events when we are setting the camera
BOOL originalIgnore = mapView.ignoreRegionChanges;
mapView.ignoreRegionChanges = YES;
[mapView setCamera:camera animated:NO];
mapView.ignoreRegionChanges = originalIgnore;
}
}];
}

#pragma mark Gesture Recognizer Handlers

#define MAX_DISTANCE_PX 10.0f
Expand Down
14 changes: 10 additions & 4 deletions ios/Maps/RNMMapViewModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,18 @@ - (dispatch_queue_t)methodQueue
// don't emit region change events when we are setting the camera
BOOL originalIgnore = mapView.ignoreRegionChanges;
mapView.ignoreRegionChanges = YES;
[RNMMap animateWithDuration:duration/1000 animations:^{
[mapView setCamera:camera animated:YES];
} completion:^(BOOL finished){
if(duration > 0.0f) {
[RNMMap animateWithDuration:duration/1000 animations:^{
[mapView setCamera:camera animated:YES];
} completion:^(BOOL finished){
mapView.ignoreRegionChanges = originalIgnore;
resolve(nil);
}];
} else {
[mapView setCamera:camera animated:NO];
mapView.ignoreRegionChanges = originalIgnore;
resolve(nil);
}];
}
}
}];
}
Expand Down
6 changes: 0 additions & 6 deletions src/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -771,12 +771,6 @@ class MapView extends React.Component<MapViewProps, State> {
return mapViewModuleMethod('getCamera')(this._getHandle());
}

setCamera(camera: Partial<Camera>) {
if (this.map.current) {
Commands.setCamera(this.map.current, camera);
}
}

animateCamera(
camera: Partial<Camera>,
duration: number = 500,
Expand Down
10 changes: 1 addition & 9 deletions src/MapViewNativeComponent.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import type {HostComponent} from 'react-native';
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
import {NativeProps} from './MapView';
import {Camera} from './MapView.types';

export type MapViewNativeComponentType = HostComponent<NativeProps>;

interface NativeCommands {
setCamera: (
viewRef: NonNullable<
React.RefObject<MapViewNativeComponentType>['current']
>,
camera: Partial<Camera>,
) => void;

setIndoorActiveLevelIndex: (
viewRef: NonNullable<
React.RefObject<MapViewNativeComponentType>['current']
Expand All @@ -22,5 +14,5 @@ interface NativeCommands {
}

export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
supportedCommands: ['setCamera', 'setIndoorActiveLevelIndex'],
supportedCommands: ['setIndoorActiveLevelIndex'],
});

0 comments on commit aef8148

Please sign in to comment.