forked from cemaden-educacao/WPD-MobileApp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.3 KiB
98 lines
2.3 KiB
import React, { useState } from "react";
|
|
import {
|
|
View,
|
|
StyleSheet,
|
|
TouchableWithoutFeedback,
|
|
Modal,
|
|
Button,
|
|
FlatList,
|
|
} from "react-native";
|
|
import { MaterialCommunityIcons } from "@expo/vector-icons";
|
|
|
|
import Text from "./Text";
|
|
import defaultStyles from "../config/styles";
|
|
import PickerItem from "./PickerItem";
|
|
import Screen from "./Screen";
|
|
|
|
function AppPicker({
|
|
icon,
|
|
items,
|
|
numberOfColumns = 1,
|
|
onSelectItem,
|
|
PickerItemComponent = PickerItem,
|
|
placeholder,
|
|
selectedItem,
|
|
width = "100%",
|
|
}) {
|
|
const [modalVisible, setModalVisible] = useState(false);
|
|
|
|
return (
|
|
<>
|
|
<TouchableWithoutFeedback onPress={() => setModalVisible(true)}>
|
|
<View style={[styles.container, { width }]}>
|
|
{icon && (
|
|
<MaterialCommunityIcons
|
|
name={icon}
|
|
size={20}
|
|
color={defaultStyles.colors.medium}
|
|
style={styles.icon}
|
|
/>
|
|
)}
|
|
{selectedItem ? (
|
|
<Text style={styles.text}>{selectedItem.label}</Text>
|
|
) : (
|
|
<Text style={styles.placeholder}>{placeholder}</Text>
|
|
)}
|
|
|
|
<MaterialCommunityIcons
|
|
name="chevron-down"
|
|
size={20}
|
|
color={defaultStyles.colors.medium}
|
|
/>
|
|
</View>
|
|
</TouchableWithoutFeedback>
|
|
<Modal visible={modalVisible} animationType="slide">
|
|
<Screen>
|
|
<Button title="Close" onPress={() => setModalVisible(false)} />
|
|
<FlatList
|
|
data={items}
|
|
keyExtractor={(item) => item.value.toString()}
|
|
numColumns={numberOfColumns}
|
|
renderItem={({ item }) => (
|
|
<PickerItemComponent
|
|
item={item}
|
|
label={item.label}
|
|
onPress={() => {
|
|
setModalVisible(false);
|
|
onSelectItem(item);
|
|
}}
|
|
/>
|
|
)}
|
|
/>
|
|
</Screen>
|
|
</Modal>
|
|
</>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
backgroundColor: defaultStyles.colors.light,
|
|
borderRadius: 25,
|
|
flexDirection: "row",
|
|
padding: 15,
|
|
marginVertical: 10,
|
|
},
|
|
icon: {
|
|
marginRight: 10,
|
|
},
|
|
placeholder: {
|
|
color: defaultStyles.colors.medium,
|
|
flex: 1,
|
|
},
|
|
text: {
|
|
flex: 1,
|
|
},
|
|
});
|
|
|
|
export default AppPicker;
|