concept Modal component in category react native
appears as: Modal component, The Modal component

This is an excerpt from Manning's book React Native in Action.
You’ll use the
modalVisbleBoolean to show and hide theModalcomponent that will fetch information about the character’s home world. You’ll usepickerVisibleto show and hide aPickercomponent that will let you choose the gender of the person you want to view, and will pass the result to a filter that will filter the results accordingly.
Listing 12.9
rendermethodrender() { let { data } = this.state #1 if (this.state.gender !== 'all') { #2 data = data.filter(f => f.gender === this.state.gender) #2 } return ( <Container> <TouchableHighlight style={styles.pickerToggleContainer} onPress={this.togglePicker}> #3 <Text style={styles.pickerToggle}> {this.state.pickerVisible ? 'Close Filter' : 'Open Filter'} </Text> #3 </TouchableHighlight> { #4 this.state.loading ? <ActivityIndicator color='#ffe81f' /> : ( #4 <FlatList #4 data={data} #4 keyExtractor={(item) => item.name} #4 renderItem={this.renderItem} #4 /> #4 ) #4 } <Modal #5 onRequestClose={() => console.log('onrequest close called')} #6 animationType="slide" #7 visible={this.state.modalVisible}> #5 <HomeWorld closeModal={this.closeModal} url={this.state.url} /> </Modal> #5 { this.state.pickerVisible && ( #8 <View style={styles.pickerContainer}> <Picker #9 style={{ backgroundColor: '#ffe81f' }} #9 selectedValue={this.state.gender} #9 onValueChange={(item) => this.filter(item)}> #9 <Picker.Item itemStyle={{ color: 'yellow' }} label="All" value="all" /> <Picker.Item label="Males" value="male" /> <Picker.Item label="Females" value="female" /> <Picker.Item label="Other" value="n/a" /> </Picker> </View> ) } </Container> ); } #1 Destructures the data array from the state for easier access #2 Checks whether the filter is set to all: if so, skips this function; if not, performs a filter based on the gender of the character vs. the gender set in the state #3 Creates a button: Close Filter or Open Filter, based on the value of this.state.pickerVisible #4 Checks whether the data is loading by evaluating this.state.loading: if so, shows an ActivityIndicator to indicate loading is taking place; if not, renders the FlatList, passing in the data, this.renderItem, and keyExtractor #5 The Modal component stays hidden until modalVisible is set to true and then slides up into view. #6 onRequestClose is a required property. You don’t need to do anything, so just logs to the console when called. #7 Animation type of the Modal; could also be none or fade #8 If this.state.pickerVisible is set to true, renders the Picker component #9 Renders the Picker, passing in a value, a style, and an onValueChange method