react-native-maps 1.21.0-alpha.115 → 1.21.0-alpha.117

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.
Files changed (151) hide show
  1. package/android/src/generated/RCTAppDependencyProvider.h +25 -0
  2. package/android/src/generated/RCTAppDependencyProvider.mm +55 -0
  3. package/android/src/generated/RCTModulesConformingToProtocolsProvider.h +18 -0
  4. package/android/src/generated/RCTModulesConformingToProtocolsProvider.mm +33 -0
  5. package/android/src/generated/RCTThirdPartyComponentsProvider.h +16 -0
  6. package/android/src/generated/RCTThirdPartyComponentsProvider.mm +26 -0
  7. package/android/src/generated/ReactAppDependencyProvider.podspec +34 -0
  8. package/android/src/generated/java/com/facebook/fbreact/specs/NativeAirMapsModuleSpec.java +63 -0
  9. package/android/src/generated/java/com/facebook/react/viewmanagers/RNMapsCalloutManagerDelegate.java +35 -0
  10. package/android/src/generated/java/com/facebook/react/viewmanagers/RNMapsCalloutManagerInterface.java +17 -0
  11. package/android/src/generated/java/com/facebook/react/viewmanagers/RNMapsCircleManagerDelegate.java +49 -0
  12. package/android/src/generated/java/com/facebook/react/viewmanagers/RNMapsCircleManagerInterface.java +23 -0
  13. package/android/src/generated/java/com/facebook/react/viewmanagers/RNMapsGooglePolygonManagerDelegate.java +49 -0
  14. package/android/src/generated/java/com/facebook/react/viewmanagers/RNMapsGooglePolygonManagerInterface.java +23 -0
  15. package/android/src/generated/java/com/facebook/react/viewmanagers/RNMapsMapViewManagerDelegate.java +206 -0
  16. package/android/src/generated/java/com/facebook/react/viewmanagers/RNMapsMapViewManagerInterface.java +73 -0
  17. package/android/src/generated/java/com/facebook/react/viewmanagers/RNMapsMarkerManagerDelegate.java +104 -0
  18. package/android/src/generated/java/com/facebook/react/viewmanagers/RNMapsMarkerManagerInterface.java +39 -0
  19. package/android/src/generated/java/com/facebook/react/viewmanagers/RNMapsOverlayManagerDelegate.java +46 -0
  20. package/android/src/generated/java/com/facebook/react/viewmanagers/RNMapsOverlayManagerInterface.java +23 -0
  21. package/android/src/generated/java/com/facebook/react/viewmanagers/RNMapsPolylineManagerDelegate.java +58 -0
  22. package/android/src/generated/java/com/facebook/react/viewmanagers/RNMapsPolylineManagerInterface.java +26 -0
  23. package/android/src/generated/jni/CMakeLists.txt +36 -0
  24. package/android/src/generated/jni/RNMapsSpecs-generated.cpp +68 -0
  25. package/android/src/generated/jni/RNMapsSpecs.h +31 -0
  26. package/android/src/generated/jni/react/renderer/components/RNMapsSpecs/ComponentDescriptors.cpp +29 -0
  27. package/android/src/generated/jni/react/renderer/components/RNMapsSpecs/ComponentDescriptors.h +31 -0
  28. package/android/src/generated/jni/react/renderer/components/RNMapsSpecs/EventEmitters.cpp +977 -0
  29. package/android/src/generated/jni/react/renderer/components/RNMapsSpecs/EventEmitters.h +846 -0
  30. package/android/src/generated/jni/react/renderer/components/RNMapsSpecs/Props.cpp +193 -0
  31. package/android/src/generated/jni/react/renderer/components/RNMapsSpecs/Props.h +1223 -0
  32. package/android/src/generated/jni/react/renderer/components/RNMapsSpecs/RNMapsSpecsJSI-generated.cpp +74 -0
  33. package/android/src/generated/jni/react/renderer/components/RNMapsSpecs/RNMapsSpecsJSI.h +268 -0
  34. package/android/src/generated/jni/react/renderer/components/RNMapsSpecs/ShadowNodes.cpp +24 -0
  35. package/android/src/generated/jni/react/renderer/components/RNMapsSpecs/ShadowNodes.h +109 -0
  36. package/android/src/generated/jni/react/renderer/components/RNMapsSpecs/States.cpp +16 -0
  37. package/android/src/generated/jni/react/renderer/components/RNMapsSpecs/States.h +113 -0
  38. package/ios/AirMaps/FabricPlaceholders/PlaceHolderGoogleMapView.h +28 -0
  39. package/ios/AirMaps/FabricPlaceholders/PlaceHolderGoogleMapView.mm +68 -0
  40. package/ios/AirMaps/FabricPlaceholders/PlaceHolderPolygonView.h +25 -0
  41. package/ios/AirMaps/FabricPlaceholders/PlaceHolderPolygonView.mm +43 -0
  42. package/ios/generated/RNMapsSpecs/RCTComponentViewHelpers.h +0 -12
  43. package/ios/generated/ReactAppDependencyProvider.podspec +1 -1
  44. package/package.json +16 -18
  45. package/react-native-google-maps.podspec +29 -0
  46. package/src/AnimatedRegion.ts +169 -0
  47. package/src/Geojson.tsx +541 -0
  48. package/src/MapCallout.tsx +77 -0
  49. package/src/MapCalloutSubview.tsx +64 -0
  50. package/src/MapCircle.tsx +162 -0
  51. package/src/MapHeatmap.tsx +125 -0
  52. package/src/MapLocalTile.tsx +60 -0
  53. package/src/MapMarker.tsx +531 -0
  54. package/src/MapMarkerNativeComponent.ts +51 -0
  55. package/src/MapOverlay.tsx +156 -0
  56. package/src/MapPolygon.tsx +188 -0
  57. package/src/MapPolygon.types.ts +25 -0
  58. package/src/MapPolyline.tsx +215 -0
  59. package/src/MapUrlTile.tsx +169 -0
  60. package/src/MapView.tsx +1223 -0
  61. package/src/MapView.types.ts +212 -0
  62. package/src/MapView.web.ts +2 -0
  63. package/src/MapViewNativeComponent.ts +86 -0
  64. package/src/MapWMSTile.tsx +148 -0
  65. package/src/ProviderConstants.ts +2 -0
  66. package/src/createFabricMap.tsx +253 -0
  67. package/src/decorateMapComponent.ts +219 -0
  68. package/src/fixImageProp.ts +17 -0
  69. package/src/index.ts +52 -0
  70. package/src/sharedTypes.ts +101 -0
  71. package/src/specs/NativeAirMapsModule.ts +36 -0
  72. package/src/specs/NativeComponentCallout.ts +63 -0
  73. package/src/specs/NativeComponentCircle.ts +93 -0
  74. package/src/specs/NativeComponentGoogleMapView.ts +913 -0
  75. package/src/specs/NativeComponentGooglePolygon.ts +94 -0
  76. package/src/specs/NativeComponentMapView.ts +1091 -0
  77. package/src/specs/NativeComponentMarker.ts +326 -0
  78. package/src/specs/NativeComponentOverlay.ts +89 -0
  79. package/src/specs/NativeComponentPolyline.ts +124 -0
  80. package/ios/AirMaps/NSObject+DynamicLoad.h +0 -16
  81. package/ios/AirMaps/NSObject+DynamicLoad.m +0 -28
  82. package/lib/AnimatedRegion.d.ts +0 -19
  83. package/lib/AnimatedRegion.js +0 -134
  84. package/lib/Geojson.d.ts +0 -204
  85. package/lib/Geojson.js +0 -166
  86. package/lib/MapCallout.d.ts +0 -40
  87. package/lib/MapCallout.js +0 -51
  88. package/lib/MapCalloutSubview.d.ts +0 -34
  89. package/lib/MapCalloutSubview.js +0 -48
  90. package/lib/MapCircle.d.ts +0 -117
  91. package/lib/MapCircle.js +0 -53
  92. package/lib/MapHeatmap.d.ts +0 -78
  93. package/lib/MapHeatmap.js +0 -59
  94. package/lib/MapLocalTile.d.ts +0 -35
  95. package/lib/MapLocalTile.js +0 -44
  96. package/lib/MapMarker.d.ts +0 -322
  97. package/lib/MapMarker.js +0 -158
  98. package/lib/MapMarkerNativeComponent.d.ts +0 -15
  99. package/lib/MapMarkerNativeComponent.js +0 -15
  100. package/lib/MapOverlay.d.ts +0 -88
  101. package/lib/MapOverlay.js +0 -65
  102. package/lib/MapPolygon.d.ts +0 -140
  103. package/lib/MapPolygon.js +0 -53
  104. package/lib/MapPolygon.types.d.ts +0 -18
  105. package/lib/MapPolygon.types.js +0 -2
  106. package/lib/MapPolyline.d.ts +0 -156
  107. package/lib/MapPolyline.js +0 -53
  108. package/lib/MapUrlTile.d.ts +0 -134
  109. package/lib/MapUrlTile.js +0 -44
  110. package/lib/MapView.d.ts +0 -703
  111. package/lib/MapView.js +0 -428
  112. package/lib/MapView.types.d.ts +0 -161
  113. package/lib/MapView.types.js +0 -2
  114. package/lib/MapView.web.d.ts +0 -1
  115. package/lib/MapView.web.js +0 -9
  116. package/lib/MapViewNativeComponent.d.ts +0 -18
  117. package/lib/MapViewNativeComponent.js +0 -19
  118. package/lib/MapWMSTile.d.ts +0 -116
  119. package/lib/MapWMSTile.js +0 -44
  120. package/lib/ProviderConstants.d.ts +0 -2
  121. package/lib/ProviderConstants.js +0 -5
  122. package/lib/createFabricMap.d.ts +0 -24
  123. package/lib/createFabricMap.js +0 -188
  124. package/lib/decorateMapComponent.d.ts +0 -36
  125. package/lib/decorateMapComponent.js +0 -120
  126. package/lib/fixImageProp.d.ts +0 -4
  127. package/lib/fixImageProp.js +0 -16
  128. package/lib/index.d.ts +0 -38
  129. package/lib/index.js +0 -81
  130. package/lib/sharedTypes.d.ts +0 -81
  131. package/lib/sharedTypes.js +0 -2
  132. package/lib/sharedTypesInternal.js +0 -2
  133. package/lib/specs/NativeAirMapsModule.d.ts +0 -31
  134. package/lib/specs/NativeAirMapsModule.js +0 -4
  135. package/lib/specs/NativeComponentCallout.d.ts +0 -46
  136. package/lib/specs/NativeComponentCallout.js +0 -9
  137. package/lib/specs/NativeComponentCircle.d.ts +0 -74
  138. package/lib/specs/NativeComponentCircle.js +0 -7
  139. package/lib/specs/NativeComponentGoogleMapView.d.ts +0 -710
  140. package/lib/specs/NativeComponentGoogleMapView.js +0 -22
  141. package/lib/specs/NativeComponentGooglePolygon.d.ts +0 -75
  142. package/lib/specs/NativeComponentGooglePolygon.js +0 -7
  143. package/lib/specs/NativeComponentMapView.d.ts +0 -872
  144. package/lib/specs/NativeComponentMapView.js +0 -20
  145. package/lib/specs/NativeComponentMarker.d.ts +0 -258
  146. package/lib/specs/NativeComponentMarker.js +0 -19
  147. package/lib/specs/NativeComponentOverlay.d.ts +0 -67
  148. package/lib/specs/NativeComponentOverlay.js +0 -7
  149. package/lib/specs/NativeComponentPolyline.d.ts +0 -101
  150. package/lib/specs/NativeComponentPolyline.js +0 -7
  151. /package/{lib/sharedTypesInternal.d.ts → src/sharedTypesInternal.ts} +0 -0
