Skip to content

Commit 928abfa

Browse files
committed
fix: decorate map component
1 parent 97e0560 commit 928abfa

File tree

8 files changed

+5
-220
lines changed

8 files changed

+5
-220
lines changed

src/MapCallout.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import * as React from 'react';
22
import { requireNativeComponent, StyleSheet, ViewProps } from 'react-native';
3-
import type {
4-
MapManagerCommand,
5-
NativeComponent,
6-
UIManagerCommand,
7-
} from './decorateMapComponent';
83
import type { CalloutPressEvent } from './sharedTypes';
94

105
export type MapCalloutProps = ViewProps & {
@@ -26,10 +21,6 @@ export type MapCalloutProps = ViewProps & {
2621
type NativeProps = MapCalloutProps;
2722

2823
class MapCallout extends React.Component<MapCalloutProps> {
29-
getNativeComponent!: () => NativeComponent<NativeProps>;
30-
getMapManagerCommand!: (name: string) => MapManagerCommand;
31-
getUIManagerCommand!: (name: string) => UIManagerCommand;
32-
3324
render() {
3425
const { tooltip = false } = this.props;
3526
return (

src/MapCircle.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import * as React from 'react';
22
import { requireNativeComponent, View, ViewProps } from 'react-native';
3-
import type {
4-
NativeComponent,
5-
MapManagerCommand,
6-
UIManagerCommand,
7-
} from './decorateMapComponent';
3+
import type { NativeComponent } from './decorateMapComponent';
84
import type { LatLng } from './sharedTypes';
95

106
export type MapCircleProps = ViewProps & {
@@ -45,10 +41,6 @@ export type MapCircleProps = ViewProps & {
4541
type NativeProps = MapCircleProps & { ref: React.RefObject<View> };
4642

4743
class MapCircle extends React.Component<MapCircleProps> {
48-
getNativeComponent!: () => NativeComponent<NativeProps>;
49-
getMapManagerCommand!: (name: string) => MapManagerCommand;
50-
getUIManagerCommand!: (name: string) => UIManagerCommand;
51-
5244
private circle: NativeProps['ref'];
5345

5446
constructor(props: MapCircleProps) {

src/MapMarker.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ import {
99
requireNativeComponent,
1010
} from 'react-native';
1111

12-
import type {
13-
MapManagerCommand,
14-
NativeComponent,
15-
UIManagerCommand,
16-
} from './decorateMapComponent';
12+
import type { NativeComponent } from './decorateMapComponent';
1713
import {
1814
Commands,
1915
MapMarkerNativeComponentType,
@@ -175,12 +171,6 @@ export type NativeProps = Modify<
175171
};
176172

177173
class MapMarker extends React.Component<MapMarkerProps> {
178-
// declaration only, as they are set through decorateMap
179-
180-
getNativeComponent!: () => NativeComponent<NativeProps>;
181-
getMapManagerCommand!: (name: string) => MapManagerCommand;
182-
getUIManagerCommand!: (name: string) => UIManagerCommand;
183-
184174
static Animated: Animated.AnimatedComponent<typeof MapMarker>;
185175

186176
private marker: NativeProps['ref'];

src/MapPolygon.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import {
55
View,
66
ViewProps,
77
} from 'react-native';
8-
import type {
9-
NativeComponent,
10-
MapManagerCommand,
11-
UIManagerCommand,
12-
} from './decorateMapComponent';
8+
import type { NativeComponent } from './decorateMapComponent';
139
import type { LatLng, Point } from './sharedTypes';
1410

1511
export type MapPolygonProps = ViewProps & {
@@ -77,10 +73,6 @@ type PolygonPressEvent = NativeSyntheticEvent<{
7773
type NativeProps = MapPolygonProps & { ref: React.RefObject<View> };
7874

7975
class MapPolygon extends React.Component<MapPolygonProps> {
80-
getNativeComponent!: () => NativeComponent<NativeProps>;
81-
getMapManagerCommand!: (name: string) => MapManagerCommand;
82-
getUIManagerCommand!: (name: string) => UIManagerCommand;
83-
8476
private polygon: NativeProps['ref'];
8577

8678
constructor(props: MapPolygonProps) {

src/MapPolyline.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import {
55
View,
66
ViewProps,
77
} from 'react-native';
8-
import type {
9-
NativeComponent,
10-
MapManagerCommand,
11-
UIManagerCommand,
12-
} from './decorateMapComponent';
8+
import type { NativeComponent } from './decorateMapComponent';
139
import type { LatLng, LineCapType, Point } from './sharedTypes';
1410

1511
export type MapPolylineProps = ViewProps & {
@@ -90,10 +86,6 @@ type PolylinePressEvent = NativeSyntheticEvent<{
9086
type NativeProps = MapPolylineProps & { ref: React.RefObject<View> };
9187

9288
class MapPolyline extends React.Component<MapPolylineProps> {
93-
getNativeComponent!: () => NativeComponent<NativeProps>;
94-
getMapManagerCommand!: (name: string) => MapManagerCommand;
95-
getUIManagerCommand!: (name: string) => UIManagerCommand;
96-
9789
private polyline: NativeProps['ref'];
9890

9991
constructor(props: MapPolylineProps) {

src/MapUrlTile.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import * as React from 'react';
22

3-
import type {
4-
NativeComponent,
5-
MapManagerCommand,
6-
UIManagerCommand,
7-
} from './decorateMapComponent';
83
import { requireNativeComponent, ViewProps } from 'react-native';
94

105
export type MapUrlTileProps = ViewProps & {
@@ -95,10 +90,6 @@ export type MapUrlTileProps = ViewProps & {
9590
type NativeProps = MapUrlTileProps;
9691

9792
class MapUrlTile extends React.Component<MapUrlTileProps> {
98-
getNativeComponent!: () => NativeComponent<NativeProps>;
99-
getMapManagerCommand!: (name: string) => MapManagerCommand;
100-
getUIManagerCommand!: (name: string) => UIManagerCommand;
101-
10293
render() {
10394
return <OsmMapUrlTile {...this.props} />;
10495
}

src/decorateMapComponent.ts

Lines changed: 0 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -1,174 +1,10 @@
1-
import { createContext } from 'react';
21
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-
// }
372

383
export const createNotSupportedComponent = (message: string) => () => {
394
console.error(message);
405
return null;
416
};
427

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-
1468
export type NativeComponent<H = unknown> =
1479
| HostComponent<H>
14810
| 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';

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ export * from './MapView.types';
1515
export * from './sharedTypes';
1616
export default MapView;
1717
export { Marker, Polyline, Polygon };
18+
export { default as AnimatedRegion } from './AnimatedRegion';

0 commit comments

Comments
 (0)