@maplibre/maplibre-react-native 10.0.0-alpha.6 → 10.0.0-alpha.7

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 (51) hide show
  1. package/.eslintrc.js +3 -1
  2. package/.yarn/sdks/eslint/bin/eslint.js +8 -1
  3. package/.yarn/sdks/eslint/lib/api.js +8 -1
  4. package/.yarn/sdks/eslint/lib/unsupported-api.js +8 -1
  5. package/.yarn/sdks/prettier/bin/prettier.cjs +8 -1
  6. package/.yarn/sdks/prettier/index.cjs +8 -1
  7. package/.yarn/sdks/typescript/bin/tsc +8 -1
  8. package/.yarn/sdks/typescript/bin/tsserver +8 -1
  9. package/.yarn/sdks/typescript/lib/tsc.js +8 -1
  10. package/.yarn/sdks/typescript/lib/tsserver.js +20 -6
  11. package/.yarn/sdks/typescript/lib/tsserverlibrary.js +20 -6
  12. package/.yarn/sdks/typescript/lib/typescript.js +8 -1
  13. package/CHANGELOG.md +4 -0
  14. package/CONTRIBUTING.md +10 -9
  15. package/docs/Camera.md +3 -3
  16. package/docs/MapView.md +9 -33
  17. package/docs/UserLocation.md +10 -2
  18. package/docs/docs.json +16 -31
  19. package/javascript/Maplibre.ts +5 -1
  20. package/javascript/components/BackgroundLayer.tsx +27 -20
  21. package/javascript/components/Callout.tsx +40 -40
  22. package/javascript/components/Camera.tsx +421 -478
  23. package/javascript/components/CircleLayer.tsx +29 -22
  24. package/javascript/components/FillExtrusionLayer.tsx +23 -23
  25. package/javascript/components/FillLayer.tsx +22 -19
  26. package/javascript/components/HeatmapLayer.tsx +21 -19
  27. package/javascript/components/ImageSource.tsx +25 -32
  28. package/javascript/components/Images.tsx +36 -35
  29. package/javascript/components/Light.tsx +20 -47
  30. package/javascript/components/LineLayer.tsx +23 -20
  31. package/javascript/components/MapView.tsx +604 -554
  32. package/javascript/components/MarkerView.tsx +23 -38
  33. package/javascript/components/NativeUserLocation.tsx +3 -5
  34. package/javascript/components/PointAnnotation.tsx +111 -87
  35. package/javascript/components/RasterLayer.tsx +21 -18
  36. package/javascript/components/RasterSource.tsx +39 -42
  37. package/javascript/components/ShapeSource.tsx +287 -239
  38. package/javascript/components/Style.tsx +1 -1
  39. package/javascript/components/SymbolLayer.tsx +34 -28
  40. package/javascript/components/UserLocation.tsx +164 -151
  41. package/javascript/components/VectorSource.tsx +128 -117
  42. package/javascript/components/annotations/Annotation.tsx +105 -79
  43. package/javascript/{components/AbstractLayer.tsx → hooks/useAbstractLayer.ts} +54 -37
  44. package/javascript/hooks/useAbstractSource.ts +34 -0
  45. package/javascript/hooks/useNativeBridge.ts +125 -0
  46. package/javascript/hooks/useNativeRef.ts +13 -0
  47. package/javascript/hooks/useOnce.ts +12 -0
  48. package/javascript/utils/Logger.ts +3 -3
  49. package/package.json +2 -1
  50. package/javascript/components/AbstractSource.tsx +0 -27
  51. package/javascript/components/NativeBridgeComponent.tsx +0 -117
@@ -5,10 +5,12 @@ export {
5
5
  type CameraPadding,
6
6
  type CameraAnimationMode,
7
7
  type CameraBounds,
8
+ type CameraRef,
8
9
  } from './components/Camera';
9
- export {default as MapView, type MapViewState} from './components/MapView';
10
+ export {default as MapView, type MapViewRef} from './components/MapView';
10
11
  export {default as Light} from './components/Light';
11
12
  export {default as PointAnnotation} from './components/PointAnnotation';
13
+ export type {PointAnnotationRef} from './components/PointAnnotation';
12
14
  export {default as Annotation} from './components/annotations/Annotation';
13
15
  export {default as Callout} from './components/Callout';
14
16
  export {requestAndroidLocationPermissions} from './requestAndroidLocationPermissions';
@@ -16,8 +18,10 @@ export {
16
18
  default as UserLocation,
17
19
  UserLocationRenderMode,
18
20
  } from './components/UserLocation';
21
+ export type {UserLocationRef} from './components/UserLocation';
19
22
  export {default as VectorSource} from './components/VectorSource';
20
23
  export {default as ShapeSource} from './components/ShapeSource';
24
+ export type {ShapeSourceRef} from './components/ShapeSource';
21
25
  export {default as RasterSource} from './components/RasterSource';
22
26
  export {default as ImageSource} from './components/ImageSource';
23
27
  export {default as Images} from './components/Images';
@@ -1,16 +1,18 @@
1
1
  import {BackgroundLayerStyleProps} from '../utils/MaplibreStyles';
2
2
  import BaseProps from '../types/BaseProps';
3
+ import useAbstractLayer, {
4
+ BaseLayerProps,
5
+ NativeBaseProps,
6
+ } from '../hooks/useAbstractLayer';
3
7
 
4
- import AbstractLayer, {BaseLayerProps, NativeBaseProps} from './AbstractLayer';
5
-
6
- import React, {ReactNode} from 'react';
8
+ import React from 'react';
7
9
  import {NativeModules, requireNativeComponent} from 'react-native';
