|
1 |
| -import { createContext } from 'react'; |
2 | 1 | import type { HostComponent } from 'react-native';
|
3 |
| -// import { PROVIDER_DEFAULT, PROVIDER_GOOGLE } from './ProviderConstants'; |
4 |
| -import type { Provider } from './sharedTypes'; |
5 |
| -// import type { MapCallout } from './MapCallout'; |
6 |
| -// import type { MapOverlay } from './MapOverlay'; |
7 |
| -// import type { MapCalloutSubview } from './MapCalloutSubview'; |
8 |
| -// import type { MapCircle } from './MapCircle'; |
9 |
| -// import type { MapHeatmap } from './MapHeatmap'; |
10 |
| -// import type { MapLocalTile } from './MapLocalTile'; |
11 |
| -// import type { MapMarker } from './MapMarker'; |
12 |
| -// import type { MapPolygon } from './MapPolygon'; |
13 |
| -// import type { MapPolyline } from './MapPolyline'; |
14 |
| -// import type { MapUrlTile } from './MapUrlTile'; |
15 |
| -// import type { MapWMSTile } from './MapWMSTile'; |
16 |
| - |
17 |
| -export const SUPPORTED: ImplementationStatus = 'SUPPORTED'; |
18 |
| -export const USES_DEFAULT_IMPLEMENTATION: ImplementationStatus = |
19 |
| - 'USES_DEFAULT_IMPLEMENTATION'; |
20 |
| -export const NOT_SUPPORTED: ImplementationStatus = 'NOT_SUPPORTED'; |
21 |
| - |
22 |
| -export const ProviderContext = createContext<Provider>(undefined); |
23 |
| - |
24 |
| -// export function getNativeMapName(provider: Provider) { |
25 |
| -// if (Platform.OS === 'android') { |
26 |
| -// return 'AIRMap'; |
27 |
| -// } |
28 |
| -// if (provider === PROVIDER_GOOGLE) { |
29 |
| -// return 'AIRGoogleMap'; |
30 |
| -// } |
31 |
| -// return 'AIRMap'; |
32 |
| -// } |
33 |
| - |
34 |
| -// function getNativeComponentName(provider: Provider, component: ComponentName) { |
35 |
| -// return `${getNativeMapName(provider)}${component}`; |
36 |
| -// } |
37 | 2 |
|
38 | 3 | export const createNotSupportedComponent = (message: string) => () => {
|
39 | 4 | console.error(message);
|
40 | 5 | return null;
|
41 | 6 | };
|
42 | 7 |
|
43 |
| -// export const googleMapIsInstalled = !!UIManager.getViewManagerConfig( |
44 |
| -// getNativeMapName(PROVIDER_GOOGLE) |
45 |
| -// ); |
46 |
| - |
47 |
| -// export default function decorateMapComponent<Type extends Component>( |
48 |
| -// Component: Type, |
49 |
| -// componentName: ComponentName, |
50 |
| -// providers: Providers |
51 |
| -// ): Type { |
52 |
| -// const components: { |
53 |
| -// [key: string]: NativeComponent; |
54 |
| -// } = {}; |
55 |
| - |
56 |
| -// const getDefaultComponent = () => |
57 |
| -// requireNativeComponent(getNativeComponentName(undefined, componentName)); |
58 |
| - |
59 |
| -// Component.contextType = ProviderContext; |
60 |
| - |
61 |
| -// Component.prototype.getNativeComponent = |
62 |
| -// function getNativeComponent(): NativeComponent { |
63 |
| -// const provider = this.context; |
64 |
| -// const key = provider || 'default'; |
65 |
| -// if (components[key]) { |
66 |
| -// return components[key]; |
67 |
| -// } |
68 |
| - |
69 |
| -// if (provider === PROVIDER_DEFAULT) { |
70 |
| -// components[key] = getDefaultComponent(); |
71 |
| -// return components[key]; |
72 |
| -// } |
73 |
| - |
74 |
| -// const providerInfo = providers[provider]; |
75 |
| -// // quick fix. Previous code assumed android | ios |
76 |
| -// if (Platform.OS !== 'android' && Platform.OS !== 'ios') { |
77 |
| -// throw new Error(`react-native-maps doesn't support ${Platform.OS}`); |
78 |
| -// } |
79 |
| -// const platformSupport = providerInfo[Platform.OS]; |
80 |
| -// const nativeComponentName = getNativeComponentName( |
81 |
| -// provider, |
82 |
| -// componentName |
83 |
| -// ); |
84 |
| -// if (platformSupport === NOT_SUPPORTED) { |
85 |
| -// components[key] = createNotSupportedComponent( |
86 |
| -// `react-native-maps: ${nativeComponentName} is not supported on ${Platform.OS}` |
87 |
| -// ); |
88 |
| -// } else if (platformSupport === SUPPORTED) { |
89 |
| -// if ( |
90 |
| -// provider !== PROVIDER_GOOGLE || |
91 |
| -// (Platform.OS === 'ios' && googleMapIsInstalled) |
92 |
| -// ) { |
93 |
| -// components[key] = requireNativeComponent(nativeComponentName); |
94 |
| -// } |
95 |
| -// } else { |
96 |
| -// // (platformSupport === USES_DEFAULT_IMPLEMENTATION) |
97 |
| -// if (!components.default) { |
98 |
| -// components.default = getDefaultComponent(); |
99 |
| -// } |
100 |
| -// components[key] = components.default; |
101 |
| -// } |
102 |
| - |
103 |
| -// return components[key]; |
104 |
| -// }; |
105 |
| - |
106 |
| -// Component.prototype.getUIManagerCommand = function getUIManagerCommand( |
107 |
| -// name: string |
108 |
| -// ): UIManagerCommand { |
109 |
| -// const nativeComponentName = getNativeComponentName( |
110 |
| -// this.context, |
111 |
| -// componentName |
112 |
| -// ); |
113 |
| -// return UIManager.getViewManagerConfig(nativeComponentName).Commands[name]; |
114 |
| -// }; |
115 |
| - |
116 |
| -// Component.prototype.getMapManagerCommand = function getMapManagerCommand( |
117 |
| -// name: string |
118 |
| -// ): MapManagerCommand { |
119 |
| -// const nativeComponentName = `${getNativeComponentName( |
120 |
| -// this.context, |
121 |
| -// componentName |
122 |
| -// )}Manager`; |
123 |
| -// return NativeModules[nativeComponentName][name]; |
124 |
| -// }; |
125 |
| - |
126 |
| -// return Component; |
127 |
| -// } |
128 |
| - |
129 |
| -type ImplementationStatus = |
130 |
| - | 'SUPPORTED' |
131 |
| - | 'USES_DEFAULT_IMPLEMENTATION' |
132 |
| - | 'NOT_SUPPORTED'; |
133 |
| - |
134 |
| -// type Providers = { |
135 |
| -// google: { |
136 |
| -// ios: ImplementationStatus; |
137 |
| -// android: ImplementationStatus; |
138 |
| -// }; |
139 |
| -// }; |
140 |
| - |
141 |
| -export type UIManagerCommand = number; |
142 |
| - |
143 |
| -//todo: narrow down type |
144 |
| -export type MapManagerCommand = any; |
145 |
| - |
146 | 8 | export type NativeComponent<H = unknown> =
|
147 | 9 | | HostComponent<H>
|
148 | 10 | | ReturnType<typeof createNotSupportedComponent>;
|
149 |
| - |
150 |
| -// type Component = |
151 |
| -// | typeof MapCallout |
152 |
| -// | typeof MapCalloutSubview |
153 |
| -// | typeof MapCircle |
154 |
| -// | typeof MapHeatmap |
155 |
| -// | typeof MapLocalTile |
156 |
| -// | typeof MapMarker |
157 |
| -// | typeof MapOverlay |
158 |
| -// | typeof MapPolygon |
159 |
| -// | typeof MapPolyline |
160 |
| -// | typeof MapUrlTile |
161 |
| -// | typeof MapWMSTile; |
162 |
| - |
163 |
| -// type ComponentName = |
164 |
| -// | 'Callout' |
165 |
| -// | 'CalloutSubview' |
166 |
| -// | 'Circle' |
167 |
| -// | 'Heatmap' |
168 |
| -// | 'LocalTile' |
169 |
| -// | 'Marker' |
170 |
| -// | 'Overlay' |
171 |
| -// | 'Polygon' |
172 |
| -// | 'Polyline' |
173 |
| -// | 'UrlTile' |
174 |
| -// | 'WMSTile'; |
0 commit comments