Skip to content

Commit

Permalink
[fix] heading not working on CustomLocationProvider (#3171)
Browse files Browse the repository at this point in the history
* [android] add heading to custom location provider

* [ios] add heading to custom location provider

* export CameraStop
  • Loading branch information
g4rb4g3 authored Nov 14, 2023
1 parent 17dab8a commit 006323a
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ class RNMBXCustomLocationProviderManager : ViewGroupManager<RNMBXCustomLocationP
}
}

@ReactProp(name = "heading")
override fun setHeading(view: RNMBXCustomLocationProvider, value: Dynamic?) {
if (value?.type == ReadableType.Number) {
view.heading = value.asDouble()
} else {
Logger.e(LOG_TAG, "heading is expected to be a number")
}
}

override fun onAfterUpdateTransaction(view: RNMBXCustomLocationProvider) {
super.onAfterUpdateTransaction(view)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public void setProperty(T view, String propName, @Nullable Object value) {
case "coordinate":
mViewManager.setCoordinate(view, new DynamicFromObject(value));
break;
case "heading":
mViewManager.setHeading(view, new DynamicFromObject(value));
break;
default:
super.setProperty(view, propName, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@

public interface RNMBXCustomLocationProviderManagerInterface<T extends View> {
void setCoordinate(T view, Dynamic value);
void setHeading(T view, Dynamic value);
}
39 changes: 39 additions & 0 deletions docs/CustomLocationProvider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!-- This file was autogenerated from CustomLocationProvider.tsx do not modify -->



```tsx
import { CustomLocationProvider } from '@rnmapbox/maps';

CustomLocationProvider

```


## props


### coordinate

```tsx
Position
```
longitude and latitude to use for the custom location provider that gets applied to the NativeUserLocation



### heading

```tsx
number
```
heading/bearing to use for custom location provider that gets applied to the NativeUserLocation









2 changes: 1 addition & 1 deletion docs/NativeUserLocation.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ The name of image to use as the middle layer for the location indicator. Images
```tsx
string
```
The name of image asset to use as the background0 for the location indicator. Images component should define this image.
The name of image to use as the background for the location indicator. Images component should define this image.



Expand Down
11 changes: 9 additions & 2 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,14 @@
"required": false,
"type": "Position",
"default": "none",
"description": "FIX ME NO DESCRIPTION"
"description": "longitude and latitude to use for the custom location provider that gets applied to the NativeUserLocation"
},
{
"name": "heading",
"required": false,
"type": "number",
"default": "none",
"description": "heading/bearing to use for custom location provider that gets applied to the NativeUserLocation"
}
],
"fileNameWithExt": "CustomLocationProvider.tsx",
Expand Down Expand Up @@ -4169,7 +4176,7 @@
"required": false,
"type": "string",
"default": "none",
"description": "The name of image asset to use as the background0 for the location indicator. Images component should define this image."
"description": "The name of image to use as the background for the location indicator. Images component should define this image."
},
{
"name": "scale",
Expand Down
7 changes: 6 additions & 1 deletion ios/RNMBX/RNMBXCustomLocationProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public class RNMBXCustomLocationProvider: UIView, RNMBXMapComponent {
public var coordinate: [Double] = [] {
didSet { changed(.coordinate) }
}

@objc
public var heading: NSNumber = 0.0 {
didSet { changed(.heading) }
}

func changed(_ property: Property) {
changes.add(name: property.rawValue, update: property.apply)
Expand Down Expand Up @@ -50,7 +55,7 @@ public class RNMBXCustomLocationProvider: UIView, RNMBXMapComponent {
}

private func applyHeading() {
// updateHeading()
updateHeading(heading: heading.doubleValue)
}

func removeFromMap(_ map: RNMBXMapView, reason: RemovalReason) -> Bool {
Expand Down
1 change: 1 addition & 0 deletions ios/RNMBX/RNMBXCustomLocationProviderViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ @interface RCT_EXTERN_REMAP_MODULE(RNMBXCustomLocationProvider, RNMBXCustomLocat

// circle layer props
RCT_EXPORT_VIEW_PROPERTY(coordinate, NSArray)
RCT_EXPORT_VIEW_PROPERTY(heading, NSNumber)

@end
1 change: 1 addition & 0 deletions src/Mapbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export {
type CameraPadding,
type CameraAnimationMode,
type CameraBounds,
type CameraStop,
} from './components/Camera';
export { Atmosphere } from './components/Atmosphere';
export { default as MapView, type MapState } from './components/MapView';
Expand Down
8 changes: 8 additions & 0 deletions src/components/CustomLocationProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import RNMBXCustomLocationProvider from '../specs/RNMBXCustomLocationProviderNat
import { Position } from '../types/Position';

export type Props = {
/**
* longitude and latitude to use for the custom location provider that gets applied to the NativeUserLocation
*/
coordinate?: Position;

/**
* heading/bearing to use for custom location provider that gets applied to the NativeUserLocation
*/
heading?: number;
};

const CustomLocationProvider = memo((props: Props) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/NativeUserLocation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export type Props = {
bearingImage?: string;

/**
* The name of image asset to use as the background0 for the location indicator. Images component should define this image.
* The name of image to use as the background for the location indicator. Images component should define this image.
*/
shadowImage?: string;

Expand Down Expand Up @@ -81,7 +81,7 @@ const NativeUserLocation = memo((props: Props) => {
let baseProps: NativeProps = { ...defaultProps };
if (iosShowsUserHeadingIndicator) {
console.warn(
'NativeUserLocation: iosShowsUserHeadingIndicator is deprecated, use puckBearingEnabled={true} puckBrearing="heading" instead',
'NativeUserLocation: iosShowsUserHeadingIndicator is deprecated, use puckBearingEnabled={true} puckBearing="heading" instead',
);
baseProps = {
...baseProps,
Expand Down
2 changes: 2 additions & 0 deletions src/specs/RNMBXCustomLocationProviderNativeComponent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { HostComponent, ViewProps } from 'react-native';
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
import { Double } from 'react-native/Libraries/Types/CodegenTypes';

import type { Position } from '../types/Position';

Expand All @@ -10,6 +11,7 @@ type OptionalProp<T> = UnsafeMixed<T>;

export interface NativeProps extends ViewProps {
coordinate?: OptionalProp<Position>;
heading?: OptionalProp<Double>;
}

export default codegenNativeComponent<NativeProps>(
Expand Down

0 comments on commit 006323a

Please sign in to comment.