@@ -0,0 +1,68 @@
1
+ //
2
+ // RNMapsGoogleMapView.mm
3
+ //
4
+ //
5
+ // Created by Salah Ghanim on 23.11.24.
6
+ // Copyright © 2024 react-native-maps. All rights reserved.
7
+ //
8
+ #include "RNMapsDefines.h"
9
+
10
+ #if HAVE_GOOGLE_MAPS == 0
11
+
12
+ #import <react/renderer/components/RNMapsSpecs/ComponentDescriptors.h>
13
+ #import <react/renderer/components/RNMapsSpecs/EventEmitters.h>
14
+ #import <react/renderer/components/RNMapsSpecs/Props.h>
15
+ #import <react/renderer/components/RNMapsSpecs/RCTComponentViewHelpers.h>
16
+ #import "RCTFabricComponentsPlugins.h"
17
+ #import <React/RCTConversions.h>
18
+ #import "PlaceHolderGoogleMapView.h"
19
+
20
+ using namespace facebook::react;
21
+
22
+
23
+ @implementation RNMapsGoogleMapView
24
+
25
+
26
+ #pragma mark - JS Commands
27
+ - (void)animateToRegion:(NSString *)regionJSON duration:(NSInteger)duration{
28
+ }
29
+ - (void)setCamera:(NSString *)cameraJSON{
30
+ }
31
+
32
+ - (void)animateCamera:(NSString *)cameraJSON duration:(NSInteger)duration{
33
+ }
34
+
35
+ - (void)fitToElements:(NSString *)edgePaddingJSON animated:(BOOL)animated {
36
+ }
37
+
38
+ - (void)fitToSuppliedMarkers:(NSString *)markersJSON edgePaddingJSON:(NSString *)edgePaddingJSON animated:(BOOL)animated {
39
+ }
40
+ - (void)fitToCoordinates:(NSString *)coordinatesJSON edgePaddingJSON:(NSString *)edgePaddingJSON animated:(BOOL)animated {
41
+
42
+ }
43
+ - (void) setIndoorActiveLevelIndex:(NSInteger)activeLevelIndex
44
+ {
45
+
46
+ }
47
+
48
+ #pragma mark - Native commands
49
+
50
+ - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args
51
+ {
52
+ }
53
+
54
+
55
+ + (ComponentDescriptorProvider)componentDescriptorProvider
56
+ {
57
+ return concreteComponentDescriptorProvider<RNMapsGoogleMapViewComponentDescriptor>();
58
+ }
59
+
60
+
61
+ @end
62
+
63
+ Class<RCTComponentViewProtocol> RNMapsGoogleMapViewCls(void)
64
+ {
65
+ return RNMapsGoogleMapView.class;
66
+ }
67
+
68
+ #endif
@@ -0,0 +1,25 @@
1
+ //
2
+ // RNMapsGoogleMapView.h
3
+ //
4
+ //
5
+ // Created by Salah Ghanim on 23.11.24.
6
+ // Copyright © 2024 react-native-maps. All rights reserved.
7
+ //
8
+ #ifdef RCT_NEW_ARCH_ENABLED
9
+ #include "RNMapsDefines.h"
10
+
11
+ #if HAVE_GOOGLE_MAPS == 0
12
+
13
+ #import <React/RCTViewComponentView.h>
14
+ #import <UIKit/UIKit.h>
15
+
16
+
17
+ NS_ASSUME_NONNULL_BEGIN
18
+ @interface RNMapsGooglePolygonView : RCTViewComponentView
19
+
20
+ @end
21
+
22
+ NS_ASSUME_NONNULL_END
23
+
24
+ #endif
25
+ #endif
@@ -0,0 +1,43 @@
1
+ //
2
+ // RNMapsGoogleMapView.mm
3
+ //
4
+ //
5
+ // Created by Salah Ghanim on 23.11.24.
6
+ // Copyright © 2024 react-native-maps. All rights reserved.
7
+ //
8
+ #include "RNMapsDefines.h"
9
+
10
+ #if HAVE_GOOGLE_MAPS == 0
11
+
12
+ #import <react/renderer/components/RNMapsSpecs/ComponentDescriptors.h>
13
+ #import <react/renderer/components/RNMapsSpecs/EventEmitters.h>
14
+ #import <react/renderer/components/RNMapsSpecs/Props.h>
15
+ #import <react/renderer/components/RNMapsSpecs/RCTComponentViewHelpers.h>
16
+
17
+ #import "RCTFabricComponentsPlugins.h"
18
+ #import <React/RCTConversions.h>
19
+ #import "PlaceHolderPolygonView.h"
20
+
21
+ using namespace facebook::react;
22
+
23
+
24
+ @interface RNMapsGooglePolygonView () <RCTRNMapsGooglePolygonViewProtocol>
25
+ @end
26
+
27
+ @implementation RNMapsGooglePolygonView
28
+
29
+
30
+
31
+ + (ComponentDescriptorProvider)componentDescriptorProvider
32
+ {
33
+ return concreteComponentDescriptorProvider<RNMapsGooglePolygonComponentDescriptor>();
34
+ }
35
+
36
+ @end
37
+
38
+ Class<RCTComponentViewProtocol> RNMapsGooglePolygonCls(void)
39
+ {
40
+ return RNMapsGooglePolygonView.class;
41
+ }
42
+
43
+ #endif
@@ -13,10 +13,6 @@
13
13
 
