-
-
Notifications
You must be signed in to change notification settings - Fork 937
Expand file tree
/
Copy pathMapUnMount.tsx
More file actions
51 lines (42 loc) · 1.25 KB
/
MapUnMount.tsx
File metadata and controls
51 lines (42 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import Mapbox from '@rnmapbox/maps';
import { useEffect, useState } from 'react';
import { Button } from 'react-native';
import sheet from '../../styles/sheet';
import { type ExampleWithMetadata } from '../common/ExampleMetadata'; // exclude-from-doc
const MapUnMount = () => {
const [isMounted, setIsMounted] = useState(true);
useEffect(() => {
Mapbox.locationManager.start();
return (): void => {
Mapbox.locationManager.stop();
};
}, []);
return (
<>
<Button
onPress={() => setIsMounted((mounted) => !mounted)}
title={isMounted ? 'unmount MapView' : 'mount MapView'}
/>
{isMounted ? (
<Mapbox.MapView
styleURL={Mapbox.StyleURL.Dark}
style={sheet.matchParent}
testID={'show-map'}
>
<Mapbox.Camera followZoomLevel={12} followUserLocation />
<Mapbox.UserLocation />
</Mapbox.MapView>
) : null}
</>
);
};
export default MapUnMount;
/* end-example-doc */
const metadata: ExampleWithMetadata['metadata'] = {
title: 'Map (un-)mount',
tags: [],
docs: `
Showing and hiding the the map should not lead to increased memory consumption, use this example to check it on the profiler.
`,
};
MapUnMount.metadata = metadata;