Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make follow props on Camera deterministic #550

Merged
merged 117 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
9c84b59
chore: migrate BugReport example
KiwiKilian Nov 21, 2024
8782347
refactor: align GeoJSON imports
KiwiKilian Nov 21, 2024
e89406c
chore: migrate RestrictMapBounds example
KiwiKilian Nov 21, 2024
f4c0035
chore: migrate GetZoom example
KiwiKilian Nov 22, 2024
fb33c95
fix: expo android status bar color
KiwiKilian Nov 23, 2024
5be17ff
chore: simplify ShowMap example
KiwiKilian Nov 23, 2024
4dd9711
chore: cleanup more examples
KiwiKilian Nov 23, 2024
215e8bd
Merge branch 'main' into feat/typescript-examples
KiwiKilian Nov 28, 2024
96d8e69
style: fix linting
KiwiKilian Nov 28, 2024
a87d24f
fix: allow MapView and Images to have no children
KiwiKilian Nov 28, 2024
62dd347
docs: update changelog
KiwiKilian Nov 28, 2024
ba28f5d
Merge branch 'feat/optional-children' into feat/typescript-examples
KiwiKilian Nov 28, 2024
af415d2
Merge branch 'main' into feat/typescript-examples
KiwiKilian Nov 28, 2024
6b3053f
Merge branch 'main' into feat/typescript-examples
KiwiKilian Nov 28, 2024
6bd959a
chore: rename earthquakesData
KiwiKilian Nov 28, 2024
3e37439
chore: update earthquakes
KiwiKilian Nov 28, 2024
63539a5
chore: cleanup more assets
KiwiKilian Nov 28, 2024
1783087
chore: cleanup styles
KiwiKilian Nov 28, 2024
8a1c809
chore: use blue as expo splash backgroundColor
KiwiKilian Nov 29, 2024
064ff12
docs: new screenshots
KiwiKilian Nov 29, 2024
f6341d3
docs: resize screenshots
KiwiKilian Nov 29, 2024
61874d5
chore: remove duplicate example
KiwiKilian Nov 29, 2024
92142ef
chore: align example headings
KiwiKilian Nov 29, 2024
5163549
fix: use cover for splash
KiwiKilian Nov 29, 2024
9eb7a09
fix: bug report heading
KiwiKilian Nov 29, 2024
e25ffe5
Merge branch 'main' into feat/typescript-examples
KiwiKilian Dec 1, 2024
fd686ec
fix: keep plugin without build
KiwiKilian Dec 1, 2024
ece14e3
chore: further simplify examples
KiwiKilian Dec 1, 2024
0a235dd
chore: cleanup more examples
KiwiKilian Dec 1, 2024
c32923d
refactor: use sheet instead of styles
KiwiKilian Dec 2, 2024
dc47bed
refactor: reorder Camera component
KiwiKilian Dec 2, 2024
7757867
Merge branch 'beta' into fix/camera
KiwiKilian Dec 3, 2024
d2af5cb
fix: followUserLocation toggling of Camera
KiwiKilian Dec 3, 2024
463bf48
chore: add UserLocationForNavigation example
KiwiKilian Dec 3, 2024
c63687a
fix: first set camera before following user on ios
KiwiKilian Dec 3, 2024
4cc6bda
feat: upgrade and cleanup dependencies
KiwiKilian Dec 4, 2024
b98bf1e
feat: move types to optional peer dependencies
KiwiKilian Dec 5, 2024
44a7a25
chore: align gradle.properties with template
KiwiKilian Dec 5, 2024
2e864e5
chore: ignore all build directories from eslint
KiwiKilian Dec 5, 2024
e6aeb00
chore: reduce duplicate dependencies
KiwiKilian Dec 5, 2024
4b009a9
refactor: align node imports
KiwiKilian Dec 5, 2024
b5a9a39
ci: align working-directory
KiwiKilian Dec 5, 2024
ed70c1d
ci: fix working-directory
KiwiKilian Dec 5, 2024
9552bc1
ci: android try setup only in react-native-app
KiwiKilian Dec 5, 2024
67ae66e
ci: try again with default working-directory
KiwiKilian Dec 5, 2024
5444143
chore: keep jest for detox
KiwiKilian Dec 5, 2024
2d6b810
ci: try react-native build-android command
KiwiKilian Dec 5, 2024
4f218aa
ci: try running react-native through yarn
KiwiKilian Dec 5, 2024
131d1ff
ci: fix jest config e2e
KiwiKilian Dec 5, 2024
3f51dbc
ci: use npx for jest e2e
KiwiKilian Dec 5, 2024
9a04cbc
chore: upgrade ios example
KiwiKilian Dec 5, 2024
9cf5da7
ci: test maestro
KiwiKilian Dec 5, 2024
3edc27d
ci: try iPhone 15 Pro
KiwiKilian Dec 5, 2024
080a28e
ci: add maestro to path
KiwiKilian Dec 5, 2024
fe8978c
ci: debug maestro
KiwiKilian Dec 5, 2024
b007bdc
ci: test maestro path
KiwiKilian Dec 5, 2024
b3e96fd
ci: export path in test job
KiwiKilian Dec 5, 2024
c6238e2
chore: remove detox
KiwiKilian Dec 6, 2024
ff4993b
ci: use GITHUB_PATH
KiwiKilian Dec 6, 2024
c1882a9
ci: remove maestro version testing
KiwiKilian Dec 6, 2024
9d7516b
ci: setup cocoapods cache
KiwiKilian Dec 6, 2024
7f72647
ci: setup iOS build cache
KiwiKilian Dec 6, 2024
ca6f6f3
ci: separate iOS build and test
KiwiKilian Dec 6, 2024
c6a60d2
ci: improve cache keys
KiwiKilian Dec 6, 2024
abc195c
ci: fix cache and upload paths
KiwiKilian Dec 6, 2024
6689de0
ci: keep diretory structure for app
KiwiKilian Dec 6, 2024
ae85526
ci: fix pods path
KiwiKilian Dec 6, 2024
3002990
ci: debug pathes
KiwiKilian Dec 6, 2024
52f516b
ci: add Android app artifact
KiwiKilian Dec 6, 2024
d315f6e
ci: fix artifact download path
KiwiKilian Dec 6, 2024
23db283
ci: fix artifact download path
KiwiKilian Dec 6, 2024
78006cf
ci: add Android build cache
KiwiKilian Dec 6, 2024
97f4848
ci: fix android apk path
KiwiKilian Dec 6, 2024
812436c
ci: try without idb
KiwiKilian Dec 6, 2024
341a04b
ci: add Android test
KiwiKilian Dec 6, 2024
209753d
ci: use reactivecircus/android-emulator-runner@v2
KiwiKilian Dec 6, 2024
e5471bc
ci: fix android apk path
KiwiKilian Dec 6, 2024
2122b54
ci: align tests
KiwiKilian Dec 6, 2024
3f2a4eb
ci: fix apk path
KiwiKilian Dec 6, 2024
ff71fd8
test: adapt e2e test for Android
KiwiKilian Dec 6, 2024
552e45f
ci: improve android caching
KiwiKilian Dec 6, 2024
75bee7d
ci: add report upload
KiwiKilian Dec 6, 2024
671f2e8
chore: ignore report.xml
KiwiKilian Dec 6, 2024
ed38256
ci: test android workflows on macos
KiwiKilian Dec 6, 2024
e311fdc
ci: improve emulator setup
KiwiKilian Dec 6, 2024
842e723
Revert "ci: test android workflows on macos"
KiwiKilian Dec 6, 2024
b076b63
ci: keep default emulator setup
KiwiKilian Dec 6, 2024
d76bb05
ci: reorder jobs
KiwiKilian Dec 6, 2024
19dd210
ci: list emulators
KiwiKilian Dec 6, 2024
30b8f4e
ci: cache android virtual device
KiwiKilian Dec 6, 2024
048bacd
ci: remove avd list
KiwiKilian Dec 6, 2024
1381a95
ci: align emulator versions
KiwiKilian Dec 6, 2024
574d620
ci: change api-level
KiwiKilian Dec 6, 2024
8090c33
ci: try different profile
KiwiKilian Dec 6, 2024
b86bd63
ci: remove sdkmanager debugging
KiwiKilian Dec 6, 2024
21442a6
feat: upgrade gradle setup
KiwiKilian Dec 6, 2024
ee3c9b3
chore: align with scaffold
KiwiKilian Dec 8, 2024
f2b9019
fix: use old arch for RN example
KiwiKilian Dec 8, 2024
b7b0632
chore: fix typo
KiwiKilian Dec 8, 2024
63bf3fb
ci: separate Android and iOS workflow for arch matrix
KiwiKilian Dec 8, 2024
064d191
ci: adopt matrxi for tests
KiwiKilian Dec 8, 2024
eb0fa78
ci: move matrix to jobs
KiwiKilian Dec 8, 2024
53bc0d5
ci: shorten job names
KiwiKilian Dec 8, 2024
3361869
ci: add matrix to test name
KiwiKilian Dec 8, 2024
e82c78b
Merge branch 'feat/upgrades' into feat/android-gradle
KiwiKilian Dec 8, 2024
7a1c080
ci: Podfile.lock needs update for new arch
KiwiKilian Dec 8, 2024
5c313f1
fix: new arch support
KiwiKilian Dec 8, 2024
c69a4ee
Merge branch 'beta' into feat/android-gradle
KiwiKilian Dec 8, 2024
ee0a8e0
Merge branch 'beta' into fix/camera
KiwiKilian Dec 8, 2024
693cfb3
Merge branch 'feat/android-gradle' into fix/camera
KiwiKilian Dec 8, 2024
63e2976
fix: onUserTrackingModeChange on Android
KiwiKilian Dec 8, 2024
31bf4cc
style: remove unused import
KiwiKilian Dec 8, 2024
869db53
Merge branch 'beta' into fix/camera
KiwiKilian Dec 9, 2024
beb5cdb
Merge branch 'beta' into fix/camera
KiwiKilian Dec 10, 2024
27b4740
Merge branch 'beta' into fix/camera
KiwiKilian Dec 27, 2024
80ee004
chore: fix UserLocationForNavigation example
KiwiKilian Dec 27, 2024
7731384
test: adapt Camera test to setNativeProps
KiwiKilian Dec 27, 2024
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 @@ -2,6 +2,7 @@

