Skip to content

Commit a280a6c

Browse files
authored
Feat/allow reanimated animation markerview (#3294)
* feat: allow reanimated animation for marker view * feat: fix build error * fix lint errors
1 parent 7d7778e commit a280a6c

File tree

6 files changed

+34
-34
lines changed

6 files changed

+34
-34
lines changed

android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXMarkerViewManager.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import com.mapbox.maps.ScreenCoordinate
1616
import com.mapbox.maps.viewannotation.ViewAnnotationManager
1717
import com.rnmapbox.rnmbx.components.mapview.RNMBXMapView
1818
import com.rnmapbox.rnmbx.v11compat.annotation.*
19+
import com.rnmapbox.rnmbx.utils.LatLng
20+
import com.rnmapbox.rnmbx.utils.GeoJSONUtils.toGNPointGeometry
1921

2022
class RNMBXMarkerViewManager(reactApplicationContext: ReactApplicationContext) :
2123
AbstractEventEmitter<RNMBXMarkerView>(reactApplicationContext),
@@ -35,8 +37,9 @@ class RNMBXMarkerViewManager(reactApplicationContext: ReactApplicationContext) :
3537
}
3638

3739
@ReactProp(name = "coordinate")
38-
override fun setCoordinate(markerView: RNMBXMarkerView, geoJSONStr: Dynamic) {
39-
markerView.setCoordinate(toPointGeometry(geoJSONStr.asString()))
40+
override fun setCoordinate(markerView: RNMBXMarkerView, value: Dynamic) {
41+
val array = value.asArray()
42+
markerView.setCoordinate(toGNPointGeometry(LatLng(array.getDouble(1), array.getDouble(0))))
4043
}
4144

4245
@ReactProp(name = "anchor")

android/src/main/java/com/rnmapbox/rnmbx/utils/GeoJSONUtils.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ object GeoJSONUtils {
109109
return map
110110
}
111111

112+
@JvmStatic
113+
fun toGNPointGeometry(latLng: LatLng): Point? {
114+
return Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())
115+
}
116+
112117
fun toPointGeometry(latLng: LatLng): WritableMap {
113118
val geometry: WritableMap = WritableNativeMap()
114119
geometry.putString("type", "Point")

ios/RNMBX/RNMBXMarkerView.swift

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class RNMBXMarkerView: UIView, RNMBXMapComponent {
4242

4343
var didAddToMap = false
4444

45-
@objc public var coordinate: String? {
45+
@objc public var coordinate: Array<NSNumber>? {
4646
didSet {
4747
update()
4848
}
@@ -79,32 +79,19 @@ public class RNMBXMarkerView: UIView, RNMBXMapComponent {
7979
}
8080

8181
var point: Point? {
82-
guard let _coordinate = coordinate else {
83-
Logger.log(level: .error, message: "[getPoint] No coordinates were set")
84-
return nil
82+
guard let _lat = coordinate?[1] else {
83+
Logger.log(level: .error, message: "[getPoint] No latitude were set")
84+
return nil
8585
}
86-
87-
guard let _data = _coordinate.data(using: .utf8) else {
88-
Logger.log(level: .error, message: "[getPoint] Cannot serialize coordinate")
89-
return nil
90-
}
91-
92-
guard let _feature = try? JSONDecoder().decode(Feature.self, from: _data) else {
93-
Logger.log(level: .error, message: "[getPoint] Cannot parse serialized coordinate")
94-
return nil
86+
guard let _lon = coordinate?[0] else {
87+
Logger.log(level: .error, message: "[getPoint] No Longitude were set")
88+
return nil
9589
}
90+
91+
let coord = CLLocationCoordinate2D(
92+
latitude: Double(_lat) as CLLocationDegrees, longitude: Double(_lon) as CLLocationDegrees);
9693

97-
guard let _geometry = _feature.geometry else {
98-
Logger.log(level: .error, message: "[getPoint] Invalid geometry")
99-
return nil
100-
}
101-
102-
guard case .point(let _point) = _geometry else {
103-
Logger.log(level: .error, message: "[getPoint] Invalid point")
104-
return nil
105-
}
106-
107-
return _point
94+
return Point(coord)
10895
}
10996

11097
// MARK: - RNMBXMapComponent methods

ios/RNMBX/RNMBXMarkerViewManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
@interface RCT_EXTERN_REMAP_MODULE(RNMBXMarkerView, RNMBXMarkerViewManager, RCTViewManager)
66

7-
RCT_EXPORT_VIEW_PROPERTY(coordinate, NSString)
7+
RCT_EXPORT_VIEW_PROPERTY(coordinate, NSArray)
88
RCT_EXPORT_VIEW_PROPERTY(anchor, NSDictionary)
99
RCT_EXPORT_VIEW_PROPERTY(allowOverlap, BOOL)
1010
RCT_EXPORT_VIEW_PROPERTY(allowOverlapWithPuck, BOOL)

src/components/MarkerView.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react';
2-
import { Platform, NativeModules, type ViewProps } from 'react-native';
2+
import { NativeModules, Platform, type ViewProps } from 'react-native';
33

4+
import RNMBXMakerViewContentCoponent from '../specs/RNMBXMarkerViewContentNativeComponent';
5+
import NativeMarkerViewComponent from '../specs/RNMBXMarkerViewNativeComponent';
6+
import { type Position } from '../types/Position';
47
import { toJSONString } from '../utils';
58
import { makePoint } from '../utils/geoUtils';
6-
import { type Position } from '../types/Position';
7-
import NativeMarkerViewComponent from '../specs/RNMBXMarkerViewNativeComponent';
8-
import RNMBXMakerViewContentCoponent from '../specs/RNMBXMarkerViewContentNativeComponent';
99

1010
import PointAnnotation from './PointAnnotation';
1111

@@ -116,7 +116,10 @@ class MarkerView extends React.PureComponent<Props> {
116116
},
117117
this.props.style,
118118
]}
119-
coordinate={this._getCoordinate(this.props.coordinate)}
119+
coordinate={[
120+
Number(this.props.coordinate[0]),
121+
Number(this.props.coordinate[1]),
122+
]}
120123
anchor={anchor}
121124
allowOverlap={this.props.allowOverlap}
122125
allowOverlapWithPuck={this.props.allowOverlapWithPuck}

src/specs/RNMBXMarkerViewNativeComponent.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { HostComponent, ViewProps } from 'react-native';
2-
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
32
import { Int32 } from 'react-native/Libraries/Types/CodegenTypes';
3+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
4+
5+
import { Position } from '../types/Position';
46

57
import { UnsafeMixed } from './codegenUtils';
68

@@ -10,7 +12,7 @@ type Point = {
1012
};
1113

1214
export interface NativeProps extends ViewProps {
13-
coordinate?: UnsafeMixed<string>;
15+
coordinate?: UnsafeMixed<Position>;
1416
anchor: UnsafeMixed<Point>;
1517
allowOverlap: UnsafeMixed<boolean>;
1618
allowOverlapWithPuck: UnsafeMixed<boolean>;

0 commit comments

Comments
 (0)