14
14
  NS_ASSUME_NONNULL_BEGIN
15
15
 
16
- @protocol RCTRNMapsCircleViewProtocol <NSObject>
17
-
18
- @end
19
-
20
16
  @protocol RCTRNMapsGoogleMapViewViewProtocol <NSObject>
21
17
  - (void)animateToRegion:(NSString *)regionJSON duration:(NSInteger)duration;
22
18
  - (void)setCamera:(NSString *)cameraJSON;
@@ -592,12 +588,4 @@ if ([commandName isEqualToString:@"redraw"]) {
592
588
  #endif
593
589
  }
594
590
 
595
- @protocol RCTRNMapsOverlayViewProtocol <NSObject>
596
-
597
- @end
598
-
599
- @protocol RCTRNMapsPolylineViewProtocol <NSObject>
600
-
601
- @end
602
-
603
591
  NS_ASSUME_NONNULL_END
@@ -3,7 +3,7 @@
3
3
  # This source code is licensed under the MIT license found in the
4
4
  # LICENSE file in the root directory of this source tree.
5
5
 
6
- version = "0.77.1"
6
+ version = "0.77.2"
7
7
  source = { :git => 'https://github.com/facebook/react-native.git' }
8
8
  if version == '1000.0.0'
9
9
  # This is an unpublished version, use the latest commit hash of the react-native repo, which we’re presumably in.