import android.content.Context;
import android.location.Location;
import android.util.Log;

import org.maplibre.android.camera.CameraPosition;
import org.maplibre.android.camera.CameraUpdate;
Expand All @@ -11,13 +12,9 @@
import org.maplibre.android.geometry.VisibleRegion;
import org.maplibre.android.location.OnCameraTrackingChangedListener;
import org.maplibre.android.location.modes.CameraMode;
import org.maplibre.android.location.modes.RenderMode;
import org.maplibre.android.maps.MapLibreMap;
import org.maplibre.android.maps.Style;
import org.maplibre.android.location.LocationComponent;
import org.maplibre.android.location.LocationComponentOptions;
import org.maplibre.android.location.LocationComponentActivationOptions;
// import org.maplibre.android.plugins.locationlayer.LocationLayerPlugin;

import org.maplibre.reactnative.components.AbstractMapFeature;
import org.maplibre.reactnative.components.location.LocationComponentManager;
import org.maplibre.reactnative.components.mapview.MLRNMapView;
Expand All @@ -31,8 +28,6 @@
import org.maplibre.reactnative.location.UserTrackingState;
import org.maplibre.reactnative.utils.GeoJSONUtils;

import org.maplibre.reactnative.R;

import org.maplibre.reactnative.events.constants.EventTypes;

