Skip to content

Commit 367e1e4

Browse files
Update docs from maps rnmapbox/maps@4f91f2f
1 parent f3489f1 commit 367e1e4

File tree

1 file changed

+47
-14
lines changed

1 file changed

+47
-14
lines changed

docs/examples/V10/CameraAnimation.md

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const CameraAnimation = () => {
6262
const [paddingRight, setPaddingRight] = useState(0);
6363
const [paddingTop, setPaddingTop] = useState(0);
6464
const [paddingBottom, setPaddingBottom] = useState(0);
65+
const [zoom, setZoom] = useState(10);
6566
const [minZoom, setMinZoom] = useState<number | undefined>(undefined);
6667
const [maxZoom, setMaxZoom] = useState<number | undefined>(undefined);
6768

@@ -165,6 +166,34 @@ const CameraAnimation = () => {
165166
[easing],
166167
);
167168

169+
const zoomCounter = useMemo(() => {
170+
const disabled = coordinates.length > 1;
171+
172+
return (
173+
<View style={{ flex: 1, paddingHorizontal: 10 }}>
174+
<View style={{ flex: 0, alignItems: 'center' }}>
175+
<Text style={{ fontWeight: 'bold', opacity: disabled ? 0.4 : 1 }}>
176+
{zoom}
177+
</Text>
178+
</View>
179+
<Slider
180+
thumbStyle={[
181+
styles.thumb,
182+
{ backgroundColor: disabled ? 'lightgray' : 'black' },
183+
]}
184+
trackStyle={{ opacity: disabled ? 0.1 : 1 }}
185+
value={zoom}
186+
disabled={disabled}
187+
minimumValue={1}
188+
maximumValue={20}
189+
onSlidingComplete={(_value) => {
190+
setZoom(Math.round(_value));
191+
}}
192+
/>
193+
</View>
194+
);
195+
}, [coordinates.length, zoom]);
196+
168197
const paddingCounter = useCallback(
169198
(value: number, setValue: (value: number) => void, label: string) => {
170199
return (
@@ -174,11 +203,7 @@ const CameraAnimation = () => {
174203
<Text style={{ fontWeight: 'bold' }}>{`${Math.round(value)}`}</Text>
175204
</View>
176205
<Slider
177-
thumbStyle={{
178-
backgroundColor: 'black',
179-
width: 15,
180-
height: 15,
181-
}}
206+
thumbStyle={styles.thumb}
182207
value={value}
183208
minimumValue={0}
184209
maximumValue={500}
@@ -200,16 +225,12 @@ const CameraAnimation = () => {
200225
<View style={{ flex: 1, paddingHorizontal: 10 }}>
201226
<View style={{ flex: 0, alignItems: 'center' }}>
202227
<Text>{label}</Text>
203-
<Text style={{ fontWeight: 'bold' }}>{`${
204-
value ?? 'Not set'
205-
}`}</Text>
228+
<Text style={{ fontWeight: 'bold' }}>
229+
{`${value ?? 'Not set'}`}
230+
</Text>
206231
</View>
207232
<Slider
208-
thumbStyle={{
209-
backgroundColor: 'black',
210-
width: 15,
211-
height: 15,
212-
}}
233+
thumbStyle={styles.thumb}
213234
value={value}
214235
minimumValue={-1}
215236
maximumValue={20}
@@ -232,7 +253,7 @@ const CameraAnimation = () => {
232253
<MapView style={styles.map}>
233254
<Camera
234255
{...centerOrBounds}
235-
zoomLevel={12}
256+
zoomLevel={zoom}
236257
minZoomLevel={minZoom}
237258
maxZoomLevel={maxZoom}
238259
padding={{
@@ -276,6 +297,13 @@ const CameraAnimation = () => {
276297
277298
<Divider style={styles.divider} />
278299
300+
<Text style={styles.sectionText}>Zoom</Text>
301+
<View style={[styles.buttonRow, { marginBottom: -6 }]}>
302+
{zoomCounter}
303+
</View>
304+
305+
<Divider style={styles.divider} />
306+
279307
<Text style={styles.sectionText}>Padding</Text>
280308
<View style={[styles.buttonRow, { marginTop: 6 }]}>
281309
{paddingCounter(paddingTop, setPaddingTop, 'Top')}
@@ -321,6 +349,11 @@ const styles = StyleSheet.create({
321349
divider: {
322350
marginVertical: 8,
323351
},
352+
thumb: {
353+
backgroundColor: 'black',
354+
width: 15,
355+
height: 15,
356+
},
324357
});
325358
326359
export default CameraAnimation;

0 commit comments

Comments
 (0)