Skip to content

Commit

Permalink
feat(MapView): migrate setIndoorActiveLevelIndex to prop
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `setIndoorActiveLevelIndex` migrated to `indoorActiveLevelIndex` prop
  • Loading branch information
monholm committed May 6, 2023
1 parent aef8148 commit 5957e44
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 64 deletions.
13 changes: 3 additions & 10 deletions android/src/main/java/com/rnmaps/maps/MapManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,9 @@ public void setBoundary(MapView view, ReadableMap boundary) {
view.setBoundary(boundary);
}

@Override
public void receiveCommand(@NonNull MapView view, String commandId, @Nullable ReadableArray args) {
switch (commandId) {
case "setIndoorActiveLevelIndex":
if(args == null) {
break;
}
view.setIndoorActiveLevelIndex(args.getInt(0));
break;
}
@ReactProp(name = "indoorActiveLevelIndex")
public void setIndoorActiveLevelIndex(MapView view, int index) {
view.setIndoorActiveLevelIndex(index);
}

@Override
Expand Down
28 changes: 14 additions & 14 deletions docs/mapview.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
| `compassOffset` | `Point` | | If set, changes the position of the compass. **Note:** iOS Maps only. |
| `customMapStyle` | `Array` | | Adds custom styling to the map component. See [README](https://github.com/react-native-maps/react-native-maps#customizing-the-map-style) for more information. |
| `followsUserLocation` | `Boolean` | `false` | If `true` the map will focus on the user's location. This only works if `showsUserLocation` is true and the user has shared their location. **Note**: Apple Maps only. |
| `indoorActiveLevelIndex` | `number` | | Set to control what indoor building level to display. (Google Maps only) |
| `initialCamera` | `Camera` | | Like `initialRegion`, use this prop instead of `camera` only if you don't want to control the viewport of the map besides the initial camera setting.<br/><br/> Changing this prop after the component has mounted will not result in a region change.<br/><br/> This is similar to the `initialValue` prop of a text input. |
| `initialRegion` | `Region` | | The initial region to be displayed by the map. Use this prop instead of `region` only if you don't want to control the viewport of the map besides the initial region.<br/><br/> Changing this prop after the component has mounted will not result in a region change.<br/><br/> This is similar to the `initialValue` prop of a text input. |
| `isAccessibilityElement` | `Boolean` | `false` | Determines whether the MapView captures VoiceOver touches or forwards them to children. When `true`, map markers are not visible to VoiceOver. **Note:** iOS Maps only. |
Expand Down Expand Up @@ -80,20 +81,19 @@ To access event data, you will need to use `e.nativeEvent`. For example, `onPres

## Methods

| Method Name | Arguments | Notes |
| --------------------------- | ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `addressForCoordinate` | `coordinate: LatLng` | Converts a map coordinate to a address (`Address`). Returns a `Promise<Address>` **Note** Not supported on Google Maps for iOS. |
| `animateCamera` | `camera: Camera`, `duration?: number` | Animate the camera to a new view. You can pass a partial camera object here; any property not given will remain unmodified. Returns `Promise<void>` when the animation finishes. |
| `animateToRegion` | `region: Region`, `duration?: number` | Animates to region. Returns `Promise<void>` when the animation finishes. |
| `coordinateForPoint` | `point: Point` | Converts a view coordinate (`Point`) to a map coordinate. Returns a `Promise<Coordinate>`. |
| `fitToCoordinates` | `coordinates: Array<LatLng>, options?: { edgePadding?: EdgePadding, duration?: number }` | Returns `Promise<void>` when the animation finishes. |
| `fitToElements` | `options?: { edgePadding?: EdgePadding, duration?: number }` | **Note** edgePadding is Google Maps only. Returns `Promise<void>` when the animation finishes. |
| `fitToSuppliedMarkers` | `markerIDs: String[], options?: { edgePadding?: EdgePadding, duration?: number }` | If you need to use this in `ComponentDidMount`, make sure you put it in a timeout or it will cause performance problems. Returns `Promise<void>` when the animation finishes. **Note** edgePadding is Google Maps only |
| `getCamera` | | Returns a `Promise<Camera>` structure indicating the current camera configuration. |
| `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>`. |
| `setIndoorActiveLevelIndex` | `levelIndex: Number` |
| Method Name | Arguments | Notes |
| ---------------------- | ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `addressForCoordinate` | `coordinate: LatLng` | Converts a map coordinate to a address (`Address`). Returns a `Promise<Address>` **Note** Not supported on Google Maps for iOS. |
| `animateCamera` | `camera: Camera`, `duration?: number` | Animate the camera to a new view. You can pass a partial camera object here; any property not given will remain unmodified. Returns `Promise<void>` when the animation finishes. |
| `animateToRegion` | `region: Region`, `duration?: number` | Animates to region. Returns `Promise<void>` when the animation finishes. |
| `coordinateForPoint` | `point: Point` | Converts a view coordinate (`Point`) to a map coordinate. Returns a `Promise<Coordinate>`. |
| `fitToCoordinates` | `coordinates: Array<LatLng>, options?: { edgePadding?: EdgePadding, duration?: number }` | Returns `Promise<void>` when the animation finishes. |
| `fitToElements` | `options?: { edgePadding?: EdgePadding, duration?: number }` | **Note** edgePadding is Google Maps only. Returns `Promise<void>` when the animation finishes. |
| `fitToSuppliedMarkers` | `markerIDs: String[], options?: { edgePadding?: EdgePadding, duration?: number }` | If you need to use this in `ComponentDidMount`, make sure you put it in a timeout or it will cause performance problems. Returns `Promise<void>` when the animation finishes. **Note** edgePadding is Google Maps only |
| `getCamera` | | Returns a `Promise<Camera>` structure indicating the current camera configuration. |
| `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>`. |

## Types

Expand Down
9 changes: 9 additions & 0 deletions ios/GoogleMaps/RNMGoogleMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,15 @@ - (void)setBoundary:(GMSCoordinateBounds*)boundary {
self.cameraTargetBounds = boundary;
}

- (void)setIndoorActiveLevelIndex:(NSInteger)index {
if (!self.indoorDisplay) {
return;
}
if ( index < [self.indoorDisplay.activeBuilding.levels count]) {
self.indoorDisplay.activeLevel = self.indoorDisplay.activeBuilding.levels[index];
}
}

- (void)didPrepareMap {
UIView* mapView = [self valueForKey:@"mapView"]; //GMSVectorMapView
[self overrideGestureRecognizersForView:mapView];
Expand Down
20 changes: 1 addition & 19 deletions ios/GoogleMaps/RNMGoogleMapManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ - (UIView *)view

RCT_EXPORT_VIEW_PROPERTY(boundary, GMSCoordinateBounds*)
RCT_EXPORT_VIEW_PROPERTY(customMapStyleString, NSString)
RCT_EXPORT_VIEW_PROPERTY(indoorActiveLevelIndex, NSInteger)
RCT_EXPORT_VIEW_PROPERTY(initialCamera, GMSCameraPosition)
RCT_EXPORT_VIEW_PROPERTY(initialRegion, MKCoordinateRegion)
RCT_EXPORT_VIEW_PROPERTY(isAccessibilityElement, BOOL)
Expand Down Expand Up @@ -107,25 +108,6 @@ - (UIView *)view
RCT_REMAP_VIEW_PROPERTY(paddingAdjustmentBehavior, paddingAdjustmentBehaviorString, NSString)
RCT_REMAP_VIEW_PROPERTY(testID, accessibilityIdentifier, NSString)

RCT_EXPORT_METHOD(setIndoorActiveLevelIndex:(nonnull NSNumber *)reactTag
levelIndex:(NSInteger) levelIndex)
{
[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;
if (!mapView.indoorDisplay) {
return;
}
if ( levelIndex < [mapView.indoorDisplay.activeBuilding.levels count]) {
mapView.indoorDisplay.activeLevel = mapView.indoorDisplay.activeBuilding.levels[levelIndex];
}
}
}];
}

+ (BOOL)requiresMainQueueSetup {
return YES;
}
Expand Down
16 changes: 9 additions & 7 deletions src/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import {
UserLocationChangeEvent,
} from './MapView.types';
import {Modify} from './sharedTypesInternal';
import {Commands, MapViewNativeComponentType} from './MapViewNativeComponent';
import {MapViewNativeComponentType} from './MapViewNativeComponent';
import MapViewModule, {Spec as MapViewModuleSpec} from './NativeMapViewModule';
import GoogleMapViewModule, {
Spec as GoogleMapViewModuleSpec,
Expand Down Expand Up @@ -121,6 +121,14 @@ export type MapViewProps = ViewProps & {
*/
followsUserLocation?: boolean;

/**
* Set to control what indoor building level to display.
*
* @platform iOS: Google Maps only
* @platform Android: Supported
*/
indoorActiveLevelIndex?: number;

/**
* The initial camera view the map should use. Use this prop instead of `camera`
* only if you don't want to control the camera of the map besides the initial view.
Expand Down Expand Up @@ -873,12 +881,6 @@ class MapView extends React.Component<MapViewProps, State> {
return mapViewModuleMethod('getMapBoundaries')(this._getHandle());
}

setIndoorActiveLevelIndex(activeLevelIndex: number) {
if (this.map.current) {
Commands.setIndoorActiveLevelIndex(this.map.current, activeLevelIndex);
}
}

/**
* Takes a snapshot of the map and saves it to a picture
* file or returns the image as a base64 encoded string.
Expand Down
14 changes: 0 additions & 14 deletions src/MapViewNativeComponent.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
import type {HostComponent} from 'react-native';
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
import {NativeProps} from './MapView';

export type MapViewNativeComponentType = HostComponent<NativeProps>;

interface NativeCommands {
setIndoorActiveLevelIndex: (
viewRef: NonNullable<
React.RefObject<MapViewNativeComponentType>['current']
>,
activeLevelIndex: number,
) => void;
}

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

0 comments on commit 5957e44

Please sign in to comment.