import com.facebook.react.bridge.WritableMap;
Expand Down Expand Up @@ -87,12 +82,12 @@ public class MLRNCamera extends AbstractMapFeature {
private LocationManager.OnUserLocationChange mLocationChangeListener = new LocationManager.OnUserLocationChange() {
@Override
public void onLocationChange(Location nextLocation) {
if (getMapboxMap() == null || mLocationComponentManager == null || !mLocationComponentManager.hasLocationComponent() || (!mFollowUserLocation)) {
return;
}
if (getMapboxMap() == null || mLocationComponentManager == null || !mLocationComponentManager.hasLocationComponent() || (!mFollowUserLocation)) {
return;
}

mUserLocation.setCurrentLocation(nextLocation);
sendUserLocationUpdateEvent(nextLocation);
mUserLocation.setCurrentLocation(nextLocation);
sendUserLocationUpdateEvent(nextLocation);
}
};

Expand Down Expand Up @@ -236,12 +231,7 @@ private CameraPosition getUserLocationUpdateCameraPosition(double zoomLevel) {
}
}

return new CameraPosition.Builder()
.target(center)
.bearing(getDirectionForUserLocationUpdate())
.tilt(mPitch)
.zoom(zoomLevel)
.build();
return new CameraPosition.Builder().target(center).bearing(getDirectionForUserLocationUpdate()).tilt(mPitch).zoom(zoomLevel).build();
}

