1616
1717import { NativeModules } from 'react-native' ;
1818import type { Location } from '../../shared/types' ;
19- import { commands , sendCommand } from '../../shared/viewManager' ;
19+ import {
20+ commands ,
21+ createControllerContext ,
22+ type ControllerResult ,
23+ } from '../../shared/viewManager' ;
2024import type {
2125 CameraPosition ,
2226 Circle ,
@@ -36,19 +40,28 @@ import type {
3640} from './types' ;
3741const { NavViewModule } = NativeModules ;
3842
39- export const getMapViewController = ( viewId : number ) : MapViewController => {
40- return {
43+ export const getMapViewController = (
44+ viewId : number
45+ ) : ControllerResult < MapViewController > => {
46+ const { sendCommand, dispose } = createControllerContext (
47+ viewId ,
48+ 'MapViewController'
49+ ) ;
50+
51+ const controller : MapViewController = {
4152 setMapType : ( mapType : MapType ) => {
42- sendCommand ( viewId , commands . setMapType , [ mapType ] ) ;
53+ sendCommand ( 'setMapType' , commands . setMapType , [ mapType ] ) ;
4354 } ,
4455 setMapStyle : ( mapStyle : string ) => {
45- sendCommand ( viewId , commands . setMapStyle , [ mapStyle ] ) ;
56+ sendCommand ( 'setMapStyle' , commands . setMapStyle , [ mapStyle ] ) ;
4657 } ,
4758 setMapToolbarEnabled : ( index : boolean ) => {
48- sendCommand ( viewId , commands . setMapToolbarEnabled , [ index ] ) ;
59+ sendCommand ( 'setMapToolbarEnabled' , commands . setMapToolbarEnabled , [
60+ index ,
61+ ] ) ;
4962 } ,
5063 clearMapView : ( ) => {
51- sendCommand ( viewId , commands . clearMapView , [ ] ) ;
64+ sendCommand ( 'clearMapView' , commands . clearMapView , [ ] ) ;
5265 } ,
5366
5467 addCircle : async ( circleOptions : CircleOptions ) : Promise < Circle > => {
@@ -77,73 +90,95 @@ export const getMapViewController = (viewId: number): MapViewController => {
7790 } ,
7891
7992 removeMarker : ( id : string ) => {
80- sendCommand ( viewId , commands . removeMarker , [ id ] ) ;
93+ sendCommand ( 'removeMarker' , commands . removeMarker , [ id ] ) ;
8194 } ,
8295
8396 removePolyline : ( id : string ) => {
84- sendCommand ( viewId , commands . removePolyline , [ id ] ) ;
97+ sendCommand ( 'removePolyline' , commands . removePolyline , [ id ] ) ;
8598 } ,
8699
87100 removePolygon : ( id : string ) => {
88- sendCommand ( viewId , commands . removePolygon , [ id ] ) ;
101+ sendCommand ( 'removePolygon' , commands . removePolygon , [ id ] ) ;
89102 } ,
90103
91104 removeCircle : ( id : string ) => {
92- sendCommand ( viewId , commands . removeCircle , [ id ] ) ;
105+ sendCommand ( 'removeCircle' , commands . removeCircle , [ id ] ) ;
93106 } ,
94107
95108 setIndoorEnabled : ( isOn : boolean ) => {
96- sendCommand ( viewId , commands . setIndoorEnabled , [ isOn ] ) ;
109+ sendCommand ( 'setIndoorEnabled' , commands . setIndoorEnabled , [ isOn ] ) ;
97110 } ,
98111
99112 setTrafficEnabled : ( isOn : boolean ) => {
100- sendCommand ( viewId , commands . setTrafficEnabled , [ isOn ] ) ;
113+ sendCommand ( 'setTrafficEnabled' , commands . setTrafficEnabled , [ isOn ] ) ;
101114 } ,
102115
103116 setCompassEnabled : ( isOn : boolean ) => {
104- sendCommand ( viewId , commands . setCompassEnabled , [ isOn ] ) ;
117+ sendCommand ( 'setCompassEnabled' , commands . setCompassEnabled , [ isOn ] ) ;
105118 } ,
106119
107120 setMyLocationButtonEnabled : ( isOn : boolean ) => {
108- sendCommand ( viewId , commands . setMyLocationButtonEnabled , [ isOn ] ) ;
121+ sendCommand (
122+ 'setMyLocationButtonEnabled' ,
123+ commands . setMyLocationButtonEnabled ,
124+ [ isOn ]
125+ ) ;
109126 } ,
110127
111128 setMyLocationEnabled : ( isOn : boolean ) => {
112- sendCommand ( viewId , commands . setMyLocationEnabled , [ isOn ] ) ;
129+ sendCommand ( 'setMyLocationEnabled' , commands . setMyLocationEnabled , [
130+ isOn ,
131+ ] ) ;
113132 } ,
114133
115134 setRotateGesturesEnabled : ( isOn : boolean ) => {
116- sendCommand ( viewId , commands . setRotateGesturesEnabled , [ isOn ] ) ;
135+ sendCommand (
136+ 'setRotateGesturesEnabled' ,
137+ commands . setRotateGesturesEnabled ,
138+ [ isOn ]
139+ ) ;
117140 } ,
118141
119142 setScrollGesturesEnabled : ( isOn : boolean ) => {
120- sendCommand ( viewId , commands . setScrollGesturesEnabled , [ isOn ] ) ;
143+ sendCommand (
144+ 'setScrollGesturesEnabled' ,
145+ commands . setScrollGesturesEnabled ,
146+ [ isOn ]
147+ ) ;
121148 } ,
122149
123150 setScrollGesturesEnabledDuringRotateOrZoom : ( isOn : boolean ) => {
124- sendCommand ( viewId , commands . setScrollGesturesEnabledDuringRotateOrZoom , [
125- isOn ,
126- ] ) ;
151+ sendCommand (
152+ 'setScrollGesturesEnabledDuringRotateOrZoom' ,
153+ commands . setScrollGesturesEnabledDuringRotateOrZoom ,
154+ [ isOn ]
155+ ) ;
127156 } ,
128157
129158 setZoomControlsEnabled : ( isOn : boolean ) => {
130- sendCommand ( viewId , commands . setZoomControlsEnabled , [ isOn ] ) ;
159+ sendCommand ( 'setZoomControlsEnabled' , commands . setZoomControlsEnabled , [
160+ isOn ,
161+ ] ) ;
131162 } ,
132163
133164 setZoomLevel : ( level : number ) => {
134- sendCommand ( viewId , commands . setZoomLevel , [ level ] ) ;
165+ sendCommand ( 'setZoomLevel' , commands . setZoomLevel , [ level ] ) ;
135166 } ,
136167
137168 setTiltGesturesEnabled : ( isOn : boolean ) => {
138- sendCommand ( viewId , commands . setTiltGesturesEnabled , [ isOn ] ) ;
169+ sendCommand ( 'setTiltGesturesEnabled' , commands . setTiltGesturesEnabled , [
170+ isOn ,
171+ ] ) ;
139172 } ,
140173
141174 setZoomGesturesEnabled : ( isOn : boolean ) => {
142- sendCommand ( viewId , commands . setZoomGesturesEnabled , [ isOn ] ) ;
175+ sendCommand ( 'setZoomGesturesEnabled' , commands . setZoomGesturesEnabled , [
176+ isOn ,
177+ ] ) ;
143178 } ,
144179
145180 setBuildingsEnabled : ( isOn : boolean ) => {
146- sendCommand ( viewId , commands . setBuildingsEnabled , [ isOn ] ) ;
181+ sendCommand ( 'setBuildingsEnabled' , commands . setBuildingsEnabled , [ isOn ] ) ;
147182 } ,
148183
149184 getCameraPosition : async ( ) : Promise < CameraPosition > => {
@@ -163,12 +198,19 @@ export const getMapViewController = (viewId: number): MapViewController => {
163198 } ,
164199
165200 moveCamera : ( cameraPosition : CameraPosition ) => {
166- sendCommand ( viewId , commands . moveCamera , [ cameraPosition ] ) ;
201+ sendCommand ( 'moveCamera' , commands . moveCamera , [ cameraPosition ] ) ;
167202 } ,
168203
169204 setPadding : ( padding : Padding ) => {
170205 const { top = 0 , left = 0 , bottom = 0 , right = 0 } = padding ;
171- sendCommand ( viewId , commands . setPadding , [ top , left , bottom , right ] ) ;
206+ sendCommand ( 'setPadding' , commands . setPadding , [
207+ top ,
208+ left ,
209+ bottom ,
210+ right ,
211+ ] ) ;
172212 } ,
173213 } ;
214+
215+ return { controller, dispose } ;
174216} ;
0 commit comments