1616
1717import React , { useEffect , useState } from 'react' ;
1818
19- import { Button , Switch , Text , TextInput , View } from 'react-native' ;
19+ import { Button , Text , TextInput , View } from 'react-native' ;
2020
2121import SelectDropdown from 'react-native-select-dropdown' ;
2222import styles from '../styles' ;
@@ -27,7 +27,6 @@ import {
2727 type Circle ,
2828 type Polyline ,
2929 type Polygon ,
30- type Padding ,
3130} from '@googlemaps/react-native-navigation-sdk' ;
3231
3332export interface MapControlsProps {
@@ -42,12 +41,7 @@ const MapsControls: React.FC<MapControlsProps> = ({ mapViewController }) => {
4241 const [ enableLocationMarker , setEnableLocationMarker ] = useState ( true ) ;
4342 const [ latitude , onLatChanged ] = useState ( '' ) ;
4443 const [ longitude , onLngChanged ] = useState ( '' ) ;
45- const [ padding , setPadding ] = useState < Padding > ( {
46- top : 0 ,
47- bottom : 0 ,
48- left : 0 ,
49- right : 0 ,
50- } ) ;
44+ const [ customPaddingEnabled , setCustomPaddingEnabled ] = useState ( false ) ;
5145
5246 useEffect ( ( ) => {
5347 if ( zoom !== null ) {
@@ -202,10 +196,20 @@ const MapsControls: React.FC<MapControlsProps> = ({ mapViewController }) => {
202196 mapViewController . clearMapView ( ) ;
203197 } ;
204198
205- const onPaddingChanged = ( edge : keyof typeof padding , value : string ) => {
206- const updatedPadding : Padding = { ...padding , [ edge ] : Number ( value ) } ;
207- setPadding ( updatedPadding ) ;
208- mapViewController . setPadding ( updatedPadding ) ;
199+ const toggleCustomPadding = ( ) => {
200+ if ( ! customPaddingEnabled ) {
201+ // Enable custom paddings: more on top and bottom
202+ mapViewController . setPadding ( {
203+ top : 60 ,
204+ bottom : 40 ,
205+ left : 10 ,
206+ right : 10 ,
207+ } ) ;
208+ } else {
209+ // Disable: reset paddings
210+ mapViewController . setPadding ( { top : 0 , bottom : 0 , left : 0 , right : 0 } ) ;
211+ }
212+ setCustomPaddingEnabled ( ! customPaddingEnabled ) ;
209213 } ;
210214
211215 return (
@@ -254,9 +258,9 @@ const MapsControls: React.FC<MapControlsProps> = ({ mapViewController }) => {
254258 < Button title = "Get camera position" onPress = { getCameraPositionClicked } />
255259 < View style = { styles . rowContainer } >
256260 < Text > Location marker</ Text >
257- < Switch
258- value = { enableLocationMarker }
259- onValueChange = { ( ) => {
261+ < Button
262+ title = { enableLocationMarker ? 'Disable' : 'Enable' }
263+ onPress = { ( ) => {
260264 setEnableLocationMarker ( ! enableLocationMarker ) ;
261265 setMyLocationButtonEnabled ( ! enableLocationMarker ) ;
262266 } }
@@ -295,43 +299,10 @@ const MapsControls: React.FC<MapControlsProps> = ({ mapViewController }) => {
295299 </ View >
296300 < View style = { styles . controlButtonGap } />
297301 < View style = { styles . rowContainer } >
298- < Text > Top padding</ Text >
299- < TextInput
300- style = { styles . input }
301- onChangeText = { value => onPaddingChanged ( 'top' , value ) }
302- value = { padding . top ?. toFixed ( 0 ) }
303- keyboardType = "numeric"
304- inputMode = "numeric"
305- />
306- </ View >
307- < View style = { styles . rowContainer } >
308- < Text > Bottom padding</ Text >
309- < TextInput
310- style = { styles . input }
311- onChangeText = { value => onPaddingChanged ( 'bottom' , value ) }
312- value = { padding . bottom ?. toFixed ( 0 ) }
313- keyboardType = "numeric"
314- inputMode = "numeric"
315- />
316- </ View >
317- < View style = { styles . rowContainer } >
318- < Text > Left padding</ Text >
319- < TextInput
320- style = { styles . input }
321- onChangeText = { value => onPaddingChanged ( 'left' , value ) }
322- value = { padding . left ?. toFixed ( 0 ) }
323- keyboardType = "numeric"
324- inputMode = "numeric"
325- />
326- </ View >
327- < View style = { styles . rowContainer } >
328- < Text > Right padding</ Text >
329- < TextInput
330- style = { styles . input }
331- onChangeText = { value => onPaddingChanged ( 'right' , value ) }
332- value = { padding . right ?. toFixed ( 0 ) }
333- keyboardType = "numeric"
334- inputMode = "numeric"
302+ < Text > Custom map paddings</ Text >
303+ < Button
304+ title = { customPaddingEnabled ? 'Disable' : 'Enable' }
305+ onPress = { toggleCustomPadding }
335306 />
336307 </ View >
337308 </ View >
0 commit comments