8
10
 
9
11
  const MapLibreGL = NativeModules.MLNModule;
10
12
 
11
13
  export const NATIVE_MODULE_NAME = 'RCTMLNBackgroundLayer';
12
14
 
13
- interface BackgroundLayerProps extends BaseProps, BaseLayerProps {
15
+ export interface BackgroundLayerProps extends BaseProps, BaseLayerProps {
14
16
  /**
15
17
  * Customizable style attributes
16
18
  */
@@ -21,23 +23,28 @@ interface NativeProps
21
23
  extends Omit<BackgroundLayerProps, 'style'>,
22
24
  NativeBaseProps {}
23
25
 
24
- class BackgroundLayer extends AbstractLayer<BackgroundLayerProps, NativeProps> {
25
- static defaultProps = {
26
- sourceID: MapLibreGL.StyleSource.DefaultSourceID,
27
- };
28
-
29
- render(): ReactNode {
30
- return (
31
- <RCTMLNBackgroundLayer
32
- testID="rctmlnBackgroundLayer"
33
- ref={this.setNativeLayer}
34
- {...this.baseProps}
35
- />
36
- );
37
- }
38
- }
39
-
40
26
  const RCTMLNBackgroundLayer =
41
27
  requireNativeComponent<BackgroundLayerProps>(NATIVE_MODULE_NAME);
42
28
 
29
+ const BackgroundLayer: React.FC<BackgroundLayerProps> = ({
30
+ sourceID = MapLibreGL.StyleSource.DefaultSourceID,
31
+ ...props
32
+ }: BackgroundLayerProps) => {
33
+ const {baseProps, setNativeLayer} = useAbstractLayer<
34
+ BackgroundLayerProps,
35
+ NativeProps
36
+ >({
37
+ ...props,
38
+ sourceID,
39
+ });
40
+
41
+ return (
42
+ <RCTMLNBackgroundLayer
43
+ testID="rctmlnBackgroundLayer"
44
+ ref={setNativeLayer}
45
+ {...baseProps}
46
+ />
47
+ );
48
+ };
49
+
43
50
  export default BackgroundLayer;
@@ -82,59 +82,59 @@ interface NativeProps extends Omit<CalloutProps, 'style'> {
82
82
  /**
83
83
  * Callout that displays information about a selected annotation near the annotation.
84
84
  */
85
- class Callout extends React.PureComponent<CalloutProps> {
86
- get _containerStyle(): ViewStyle[] {
87
- const style = [
88
- {
89
- position: 'absolute',
90
- zIndex: 999,
91
- backgroundColor: 'transparent',
92
- } as ViewStyle,
93
- ];
85
+ const Callout = (props: CalloutProps): ReactElement => {
86
+ const {
87
+ title,
88
+ style,
89
+ containerStyle,
90
+ contentStyle,
91
+ tipStyle,
92
+ textStyle,
93
+ children,
94
+ } = props;
94
95
 
95
- if (this.props.containerStyle) {
96
- style.push(this.props.containerStyle);
97
- }
96
+ const _containerStyle: ViewStyle[] = [
97
+ {
98
+ position: 'absolute',
99
+ zIndex: 999,
100
+ backgroundColor: 'transparent',
101
+ ...containerStyle,
102
+ } as ViewStyle,
103
+ ];
98
104
 
99
- return style;
100
- }
105
+ const _hasChildren = React.Children.count(children) > 0;
101
106
 
102
- get _hasChildren(): boolean {
103
- return React.Children.count(this.props.children) > 0;
104
- }
105
-
106
- _renderDefaultCallout(): ReactElement {
107
+ const _renderDefaultCallout = (): ReactElement => {
107
108
  return (
108
- <Animated.View style={[styles.container, this.props.style]}>
109
- <View style={[styles.content, this.props.contentStyle]}>
110
- <Text style={[styles.title, this.props.textStyle]}>
111
- {this.props.title}
109
+ <Animated.View testID="container" style={[styles.container, style]}>
110
+ <View testID="wrapper" style={[styles.content, contentStyle]}>
111
+ <Text testID="title" style={[styles.title, textStyle]}>
112
+ {title}
112
113
  </Text>
113
114
  </View>
114
- <View style={[styles.tip, this.props.tipStyle]} />
115
+ <View testID="tip" style={[styles.tip, tipStyle]} />
115
116
  </Animated.View>
116
117
  );
117
- }
118
+ };
118
119
 
119
- _renderCustomCallout(): ReactElement {
120
+ const _renderCustomCallout = (): ReactElement => {
120
121
  return (
121
- <Animated.View {...this.props} style={this.props.style}>
122
- {this.props.children}
122
+ <Animated.View testID="container" {...props} style={style}>
123
+ {children}
123
124
  </Animated.View>
124
125
  );
125
- }
126
+ };
126
127
 
127
- render(): ReactElement {
128
- const calloutContent = this._hasChildren
129
- ? this._renderCustomCallout()
130
- : this._renderDefaultCallout();
131
- return (
132
- <RCTMLNCallout style={this._containerStyle}>
133
- {calloutContent}
134
- </RCTMLNCallout>
135
- );
136
- }
137
- }
128
+ const calloutContent = _hasChildren
129
+ ? _renderCustomCallout()
130
+ : _renderDefaultCallout();
131
+
132
+ return (
133
+ <RCTMLNCallout testID="callout" style={_containerStyle}>
134
+ {calloutContent}
135
+ </RCTMLNCallout>
136
+ );
137
+ };
138
138
 
139
139
  const RCTMLNCallout = requireNativeComponent<NativeProps>(NATIVE_MODULE_NAME);
140
140