package/package.json CHANGED
@@ -2,10 +2,10 @@
2
2
  "name": "react-native-maps",
3
3
  "description": "React Native Mapview component for iOS + Android",
4
4
  "source": "src/index",
5
- "main": "lib/index.js",
5
+ "main": "src/index.ts",
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.115",
8
+ "version": "1.21.0-alpha.117",
9
9
  "license": "MIT",
10
10
  "scripts": {
11
11
  "lint": "eslint . --max-warnings 0",
@@ -17,11 +17,10 @@
17
17
  "release": "semantic-release",
18
18
  "bundle-install": "cd example && bundle install",
19
19
  "pod-install": "cd example/ios && bundle exec pod install",
20
- "bootstrap": "yarn --cwd example && yarn && yarn bundle-install && yarn pod-install",
21
- "prepack": "node updateCodegenConfig.js"
20
+ "bootstrap": "yarn --cwd example && yarn && yarn bundle-install && yarn pod-install"
22
21
  },
23
22
  "files": [
24
- "lib",
23
+ "src",
25
24
  "android",
26
25
  "ios",
27
26
  "react-native-maps-generated.podspec",
@@ -48,7 +47,7 @@
48
47
  ],
49
48
  "peerDependencies": {
50
49
  "react": ">= 18.3.1",
51
- "react-native": ">= 0.77.1",
50
+ "react-native": ">= 0.76.0",
52
51
  "react-native-web": ">= 0.11"
53
52
  },
