@rnmapbox/maps 10.0.0-beta.74 → 10.0.0-beta.76
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/README.md +3 -3
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/CameraStop.kt +61 -46
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImagesManager.kt +5 -5
- package/ios/RCTMGL-v10/RCMTGLImage.swift +2 -1
- package/ios/RCTMGL-v10/RCTMGLImages.swift +57 -17
- package/ios/RCTMGL-v10/RCTMGLMapView.swift +11 -1
- package/ios/RCTMGL-v10/RCTMGLUtils.swift +14 -5
- package/javascript/MGLModule.ts +54 -0
- package/javascript/Mapbox.ts +97 -0
- package/javascript/classes/index.d.ts +20 -1
- package/javascript/components/Annotation.tsx +141 -0
- package/javascript/components/Callout.d.ts +35 -0
- package/javascript/components/ImageSource.tsx +81 -0
- package/javascript/components/Images.tsx +58 -6
- package/javascript/components/{MapView.js → MapView.tsx} +456 -383
- package/javascript/components/MarkerView.tsx +3 -2
- package/javascript/components/NativeBridgeComponent.tsx +1 -1
- package/javascript/components/PointAnnotation.tsx +4 -3
- package/javascript/components/RasterDemSource.tsx +105 -0
- package/javascript/components/RasterSource.tsx +124 -0
- package/javascript/components/ShapeSource.tsx +1 -1
- package/javascript/components/{Style.js → Style.tsx} +117 -35
- package/javascript/components/Terrain.tsx +8 -7
- package/javascript/components/{UserLocation.js → UserLocation.tsx} +105 -94
- package/javascript/components/VectorSource.tsx +1 -1
- package/javascript/index.ts +4 -0
- package/javascript/modules/offline/{OfflineCreatePackOptions.js → OfflineCreatePackOptions.ts} +21 -6
- package/javascript/modules/offline/{OfflinePack.js → OfflinePack.ts} +19 -4
- package/javascript/modules/offline/{offlineManager.js → offlineManager.ts} +81 -21
- package/javascript/modules/snapshot/{SnapshotOptions.js → SnapshotOptions.ts} +27 -3
- package/javascript/modules/snapshot/{snapshotManager.js → snapshotManager.ts} +2 -1
- package/javascript/types/Position.ts +1 -0
- package/javascript/utils/Logger.ts +1 -1
- package/javascript/utils/geoUtils.ts +56 -0
- package/javascript/utils/{index.js → index.ts} +41 -19
- package/lib/commonjs/MGLModule.js +37 -0
- package/lib/commonjs/MGLModule.js.map +1 -0
- package/lib/commonjs/Mapbox.js +372 -0
- package/lib/commonjs/Mapbox.js.map +1 -0
- package/lib/commonjs/classes/index.d.js +2 -0
- package/lib/commonjs/classes/index.d.js.map +1 -1
- package/lib/commonjs/components/{annotations/Annotation.js → Annotation.js} +26 -27
- package/lib/commonjs/components/Annotation.js.map +1 -0
- package/lib/commonjs/components/Callout.d.js +9 -0
- package/lib/commonjs/components/Callout.d.js.map +1 -0
- package/lib/commonjs/components/ImageSource.js +8 -25
- package/lib/commonjs/components/ImageSource.js.map +1 -1
- package/lib/commonjs/components/Images.js +17 -1
- package/lib/commonjs/components/Images.js.map +1 -1
- package/lib/commonjs/components/MapView.js +30 -289
- package/lib/commonjs/components/MapView.js.map +1 -1
- package/lib/commonjs/components/MarkerView.js.map +1 -1
- package/lib/commonjs/components/NativeBridgeComponent.js.map +1 -1
- package/lib/commonjs/components/PointAnnotation.js.map +1 -1
- package/lib/commonjs/components/RasterDemSource.js +3 -37
- package/lib/commonjs/components/RasterDemSource.js.map +1 -1
- package/lib/commonjs/components/RasterSource.js +2 -46
- package/lib/commonjs/components/RasterSource.js.map +1 -1
- package/lib/commonjs/components/Style.js +11 -15
- package/lib/commonjs/components/Style.js.map +1 -1
- package/lib/commonjs/components/Terrain.js.map +1 -1
- package/lib/commonjs/components/UserLocation.js +26 -77
- package/lib/commonjs/components/UserLocation.js.map +1 -1
- package/lib/commonjs/index.js +16 -339
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/modules/offline/OfflineCreatePackOptions.js +2 -4
- package/lib/commonjs/modules/offline/OfflineCreatePackOptions.js.map +1 -1
- package/lib/commonjs/modules/offline/OfflinePack.js.map +1 -1
- package/lib/commonjs/modules/offline/offlineManager.js +7 -2
- package/lib/commonjs/modules/offline/offlineManager.js.map +1 -1
- package/lib/commonjs/modules/snapshot/SnapshotOptions.js.map +1 -1
- package/lib/commonjs/modules/snapshot/snapshotManager.js.map +1 -1
- package/lib/commonjs/types/Position.js +2 -0
- package/lib/commonjs/{utils/index.d.js.map → types/Position.js.map} +1 -1
- package/lib/commonjs/utils/animated/Animated.js.map +1 -1
- package/lib/commonjs/utils/geoUtils.js +12 -38
- package/lib/commonjs/utils/geoUtils.js.map +1 -1
- package/lib/commonjs/utils/index.js +3 -6
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/module/MGLModule.js +19 -0
- package/lib/module/MGLModule.js.map +1 -0
- package/lib/module/Mapbox.js +59 -0
- package/lib/module/Mapbox.js.map +1 -0
- package/lib/module/classes/index.d.js +2 -0
- package/lib/module/classes/index.d.js.map +1 -1
- package/lib/module/components/{annotations/Annotation.js → Annotation.js} +26 -27
- package/lib/module/components/Annotation.js.map +1 -0
- package/lib/module/components/Callout.d.js +2 -0
- package/lib/module/components/Callout.d.js.map +1 -0
- package/lib/module/components/ImageSource.js +8 -25
- package/lib/module/components/ImageSource.js.map +1 -1
- package/lib/module/components/Images.js +17 -1
- package/lib/module/components/Images.js.map +1 -1
- package/lib/module/components/MapView.js +31 -290
- package/lib/module/components/MapView.js.map +1 -1
- package/lib/module/components/MarkerView.js.map +1 -1
- package/lib/module/components/NativeBridgeComponent.js.map +1 -1
- package/lib/module/components/PointAnnotation.js.map +1 -1
- package/lib/module/components/RasterDemSource.js +4 -38
- package/lib/module/components/RasterDemSource.js.map +1 -1
- package/lib/module/components/RasterSource.js +3 -47
- package/lib/module/components/RasterSource.js.map +1 -1
- package/lib/module/components/Style.js +11 -15
- package/lib/module/components/Style.js.map +1 -1
- package/lib/module/components/Terrain.js.map +1 -1
- package/lib/module/components/UserLocation.js +25 -76
- package/lib/module/components/UserLocation.js.map +1 -1
- package/lib/module/index.js +3 -108
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/offline/OfflineCreatePackOptions.js +2 -4
- package/lib/module/modules/offline/OfflineCreatePackOptions.js.map +1 -1
- package/lib/module/modules/offline/OfflinePack.js.map +1 -1
- package/lib/module/modules/offline/offlineManager.js +1 -1
- package/lib/module/modules/offline/offlineManager.js.map +1 -1
- package/lib/module/modules/snapshot/SnapshotOptions.js.map +1 -1
- package/lib/module/modules/snapshot/snapshotManager.js.map +1 -1
- package/lib/module/types/Position.js +2 -0
- package/lib/module/{utils/index.d.js.map → types/Position.js.map} +1 -1
- package/lib/module/utils/animated/Animated.js.map +1 -1
- package/lib/module/utils/geoUtils.js +5 -32
- package/lib/module/utils/geoUtils.js.map +1 -1
- package/lib/module/utils/index.js +3 -5
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/MGLModule.d.ts +22 -0
- package/lib/typescript/MGLModule.d.ts.map +1 -0
- package/lib/typescript/Mapbox.d.ts +54 -0
- package/lib/typescript/Mapbox.d.ts.map +1 -0
- package/lib/typescript/components/Annotation.d.ts +34 -0
- package/lib/typescript/components/Annotation.d.ts.map +1 -0
- package/lib/typescript/components/ImageSource.d.ts +32 -0
- package/lib/typescript/components/ImageSource.d.ts.map +1 -0
- package/lib/typescript/components/Images.d.ts +24 -2
- package/lib/typescript/components/Images.d.ts.map +1 -1
- package/lib/typescript/components/MapView.d.ts +469 -0
- package/lib/typescript/components/MapView.d.ts.map +1 -0
- package/lib/typescript/components/MarkerView.d.ts +3 -2
- package/lib/typescript/components/MarkerView.d.ts.map +1 -1
- package/lib/typescript/components/NativeBridgeComponent.d.ts +1 -1
- package/lib/typescript/components/NativeBridgeComponent.d.ts.map +1 -1
- package/lib/typescript/components/PointAnnotation.d.ts +10 -4
- package/lib/typescript/components/PointAnnotation.d.ts.map +1 -1
- package/lib/typescript/components/RasterDemSource.d.ts +46 -0
- package/lib/typescript/components/RasterDemSource.d.ts.map +1 -0
- package/lib/typescript/components/RasterSource.d.ts +59 -0
- package/lib/typescript/components/RasterSource.d.ts.map +1 -0
- package/lib/typescript/components/ShapeSource.d.ts +2 -2
- package/lib/typescript/components/ShapeSource.d.ts.map +1 -1
- package/lib/typescript/components/Style.d.ts +74 -0
- package/lib/typescript/components/Style.d.ts.map +1 -0
- package/lib/typescript/components/Terrain.d.ts +2 -2
- package/lib/typescript/components/Terrain.d.ts.map +1 -1
- package/lib/typescript/components/UserLocation.d.ts +102 -0
- package/lib/typescript/components/UserLocation.d.ts.map +1 -0
- package/lib/typescript/components/VectorSource.d.ts +2 -2
- package/lib/typescript/components/VectorSource.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +4 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/modules/offline/OfflineCreatePackOptions.d.ts +22 -0
- package/lib/typescript/modules/offline/OfflineCreatePackOptions.d.ts.map +1 -0
- package/lib/typescript/modules/offline/OfflinePack.d.ts +24 -0
- package/lib/typescript/modules/offline/OfflinePack.d.ts.map +1 -0
- package/lib/typescript/modules/offline/offlineManager.d.ts +220 -0
- package/lib/typescript/modules/offline/offlineManager.d.ts.map +1 -0
- package/lib/typescript/modules/snapshot/SnapshotOptions.d.ts +41 -0
- package/lib/typescript/modules/snapshot/SnapshotOptions.d.ts.map +1 -0
- package/lib/typescript/modules/snapshot/snapshotManager.d.ts +52 -0
- package/lib/typescript/modules/snapshot/snapshotManager.d.ts.map +1 -0
- package/lib/typescript/types/Position.d.ts +2 -0
- package/lib/typescript/types/Position.d.ts.map +1 -0
- package/lib/typescript/utils/Logger.d.ts +1 -1
- package/lib/typescript/utils/Logger.d.ts.map +1 -1
- package/lib/typescript/utils/animated/Animated.d.ts +23 -0
- package/lib/typescript/utils/animated/Animated.d.ts.map +1 -0
- package/lib/typescript/utils/geoUtils.d.ts +15 -0
- package/lib/typescript/utils/geoUtils.d.ts.map +1 -0
- package/lib/typescript/utils/index.d.ts +48 -0
- package/lib/typescript/utils/index.d.ts.map +1 -0
- package/package.json +4 -4
- package/index.d.ts +0 -745
- package/javascript/components/ImageSource.js +0 -82
- package/javascript/components/RasterDemSource.js +0 -106
- package/javascript/components/RasterSource.js +0 -124
- package/javascript/components/annotations/Annotation.js +0 -122
- package/javascript/index.js +0 -162
- package/javascript/utils/geoUtils.d.ts +0 -10
- package/javascript/utils/geoUtils.js +0 -73
- package/javascript/utils/index.d.ts +0 -27
- package/lib/commonjs/components/annotations/Annotation.js.map +0 -1
- package/lib/commonjs/utils/geoUtils.d.js +0 -2
- package/lib/commonjs/utils/geoUtils.d.js.map +0 -1
- package/lib/commonjs/utils/index.d.js +0 -2
- package/lib/module/components/annotations/Annotation.js.map +0 -1
- package/lib/module/utils/geoUtils.d.js +0 -2
- package/lib/module/utils/geoUtils.d.js.map +0 -1
- package/lib/module/utils/index.d.js +0 -2
- /package/javascript/utils/animated/{Animated.js → Animated.ts} +0 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import React, { ReactElement } from 'react';
|
|
2
|
+
import { Animated as RNAnimated, Easing } from 'react-native';
|
|
3
|
+
import { Point } from 'geojson';
|
|
4
|
+
|
|
5
|
+
import Animated from '../utils/animated/Animated';
|
|
6
|
+
import { AnimatedPoint } from '../classes';
|
|
7
|
+
import { OnPressEvent } from '../types/OnPressEvent';
|
|
8
|
+
import { SymbolLayerStyle } from '../Mapbox';
|
|
9
|
+
|
|
10
|
+
import { SymbolLayer } from './SymbolLayer';
|
|
11
|
+
|
|
12
|
+
type Props = {
|
|
13
|
+
id: string;
|
|
14
|
+
animated?: boolean;
|
|
15
|
+
animationDuration?: number;
|
|
16
|
+
animationEasingFunction?: (x: number) => number;
|
|
17
|
+
coordinates: number[];
|
|
18
|
+
onPress?: (event: OnPressEvent) => void;
|
|
19
|
+
children: ReactElement | ReactElement[];
|
|
20
|
+
style?: object;
|
|
21
|
+
icon?: string | number | object;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type AnnotationState = {
|
|
25
|
+
shape: Point | AnimatedPoint | null;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
class Annotation extends React.Component<Props, AnnotationState> {
|
|
29
|
+
static defaultProps = {
|
|
30
|
+
animated: false,
|
|
31
|
+
animationDuration: 1000,
|
|
32
|
+
animationEasingFunction: Easing.linear,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
constructor(props: Props) {
|
|
36
|
+
super(props);
|
|
37
|
+
|
|
38
|
+
const shape = this._getShapeFromProps(props);
|
|
39
|
+
|
|
40
|
+
this.state = {
|
|
41
|
+
shape: props.animated ? new AnimatedPoint(shape) : shape,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
this.onPress = this.onPress.bind(this);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
componentDidUpdate(prevProps: Props) {
|
|
48
|
+
if (!Array.isArray(this.props.coordinates)) {
|
|
49
|
+
this.setState({ shape: null });
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const haveCoordinatesChanged =
|
|
54
|
+
prevProps.coordinates[0] !== this.props.coordinates[0] ||
|
|
55
|
+
prevProps.coordinates[1] !== this.props.coordinates[1];
|
|
56
|
+
|
|
57
|
+
if (
|
|
58
|
+
prevProps.animated !== this.props.animated ||
|
|
59
|
+
(haveCoordinatesChanged && (!this.state.shape || !this.props.animated))
|
|
60
|
+
) {
|
|
61
|
+
const shape = this._getShapeFromProps(this.props);
|
|
62
|
+
|
|
63
|
+
this.setState({
|
|
64
|
+
shape: this.props.animated ? new AnimatedPoint(shape) : shape,
|
|
65
|
+
});
|
|
66
|
+
} else if (
|
|
67
|
+
haveCoordinatesChanged &&
|
|
68
|
+
this.props.animated &&
|
|
69
|
+
this.state.shape
|
|
70
|
+
) {
|
|
71
|
+
// flush current animations
|
|
72
|
+
(this.state.shape as AnimatedPoint).stopAnimation();
|
|
73
|
+
|
|
74
|
+
(this.state.shape as AnimatedPoint)
|
|
75
|
+
.timing({
|
|
76
|
+
coordinates: this.props.coordinates,
|
|
77
|
+
easing: this.props.animationEasingFunction,
|
|
78
|
+
duration: this.props.animationDuration,
|
|
79
|
+
})
|
|
80
|
+
.start();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
onPress(event: OnPressEvent) {
|
|
85
|
+
if (this.props.onPress) {
|
|
86
|
+
this.props.onPress(event);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
_getShapeFromProps(props: Partial<Props> = {}): Point {
|
|
91
|
+
const lng = props.coordinates?.[0] || 0;
|
|
92
|
+
const lat = props.coordinates?.[1] || 0;
|
|
93
|
+
return { type: 'Point', coordinates: [lng, lat] };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
get symbolStyle(): SymbolLayerStyle | undefined {
|
|
97
|
+
if (!this.props.icon) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
return Object.assign({}, this.props.style, {
|
|
101
|
+
iconImage: this.props.icon,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
render() {
|
|
106
|
+
if (!this.props.coordinates) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const children = [];
|
|
111
|
+
|
|
112
|
+
if (this.symbolStyle) {
|
|
113
|
+
children.push(
|
|
114
|
+
<SymbolLayer
|
|
115
|
+
id={`${this.props.id}-symbol`}
|
|
116
|
+
style={this.symbolStyle as SymbolLayerStyle}
|
|
117
|
+
/>,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (this.props.children) {
|
|
122
|
+
if (Array.isArray(this.props.children)) {
|
|
123
|
+
children.push(...this.props.children);
|
|
124
|
+
} else {
|
|
125
|
+
children.push(this.props.children);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<Animated.ShapeSource
|
|
131
|
+
id={this.props.id}
|
|
132
|
+
onPress={this.onPress}
|
|
133
|
+
shape={this.state.shape as RNAnimated.WithAnimatedObject<Point>}
|
|
134
|
+
>
|
|
135
|
+
{children}
|
|
136
|
+
</Animated.ShapeSource>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export default Annotation;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ViewStyle } from 'react-native';
|
|
2
|
+
|
|
3
|
+
type Props = Omit<ViewProps, 'style'> & {
|
|
4
|
+
/**
|
|
5
|
+
* String that gets displayed in the default callout.
|
|
6
|
+
*/
|
|
7
|
+
title: string;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Style property for the Animated.View wrapper, apply animations to this
|
|
11
|
+
*/
|
|
12
|
+
style?: ViewStyle;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Style property for the native RCTMGLCallout container, set at your own risk.
|
|
16
|
+
*/
|
|
17
|
+
containerStyle?: ViewStyle;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Style property for the content bubble.
|
|
21
|
+
*/
|
|
22
|
+
contentStyle?: ViewStyle;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Style property for the triangle tip under the content.
|
|
26
|
+
*/
|
|
27
|
+
tipStyle?: ViewStyle;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Style property for the title in the content bubble.
|
|
31
|
+
*/
|
|
32
|
+
textStyle?: ViewStyle;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default class Callout extends React.Component<Props> {}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { requireNativeComponent } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
cloneReactChildrenWithProps,
|
|
6
|
+
isNumber,
|
|
7
|
+
resolveImagePath,
|
|
8
|
+
} from '../utils';
|
|
9
|
+
import { BaseProps } from '../types/BaseProps';
|
|
10
|
+
|
|
11
|
+
import AbstractSource from './AbstractSource';
|
|
12
|
+
|
|
13
|
+
export const NATIVE_MODULE_NAME = 'RCTMGLImageSource';
|
|
14
|
+
|
|
15
|
+
type Position = [number, number];
|
|
16
|
+
|
|
17
|
+
type Props = BaseProps & {
|
|
18
|
+
/**
|
|
19
|
+
* A string that uniquely identifies the source.
|
|
20
|
+
*/
|
|
21
|
+
id: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* An HTTP(S) URL, absolute file URL, or local file URL to the source image.
|
|
25
|
+
* Gifs are currently not supported.
|
|
26
|
+
*/
|
|
27
|
+
url?: number | string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The top left, top right, bottom right, and bottom left coordinates for the image.
|
|
31
|
+
*/
|
|
32
|
+
coordinates?: [Position, Position, Position, Position];
|
|
33
|
+
|
|
34
|
+
children?: React.ReactElement | React.ReactElement[];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type NativeProps = Props;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* ImageSource is a content source that is used for a georeferenced raster image to be shown on the map.
|
|
41
|
+
* The georeferenced image scales and rotates as the user zooms and rotates the map
|
|
42
|
+
*/
|
|
43
|
+
class ImageSource extends AbstractSource<Props, NativeProps> {
|
|
44
|
+
_getURL(): string | undefined {
|
|
45
|
+
const { url } = this.props;
|
|
46
|
+
|
|
47
|
+
if (isNumber(url)) {
|
|
48
|
+
return resolveImagePath(url);
|
|
49
|
+
} else {
|
|
50
|
+
return url;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
render() {
|
|
55
|
+
if (
|
|
56
|
+
!this.props.url ||
|
|
57
|
+
!this.props.coordinates ||
|
|
58
|
+
!this.props.coordinates.length
|
|
59
|
+
) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const props = {
|
|
64
|
+
...this.props,
|
|
65
|
+
url: this._getURL(),
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<RCTMGLImageSource ref={this.setNativeRef} {...props}>
|
|
70
|
+
{cloneReactChildrenWithProps(this.props.children, {
|
|
71
|
+
sourceID: this.props.id,
|
|
72
|
+
})}
|
|
73
|
+
</RCTMGLImageSource>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const RCTMGLImageSource =
|
|
79
|
+
requireNativeComponent<NativeProps>(NATIVE_MODULE_NAME);
|
|
80
|
+
|
|
81
|
+
export default ImageSource;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import React, { ReactNode, ReactElement } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
requireNativeComponent,
|
|
4
|
+
Image as RNImage,
|
|
5
|
+
ImageURISource,
|
|
6
|
+
} from 'react-native';
|
|
3
7
|
import { ImageSourcePropType, ImageResolvedAssetSource } from 'react-native';
|
|
4
8
|
|
|
5
9
|
import { ShapeSource } from './ShapeSource';
|
|
@@ -12,7 +16,7 @@ export type RNMBEvent<PayloadType = { [key: string]: string }> = {
|
|
|
12
16
|
type: string;
|
|
13
17
|
};
|
|
14
18
|
|
|
15
|
-
function _isUrlOrPath(value:
|
|
19
|
+
function _isUrlOrPath(value: ImageEntry): value is string {
|
|
16
20
|
return (
|
|
17
21
|
(typeof value === 'string' || value instanceof String) &&
|
|
18
22
|
(value.startsWith('file://') ||
|
|
@@ -24,6 +28,16 @@ function _isUrlOrPath(value: string | ImageSourcePropType): value is string {
|
|
|
24
28
|
);
|
|
25
29
|
}
|
|
26
30
|
|
|
31
|
+
function isImageSourcePropType(
|
|
32
|
+
value: ImageEntry,
|
|
33
|
+
): value is ImageSourcePropType {
|
|
34
|
+
if (typeof value === 'number' || value instanceof Number) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
const valueAsSource = value as ImageURISource;
|
|
38
|
+
return !!valueAsSource.uri && typeof valueAsSource.uri === 'string';
|
|
39
|
+
}
|
|
40
|
+
|
|
27
41
|
type TypedReactNode<T> = ReactElement<T> | Array<TypedReactNode<T>> | never;
|
|
28
42
|
|
|
29
43
|
type NativeImage =
|
|
@@ -33,8 +47,33 @@ type NativeImage =
|
|
|
33
47
|
sdf?: boolean;
|
|
34
48
|
stretchX?: [number, number][];
|
|
35
49
|
stretchY?: [number, number][];
|
|
50
|
+
content?: [number, number, number, number];
|
|
51
|
+
scale?: number;
|
|
36
52
|
};
|
|
37
53
|
|
|
54
|
+
export type ImageEntryData = {
|
|
55
|
+
url?: string;
|
|
56
|
+
image?: ImageSourcePropType;
|
|
57
|
+
resolvedImage?: ImageResolvedAssetSource;
|
|
58
|
+
sdf?: boolean;
|
|
59
|
+
stretchX?: [number, number][];
|
|
60
|
+
stretchY?: [number, number][];
|
|
61
|
+
content?: [number, number, number, number];
|
|
62
|
+
scale?: number;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
type ResolvedImageEntryData = {
|
|
66
|
+
url?: string;
|
|
67
|
+
resolvedImage?: ImageResolvedAssetSource;
|
|
68
|
+
sdf?: boolean;
|
|
69
|
+
stretchX?: [number, number][];
|
|
70
|
+
stretchY?: [number, number][];
|
|
71
|
+
content?: [number, number, number, number];
|
|
72
|
+
scale?: number;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type ImageEntry = string | ImageSourcePropType | ImageEntryData;
|
|
76
|
+
|
|
38
77
|
const isChildAnImage = (
|
|
39
78
|
child: ReactNode,
|
|
40
79
|
): child is React.ReactElement<typeof Image> => {
|
|
@@ -47,7 +86,7 @@ interface Props {
|
|
|
47
86
|
* Keys are names - see iconImage expressions, values can be either urls-s objects
|
|
48
87
|
* with format {uri: 'http://...'}` or `require('image.png')` or `import 'image.png'`
|
|
49
88
|
*/
|
|
50
|
-
images?: { [key: string]:
|
|
89
|
+
images?: { [key: string]: ImageEntry };
|
|
51
90
|
|
|
52
91
|
/**
|
|
53
92
|
* If you have an asset under Image.xcassets on iOS and the drawables directory on android
|
|
@@ -77,7 +116,9 @@ class Images extends React.PureComponent<Props> {
|
|
|
77
116
|
return {};
|
|
78
117
|
}
|
|
79
118
|
|
|
80
|
-
const images: {
|
|
119
|
+
const images: {
|
|
120
|
+
[key: string]: string | ImageResolvedAssetSource | ResolvedImageEntryData;
|
|
121
|
+
} = {};
|
|
81
122
|
let nativeImages: NativeImage[] = [];
|
|
82
123
|
|
|
83
124
|
if (this.props.images) {
|
|
@@ -93,11 +134,20 @@ class Images extends React.PureComponent<Props> {
|
|
|
93
134
|
);
|
|
94
135
|
} else if (_isUrlOrPath(value)) {
|
|
95
136
|
images[imageName] = value;
|
|
96
|
-
} else {
|
|
137
|
+
} else if (isImageSourcePropType(value)) {
|
|
97
138
|
const res = RNImage.resolveAssetSource(value);
|
|
98
139
|
if (res && res.uri) {
|
|
99
140
|
images[imageName] = res;
|
|
100
141
|
}
|
|
142
|
+
} else {
|
|
143
|
+
let imageEntry = value as ImageEntryData;
|
|
144
|
+
if (imageEntry.image) {
|
|
145
|
+
imageEntry = {
|
|
146
|
+
...imageEntry,
|
|
147
|
+
resolvedImage: RNImage.resolveAssetSource(imageEntry.image),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
images[imageName] = imageEntry;
|
|
101
151
|
}
|
|
102
152
|
}
|
|
103
153
|
}
|
|
@@ -147,7 +197,9 @@ class Images extends React.PureComponent<Props> {
|
|
|
147
197
|
type NativeProps = {
|
|
148
198
|
hasOnImageMissing: boolean;
|
|
149
199
|
onImageMissing?: (event: React.SyntheticEvent<Element, RNMBEvent>) => void;
|
|
150
|
-
images?: {
|
|
200
|
+
images?: {
|
|
201
|
+
[key: string]: string | ImageResolvedAssetSource | ResolvedImageEntryData;
|
|
202
|
+
};
|
|
151
203
|
nativeImages?: NativeImage[];
|
|
152
204
|
};
|
|
153
205
|
|