Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
applyMapColorSchemeToMap();
applyNightModePreference();

googleMap.setOnFollowMyLocationCallback(
new GoogleMap.OnCameraFollowLocationCallback() {
@Override
public void onCameraStartedFollowingLocation() {
WritableMap map = Arguments.createMap();
map.putBoolean("isFollowing", true);
emitEvent("onCameraFollowLocationChanged", map);
}

@Override
public void onCameraStoppedFollowingLocation() {
WritableMap map = Arguments.createMap();
map.putBoolean("isFollowing", false);
emitEvent("onCameraFollowLocationChanged", map);
}
});

emitEvent("onMapReady", null);

// Request layout to ensure fragment is properly sized
Expand Down
1 change: 1 addition & 0 deletions ios/react-native-navigation-sdk/INavigationViewCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)handleCircleClick:(GMSCircle *)circle;
- (void)handleGroundOverlayClick:(GMSGroundOverlay *)groundOverlay;
- (void)handlePromptVisibilityChanged:(BOOL)isVisible;
- (void)handleCameraFollowLocationChanged:(BOOL)isFollowing;
@end

NS_ASSUME_NONNULL_END
Expand Down
5 changes: 5 additions & 0 deletions ios/react-native-navigation-sdk/NavView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,11 @@ - (void)handleCircleClick:(GMSCircle *)circle {
self.eventEmitter.onCircleClick(result);
}

- (void)handleCameraFollowLocationChanged:(BOOL)isFollowing {
NavViewEventEmitter::OnCameraFollowLocationChanged result = {isFollowing};
self.eventEmitter.onCameraFollowLocationChanged(result);
}

- (void)handleGroundOverlayClick:(GMSGroundOverlay *)groundOverlay {
NavViewEventEmitter::OnGroundOverlayClick result = {
[ObjectTranslationUtil isIdOnUserData:groundOverlay.userData]
Expand Down
26 changes: 26 additions & 0 deletions ios/react-native-navigation-sdk/NavViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ @implementation NavViewController {
MapViewType *_mapViewType; // Nullable - must be set before loadView
id<INavigationViewCallback> _viewCallbacks;
BOOL _isSessionAttached;
BOOL _lastReportedIsFollowing;
NSNumber *_isNavigationUIEnabled;
NSNumber *_navigationUIEnabledPreference; // 0=AUTOMATIC, 1=DISABLED
NSNumber *_navigationLightingMode;
Expand Down Expand Up @@ -270,6 +271,29 @@ - (void)dealloc {

- (void)mapViewDidTapRecenterButton:(GMSMapView *)mapView {
[_viewCallbacks handleRecenterButtonClick];
dispatch_async(dispatch_get_main_queue(), ^{
[self reportFollowingStateIfChanged];
});
}

- (void)mapView:(GMSMapView *)mapView willMove:(BOOL)gesture {
if (gesture) {
dispatch_async(dispatch_get_main_queue(), ^{
[self reportFollowingStateIfChanged];
});
}
}

- (void)mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position {
[self reportFollowingStateIfChanged];
}

- (void)reportFollowingStateIfChanged {
BOOL isFollowing = (_mapView.cameraMode == GMSNavigationCameraModeFollowing);
if (_lastReportedIsFollowing != isFollowing) {
_lastReportedIsFollowing = isFollowing;
[_viewCallbacks handleCameraFollowLocationChanged:isFollowing];
}
}

- (void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker {
Expand Down Expand Up @@ -518,6 +542,7 @@ - (void)setNightMode:(NSNumber *)index {

- (void)showRouteOverview {
_mapView.cameraMode = GMSNavigationCameraModeOverview;
[self reportFollowingStateIfChanged];
}

- (void)setTripProgressBarEnabled:(BOOL)isEnabled {
Expand Down Expand Up @@ -569,6 +594,7 @@ - (void)setFollowingPerspective:(NSNumber *)index {
[_mapView setFollowingPerspective:GMSNavigationCameraPerspectiveTilted];
}
_mapView.cameraMode = GMSNavigationCameraModeFollowing;
[self reportFollowingStateIfChanged];
}

- (void)setSpeedometerEnabled:(BOOL)isEnabled {
Expand Down
1 change: 1 addition & 0 deletions src/native/NativeNavViewComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export interface NativeNavViewProps extends ViewProps {
}>;
onRecenterButtonClick?: DirectEventHandler<null>;
onPromptVisibilityChanged?: DirectEventHandler<{ visible: boolean }>;
onCameraFollowLocationChanged?: DirectEventHandler<{ isFollowing: boolean }>;
}

export type NativeNavViewType = HostComponent<NativeNavViewProps>;
Expand Down
10 changes: 10 additions & 0 deletions src/navigation/navigationView/navigationView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ export const NavigationView = (
[onPromptVisibilityChangedProp]
);

const { onCameraFollowLocationChanged: onCameraFollowLocationChangedProp } =
props;
const onCameraFollowLocationChanged = useCallback(
(event: { nativeEvent: { isFollowing: boolean } }) => {
onCameraFollowLocationChangedProp?.(event.nativeEvent.isFollowing);
},
[onCameraFollowLocationChangedProp]
);

return (
<NavView
style={props.style ?? styles.defaultStyle}
Expand Down Expand Up @@ -276,6 +285,7 @@ export const NavigationView = (
onMarkerInfoWindowTapped={onMarkerInfoWindowTapped}
onRecenterButtonClick={onRecenterButtonClick}
onPromptVisibilityChanged={onPromptVisibilityChanged}
onCameraFollowLocationChanged={onCameraFollowLocationChanged}
/>
);
};
Expand Down
8 changes: 8 additions & 0 deletions src/navigation/navigationView/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ export interface NavigationViewProps extends MapViewProps {
*/
readonly onRecenterButtonClick?: () => void;

/**
* Callback invoked when the camera enters or exits follow-my-location mode.
*
* @param isFollowing - True when the camera is following the user's location,
* false when the user has panned or zoomed away.
*/
readonly onCameraFollowLocationChanged?: (isFollowing: boolean) => void;

/**
* A callback function invoked before a Navigation SDK UI prompt
* element is about to appear and as soon as the element is removed.
Expand Down