-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMapView.tsx
36 lines (30 loc) · 1.19 KB
/
MapView.tsx
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
import * as React from 'react'
import { useEffect, useRef } from 'react';
import { Platform, UIManager, findNodeHandle, requireNativeComponent } from "react-native";
import MPCameraPosition from './MPCameraPosition';
const createFragment = (viewId: number | null, camera?: MPCameraPosition, showCompass?: boolean) => {
let command = (UIManager as any).MapsIndoorsView.Commands.create;
if (Platform.OS === 'android') {
command = command.toString();
}
UIManager.dispatchViewManagerCommand(
viewId,
// we are calling the 'create' command
command,
[viewId, JSON.stringify(camera), showCompass],
);
}
const MapView = ({ style, camera, showCompass }: { style: any, camera?: MPCameraPosition, showCompass?: boolean}) => {
const ref = useRef(null);
useEffect(() => {
const viewId = findNodeHandle(ref.current);
createFragment(viewId, camera, showCompass !== undefined ? showCompass : true);
}, []);
return (<MapsIndoorsViewManager
style={style}
ref={ref}
camera={camera}
showCompass={showCompass} />);
}
const MapsIndoorsViewManager = requireNativeComponent('MapsIndoorsView');
export default MapView;