This code is using core components without any third party library except icons, I love icons!!! :D ;) <3
Android Sample
Web Sample
iOs Sample
Click Me!!! to try this code on Expo Snack
import { StyleSheet, Text, View, Pressable, Dimensions, Modal, TouchableOpacity, FlatList } from "react-native";
import React from "react";
import Icon from 'react-native-vector-icons/AntDesign';
export default class SignUp extends React.Component {
constructor(props) {
super(props);
this.state = {
genders: ['Male', 'Female', 'Others'],
genderModal: false,
selectedGender: "Select Gender",
genderDropdownTop: 0,
}
}
componentDidMount() {
console.log('componentDidMount called.');
}
shouldComponentUpdate(nextProp, nextState) {
console.log('shouldComponentUpdate nextProp: ' + nextProp);
console.log('shouldComponentUpdate nextState: ' + nextState);
return true;
}
render() {
return (
<>
<View style={{ alignSelf: "center", alignItems: "center", backgroundColor: "black", marginLeft: 10, marginRight: 10, width: Dimensions.get('window').width - 30, height: 600 }}>
{/* Selecting person dropdown */}
<View>
<Modal visible={this.state.genderModal}
transparent
animationType="slide"
onRequestClose={() => this.setState({ genderModal: false })}>
<TouchableOpacity
style={{ width: '100%', height: '80%', justifyContent: 'center', alignItems: 'center' }}>
<View style={{ backgroundColor: '#000000', width: 130, shadowRadius: 4, shadowOffset: { height: 4, width: 0 }, shadowOpacity: 0.5, borderColor: 'white', borderWidth: 1, top: this.state.genderDropdownTop }}>
<FlatList
data={this.state.genders}
renderItem={({ item }) => (
<TouchableOpacity style={{ paddingHorizontal: 10, paddingVertical: 10, borderBottomWidth: 1, borderColor: 'white', borderWidth: 1 }} onPress={() => {
this.setState({ genderModal: false })
this.setState({ selectedGender: item })
}}>
<Text style={{ color: '#fff' }}> {item} </Text>
</TouchableOpacity>
)}
keyExtractor={(index) => index.toString()}
/>
</View>
</TouchableOpacity>
</Modal>
</View>
< View style={{ flexDirection: 'row-reverse', borderColor: 'white', borderWidth: 1, width: 150, marginTop: 10 }}>
<Pressable
onPress={() => this.setState({ genderModal: true })}>
<Icon size={30} color="white" name="circledown" />
</Pressable>
< Text style={{ color: 'white', marginRight: 10, fontSize: 20 }}> {this.state.selectedGender} </Text>
</View>
</View >
</>
);
}
componentDidUpdate(prevProp, prevState) {
console.log('componentDidUpdate prevProp: ' + prevProp);
console.log('componentDidUpdate prevState: ' + prevState);
}
componentWillUnmount() {
console.log('componentWillUnmount called.');
}
componentDidCatch(error, info) {
console.log('componentDidCatch Error: ' + error);
console.log('componentDidCatch Info: ' + info);
}
}