Skip to content

Commit

Permalink
chore: small logic improvements to example app (#371)
Browse files Browse the repository at this point in the history
Release-As: 0.9.2
  • Loading branch information
jokerttu authored Dec 4, 2024
1 parent a6fa22e commit 17f5458
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
26 changes: 14 additions & 12 deletions example/src/controls/navigationControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const NavigationControls: React.FC<NavigationControlsProps> = ({
// single destination:
const initWaypoint = async () => {
if (!latitude.trim() || !longitude.trim()) {
Alert.alert('Invalid destination');
Alert.alert('Set lat lng values first');
return;
}
const waypoint: Waypoint = {
Expand Down Expand Up @@ -117,19 +117,16 @@ const NavigationControls: React.FC<NavigationControlsProps> = ({
);
};

const initWaypointToCameraLocation = async () => {
const setLocationFromCameraLocation = async () => {
if (getCameraPosition) {
const cameraPosition = await getCameraPosition();
if (cameraPosition) {
onLatChanged(cameraPosition.target.lat.toString());
onLngChanged(cameraPosition.target.lng.toString());
}
await initWaypoint();
}
};

// multi destination:
// set your device (emulator) location to new new york timesquare
const initWaypoints = async () => {
const wp1 = {
placeId: 'ChIJw____96GhYARCVVwg5cT7c0', // Golden gate, SF
Expand Down Expand Up @@ -199,7 +196,7 @@ const NavigationControls: React.FC<NavigationControlsProps> = ({

const simulateLocation = () => {
if (!latitude.trim() || !longitude.trim()) {
Alert.alert('Invalid destination');
Alert.alert('Set lat lng values first');
return;
}

Expand Down Expand Up @@ -330,6 +327,7 @@ const NavigationControls: React.FC<NavigationControlsProps> = ({

return (
<View>
<Text>Target</Text>
<TextInput
style={styles.input}
onChangeText={onLatChanged}
Expand All @@ -346,13 +344,18 @@ const NavigationControls: React.FC<NavigationControlsProps> = ({
placeholderTextColor="#000"
keyboardType="numeric"
/>
<Button title="Dispose navigation" onPress={disposeNavigation} />
<Button title="Single Destination" onPress={initWaypoint} />
<Button title="Multiple Destination" onPress={initWaypoints} />
<Button
title="Set destination from Camera Location"
onPress={initWaypointToCameraLocation}
title="Set target from Camera Location"
onPress={setLocationFromCameraLocation}
/>
<Button
title="Simulate location from target"
onPress={simulateLocation}
/>
<Button title="Set target as Destination" onPress={initWaypoint} />
<View style={styles.controlButtonGap} />
<Button title="Multiple Destination" onPress={initWaypoints} />
<Button title="Dispose navigation" onPress={disposeNavigation} />
<Button
title="Continue to next destination"
onPress={continueToNextDestination}
Expand All @@ -362,7 +365,6 @@ const NavigationControls: React.FC<NavigationControlsProps> = ({
<Button title="Stop guidance" onPress={stopGuidance} />
<Button title="Start updating location" onPress={startUpdatingLocation} />
<Button title="Stop updating location" onPress={stopUpdatingLocation} />
<Button title="Simulate location" onPress={simulateLocation} />
<Button title="Start simulation" onPress={startSimulation} />
<Button title="Stop simulation" onPress={stopSimulation} />
<Button title="Pause simulation" onPress={pauseSimulation} />
Expand Down
3 changes: 3 additions & 0 deletions example/src/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ const styles = StyleSheet.create({
margin: 10,
justifyContent: 'space-evenly',
},
controlButtonGap: {
height: 15,
},
dropdownButtonStyle: {
marginLeft: 12,
width: '50%',
Expand Down

0 comments on commit 17f5458

Please sign in to comment.