Skip to content

Commit

Permalink
feat(ios): add isGesture support to onRegionChange and onRegionChange…
Browse files Browse the repository at this point in the history
…Complete for iOS (#5022)
  • Loading branch information
stijnstroeve committed May 4, 2024
1 parent 5498123 commit 12a0cbc
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 22 deletions.
44 changes: 22 additions & 22 deletions docs/mapview.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,28 @@

To access event data, you will need to use `e.nativeEvent`. For example, `onPress={e => console.log(e.nativeEvent)}` will log the entire event object to your console.

| Event Name | Returns | Notes |
| ------------------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `onCalloutPress` | | Callback that is called when a callout is tapped by the user. |
| `onDoublePress` | `{ coordinate: LatLng, position: Point }` | Callback that is called when user double taps on the map. **NOTE**: Not supported on Google Maps iOS |
| `onIndoorBuildingFocused` | `IndoorBuilding` | Callback that is called when a indoor building is focused/unfocused |
| `onIndoorLevelActivated` | `IndoorLevel` | Callback that is called when a level on indoor building is activated |
| `onKmlReady` | `KmlContainer` | Callback that is called once the kml is fully loaded. |
| `onLongPress` | `{ coordinate: LatLng, position: Point }` | Callback that is called when user makes a "long press" somewhere on the map. |
| `onMapReady` | | Callback that is called once the map is fully loaded. |
| `onMarkerDeselect` | | Callback that is called when a marker on the map becomes deselected. This will be called when the callout for that marker is about to be hidden. **Note**: iOS only. |
| `onMarkerDrag` | `{ coordinate: LatLng, position: Point }` | Callback called continuously as a marker is dragged |
| `onMarkerDragEnd` | `{ coordinate: LatLng, position: Point }` | Callback that is called when a drag on a marker finishes. This is usually the point you will want to setState on the marker's coordinate again |
| `onMarkerDragStart` | `{ coordinate: LatLng, position: Point }` | Callback that is called when the user initiates a drag on a marker (if it is draggable) |
| `onMarkerPress` | | Callback that is called when a marker on the map is tapped by the user. |
| `onMarkerSelect` | | Callback that is called when a marker on the map becomes selected. This will be called when the callout for that marker is about to be shown. **Note**: iOS only. |
| `onPanDrag` | `{ coordinate: LatLng, position: Point }` | Callback that is called when user presses and drags the map. **NOTE**: for iOS `scrollEnabled` should be set to false to trigger the event |
| `onPoiClick` | `{ coordinate: LatLng, position: Point, placeId: string, name: string }` | Callback that is called when user click on a POI. |
| `onPress` | `{ coordinate: LatLng, position: Point }` | Callback that is called when user taps on the map. |
| `onRegionChange` | (`Region`, `{isGesture: boolean}`) | Callback that is called continuously when the region changes, such as when a user is dragging the map. The second parameter is an object containing more details about the move. `isGesture` property indicates if the move was from the user (true) or an animation (false). **Note**: `isGesture` is supported by Google Maps only. |
| `onRegionChangeComplete` | (`Region`, `{isGesture: boolean}`) | Callback that is called once when the region changes, such as when the user is done moving the map. The second parameter is an object containing more details about the move. `isGesture` property indicates if the move was from the user (true) or an animation (false). **Note**: `isGesture` is supported by Google Maps only. |
| `onTilesRendered` | | Callback that is called everytime all tiles have been rendered (or failed permanently) after new tiles are required. **NOTE**: for Android the callback will only be invoked once, after rendering the first time. |
| `onUserLocationChange` | `{ coordinate: Location }` | Callback that is called when the underlying map figures our users current location (coordinate also includes isFromMockProvider value for Android API 18 and above). Make sure **showsUserLocation** is set to _true_. |
| Event Name | Returns | Notes |
| ------------------------- | ------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `onCalloutPress` | | Callback that is called when a callout is tapped by the user. |
| `onDoublePress` | `{ coordinate: LatLng, position: Point }` | Callback that is called when user double taps on the map. **NOTE**: Not supported on Google Maps iOS |
| `onIndoorBuildingFocused` | `IndoorBuilding` | Callback that is called when a indoor building is focused/unfocused |
| `onIndoorLevelActivated` | `IndoorLevel` | Callback that is called when a level on indoor building is activated |
| `onKmlReady` | `KmlContainer` | Callback that is called once the kml is fully loaded. |
| `onLongPress` | `{ coordinate: LatLng, position: Point }` | Callback that is called when user makes a "long press" somewhere on the map. |
| `onMapReady` | | Callback that is called once the map is fully loaded. |
| `onMarkerDeselect` | | Callback that is called when a marker on the map becomes deselected. This will be called when the callout for that marker is about to be hidden. **Note**: iOS only. |
| `onMarkerDrag` | `{ coordinate: LatLng, position: Point }` | Callback called continuously as a marker is dragged |
| `onMarkerDragEnd` | `{ coordinate: LatLng, position: Point }` | Callback that is called when a drag on a marker finishes. This is usually the point you will want to setState on the marker's coordinate again |
| `onMarkerDragStart` | `{ coordinate: LatLng, position: Point }` | Callback that is called when the user initiates a drag on a marker (if it is draggable) |
| `onMarkerPress` | | Callback that is called when a marker on the map is tapped by the user. |
| `onMarkerSelect` | | Callback that is called when a marker on the map becomes selected. This will be called when the callout for that marker is about to be shown. **Note**: iOS only. |
| `onPanDrag` | `{ coordinate: LatLng, position: Point }` | Callback that is called when user presses and drags the map. **NOTE**: for iOS `scrollEnabled` should be set to false to trigger the event |
| `onPoiClick` | `{ coordinate: LatLng, position: Point, placeId: string, name: string }` | Callback that is called when user click on a POI. |
| `onPress` | `{ coordinate: LatLng, position: Point }` | Callback that is called when user taps on the map. |
| `onRegionChange` | (`Region`, `{isGesture: boolean}`) | Callback that is called continuously when the region changes, such as when a user is dragging the map. The second parameter is an object containing more details about the move. `isGesture` property indicates if the move was from the user (true) or an animation (false). |
| `onRegionChangeComplete` | (`Region`, `{isGesture: boolean}`) | Callback that is called once when the region changes, such as when the user is done moving the map. The second parameter is an object containing more details about the move. `isGesture` property indicates if the move was from the user (true) or an animation (false). |
| `onTilesRendered` | | Callback that is called everytime all tiles have been rendered (or failed permanently) after new tiles are required. **NOTE**: for Android the callback will only be invoked once, after rendering the first time. |
| `onUserLocationChange` | `{ coordinate: Location }` | Callback that is called when the underlying map figures our users current location (coordinate also includes isFromMockProvider value for Android API 18 and above). Make sure **showsUserLocation** is set to _true_. |

## Methods

Expand Down
1 change: 1 addition & 0 deletions ios/Maps/RNMMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extern const NSInteger RNMMapMaxZoomLevel;
@property (nonatomic, assign) BOOL ignoreRegionChanges;
@property (nonatomic, assign) BOOL mapLoaded;
@property (nonatomic, assign) BOOL userLocationCalloutEnabled;
@property (nonatomic, assign) BOOL mapChangedFromUserInteraction;
@property (nonatomic, assign) CGFloat maxDelta;
@property (nonatomic, assign) CGFloat maxZoomLevel;
@property (nonatomic, assign) CGFloat minDelta;
Expand Down
11 changes: 11 additions & 0 deletions ios/Maps/RNMMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ - (instancetype)init
self.minZoomLevel = 0;
self.maxZoomLevel = RNMMapMaxZoomLevel;
self.compassOffset = CGPointMake(0, 0);
self.mapChangedFromUserInteraction = NO;
}
return self;
}
Expand Down Expand Up @@ -405,6 +406,11 @@ - (void)setRegion:(MKCoordinateRegion)region animated:(BOOL)animated
region.span.longitudeDelta = self.region.span.longitudeDelta;
}

// If the region was changed with an animation, there is no way it was a user interaction
if (animated) {
self.mapChangedFromUserInteraction = NO;
}

// Animate/move to new position
[super setRegion:region animated:animated];
}
Expand All @@ -418,6 +424,11 @@ - (void)setInitialRegion:(MKCoordinateRegion)initialRegion {

- (void)setCamera:(MKMapCamera*)camera animated:(BOOL)animated
{
// If the camera was changed with an animation, there is no way it was a user interaction
if (animated) {
self.mapChangedFromUserInteraction = NO;
}

[super setCamera:camera animated:animated];
}

Expand Down

0 comments on commit 12a0cbc

Please sign in to comment.