private double getDirectionForUserLocationUpdate() {
Expand All @@ -260,7 +250,7 @@ private double getDirectionForUserLocationUpdate() {
}

private void sendUserLocationUpdateEvent(Location location) {
if(location == null){
if (location == null) {
return;
}
IEvent event = new MapChangeEvent(this, EventTypes.USER_LOCATION_UPDATED, makeLocationChangePayload(location));
Expand Down Expand Up @@ -376,37 +366,38 @@ private void updateLocationLayer(@NonNull Style style) {
}

mLocationComponentManager.update(style);

if (mFollowUserLocation) {
mLocationComponentManager.setCameraMode(UserTrackingMode.getCameraMode(mUserTrackingMode));
}
mLocationComponentManager.setFollowUserLocation(mFollowUserLocation);

if (mFollowUserLocation) {
mLocationComponentManager.setCameraMode(UserTrackingMode.getCameraMode(mUserTrackingMode));
mLocationComponentManager.addOnCameraTrackingChangedListener(new OnCameraTrackingChangedListener() {
@Override public void onCameraTrackingChanged(int currentMode) {
int userTrackingMode = UserTrackingMode.NONE;
switch (currentMode) {
case CameraMode.NONE:
userTrackingMode = UserTrackingMode.NONE;
break;
case CameraMode.TRACKING:
userTrackingMode = UserTrackingMode.FOLLOW;
break;
case CameraMode.TRACKING_COMPASS:
userTrackingMode = UserTrackingMode.FollowWithHeading;
break;
case CameraMode.TRACKING_GPS:
userTrackingMode = UserTrackingMode.FollowWithCourse;
break;
default:
userTrackingMode = UserTrackingMode.NONE;
}
updateUserTrackingMode(userTrackingMode);
}
@Override public void onCameraTrackingDismissed() {
@Override
public void onCameraTrackingChanged(int currentMode) {
int userTrackingMode;

switch (currentMode) {
case CameraMode.NONE:
userTrackingMode = UserTrackingMode.NONE;
break;
case CameraMode.TRACKING:
userTrackingMode = UserTrackingMode.FOLLOW;
break;
case CameraMode.TRACKING_COMPASS:
userTrackingMode = UserTrackingMode.FollowWithHeading;
break;
case CameraMode.TRACKING_GPS:
userTrackingMode = UserTrackingMode.FollowWithCourse;
break;
default:
userTrackingMode = UserTrackingMode.NONE;
}

updateUserTrackingMode(userTrackingMode);
}

@Override
public void onCameraTrackingDismissed() {
}
});
} else {
mLocationComponentManager.setCameraMode(CameraMode.NONE);
Expand All @@ -429,10 +420,7 @@ public void setZoomLevel(double zoomLevel) {
}

private CameraPosition buildCamera(CameraPosition previousPosition, boolean shouldUpdateTarget) {
CameraPosition.Builder builder = new CameraPosition.Builder(previousPosition)
.bearing(mHeading)
.tilt(mPitch)
.zoom(mZoomLevel);
CameraPosition.Builder builder = new CameraPosition.Builder(previousPosition).bearing(mHeading).tilt(mPitch).zoom(mZoomLevel);

if (shouldUpdateTarget) {
builder.target(GeoJSONUtils.toLatLng(mCenterCoordinate));
Expand Down Expand Up @@ -507,6 +495,7 @@ MapLibreMap getMapboxMap() {
/**
* Create a payload of the location data per the web api geolocation spec
* https://dev.w3.org/geo/api/spec-source.html#position
*
* @return
*/
private WritableMap makeLocationChangePayload(Location location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public LocationComponentManager(MLRNMapView mlrnMapView, Context context) {

private boolean mShowingUserLocation = false;

private OnCameraTrackingChangedListener mOnCameraTrackingChangedListener = null;

public void showUserLocation(boolean showUserLocation) {
mShowUserLocation = showUserLocation;
stateChanged();
Expand All @@ -68,16 +70,21 @@ public void setRenderMode(@RenderMode.Mode int renderMode) {
}

public void setPreferredFramesPerSecond(int preferredFramesPerSecond) {
if(mLocationComponent == null || preferredFramesPerSecond <= 0) {
if (mLocationComponent == null || preferredFramesPerSecond <= 0) {
return;
}
}

mLocationComponent.setMaxAnimationFps(preferredFramesPerSecond);
}


public void addOnCameraTrackingChangedListener(OnCameraTrackingChangedListener onCameraTrackingChangedListener) {
mLocationComponent.addOnCameraTrackingChangedListener(onCameraTrackingChangedListener);
if (mOnCameraTrackingChangedListener != null) {
mLocationComponent.removeOnCameraTrackingChangedListener(mOnCameraTrackingChangedListener);
}

mOnCameraTrackingChangedListener = onCameraTrackingChangedListener;

mLocationComponent.addOnCameraTrackingChangedListener(mOnCameraTrackingChangedListener);
}

@SuppressLint("MissingPermission")
Expand Down Expand Up @@ -111,7 +118,7 @@ public void update(@NonNull Style style) {
public void update(boolean displayUserLocation, @NonNull Style style) {
Integer tintColor = mMapView.getTintColor();

if (mLocationComponent == null || tintColor != null ) {
if (mLocationComponent == null || tintColor != null) {
mLocationComponent = mMap.getLocationComponent();

LocationComponentActivationOptions locationComponentActivationOptions = LocationComponentActivationOptions
Expand Down Expand Up @@ -148,10 +155,10 @@ LocationComponentOptions options(boolean displayUserLocation) {
.accuracyAlpha(0.0f);
} else if (tintColor != null) {
builder = builder
.enableStaleState(false)
.bearingTintColor(tintColor)
.foregroundTintColor(tintColor)
.accuracyColor(tintColor);
.enableStaleState(false)
.bearingTintColor(tintColor)
.foregroundTintColor(tintColor)
.accuracyColor(tintColor);
}
return builder.build();
}
Expand Down
13 changes: 6 additions & 7 deletions ios/MLRN/MLRNCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,6 @@ - (void)_updateCameraFromTrackingMode
return;
}

if (_map.userTrackingMode != [self _userTrackingMode]) {
_map.showsUserLocation = [self _userTrackingMode] != MLNUserTrackingModeNone;
_map.userTrackingMode = [self _userTrackingMode];
}

MLNMapCamera *camera = _map.camera;
if (_followPitch != nil && [_followPitch floatValue] >= 0.0) {
camera.pitch = [_followPitch floatValue];
Expand All @@ -202,8 +197,12 @@ - (void)_updateCameraFromTrackingMode
if (_followZoomLevel != nil && [_followZoomLevel doubleValue] >= 0.0) {
camera.altitude = [_map altitudeFromZoom:[_followZoomLevel doubleValue]];
}

[_map setCamera:camera animated:YES];

[_map setCamera:camera animated:NO];

if (_map.userTrackingMode != [self _userTrackingMode]) {
[_map setUserTrackingMode:[self _userTrackingMode] animated:NO completionHandler:nil];
}
}

- (NSUInteger)_userTrackingMode
Expand Down
4 changes: 4 additions & 0 deletions packages/examples/src/Examples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ const Examples = new ExampleGroup(
"Follow User Location Render Mode",
MapLibreExamples.FollowUserLocationRenderMode,
),
new ExampleItem(
"User Location for Navigation",
MapLibreExamples.UserLocationForNavigation,
),
new ExampleItem(
"User Location Updates",
MapLibreExamples.UserLocationUpdate,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import {
Camera,
MapView,
SymbolLayer,
UserLocation,
UserLocationRenderMode,
UserTrackingMode,
} from "@maplibre/maplibre-react-native";
import { useState } from "react";
import { Button } from "react-native";

import maplibreIcon from "../../assets/images/maplibre.png";
import { OSM_RASTER_STYLE } from "../../constants/OSM_RASTER_STYLE";
import { sheet } from "../../styles/sheet";

export function UserLocationForNavigation() {
const [navigationActive, setNavigationActive] = useState(false);

return (
<>
<Button
title={`Navigation is ${navigationActive ? "active" : "inactive"}`}
onPress={() => setNavigationActive((prevState) => !prevState)}
/>

<MapView
style={sheet.matchParent}
mapStyle={OSM_RASTER_STYLE}
contentInset={navigationActive ? [200, 0, 0, 0] : undefined}
pitchEnabled={navigationActive}
>
{navigationActive ? (
<UserLocation
renderMode={
navigationActive
? UserLocationRenderMode.Normal
: UserLocationRenderMode.Native
}
showsUserHeadingIndicator
>
<SymbolLayer
id="navigation-icon"
style={{
iconImage: maplibreIcon,
iconPitchAlignment: "map",
iconAllowOverlap: true,
}}
/>
</UserLocation>
) : null}

<Camera
followUserLocation={navigationActive}
followUserMode={
navigationActive
? UserTrackingMode.FollowWithHeading
: UserTrackingMode.Follow
}
followZoomLevel={19}
followPitch={60}
pitch={0}
onUserTrackingModeChange={(event) => {
console.log("js userTrackingModeChange");
console.log("js", event.type);
console.log("js", JSON.stringify(event.nativeEvent));

if (
navigationActive &&
!event.nativeEvent.payload.followUserLocation
) {
setNavigationActive(false);
}
}}
/>
</MapView>
</>
);
}
1 change: 1 addition & 0 deletions packages/examples/src/examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export { ShapeSourceIcon } from "./SymbolCircleLayer/ShapeSourceIcon";
// USERLOCATION
export { FollowUserLocationRenderMode } from "./UserLocation/FollowUserLocationRenderMode";
export { FollowUserLocationAlignment } from "./UserLocation/FollowUserLocationAlignment";
export { UserLocationForNavigation } from "./UserLocation/UserLocationForNavigation";
export { SetAndroidPreferredFramesPerSecond } from "./UserLocation/SetAndroidPreferredFramesPerSecond";
export { UserLocationDisplacement } from "./UserLocation/UserLocationDisplacement";
export { UserLocationUpdate } from "./UserLocation/UserLocationUpdate";
Expand Down
Loading
Loading