Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: small logic improvements to example app #371

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading