react-native-maps 1.21.0-alpha.20 → 1.21.0-alpha.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -55,6 +55,7 @@
55
55
  - (void)hideCalloutView;
56
56
  - (void)addTapGestureRecognizer;
57
57
  - (void)setUseLegacyPinView:(BOOL)value;
58
+ - (void)animateToCoordinate:(CLLocationCoordinate2D)newCoordinate duration:(NSTimeInterval)duration;
58
59
 
59
60
  @end
60
61
 
@@ -30,6 +30,13 @@ NSInteger const AIR_CALLOUT_OPEN_ZINDEX_BASELINE = 999;
30
30
  BOOL _calloutIsOpen;
31
31
  NSInteger _zIndexBeforeOpen;
32
32
  BOOL _useLegacyPinView;
33
+
34
+ CADisplayLink *_displayLink;
35
+ CLLocationCoordinate2D _startCoordinate;
36
+ CLLocationCoordinate2D _endCoordinate;
37
+ NSTimeInterval _animationStartTime;
38
+ NSTimeInterval _animationDuration;
39
+ BOOL _isAnimating;
33
40
  }
34
41
 
35
42
  - (instancetype)initWithFrame:(CGRect)frame {
@@ -404,4 +411,47 @@ NSInteger const AIR_CALLOUT_OPEN_ZINDEX_BASELINE = 999;
404
411
  _useLegacyPinView = value;
405
412
  }
406
413
 
414
+ - (void)animateToCoordinate:(CLLocationCoordinate2D)newCoordinate duration:(NSTimeInterval)duration {
415
+ if (_isAnimating) {
416
+ NSLog(@"Animation already in progress. Rejecting new animation request.");
417
+ return;
418
+ }
419
+
420
+ // Mark as animating
421
+ _isAnimating = YES;
422
+
423
+ // Store animation parameters
424
+ _startCoordinate = self.coordinate;
425
+ _endCoordinate = newCoordinate;
426
+ _animationDuration = duration;
427
+ _animationStartTime = [NSDate timeIntervalSinceReferenceDate];
428
+
429
+ // Start a CADisplayLink
430
+ if (_displayLink) {
431
+ [_displayLink invalidate];
432
+ }
433
+ _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(updatePosition)];
434
+ [_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
435
+ }
436
+
437
+ - (void)updatePosition {
438
+ NSTimeInterval elapsed = [NSDate timeIntervalSinceReferenceDate] - _animationStartTime;
439
+ CGFloat progress = MIN(elapsed / _animationDuration, 1.0);
440
+
441
+ // Interpolate coordinates
442
+ CLLocationDegrees currentLatitude = _startCoordinate.latitude + progress * (_endCoordinate.latitude - _startCoordinate.latitude);
443
+ CLLocationDegrees currentLongitude = _startCoordinate.longitude + progress * (_endCoordinate.longitude - _startCoordinate.longitude);
444
+
445
+ // Update annotation's coordinate
446
+ CLLocationCoordinate2D currentCoordinate = CLLocationCoordinate2DMake(currentLatitude, currentLongitude);
447
+ [self setValue:[NSValue valueWithMKCoordinate:currentCoordinate] forKey:@"coordinate"];
448
+
449
+ // Stop the animation when complete
450
+ if (progress == 1.0) {
451
+ [_displayLink invalidate];
452
+ _displayLink = nil;
453
+ _isAnimating = NO; // Reset the animation state
454
+ }
455
+ }
456
+
407
457
  @end
