Skip to content

Commit b613c23

Browse files
Merge pull request #34 from AdvancedSoftwareEngineeringGroup3/hotfix/wf-maps/ios-transit-picker
Fixed iOS dropdown bug
2 parents cd1cabb + ed015d6 commit b613c23

3 files changed

Lines changed: 724 additions & 1076 deletions

File tree

client/FindRoute.js

Lines changed: 84 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import * as React from 'react';
22
import { useState, useRef } from 'react';
3-
import { StyleSheet, View, SafeAreaView, TextInput, Button, TouchableOpacity, Text, KeyboardAvoidingView, Platform } from 'react-native';
4-
import RNPickerSelect from 'react-native-picker-select';
3+
import { Platform } from 'react-native';
4+
import { StyleSheet, View, SafeAreaView, TextInput, Button, TouchableOpacity, Text, KeyboardAvoidingView } from 'react-native';
5+
import Picker from 'react-native-picker-select';
6+
import ActionSheet from 'react-native-actionsheet';
57

68
export default function FindRouteScreen({ navigation }){
79

10+
const pickerRef = useRef();
11+
const actionSheetRef = useRef();
812
const [start, setStartPoint] = useState("");
913
const [destination, setDestinationPoint] = useState("");
1014
const ref2 = React.useRef(null);
@@ -62,6 +66,10 @@ export default function FindRouteScreen({ navigation }){
6266
{label: 'Transit', value: 'transit'}
6367
];
6468

69+
const handlePickerSelect = (value) => {
70+
setSelectedMode(value);
71+
};
72+
6573
return (
6674
<SafeAreaView style={styles.container}>
6775
<TextInput
@@ -77,15 +85,39 @@ export default function FindRouteScreen({ navigation }){
7785
onChangeText={(text) => setDestinationPoint(text)}
7886
onSubmitEditing={() => alert(`Route Entered`)}
7987
/>
80-
81-
<Text style={styles.label}>Select an option:</Text>
82-
<RNPickerSelect
83-
onValueChange={(value) => setSelectedMode(value)}
84-
items={modeDropdownData}
85-
placeholder={{ label: "Choose an option...", value: null }}
86-
/>
87-
{selectedMode && <Text style={styles.selected}>Selected: {selectedMode}</Text>}
88-
88+
89+
<Text style={styles.label}>Select an option:</Text>
90+
{Platform.OS === 'android' ? (
91+
<TouchableOpacity onPress={() => pickerRef.current.togglePicker()}>
92+
<Picker
93+
ref={pickerRef}
94+
onValueChange={handlePickerSelect}
95+
items={modeDropdownData}
96+
placeholder={{ label: "Choose an option...", value: null }}
97+
useNativeAndroidPickerStyle={false}
98+
style={pickerSelectStyles}
99+
doneText="Done"
100+
/>
101+
</TouchableOpacity>
102+
) : (
103+
<>
104+
<TouchableOpacity onPress={() => actionSheetRef.current.show()}>
105+
<Text style={styles.label}>Choose an option...</Text>
106+
</TouchableOpacity>
107+
<ActionSheet
108+
ref={actionSheetRef}
109+
title={'Select Mode'}
110+
options={modeDropdownData.map(item => item.label).concat('Cancel')}
111+
cancelButtonIndex={modeDropdownData.length}
112+
onPress={(index) => {
113+
if (index !== modeDropdownData.length) {
114+
handlePickerSelect(modeDropdownData[index].value);
115+
}
116+
}}
117+
/>
118+
</>
119+
)}
120+
{selectedMode && <Text style={styles.selected}>Selected: {selectedMode}</Text>}
89121

90122
<TouchableOpacity style={styles.TouchableOpacity}
91123
onPress={isFormValid ? fetchRoutes : null}
@@ -105,6 +137,45 @@ const styles = StyleSheet.create({
105137
alignItems: "center",
106138
justifyContent: "center",
107139
},
108-
109-
140+
input: {
141+
width: '100%',
142+
padding: 10,
143+
borderWidth: 1,
144+
borderColor: 'gray',
145+
borderRadius: 4,
146+
marginBottom: 10,
147+
},
148+
label: {
149+
marginBottom: 10,
150+
},
151+
selected: {
152+
marginTop: 10,
153+
marginBottom: 10,
154+
},
155+
TouchableOpacity: {
156+
padding: 10,
157+
backgroundColor: '#841584',
158+
borderRadius: 5,
159+
},
160+
disabledButton: {
161+
backgroundColor: '#ccc',
162+
},
163+
});
164+
165+
const pickerSelectStyles = StyleSheet.create({
166+
inputIOS: {
167+
color: 'black',
168+
paddingTop: 13,
169+
paddingHorizontal: 10,
170+
paddingBottom: 12,
171+
borderWidth: 1,
172+
borderColor: 'gray',
173+
borderRadius: 4,
174+
backgroundColor: 'white',
175+
width: '100%',
176+
},
177+
inputAndroid: {
178+
color: 'black',
179+
width: '80%',
180+
},
110181
});

0 commit comments

Comments
 (0)