Skip to content

Commit b419ff2

Browse files
Update docs from maps rnmapbox/maps@cedd998
1 parent b453b97 commit b419ff2

File tree

4 files changed

+241
-75
lines changed

4 files changed

+241
-75
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
custom_edit_url: https://github.com/rnmapbox/maps/blob/main/src/components/CameraGestureObserver.tsx
3+
---
4+
5+
6+
7+
```tsx
8+
import { CameraGestureObserver } from '@rnmapbox/maps';
9+
10+
CameraGestureObserver
11+
12+
```
13+
CameraGestureObserver
14+
15+
Unified native observer optimized for onMapSteady.
16+
17+
## props
18+
19+
20+
### quietPeriodMs
21+
22+
```tsx
23+
number
24+
```
25+
Time in milliseconds to wait after last camera change before emitting 'steady' event.
26+
Default is 200ms.
27+
28+
[Camera Gesture Observer](../examples/Map/CameraGestureObserver)
29+
30+
### maxIntervalMs
31+
32+
```tsx
33+
number
34+
```
35+
Maximum time in milliseconds before emitting 'timeout' event during continuous activity.
36+
37+
[Camera Gesture Observer](../examples/Map/CameraGestureObserver)
38+
39+
### onMapSteady
40+
41+
```tsx
42+
func
43+
```
44+
Callback when the map reaches a steady state (no active gestures or animations).
45+
*signature:*`(event:{nativeEvent: OnMapSteadyEvent}) => void`
46+
47+
[Camera Gesture Observer](../examples/Map/CameraGestureObserver)
48+
49+
50+
51+
52+
53+
54+
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
title: Camera Gesture Observer
3+
tags: [CameraGestureObserver#onMapSteady, CameraGestureObserver#quietPeriodMs, CameraGestureObserver#maxIntervalMs]
4+
custom_props:
5+
example_rel_path: Map/CameraGestureObserver.tsx
6+
custom_edit_url: https://github.com/rnmapbox/maps/tree/master/example/src/examples/Map/CameraGestureObserver.tsx
7+
---
8+
9+
Demonstrates how to detect when the map becomes steady after user gestures (pan, zoom, rotate). The CameraGestureObserver component fires the onMapSteady event after a configurable quiet period, providing information about the last gesture type and idle duration.
10+
11+
12+
```jsx
13+
import { useCallback, useState } from 'react';
14+
import { View, StyleSheet, Text } from 'react-native';
15+
import { MapView, Camera, CameraGestureObserver, type OnMapSteadyEvent } from '@rnmapbox/maps';
16+
17+
import { ExampleWithMetadata } from '../common/ExampleMetadata'; // exclude-from-doc
18+
19+
const styles = StyleSheet.create({
20+
container: {
21+
flex: 1,
22+
},
23+
map: {
24+
flex: 1,
25+
},
26+
statusBar: {
27+
position: 'absolute',
28+
top: 50,
29+
left: 20,
30+
right: 20,
31+
backgroundColor: 'rgba(255, 255, 255, 0.95)',
32+
padding: 16,
33+
borderRadius: 8,
34+
shadowColor: '#000',
35+
shadowOffset: { width: 0, height: 2 },
36+
shadowOpacity: 0.25,
37+
shadowRadius: 3.84,
38+
elevation: 5,
39+
},
40+
title: {
41+
fontSize: 16,
42+
fontWeight: 'bold',
43+
marginBottom: 8,
44+
},
45+
statusText: {
46+
fontSize: 14,
47+
lineHeight: 20,
48+
},
49+
hint: {
50+
fontSize: 12,
51+
color: '#666',
52+
marginTop: 8,
53+
fontStyle: 'italic',
54+
},
55+
});
56+
57+
const CameraGestureObserverExample = () => {
58+
const [status, setStatus] = useState('Waiting for interaction...');
59+
60+
const onMapSteady = useCallback(({ nativeEvent } : { nativeEvent: OnMapSteadyEvent }) => {
61+
const { reason, idleDurationMs, lastGestureType, timestamp } = nativeEvent;
62+
63+
let message = `✓ Map is steady!\n\nReason: ${reason}`;
64+
65+
if (reason === 'steady' && idleDurationMs !== undefined) {
66+
message += `\nIdle duration: ${Math.round(idleDurationMs)}ms`;
67+
}
68+
69+
if (lastGestureType) {
70+
message += `\nLast gesture: ${lastGestureType}`;
71+
}
72+
73+
message += `\nTime: ${new Date(timestamp).toLocaleTimeString()}`;
74+
75+
console.log('[CameraGestureObserver]', nativeEvent);
76+
setStatus(message);
77+
}, []);
78+
79+
return (
80+
<View style={styles.container}>
81+
<MapView style={styles.map}>
82+
<Camera
83+
defaultSettings={{
84+
centerCoordinate: [-74.006, 40.7128],
85+
zoomLevel: 12,
86+
}}
87+
/>
88+
<CameraGestureObserver
89+
quietPeriodMs={200}
90+
maxIntervalMs={5000}
91+
onMapSteady={onMapSteady}
92+
/>
93+
</MapView>
94+
<View style={styles.statusBar}>
95+
<Text style={styles.title}>Map Steady State</Text>
96+
<Text style={styles.statusText}>{status}</Text>
97+
<Text style={styles.hint}>
98+
Pan, zoom, or rotate the map to see the steady state detection
99+
</Text>
100+
</View>
101+
</View>
102+
);
103+
};
104+
105+
export default CameraGestureObserverExample;
106+
107+
108+
```
109+
110+
}
111+

0 commit comments

Comments
 (0)