@@ -295,6 +295,7 @@ export declare class MapMarker extends React.Component<MapMarkerProps> {
295
295
  getUIManagerCommand: (name: string) => UIManagerCommand;
296
296
  static Animated: Animated.AnimatedComponent<typeof MapMarker>;
297
297
  private marker;
298
+ private fabricMarker;
298
299
  constructor(props: MapMarkerProps);
299
300
  setNativeProps(props: Partial<NativeProps>): void;
300
301
  showCallout(): void;
package/lib/MapMarker.js CHANGED
@@ -28,6 +28,7 @@ const React = __importStar(require("react"));
28
28
  const react_native_1 = require("react-native");
29
29
  const decorateMapComponent_1 = __importStar(require("./decorateMapComponent"));
30
30
  const MapMarkerNativeComponent_1 = require("./MapMarkerNativeComponent");
31
+ const NativeComponentMarker_1 = require("./specs/NativeComponentMarker");
31
32
  const ProviderConstants_1 = require("./ProviderConstants");
32
33
  class MapMarker extends React.Component {
33
34
  getNativeComponent;
@@ -35,6 +36,7 @@ class MapMarker extends React.Component {
35
36
  getUIManagerCommand;
36
37
  static Animated;
37
38
  marker;
39
+ fabricMarker = false;
38
40
  constructor(props) {
39
41
  super(props);
40
42
  this.marker = React.createRef();
@@ -43,6 +45,8 @@ class MapMarker extends React.Component {
43
45
  this.setCoordinates = this.setCoordinates.bind(this);
44
46
  this.redrawCallout = this.redrawCallout.bind(this);
45
47
  this.animateMarkerToCoordinate = this.animateMarkerToCoordinate.bind(this);
48
+ const provider = this.context;
49
+ this.fabricMarker = provider !== ProviderConstants_1.PROVIDER_GOOGLE && react_native_1.Platform.OS === 'ios';
46
50
  }
47
51
  setNativeProps(props) {
48
52
  // @ts-ignore
@@ -50,27 +54,59 @@ class MapMarker extends React.Component {
50
54
  }
51
55
  showCallout() {
52
56
  if (this.marker.current) {
53
- MapMarkerNativeComponent_1.Commands.showCallout(this.marker.current);
57
+ if (this.fabricMarker) {
58
+ // @ts-ignore
59
+ NativeComponentMarker_1.Commands.showCallout(this.marker.current);
60
+ }
61
+ else {
62
+ MapMarkerNativeComponent_1.Commands.showCallout(this.marker.current);
63
+ }
54
64
  }
55
65
  }
56
66
  hideCallout() {
57
67
  if (this.marker.current) {
58
- MapMarkerNativeComponent_1.Commands.hideCallout(this.marker.current);
68
+ if (this.fabricMarker) {
69
+ // @ts-ignore
70
+ NativeComponentMarker_1.Commands.hideCallout(this.marker.current);
71
+ }
72
+ else {
73
+ MapMarkerNativeComponent_1.Commands.hideCallout(this.marker.current);
74
+ }
59
75
  }
60
76
  }
61
77
  setCoordinates(coordinate) {
62
78
  if (this.marker.current) {
63
- MapMarkerNativeComponent_1.Commands.setCoordinates(this.marker.current, coordinate);
79
+ if (this.fabricMarker) {
80
+ NativeComponentMarker_1.Commands.setCoordinates(
81
+ // @ts-ignore
82
+ this.marker.current, coordinate.latitude, coordinate.longitude);
83
+ }
84
+ else {
85
+ MapMarkerNativeComponent_1.Commands.setCoordinates(this.marker.current, coordinate);
86
+ }
64
87
  }
65
88
  }
66
89
  redrawCallout() {
67
90
  if (this.marker.current) {
68
- MapMarkerNativeComponent_1.Commands.redrawCallout(this.marker.current);
91
+ if (this.fabricMarker) {
92
+ // @ts-ignore
93
+ NativeComponentMarker_1.Commands.redrawCallout(this.marker.current);
94
+ }
95
+ else {
96
+ MapMarkerNativeComponent_1.Commands.redrawCallout(this.marker.current);
97
+ }
69
98
  }
70
99
  }
71
100
  animateMarkerToCoordinate(coordinate, duration = 500) {
72
101
  if (this.marker.current) {
73
- MapMarkerNativeComponent_1.Commands.animateMarkerToCoordinate(this.marker.current, coordinate, duration);
102
+ if (this.fabricMarker) {
103
+ NativeComponentMarker_1.Commands.animateToCoordinates(
104
+ // @ts-ignore
105
+ this.marker.current, coordinate.latitude, coordinate.longitude, duration);
106
+ }
107
+ else {
108
+ MapMarkerNativeComponent_1.Commands.animateMarkerToCoordinate(this.marker.current, coordinate, duration);
109
+ }
74
110
  }
75
111
  }
76
112
  redraw() {
@@ -86,10 +122,9 @@ class MapMarker extends React.Component {
86
122
  icon = icon.uri;
87
123
  }
88
124
  const AIRMapMarker = this.getNativeComponent();
89
- const provider = this.context;
90
125
  let image;
91
126
  if (this.props.image) {
92
- if (provider !== ProviderConstants_1.PROVIDER_GOOGLE && react_native_1.Platform.OS === 'ios') {
127
+ if (this.fabricMarker) {
93
128
  image = this.props.image;
94
129
  }
95
130
  else {
@@ -235,6 +235,7 @@ export interface MarkerFabricNativeProps extends ViewProps {
235
235
  }
236
236
  export interface NativeCommands {
237
237
  animateToCoordinates: (viewRef: React.ElementRef<React.ComponentType>, latitude: Double, longitude: Double, duration: Int32) => void;
238
+ setCoordinates: (viewRef: React.ElementRef<React.ComponentType>, latitude: Double, longitude: Double) => void;
238
239
  showCallout: (viewRef: React.ElementRef<React.ComponentType>) => void;
239
240
  hideCallout: (viewRef: React.ElementRef<React.ComponentType>) => void;
240
241
  redrawCallout: (viewRef: React.ElementRef<React.ComponentType>) => void;
@@ -8,6 +8,7 @@ const codegenNativeComponent_1 = __importDefault(require("react-native/Libraries
8
8
  const codegenNativeCommands_1 = __importDefault(require("react-native/Libraries/Utilities/codegenNativeCommands"));
9
9
  exports.Commands = (0, codegenNativeCommands_1.default)({
10
10
  supportedCommands: [
11
+ 'setCoordinates',
11
12
  'animateToCoordinates',
12
13
  'showCallout',
13
14
  'hideCallout',
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "main": "lib/index.js",
6
6
  "author": "Leland Richardson <leland.m.richardson@gmail.com>",
7
7
  "homepage": "https://github.com/react-native-maps/react-native-maps#readme",
8
- "version": "1.21.0-alpha.20",
8
+ "version": "1.21.0-alpha.21",
9
9
  "license": "MIT",
10
10
  "scripts": {
11
11
  "lint": "eslint . --max-warnings 0",