Skip to content

Commit 74049b4

Browse files
committed
feat: update setPadding interface
1 parent 3f1731f commit 74049b4

File tree

5 files changed

+74
-77
lines changed

5 files changed

+74
-77
lines changed

example/src/controls/mapsControls.tsx

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
type Circle,
2828
type Polyline,
2929
type Polygon,
30+
type Padding,
3031
} from '@googlemaps/react-native-navigation-sdk';
3132

3233
export interface MapControlsProps {
@@ -41,11 +42,11 @@ const MapsControls: React.FC<MapControlsProps> = ({ mapViewController }) => {
4142
const [enableLocationMarker, setEnableLocationMarker] = useState(true);
4243
const [latitude, onLatChanged] = useState('');
4344
const [longitude, onLngChanged] = useState('');
44-
const [padding, setPadding] = useState({
45-
top: '',
46-
bottom: '',
47-
left: '',
48-
right: '',
45+
const [padding, setPadding] = useState<Padding>({
46+
top: 0,
47+
bottom: 0,
48+
left: 0,
49+
right: 0,
4950
});
5051

5152
useEffect(() => {
@@ -202,14 +203,9 @@ const MapsControls: React.FC<MapControlsProps> = ({ mapViewController }) => {
202203
};
203204

204205
const onPaddingChanged = (edge: keyof typeof padding, value: string) => {
205-
const updatedPadding = { ...padding, [edge]: value };
206+
const updatedPadding: Padding = { ...padding, [edge]: Number(value) };
206207
setPadding(updatedPadding);
207-
mapViewController.setPadding(
208-
Number(updatedPadding.top),
209-
Number(updatedPadding.left),
210-
Number(updatedPadding.bottom),
211-
Number(updatedPadding.right)
212-
);
208+
mapViewController.setPadding(updatedPadding);
213209
};
214210

215211
return (
@@ -297,38 +293,47 @@ const MapsControls: React.FC<MapControlsProps> = ({ mapViewController }) => {
297293
dropdownStyle={styles.dropdownMenuStyle}
298294
/>
299295
</View>
300-
<TextInput
301-
style={styles.input}
302-
onChangeText={value => onPaddingChanged('top', value)}
303-
value={padding.top}
304-
placeholder="Top padding"
305-
placeholderTextColor="#000"
306-
keyboardType="numeric"
307-
/>
308-
<TextInput
309-
style={styles.input}
310-
onChangeText={value => onPaddingChanged('bottom', value)}
311-
value={padding.bottom}
312-
placeholder="Bottom padding"
313-
placeholderTextColor="#000"
314-
keyboardType="numeric"
315-
/>
316-
<TextInput
317-
style={styles.input}
318-
onChangeText={value => onPaddingChanged('left', value)}
319-
value={padding.left}
320-
placeholder="Left padding"
321-
placeholderTextColor="#000"
322-
keyboardType="numeric"
323-
/>
324-
<TextInput
325-
style={styles.input}
326-
onChangeText={value => onPaddingChanged('right', value)}
327-
value={padding.right}
328-
placeholder="Right padding"
329-
placeholderTextColor="#000"
330-
keyboardType="numeric"
331-
/>
296+
<View style={styles.controlButtonGap} />
297+
<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"
335+
/>
336+
</View>
332337
</View>
333338
);
334339
};

example/src/styles.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,42 +27,23 @@ const styles = StyleSheet.create({
2727
button: {
2828
backgroundColor: '#2196f3',
2929
},
30-
center: {
31-
alignItems: 'center',
32-
},
33-
toggleControl: {
34-
backgroundColor: '#9ee2ff',
35-
flexDirection: 'row',
36-
alignItems: 'center',
37-
alignSelf: 'baseline',
38-
position: 'absolute',
39-
right: 0,
40-
padding: 6,
41-
marginTop: 150,
42-
},
4330
input: {
4431
backgroundColor: '#ffffff',
4532
height: 40,
4633
margin: 12,
4734
borderWidth: 1,
4835
padding: 10,
49-
},
50-
zoomBtn: {
51-
color: '#fff',
36+
flexGrow: 1,
5237
},
5338
rowContainer: {
5439
margin: 5,
5540
marginLeft: 20,
5641
marginRight: 20,
5742
flexDirection: 'row',
5843
justifyContent: 'space-between',
44+
alignItems: 'center',
5945
color: 'white',
6046
},
61-
rowBtnContainer: {
62-
flexDirection: 'row',
63-
alignSelf: 'center',
64-
justifyContent: 'space-between',
65-
},
6647
controlButtons: {
6748
alignSelf: 'stretch',
6849
flexDirection: 'row',

src/auto/useNavigationAuto.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import type {
2929
Polygon,
3030
CameraPosition,
3131
UISettings,
32+
Padding,
3233
} from '../maps';
3334
import { useMemo } from 'react';
3435

@@ -189,12 +190,8 @@ export const useNavigationAuto = (): {
189190
return NavAutoModule.moveCamera(cameraPosition);
190191
},
191192

192-
setPadding: (
193-
top: number,
194-
left: number,
195-
bottom: number,
196-
right: number
197-
) => {
193+
setPadding: (padding: Padding) => {
194+
const { top = 0, left = 0, bottom = 0, right = 0 } = padding;
198195
return NavAutoModule.setPadding(top, left, bottom, right);
199196
},
200197
}),

src/maps/mapView/mapViewController.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import type {
3030
MapType,
3131
MapViewController,
3232
MarkerOptions,
33+
Padding,
3334
PolygonOptions,
3435
PolylineOptions,
3536
} from './types';
@@ -165,7 +166,8 @@ export const getMapViewController = (viewId: number): MapViewController => {
165166
sendCommand(viewId, commands.moveCamera, [cameraPosition]);
166167
},
167168

168-
setPadding: (top: number, left: number, bottom: number, right: number) => {
169+
setPadding: (padding: Padding) => {
170+
const { top = 0, left = 0, bottom = 0, right = 0 } = padding;
169171
sendCommand(viewId, commands.setPadding, [top, left, bottom, right]);
170172
},
171173
};

src/maps/mapView/types.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@ export enum MapType {
123123
HYBRID,
124124
}
125125

126+
/**
127+
* Defines the padding options for a map.
128+
*/
129+
export interface Padding {
130+
/** Top padding in pixels. */
131+
top?: number;
132+
/** Left padding in pixels. */
133+
left?: number;
134+
/** Bottom padding in pixels. */
135+
bottom?: number;
136+
/** Right padding in pixels. */
137+
right?: number;
138+
}
139+
126140
/**
127141
* Defines the type of the map fragment.
128142
*/
@@ -416,10 +430,8 @@ export interface MapViewController {
416430
/**
417431
* Sets padding to the map.
418432
*
419-
* @param top - Top padding.
420-
* @param left - Left padding.
421-
* @param bottom - Bottom padding.
422-
* @param right - Right padding.
433+
* @param padding - An object defining padding for each side.
434+
* Example: { top: 10, left: 5, bottom: 15, right: 10 }
423435
*/
424-
setPadding(top: number, left: number, bottom: number, right: number): void;
436+
setPadding(padding: Padding): void;
425437
}

0 commit comments

Comments
 (0)