@rnmapbox/maps 10.0.0-beta.42 → 10.0.0-beta.43

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 (30) hide show
  1. package/android/install.md +20 -1
  2. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.kt +1 -0
  3. package/docs/HeadingIndicator.md +1 -1
  4. package/docs/SymbolLayer.md +4 -3
  5. package/docs/docs.json +12 -8
  6. package/index.d.ts +11 -73
  7. package/ios/RCTMGL-v10/RCTMGLCamera.swift +3 -19
  8. package/javascript/components/AbstractLayer.tsx +72 -0
  9. package/javascript/components/BackgroundLayer.js +1 -1
  10. package/javascript/components/CircleLayer.js +1 -1
  11. package/javascript/components/FillExtrusionLayer.js +1 -1
  12. package/javascript/components/FillLayer.js +1 -1
  13. package/javascript/components/{HeadingIndicator.js → HeadingIndicator.tsx} +5 -6
  14. package/javascript/components/HeatmapLayer.js +1 -1
  15. package/javascript/components/LineLayer.js +1 -1
  16. package/javascript/components/RasterLayer.js +1 -1
  17. package/javascript/components/SkyLayer.js +1 -1
  18. package/javascript/components/SymbolLayer.tsx +113 -0
  19. package/javascript/components/Terrain.tsx +0 -60
  20. package/javascript/components/UserLocation.js +1 -1
  21. package/javascript/global.d.ts +4 -0
  22. package/javascript/utils/MapboxStyles.ts +157 -50
  23. package/javascript/utils/StyleValue.ts +8 -6
  24. package/javascript/utils/{filterUtils.js → filterUtils.tsx} +1 -1
  25. package/package.json +1 -1
  26. package/scripts/autogenHelpers/DocJSONBuilder.js +2 -3
  27. package/scripts/autogenHelpers/globals.js +18 -7
  28. package/scripts/templates/MapboxStyles.ts.ejs +7 -2
  29. package/javascript/components/AbstractLayer.js +0 -46
  30. package/javascript/components/SymbolLayer.js +0 -120
