@rnmapbox/maps 10.0.0-beta.38 → 10.0.0-beta.40
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.
- package/android/install.md +25 -21
- package/docs/Annotation.md +1 -1
- package/docs/Atmosphere.md +1 -1
- package/docs/BackgroundLayer.md +1 -1
- package/docs/Callout.md +1 -1
- package/docs/Camera.md +1 -1
- package/docs/CircleLayer.md +1 -1
- package/docs/FillExtrusionLayer.md +1 -1
- package/docs/FillLayer.md +1 -1
- package/docs/HeadingIndicator.md +1 -1
- package/docs/HeatmapLayer.md +1 -1
- package/docs/ImageSource.md +1 -1
- package/docs/Images.md +1 -1
- package/docs/Light.md +1 -1
- package/docs/LineLayer.md +1 -1
- package/docs/MapView.md +1 -1
- package/docs/MarkerView.md +1 -1
- package/docs/NativeUserLocation.md +1 -1
- package/docs/PointAnnotation.md +12 -10
- package/docs/RasterDemSource.md +1 -1
- package/docs/RasterLayer.md +1 -1
- package/docs/RasterSource.md +1 -1
- package/docs/ShapeSource.md +1 -1
- package/docs/SkyLayer.md +1 -1
- package/docs/Style.md +1 -1
- package/docs/SymbolLayer.md +1 -1
- package/docs/Terrain.md +1 -1
- package/docs/UserLocation.md +1 -1
- package/docs/VectorSource.md +1 -1
- package/docs/docs.json +44 -23
- package/index.d.ts +3 -19
- package/ios/RCTMGL-v10/RCTMGLMapView.swift +11 -0
- package/ios/RCTMGL-v10/RCTMGLPointAnnotation.swift +5 -0
- package/javascript/components/AbstractLayer.js +3 -3
- package/javascript/components/Light.js +1 -1
- package/javascript/components/MarkerView.tsx +12 -1
- package/javascript/components/{NativeBridgeComponent.js → NativeBridgeComponent.tsx} +33 -10
- package/javascript/components/PointAnnotation.tsx +231 -0
- package/javascript/components/ShapeSource.js +1 -1
- package/javascript/utils/index.d.ts +11 -3
- package/package.json +8 -8
- package/scripts/autogenHelpers/DocJSONBuilder.js +68 -12
- package/scripts/templates/component.md.ejs +1 -1
- package/javascript/components/PointAnnotation.d.ts +0 -13
- package/javascript/components/PointAnnotation.js +0 -217
|
@@ -11,7 +11,7 @@ class AbstractLayer extends React.PureComponent {
|
|
|
11
11
|
...this.props,
|
|
12
12
|
id: this.props.id,
|
|
13
13
|
sourceID: this.props.sourceID,
|
|
14
|
-
reactStyle: this.getStyle(),
|
|
14
|
+
reactStyle: this.getStyle(this.props.style),
|
|
15
15
|
minZoomLevel: this.props.minZoomLevel,
|
|
16
16
|
maxZoomLevel: this.props.maxZoomLevel,
|
|
17
17
|
aboveLayerID: this.props.aboveLayerID,
|
|
@@ -28,8 +28,8 @@ class AbstractLayer extends React.PureComponent {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
getStyle() {
|
|
32
|
-
return transformStyle(
|
|
31
|
+
getStyle(style) {
|
|
32
|
+
return transformStyle(style);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
setNativeProps(props) {
|
|
@@ -58,10 +58,21 @@ class MarkerView extends React.PureComponent<{
|
|
|
58
58
|
anchor: { x: 0.5, y: 0.5 },
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
+
static lastId = 0;
|
|
62
|
+
__idForPointAnnotation?: string;
|
|
63
|
+
|
|
64
|
+
_idForPointAnnotation(): string {
|
|
65
|
+
if (this.__idForPointAnnotation === undefined) {
|
|
66
|
+
MarkerView.lastId = MarkerView.lastId + 1;
|
|
67
|
+
this.__idForPointAnnotation = `MV-${MarkerView.lastId}`;
|
|
68
|
+
}
|
|
69
|
+
return this.__idForPointAnnotation;
|
|
70
|
+
}
|
|
71
|
+
|
|
61
72
|
render() {
|
|
62
73
|
const { props } = this;
|
|
63
74
|
if (Platform.OS === 'ios' && !Mapbox.MapboxV10) {
|
|
64
|
-
return <PointAnnotation {...props} />;
|
|
75
|
+
return <PointAnnotation id={this._idForPointAnnotation()} {...props} />;
|
|
65
76
|
}
|
|
66
77
|
|
|
67
78
|
function _getCoordinate(coordinate: [number, number]): string | undefined {
|
|
@@ -1,27 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
1
3
|
import { runNativeCommand, isAndroid } from '../utils';
|
|
2
4
|
|
|
3
5
|
let callbackIncrement = 0;
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
export type RNMBEvent<PayloadType = { [key: string]: string }> = {
|
|
8
|
+
payload: PayloadType;
|
|
9
|
+
type: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const NativeBridgeComponent = <T,>(B: React.ComponentClass<T>) =>
|
|
6
13
|
class extends B {
|
|
7
|
-
|
|
14
|
+
_nativeModuleName: string;
|
|
15
|
+
_onAndroidCallback: (e: any) => void;
|
|
16
|
+
_callbackMap: Map<string, any>;
|
|
17
|
+
_preRefMapMethodQueue: Array<{
|
|
18
|
+
method: { name: string; args: Array<string> };
|
|
19
|
+
resolver: (value: unknown) => void;
|
|
20
|
+
}>;
|
|
21
|
+
|
|
22
|
+
constructor(props: T, nativeModuleName: string) {
|
|
8
23
|
super(props);
|
|
9
24
|
|
|
10
25
|
this._nativeModuleName = nativeModuleName;
|
|
11
|
-
this._onAndroidCallback = this.
|
|
26
|
+
this._onAndroidCallback = this._onAndroidCallbackO.bind(this);
|
|
12
27
|
this._callbackMap = new Map();
|
|
13
28
|
this._preRefMapMethodQueue = [];
|
|
14
29
|
}
|
|
15
30
|
|
|
16
|
-
_addAddAndroidCallback(
|
|
31
|
+
_addAddAndroidCallback(
|
|
32
|
+
id: string,
|
|
33
|
+
resolve: (value: string) => void,
|
|
34
|
+
reject: (error: Error) => void,
|
|
35
|
+
) {
|
|
17
36
|
this._callbackMap.set(id, { resolve, reject });
|
|
18
37
|
}
|
|
19
38
|
|
|
20
|
-
_removeAndroidCallback(id) {
|
|
21
|
-
this._callbackMap.
|
|
39
|
+
_removeAndroidCallback(id: string) {
|
|
40
|
+
this._callbackMap.delete(id);
|
|
22
41
|
}
|
|
23
42
|
|
|
24
|
-
|
|
43
|
+
_onAndroidCallbackO(e: React.SyntheticEvent<Element, RNMBEvent>) {
|
|
25
44
|
const callbackID = e.nativeEvent.type;
|
|
26
45
|
const callback = this._callbackMap.get(callbackID);
|
|
27
46
|
|
|
@@ -30,7 +49,7 @@ const NativeBridgeComponent = (B) =>
|
|
|
30
49
|
}
|
|
31
50
|
|
|
32
51
|
this._callbackMap.delete(callbackID);
|
|
33
|
-
|
|
52
|
+
const { payload } = e.nativeEvent;
|
|
34
53
|
if (payload.error) {
|
|
35
54
|
callback.reject.call(null, new Error(payload.error));
|
|
36
55
|
} else {
|
|
@@ -38,7 +57,7 @@ const NativeBridgeComponent = (B) =>
|
|
|
38
57
|
}
|
|
39
58
|
}
|
|
40
59
|
|
|
41
|
-
async _runPendingNativeCommands(nativeRef) {
|
|
60
|
+
async _runPendingNativeCommands<RefType>(nativeRef: RefType) {
|
|
42
61
|
if (nativeRef) {
|
|
43
62
|
while (this._preRefMapMethodQueue.length > 0) {
|
|
44
63
|
const item = this._preRefMapMethodQueue.pop();
|
|
@@ -55,7 +74,11 @@ const NativeBridgeComponent = (B) =>
|
|
|
55
74
|
}
|
|
56
75
|
}
|
|
57
76
|
|
|
58
|
-
_runNativeCommand(
|
|
77
|
+
_runNativeCommand<RefType>(
|
|
78
|
+
methodName: string,
|
|
79
|
+
nativeRef: RefType,
|
|
80
|
+
args: string[] = [],
|
|
81
|
+
) {
|
|
59
82
|
if (!nativeRef) {
|
|
60
83
|
return new Promise((resolve) => {
|
|
61
84
|
this._preRefMapMethodQueue.push({
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import React, { SyntheticEvent, type Component } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
requireNativeComponent,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
Platform,
|
|
6
|
+
type HostComponent,
|
|
7
|
+
type ViewProps,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
import { type Feature } from 'geojson';
|
|
10
|
+
|
|
11
|
+
import { toJSONString, isFunction } from '../utils';
|
|
12
|
+
import { makePoint } from '../utils/geoUtils';
|
|
13
|
+
|
|
14
|
+
import NativeBridgeComponent, { type RNMBEvent } from './NativeBridgeComponent';
|
|
15
|
+
|
|
16
|
+
export const NATIVE_MODULE_NAME = 'RCTMGLPointAnnotation';
|
|
17
|
+
|
|
18
|
+
const styles = StyleSheet.create({
|
|
19
|
+
container: {
|
|
20
|
+
alignItems: 'center',
|
|
21
|
+
justifyContent: 'center',
|
|
22
|
+
position: 'absolute',
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
type FeaturePayload = {
|
|
27
|
+
feature: Feature;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type PointAnnotationProps = {
|
|
31
|
+
/**
|
|
32
|
+
* A string that uniquely identifies the annotation
|
|
33
|
+
*/
|
|
34
|
+
id: string;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The string containing the annotation’s title. Note this is required to be set if you want to see a callout appear on iOS.
|
|
38
|
+
*/
|
|
39
|
+
title?: string;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The string containing the annotation’s snippet(subtitle). Not displayed in the default callout.
|
|
43
|
+
*/
|
|
44
|
+
snippet?: string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Manually selects/deselects annotation
|
|
48
|
+
*/
|
|
49
|
+
selected?: boolean;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Enable or disable dragging. Defaults to false.
|
|
53
|
+
*/
|
|
54
|
+
draggable?: boolean;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The center point (specified as a map coordinate) of the annotation.
|
|
58
|
+
*/
|
|
59
|
+
coordinate: [number, number];
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Specifies the anchor being set on a particular point of the annotation.
|
|
63
|
+
* The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0],
|
|
64
|
+
* where (0, 0) is the top-left corner of the image, and (1, 1) is the bottom-right corner.
|
|
65
|
+
* Note this is only for custom annotations not the default pin view.
|
|
66
|
+
* Defaults to the center of the view.
|
|
67
|
+
*/
|
|
68
|
+
anchor?: {
|
|
69
|
+
/**
|
|
70
|
+
* See anchor
|
|
71
|
+
*/
|
|
72
|
+
x: number;
|
|
73
|
+
/**
|
|
74
|
+
* See anchor
|
|
75
|
+
*/
|
|
76
|
+
y: number;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* This callback is fired once this annotation is selected. Returns a Feature as the first param.
|
|
81
|
+
*/
|
|
82
|
+
onSelected?: (payload: FeaturePayload) => void;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* This callback is fired once this annotation is deselected.
|
|
86
|
+
*/
|
|
87
|
+
onDeselected?: (payload: FeaturePayload) => void;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* This callback is fired once this annotation has started being dragged.
|
|
91
|
+
*/
|
|
92
|
+
onDragStart?: (payload: FeaturePayload) => void;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* This callback is fired once this annotation has stopped being dragged.
|
|
96
|
+
*/
|
|
97
|
+
onDragEnd?: (payload: FeaturePayload) => void;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* This callback is fired while this annotation is being dragged.
|
|
101
|
+
*/
|
|
102
|
+
onDrag?: (payload: FeaturePayload) => void;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Expects one child, and an optional callout can be added as well
|
|
106
|
+
*/
|
|
107
|
+
children: React.ReactElement;
|
|
108
|
+
|
|
109
|
+
style?: ViewProps['style'];
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* PointAnnotation represents a one-dimensional shape located at a single geographical coordinate.
|
|
114
|
+
*
|
|
115
|
+
* Consider using ShapeSource and SymbolLayer instead, if you have many points and you have static images,
|
|
116
|
+
* they'll offer much better performance.
|
|
117
|
+
*
|
|
118
|
+
* If you need interactive views please use MarkerView,
|
|
119
|
+
* as with PointAnnotation on Android child views are rendered onto a bitmap for better performance.
|
|
120
|
+
*/
|
|
121
|
+
class PointAnnotation extends NativeBridgeComponent(
|
|
122
|
+
React.PureComponent<PointAnnotationProps>,
|
|
123
|
+
) {
|
|
124
|
+
static defaultProps = {
|
|
125
|
+
anchor: { x: 0.5, y: 0.5 },
|
|
126
|
+
draggable: false,
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
_nativeRef: NativePointAnnotationRef | null = null;
|
|
130
|
+
|
|
131
|
+
constructor(props: PointAnnotationProps) {
|
|
132
|
+
super(props, NATIVE_MODULE_NAME);
|
|
133
|
+
this._onSelected = this._onSelected.bind(this);
|
|
134
|
+
this._onDeselected = this._onDeselected.bind(this);
|
|
135
|
+
this._onDragStart = this._onDragStart.bind(this);
|
|
136
|
+
this._onDrag = this._onDrag.bind(this);
|
|
137
|
+
this._onDragEnd = this._onDragEnd.bind(this);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
_onSelected(e: SyntheticEvent<Element, RNMBEvent<FeaturePayload>>) {
|
|
141
|
+
if (isFunction(this.props.onSelected)) {
|
|
142
|
+
this.props.onSelected(e.nativeEvent.payload);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
_onDeselected(e: SyntheticEvent<Element, RNMBEvent<FeaturePayload>>) {
|
|
147
|
+
if (isFunction(this.props.onDeselected)) {
|
|
148
|
+
this.props.onDeselected(e.nativeEvent.payload);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
_onDragStart(e: SyntheticEvent<Element, RNMBEvent<FeaturePayload>>) {
|
|
153
|
+
if (isFunction(this.props.onDragStart)) {
|
|
154
|
+
this.props.onDragStart(e.nativeEvent.payload);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
_onDrag(e: SyntheticEvent<Element, RNMBEvent<FeaturePayload>>) {
|
|
159
|
+
if (isFunction(this.props.onDrag)) {
|
|
160
|
+
this.props.onDrag(e.nativeEvent.payload);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
_onDragEnd(e: SyntheticEvent<Element, RNMBEvent<FeaturePayload>>) {
|
|
165
|
+
if (isFunction(this.props.onDragEnd)) {
|
|
166
|
+
this.props.onDragEnd(e.nativeEvent.payload);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
_getCoordinate(): string | undefined {
|
|
171
|
+
if (!this.props.coordinate) {
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
return toJSONString(makePoint(this.props.coordinate));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* On v10 and pre v10 android point annotation is rendered offscreen with a canvas into an image.
|
|
179
|
+
* To rerender the image from the current state of the view call refresh.
|
|
180
|
+
* Call this for example from Image#onLoad.
|
|
181
|
+
*/
|
|
182
|
+
refresh() {
|
|
183
|
+
if (Platform.OS === 'android') {
|
|
184
|
+
this._runNativeCommand('refresh', this._nativeRef, []);
|
|
185
|
+
} else {
|
|
186
|
+
this._runNativeCommand('refresh', this._nativeRef, []);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
_setNativeRef(nativeRef: NativePointAnnotationRef | null) {
|
|
191
|
+
this._nativeRef = nativeRef;
|
|
192
|
+
super._runPendingNativeCommands(nativeRef);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
render() {
|
|
196
|
+
const props = {
|
|
197
|
+
...this.props,
|
|
198
|
+
ref: (nativeRef: NativePointAnnotationRef | null) =>
|
|
199
|
+
this._setNativeRef(nativeRef),
|
|
200
|
+
id: this.props.id,
|
|
201
|
+
title: this.props.title,
|
|
202
|
+
snippet: this.props.snippet,
|
|
203
|
+
anchor: this.props.anchor,
|
|
204
|
+
selected: this.props.selected,
|
|
205
|
+
draggable: this.props.draggable,
|
|
206
|
+
style: [this.props.style, styles.container],
|
|
207
|
+
onMapboxPointAnnotationSelected: this._onSelected,
|
|
208
|
+
onMapboxPointAnnotationDeselected: this._onDeselected,
|
|
209
|
+
onMapboxPointAnnotationDragStart: this._onDragStart,
|
|
210
|
+
onMapboxPointAnnotationDrag: this._onDrag,
|
|
211
|
+
onMapboxPointAnnotationDragEnd: this._onDragEnd,
|
|
212
|
+
coordinate: this._getCoordinate(),
|
|
213
|
+
};
|
|
214
|
+
return (
|
|
215
|
+
<RCTMGLPointAnnotation {...props}>
|
|
216
|
+
{this.props.children}
|
|
217
|
+
</RCTMGLPointAnnotation>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
type NativePointAnnotationProps = Omit<PointAnnotationProps, 'coordinate'> & {
|
|
222
|
+
coordinate: string | undefined;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
type NativePointAnnotationRef = Component<NativePointAnnotationProps>;
|
|
226
|
+
type NativePointAnnotation = HostComponent<NativePointAnnotationProps>;
|
|
227
|
+
|
|
228
|
+
const RCTMGLPointAnnotation: NativePointAnnotation =
|
|
229
|
+
requireNativeComponent(NATIVE_MODULE_NAME);
|
|
230
|
+
|
|
231
|
+
export default PointAnnotation;
|
|
@@ -285,7 +285,7 @@ class ShapeSource extends NativeBridgeComponent(AbstractSource) {
|
|
|
285
285
|
const shallowProps = Object.assign({}, props);
|
|
286
286
|
|
|
287
287
|
// Adds support for Animated
|
|
288
|
-
if (shallowProps.shape && typeof shallowProps !== 'string') {
|
|
288
|
+
if (shallowProps.shape && typeof shallowProps.shape !== 'string') {
|
|
289
289
|
shallowProps.shape = JSON.stringify(shallowProps.shape);
|
|
290
290
|
}
|
|
291
291
|
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
export function isAndroid(): boolean;
|
|
2
|
-
export function isBoolean(_: unknown): boolean;
|
|
3
|
-
export function isNumber(_: unknown):
|
|
4
|
-
export function isString(_: unknown):
|
|
2
|
+
export function isBoolean(_: unknown): argument is boolean;
|
|
3
|
+
export function isNumber(_: unknown): argument is number;
|
|
4
|
+
export function isString(_: unknown): argument is string;
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
6
|
+
export function isFunction(argument: unknown): argument is Function;
|
|
5
7
|
|
|
6
8
|
export function toJSONString(_: unknown): string;
|
|
9
|
+
export function runNativeCommand<RefType>(
|
|
10
|
+
module: string,
|
|
11
|
+
name: string,
|
|
12
|
+
nativeRef: RefType,
|
|
13
|
+
args: string[],
|
|
14
|
+
): void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rnmapbox/maps",
|
|
3
3
|
"description": "A Mapbox react native module for creating custom maps",
|
|
4
|
-
"version": "10.0.0-beta.
|
|
4
|
+
"version": "10.0.0-beta.40",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -62,17 +62,17 @@
|
|
|
62
62
|
"deprecated-react-native-prop-types": "^2.3.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@babel/core": "7.
|
|
66
|
-
"@babel/eslint-parser": "^7.
|
|
67
|
-
"@babel/plugin-proposal-class-properties": "7.
|
|
68
|
-
"@babel/runtime": "7.
|
|
65
|
+
"@babel/core": "7.19.1",
|
|
66
|
+
"@babel/eslint-parser": "^7.19.1",
|
|
67
|
+
"@babel/plugin-proposal-class-properties": "7.18.6",
|
|
68
|
+
"@babel/runtime": "7.19.0",
|
|
69
69
|
"@react-native-community/eslint-config": "^3.0.1",
|
|
70
70
|
"@sinonjs/fake-timers": "^8.0.1",
|
|
71
71
|
"@testing-library/react-native": "^11.0.0",
|
|
72
72
|
"@types/mapbox-gl": "^2.7.5",
|
|
73
73
|
"@types/react-native": ">=0.59.9",
|
|
74
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
75
|
-
"@typescript-eslint/parser": "^5.
|
|
74
|
+
"@typescript-eslint/eslint-plugin": "^5.37.0",
|
|
75
|
+
"@typescript-eslint/parser": "^5.37.0",
|
|
76
76
|
"babel-jest": "^27.5.1",
|
|
77
77
|
"documentation": "13.2.5",
|
|
78
78
|
"ejs": "^3.1.3",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"mapbox-gl": "^2.9.0",
|
|
91
91
|
"metro-react-native-babel-preset": "0.71.1",
|
|
92
92
|
"node-dir": "0.1.17",
|
|
93
|
-
"prettier": "2.
|
|
93
|
+
"prettier": "2.7.1",
|
|
94
94
|
"react": "17.0.2",
|
|
95
95
|
"react-docgen": "rnmapbox/react-docgen#rnmapbox-dist",
|
|
96
96
|
"react-native": "0.67.0",
|
|
@@ -22,6 +22,7 @@ const IGNORE_FILES = [
|
|
|
22
22
|
'AbstractLayer',
|
|
23
23
|
'AbstractSource',
|
|
24
24
|
'NativeBridgeComponent',
|
|
25
|
+
'NativeBridgeComponent.tsx',
|
|
25
26
|
];
|
|
26
27
|
const IGNORE_PATTERN = /\.web\./;
|
|
27
28
|
|
|
@@ -143,29 +144,77 @@ class DocJSONBuilder {
|
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
146
|
|
|
147
|
+
/**
|
|
148
|
+
* @typedef {{arguments: {type:TSType,name:string}[], return: TSType]}} TSFuncSignature
|
|
149
|
+
* @typedef {{key:string, value:TSType}[]} TSKVProperties
|
|
150
|
+
* @typedef {{properties: TSKVProperties}} TSObjectSignature
|
|
151
|
+
* @typedef {{name: 'void'}} TSVoidType
|
|
152
|
+
* @typedef {{name: string}} TSTypeType
|
|
153
|
+
* @typedef {{name: 'signature', type:'function', raw:string, signature: TSFuncSignature}} TSFunctionType
|
|
154
|
+
* @typedef {{name: 'signature', type:'object', raw:string, signature: TSObjectSignature}} TSObjectType
|
|
155
|
+
* @typedef {TSVoidType | TSFunctionType | TSTypeType | TSObjectType} TSType
|
|
156
|
+
*/
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @params {TSType} tsType
|
|
160
|
+
* @returns {tsType is TSFunctionType}
|
|
161
|
+
*/
|
|
162
|
+
function tsTypeIsFunction(tsType) {
|
|
163
|
+
return tsType.type === 'function';
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @params {TSType} tsType
|
|
168
|
+
* @returns {tsType is TSObjectType}
|
|
169
|
+
*/
|
|
170
|
+
function tsTypeIsObject(tsType) {
|
|
171
|
+
return tsType.type === 'object';
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @param {TSType} tsType
|
|
176
|
+
*/
|
|
177
|
+
function tsTypeDump(tsType) {
|
|
178
|
+
if (tsTypeIsFunction(tsType)) {
|
|
179
|
+
let { signature } = tsType;
|
|
180
|
+
return `(${signature.arguments
|
|
181
|
+
.map(({ name, type }) => `${name}:${tsTypeDump(type)}`)
|
|
182
|
+
.join(', ')}) => ${tsTypeDump(signature.return)}`;
|
|
183
|
+
} else if (tsTypeIsObject(tsType)) {
|
|
184
|
+
let { signature } = tsType;
|
|
185
|
+
return `{${signature.properties
|
|
186
|
+
.map(({ key, value }) => `${key}: ${tsTypeDump(value)}`)
|
|
187
|
+
.join(', ')}}`;
|
|
188
|
+
} else {
|
|
189
|
+
return tsType.name;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
146
193
|
function tsTypeDescType(tsType) {
|
|
147
194
|
if (!tsType?.name) {
|
|
148
195
|
return null;
|
|
149
196
|
}
|
|
150
197
|
|
|
151
|
-
if (tsType.name === 'signature') {
|
|
198
|
+
if (tsType.name === 'signature' && tsType.type === 'object') {
|
|
152
199
|
const { properties } = tsType.signature;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (tsType.raw.length < 200) {
|
|
200
|
+
if (properties) {
|
|
201
|
+
const value = properties.map((kv) => {
|
|
202
|
+
return mapProp(
|
|
203
|
+
mapNestedProp({ ...kv.value, description: kv.description }),
|
|
204
|
+
kv.key,
|
|
205
|
+
false,
|
|
206
|
+
);
|
|
207
|
+
});
|
|
208
|
+
return { name: 'shape', value };
|
|
209
|
+
} else if (tsType.raw.length < 200) {
|
|
163
210
|
return `${tsType.raw
|
|
164
211
|
.replace(/(\n|\s)/g, '')
|
|
165
212
|
.replace(/(\|)/g, '\\|')}`;
|
|
166
213
|
} else {
|
|
167
214
|
return 'FIX ME FORMAT BIG OBJECT';
|
|
168
|
-
}
|
|
215
|
+
}
|
|
216
|
+
} else if (tsType.name === 'signature' && tsType.type === 'function') {
|
|
217
|
+
return { name: 'func', funcSignature: tsTypeDump(tsType) };
|
|
169
218
|
} else if (tsType.name === 'union') {
|
|
170
219
|
if (tsType.raw) {
|
|
171
220
|
// Props
|
|
@@ -194,6 +243,13 @@ class DocJSONBuilder {
|
|
|
194
243
|
: propMeta.defaultValue.value.replace(/\n/g, ''),
|
|
195
244
|
description: propMeta.description || 'FIX ME NO DESCRIPTION',
|
|
196
245
|
};
|
|
246
|
+
if (
|
|
247
|
+
result.type &&
|
|
248
|
+
result.type.name === 'func' &&
|
|
249
|
+
result.type.funcSignature
|
|
250
|
+
) {
|
|
251
|
+
result.description = `${result.description}\n*signature:*\`${result.type.funcSignature}\``;
|
|
252
|
+
}
|
|
197
253
|
} else {
|
|
198
254
|
if (propName) {
|
|
199
255
|
result.name = propName;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<%_ if (component.props && component.props.length) { _%>
|
|
9
9
|
## props
|
|
10
10
|
| Prop | Type | Default | Required | Description |
|
|
11
|
-
| ---- |
|
|
11
|
+
| ---- | :-- | :----- | :------ | :---------- |
|
|
12
12
|
<%- propMarkdownTableRows(component) %>
|
|
13
13
|
<%_ } _%>
|
|
14
14
|
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
export interface PointAnnotationProps {
|
|
4
|
-
coordinate: [number, number];
|
|
5
|
-
anchor: {
|
|
6
|
-
x: number;
|
|
7
|
-
y: number;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default class PointAnnotation extends React.Component<PointAnnotationProps> {
|
|
12
|
-
refresh(): void;
|
|
13
|
-
}
|