54
53
  "peerDependenciesMeta": {
@@ -57,22 +56,21 @@
57
56
  }
58
57
  },
59
58
  "devDependencies": {
60
- "@babel/core": "^7.26.9",
61
- "@babel/preset-env": "^7.26.9",
62
- "@babel/runtime": "^7.26.9",
59
+ "@babel/core": "^7.25.2",
60
+ "@babel/preset-env": "^7.25.3",
61
+ "@babel/runtime": "^7.25.0",
63
62
  "@commitlint/cli": "17.6.1",
64
63
  "@commitlint/config-conventional": "17.6.1",
65
- "@react-native-community/cli": "15.1.3",
66
- "@react-native/babel-preset": "0.77.1",
67
- "@react-native/eslint-config": "0.77.1",
68
- "@react-native/metro-config": "0.77.1",
69
- "@react-native/typescript-config": "0.77.1",
64
+ "@react-native-community/cli": "15.0.1",
65
+ "@react-native/babel-preset": "0.76.8",
66
+ "@react-native/eslint-config": "0.76.8",
67
+ "@react-native/metro-config": "0.76.8",
68
+ "@react-native/typescript-config": "0.76.8",
70
69
  "@semantic-release/changelog": "6.0.3",
71
70
  "@semantic-release/git": "10.0.1",
72
- "@types/jest": "29.5.14",
73
71
  "@types/react": "^18.2.6",
74
- "@types/react-native": "0.73.0",
75
72
  "@types/react-test-renderer": "^18.0.0",
73
+ "babel-jest": "^29.6.3",
76
74
  "eslint": "^8.19.0",
77
75
  "husky": "8.0.3",
78
76
  "jest": "^29.6.3",
@@ -96,10 +94,10 @@
96
94
  "codegenConfig": {
97
95
  "name": "RNMapsSpecs",
98
96
  "type": "all",
99
- "jsSrcsDir": "./lib/specs",
97
+ "jsSrcsDir": "./src/specs",
100
98
  "outputDir": {
101
99
  "ios": "ios/generated",
102
- "android": "android/generated"
100
+ "android": "android/src/generated"
103
101
  },
104
102
  "includesGeneratedCode": true,
105
103
  "android": {
@@ -22,4 +22,33 @@ Pod::Spec.new do |s|
22
22
  s.dependency 'Google-Maps-iOS-Utils', '6.1.0'
23
23
  s.dependency 'react-native-maps-generated'
24
24
  install_modules_dependencies(s)
25
+
26
+ # Add script phase to detect Google Maps
27
+ s.script_phases = [
28
+ {
29
+ :name => 'Check react-native-google-maps Availability',
30
+ :script => %(
31
+ GOOGLE_MAPS_HEADER_PATH="$PODS_ROOT/Headers/Public/react-native-google-maps/GoogleMaps.h"
32
+ DEFINES_FILE="$CONFIGURATION_BUILD_DIR/react-native-maps/RNMapsDefines.h"
33
+
34
+ # Ensure the defines file directory exists
35
+ mkdir -p "$(dirname "$DEFINES_FILE")"
36
+
37
+ # Check if Google Maps header exists
38
+ if [ -f "$GOOGLE_MAPS_HEADER_PATH" ]; then
39
+ echo "#define HAVE_GOOGLE_MAPS 1" > "$DEFINES_FILE"
40
+ echo "Google Maps detected. HAVE_GOOGLE_MAPS defined."
41
+ else
42
+ echo "#define HAVE_GOOGLE_MAPS 0" > "$DEFINES_FILE"
43
+ echo "Google Maps not detected."
44
+ fi
45
+ ),
46
+ :execution_position => :before_compile
47
+ }
48
+ ]
49
+
50
+ # Add the generated defines header to the header search path
51
+ s.pod_target_xcconfig = {
52
+ 'HEADER_SEARCH_PATHS' => '$(CONFIGURATION_BUILD_DIR)/react-native-maps'
53
+ }
25
54
  end
@@ -0,0 +1,169 @@
1
+ import {Animated} from 'react-native';
2
+ import {Region} from './sharedTypes';
3
+
4
+ const AnimatedWithChildren = Object.getPrototypeOf(Animated.ValueXY);
5
+ if (__DEV__) {
6
+ if (AnimatedWithChildren.name !== 'AnimatedWithChildren') {
7
+ console.error(
8
+ 'AnimatedRegion could not obtain AnimatedWithChildren base class',
9
+ );
10
+ }
11
+ }
12
+
13
+ const configTypes: (keyof Region)[] = [
14
+ 'latitude',
15
+ 'longitude',
16
+ 'latitudeDelta',
17
+ 'longitudeDelta',
18
+ ];
19
+
20
+ const defaultValues = {
21
+ // probably want to come up with better defaults
22
+ latitude: 0,
23
+ longitude: 0,
24
+ latitudeDelta: 0,
25
+ longitudeDelta: 0,
26
+ };
27
+
28
+ let _uniqueId = 1;
29
+
30
+ type TValueIn = number | Animated.Value | undefined;
31
+
32
+ type Props = Partial<Region> | undefined;
33
+
34
+ const getAnimatedValue = (valueIn: TValueIn, fallback: number) => {
35
+ if (valueIn instanceof Animated.Value) {
36
+ return valueIn;
37
+ } else if (typeof valueIn === 'number') {
38
+ return new Animated.Value(valueIn);
39
+ }
40
+ return new Animated.Value(fallback);
41
+ };
42
+
43
+ export default class AnimatedMapRegion extends AnimatedWithChildren {
44
+ constructor(valueIn: Props = {}) {
45
+ super();
46
+ this.latitude = getAnimatedValue(valueIn.latitude, defaultValues.latitude);
47
+ this.longitude = getAnimatedValue(
48
+ valueIn.longitude,
49
+ defaultValues.longitude,
50
+ );
51
+ this.latitudeDelta = getAnimatedValue(
52
+ valueIn.latitudeDelta,
53
+ defaultValues.latitudeDelta,
54
+ );
55
+ this.longitudeDelta = getAnimatedValue(
56
+ valueIn.longitudeDelta,
57
+ defaultValues.longitudeDelta,
58
+ );
59
+ this._regionListeners = {};
60
+ }
61
+
62
+ setValue(value: Region) {
63
+ this.latitude._value = value.latitude;
64
+ this.longitude._value = value.longitude;
65
+ this.latitudeDelta._value = value.latitudeDelta;
66
+ this.longitudeDelta._value = value.longitudeDelta;
67
+ }
68
+
69
+ setOffset(offset: Region) {
70
+ this.latitude.setOffset(offset.latitude);
71
+ this.longitude.setOffset(offset.longitude);
72
+ this.latitudeDelta.setOffset(offset.latitudeDelta);
73
+ this.longitudeDelta.setOffset(offset.longitudeDelta);
74
+ }
75
+
76
+ flattenOffset() {
77
+ this.latitude.flattenOffset();
78
+ this.longitude.flattenOffset();
79
+ this.latitudeDelta.flattenOffset();
80
+ this.longitudeDelta.flattenOffset();
81
+ }
82
+
83
+ private __getValue() {
84
+ return {
85
+ latitude: this.latitude.__getValue(),
86
+ longitude: this.longitude.__getValue(),
87
+ latitudeDelta: this.latitudeDelta.__getValue(),
88
+ longitudeDelta: this.longitudeDelta.__getValue(),
89
+ };
90
+ }
91
+
92
+ private __attach() {
93
+ this.latitude.__addChild(this);
94
+ this.longitude.__addChild(this);
95
+ this.latitudeDelta.__addChild(this);
96
+ this.longitudeDelta.__addChild(this);
97
+ }
98
+
99
+ private __detach() {
100
+ this.latitude.__removeChild(this);
101
+ this.longitude.__removeChild(this);
102
+ this.latitudeDelta.__removeChild(this);
103
+ this.longitudeDelta.__removeChild(this);
104
+ }
105
+
106
+ stopAnimation(callback: (region: Region) => void) {
107
+ this.latitude.stopAnimation();
108
+ this.longitude.stopAnimation();
109
+ this.latitudeDelta.stopAnimation();
110
+ this.longitudeDelta.stopAnimation();
111
+ callback && callback(this.__getValue());
112
+ }
113
+
114
+ addListener(callback: (region: Region) => void) {
115
+ const id = String(_uniqueId++);
116
+ const jointCallback = () => /*{value}*/ callback(this.__getValue());
117
+ this._regionListeners[id] = {
118
+ latitude: this.latitude.addListener(jointCallback),
119
+ longitude: this.longitude.addListener(jointCallback),
120
+ latitudeDelta: this.latitudeDelta.addListener(jointCallback),
121
+ longitudeDelta: this.longitudeDelta.addListener(jointCallback),
122
+ };
123
+ return id;
124
+ }
125
+
126
+ removeListener(id: string) {
127
+ this.latitude.removeListener(this._regionListeners[id].latitude);
128
+ this.longitude.removeListener(this._regionListeners[id].longitude);
129
+ this.latitudeDelta.removeListener(this._regionListeners[id].latitudeDelta);
130
+ this.longitudeDelta.removeListener(
131
+ this._regionListeners[id].longitudeDelta,
132
+ );
133
+ delete this._regionListeners[id];
134
+ }
135
+
136
+ spring(config: Animated.SpringAnimationConfig & Region) {
137
+ const animations = [];
138
+ for (const type of configTypes) {
139
+ if (config.hasOwnProperty(type)) {
140
+ animations.push(
141
+ Animated.spring(this[type], {
142
+ ...config,
143
+ toValue: config[type],
144
+ // may help to eliminate some dev warnings and perf issues
145
+ useNativeDriver: !!config?.useNativeDriver,
146
+ }),
147
+ );
148
+ }
149
+ }
150
+ return Animated.parallel(animations);
151
+ }
152
+
153
+ timing(config: Animated.TimingAnimationConfig & Region) {
154
+ const animations = [];
155
+ for (const type of configTypes) {
156
+ if (config.hasOwnProperty(type)) {
157
+ animations.push(
158
+ Animated.timing(this[type], {
159
+ ...config,
160
+ toValue: config[type],
161
+ // may help to eliminate some dev warnings and perf issues
162
+ useNativeDriver: !!config?.useNativeDriver,
163
+ }),
164
+ );
165
+ }
166
+ }
167
+ return Animated.parallel(animations);
168
+ }
169
+ }