@@ -28,7 +28,7 @@ export function transformStyle(
28
28
  const styleProps = Object.keys(style) as Array<keyof typeof style>;
29
29
  for (const styleProp of styleProps) {
30
30
  const styleType = getStyleType(styleProp);
31
- let rawStyle: RawValueType = style[styleProp];
31
+ let rawStyle: RawValueType | undefined = style[styleProp];
32
32
 
33
33
  if (styleType === 'color' && typeof rawStyle === 'string') {
34
34
  const color = processColor(rawStyle);
@@ -43,11 +43,13 @@ export function transformStyle(
43
43
  (Image.resolveAssetSource(rawStyle) as unknown as RawValueType) || {};
44
44
  }
45
45
 
46
- const bridgeValue = new BridgeValue(rawStyle);
47
- nativeStyle[styleProp] = {
48
- styletype: styleType,
49
- stylevalue: bridgeValue.toJSON(),
50
- };
46
+ if (rawStyle !== undefined) {
47
+ const bridgeValue = new BridgeValue(rawStyle);
48
+ nativeStyle[styleProp] = {
49
+ styletype: styleType,
50
+ stylevalue: bridgeValue.toJSON(),
51
+ };
52
+ }
51
53
  }
52
54
 
53
55
  return nativeStyle;
@@ -1,4 +1,4 @@
1
- export function getFilter(filter) {
1
+ export function getFilter(filter: string[] | unknown) {
2
2
  if (!Array.isArray(filter) || filter.length === 0) {
3
3
  return [];
4
4
  }
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.42",
4
+ "version": "10.0.0-beta.43",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -22,7 +22,6 @@ const IGNORE_FILES = [
22
22
  'AbstractLayer',
23
23
  'AbstractSource',
24
24
  'NativeBridgeComponent',
25
- 'NativeBridgeComponent.tsx',
26
25
  ];
27
26
  const IGNORE_PATTERN = /\.web\./;
28
27
 
@@ -359,7 +358,7 @@ class DocJSONBuilder {
359
358
  return reject(err);
360
359
  }
361
360
 
362
- let fileName = fileNameWithExt.replace(/.(js)/, '');
361
+ let fileName = fileNameWithExt.replace(/\.(js|tsx|ts$)/, '');
363
362
  if (
364
363
  IGNORE_FILES.includes(fileName) ||
365
364
  fileName.match(IGNORE_PATTERN)
@@ -370,7 +369,7 @@ class DocJSONBuilder {
370
369
 
371
370
  let parsedComponents = docgen.parse(content, {
372
371
  babelOptions: {
373
- filename: fileName,
372
+ filename: fileNameWithExt,
374
373
  },
375
374
  });
376
375
  let [parsed] = parsedComponents;
@@ -292,20 +292,31 @@ global.dtsInterfaceType = function (prop) {
292
292
  propTypes.push('string[]');
293
293
  break;
294
294
  case 'enum':
295
- propTypes.push(`Enum<${pascelCase(prop.name)}Enum>[]`);
295
+ propTypes.push(
296
+ `Enum<${pascelCase(prop.name)}Enum, ${pascelCase(
297
+ prop.name,
298
+ )}EnumValues>[]`,
299
+ );
296
300
  break;
297
301
  }
298
302
  // propTypes.push('ConstantPropType');
299
303
  } else if (prop.type === 'number') {
300
304
  propTypes.push('number');
301
305
  } else if (prop.type === 'enum') {
302
- propTypes.push(`Enum<${pascelCase(prop.name)}Enum>`);
303
- } else {
304
- // images can be required which result in a number
305
- if (prop.image) {
306
- propTypes.push('number');
307
- }
306
+ propTypes.push(
307
+ `Enum<${pascelCase(prop.name)}Enum, ${pascelCase(prop.name)}EnumValues>`,
308
+ );
309
+ } else if (prop.type === 'boolean') {
310
+ propTypes.push('boolean');
311
+ } else if (prop.type === 'resolvedImage') {
312
+ propTypes.push('ResolvedImageType');
313
+ } else if (prop.type === 'formatted') {
314
+ propTypes.push('FormattedString');
315
+ } else if (prop.type === 'string') {
308
316
  propTypes.push('string');
317
+ } else {
318
+ console.error('Unexpected type:', prop.type);
319
+ throw new Error(`Unexpected type: ${prop.type} for ${prop.name}`);
309
320
  }
310
321
 
311
322
  /*
@@ -2,7 +2,7 @@
2
2
  const layers = locals.layers;
3
3
  -%>
4
4
  /* This file was generated from MapboxStyle.ts.ejs do not modify */
5
-
5
+ import { type ImageSourcePropType } from 'react-native';
6
6
 
7
7
  export type Translation = { x: number; y: number } | [number, number];
8
8
 
@@ -11,6 +11,8 @@ export interface Transition {
11
11
  delay: number;
12
12
  }
13
13
 
14
+ export type FormattedString = string; /* TODO */
15
+
14
16
  type ExpressionName =
15
17
  // Types
16
18
  | 'array' | 'boolean' | 'collator' | 'format' | 'image' | 'literal' | 'number' | 'number-format' | 'object' | 'string'
@@ -47,6 +49,8 @@ export type Expression = [ExpressionName, ...ExpressionField[]];
47
49
 
48
50
  type ExpressionParameters = 'zoom' | 'feature' | 'feature-state' | 'sky-radial-progress' | 'line-progress' | 'heatmap-density';
49
51
 
52
+ type ResolvedImageType = ImageSourcePropType;
53
+
50
54
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
51
55
  export type Value<T, AllowedParameters extends ExpressionParameters[] = []> =
52
56
  | T
@@ -59,9 +63,10 @@ export type Value<T, AllowedParameters extends ExpressionParameters[] = []> =
59
63
  <%- pascelCase(k) %> = '<%- k %>',
60
64
  <%_ } _%>
61
65
  }
66
+ type <%- pascelCase(enumInfo.name) %>EnumValues = <%- Object.keys(enumInfo.values).map(k => `'${k}'`).join(' | ') %>;
62
67
  <%_ } _%>
63
68
 
64
- type Enum<EnumType> = EnumType | keyof EnumType;
69
+ type Enum<EnumType, EnumValues> = EnumType | EnumValues;
65
70
 
66
71
  <%_ for (let layer of layers) { _%>
67
72
  export interface <%- pascelCase(layer.name) %>LayerStyleProps {
@@ -1,46 +0,0 @@
1
- /* eslint react/prop-types:0 */
2
- import React from 'react';
3
- import { processColor } from 'react-native';
4
-
5
- import { getFilter } from '../utils/filterUtils';
6
- import { transformStyle } from '../utils/StyleValue';
7
-
8
- class AbstractLayer extends React.PureComponent {
9
- get baseProps() {
10
- return {
11
- ...this.props,
12
- id: this.props.id,
13
- sourceID: this.props.sourceID,
14
- reactStyle: this.getStyle(this.props.style),
15
- minZoomLevel: this.props.minZoomLevel,
16
- maxZoomLevel: this.props.maxZoomLevel,
17
- aboveLayerID: this.props.aboveLayerID,
18
- belowLayerID: this.props.belowLayerID,
19
- layerIndex: this.props.layerIndex,
20
- filter: getFilter(this.props.filter),
21
- style: undefined,
22
- };
23
- }
24
-
25
- getStyleTypeFormatter(styleType) {
26
- if (styleType === 'color') {
27
- return processColor;
28
- }
29
- }
30
-
31
- getStyle(style) {
32
- return transformStyle(style);
33
- }
34
-
35
- setNativeProps(props) {
36
- if (this.refs.nativeLayer) {
37
- let propsToPass = props;
38
- if (props.style) {
39
- propsToPass = { ...props, reactStyle: this.getStyle(props.style) };
40
- }
41
- this.refs.nativeLayer.setNativeProps(propsToPass);
42
- }
43
- }
44
- }
45
-
46
- export default AbstractLayer;
@@ -1,120 +0,0 @@
1
- import React from 'react';
2
- import { View, NativeModules, requireNativeComponent } from 'react-native';
3
- import PropTypes from 'prop-types';
4
-
5
- import { viewPropTypes } from '../utils';
6
- import { SymbolLayerStyleProp } from '../utils/styleMap';
7
-
8
- import AbstractLayer from './AbstractLayer';
9
-
10
- const MapboxGL = NativeModules.MGLModule;
11
-
12
- export const NATIVE_MODULE_NAME = 'RCTMGLSymbolLayer';
13
-
14
- /**
15
- * SymbolLayer is a style layer that renders icon and text labels at points or along lines on the map.
16
- */
17
- class SymbolLayer extends AbstractLayer {
18
- static propTypes = {
19
- ...viewPropTypes,
20
-
21
- /**
22
- * A string that uniquely identifies the source in the style to which it is added.
23
- */
24
- id: PropTypes.string.isRequired,
25
-
26
- /**
27
- * The source from which to obtain the data to style.
28
- * If the source has not yet been added to the current style, the behavior is undefined.
29
- * Inferred from parent source only if the layer is a direct child to it.
30
- */
31
- sourceID: PropTypes.string,
32
-
33
- /**
34
- * Identifier of the layer within the source identified by the sourceID property from which the receiver obtains the data to style.
35
- */
36
- sourceLayerID: PropTypes.string,
37
-
38
- /**
39
- * Inserts a layer above aboveLayerID.
40
- */
41
- aboveLayerID: PropTypes.string,
42
-
43
- /**
44
- * Inserts a layer below belowLayerID
45
- */
46
- belowLayerID: PropTypes.string,
47
-
48
- /**
49
- * Inserts a layer at a specified index
50
- */
51
- layerIndex: PropTypes.number,
52
-
53
- /**
54
- * Filter only the features in the source layer that satisfy a condition that you define
55
- */
56
- filter: PropTypes.array,
57
-
58
- /**
59
- * The minimum zoom level at which the layer gets parsed and appears.
60
- */
61
- minZoomLevel: PropTypes.number,
62
-
63
- /**
64
- * The maximum zoom level at which the layer gets parsed and appears.
65
- */
66
- maxZoomLevel: PropTypes.number,
67
-
68
- /**
69
- * Customizable style attributes
70
- */
71
- style: PropTypes.oneOfType([
72
- SymbolLayerStyleProp,
73
- PropTypes.arrayOf(SymbolLayerStyleProp),
74
- ]),
75
- };
76
-
77
- static defaultProps = {
78
- sourceID: MapboxGL.StyleSource.DefaultSourceID,
79
- };
80
-
81
- _shouldSnapshot() {
82
- let isSnapshot = false;
83
-
84
- if (React.Children.count(this.props.children) <= 0) {
85
- return isSnapshot;
86
- }
87
-
88
- React.Children.forEach(this.props.children, (child) => {
89
- if (child.type === View) {
90
- isSnapshot = true;
91
- }
92
- });
93
-
94
- return isSnapshot;
95
- }
96
-
97
- render() {
98
- const props = {
99
- ...this.baseProps,
100
- snapshot: this._shouldSnapshot(),
101
- sourceLayerID: this.props.sourceLayerID,
102
- };
103
-
104
- return (
105
- <RCTMGLSymbolLayer ref="nativeLayer" {...props}>
106
- {this.props.children}
107
- </RCTMGLSymbolLayer>
108
- );
109
- }
110
- }
111
-
112
- const RCTMGLSymbolLayer = requireNativeComponent(
113
- NATIVE_MODULE_NAME,
114
- SymbolLayer,
115
- {
116
- nativeOnly: { reactStyle: true, snapshot: true },
117
- },
118
- );
119
-
120
- export default SymbolLayer;