A Modal component covers the native view (e.g. UIViewController, Activity) that contains the React Native root.
Use Modal in hybrid apps that embed React Native; Modal allows the portion of your app written in React Native to present content above the enclosing native view hierarchy.
In apps written with React Native from the root view down, you should use Navigator instead of Modal. With a top-level Navigator, you have more control over how to present the modal scene over the rest of your app by using the configureScene property.
Props
animated bool

Use the animationType
prop instead.
animationType enum('none', 'slide', 'fade')
onRequestClose Platform.OS === 'android' ? PropTypes.func.isRequired : PropTypes.func
onShow function
transparent bool
visible bool
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | 'use strict' ; var React = require( 'react' ); var ReactNative = require( 'react-native' ); var { Modal, StyleSheet, Switch, Text, TouchableHighlight, View, } = ReactNative; exports.displayName = (undefined: ?string); exports.framework = 'React' ; exports.title = '<Modal>' ; exports.description = 'Component for presenting modal views.' ; var Button = React.createClass({ getInitialState() { return { active: false , }; }, _onHighlight() { this .setState({active: true }); }, _onUnhighlight() { this .setState({active: false }); }, render() { var colorStyle = { color: this .state.active ? '#fff' : '#000' , }; return ( <TouchableHighlight onHideUnderlay={ this ._onUnhighlight} onPress={ this .props.onPress} onShowUnderlay={ this ._onHighlight} style={[styles.button, this .props.style]} underlayColor= "#a9d9d4" > <Text style={[styles.buttonText, colorStyle]}>{ this .props.children}</Text> </TouchableHighlight> ); } }); var ModalExample = React.createClass({ getInitialState() { return { animationType: 'none' , modalVisible: false , transparent: false , }; }, _setModalVisible(visible) { this .setState({modalVisible: visible}); }, _setAnimationType(type) { this .setState({animationType: type}); }, _toggleTransparent() { this .setState({transparent: ! this .state.transparent}); }, render() { var modalBackgroundStyle = { backgroundColor: this .state.transparent ? 'rgba(0, 0, 0, 0.5)' : '#f5fcff' , }; var innerContainerTransparentStyle = this .state.transparent ? {backgroundColor: '#fff' , padding: 20} : null ; var activeButtonStyle = { backgroundColor: '#ddd' }; return ( <View> <Modal animationType={ this .state.animationType} transparent={ this .state.transparent} visible={ this .state.modalVisible} onRequestClose={() => { this ._setModalVisible( false )}} > <View style={[styles.container, modalBackgroundStyle]}> <View style={[styles.innerContainer, innerContainerTransparentStyle]}> <Text>This modal was presented { this .state.animationType === 'none' ? 'without' : 'with' } animation.</Text> <Button onPress={ this ._setModalVisible.bind( this , false )} style={styles.modalButton}> Close </Button> </View> </View> </Modal> <View style={styles.row}> <Text style={styles.rowTitle}>Animation Type</Text> <Button onPress={ this ._setAnimationType.bind( this , 'none' )} style={ this .state.animationType === 'none' ? activeButtonStyle : {}}> none </Button> <Button onPress={ this ._setAnimationType.bind( this , 'slide' )} style={ this .state.animationType === 'slide' ? activeButtonStyle : {}}> slide </Button> <Button onPress={ this ._setAnimationType.bind( this , 'fade' )} style={ this .state.animationType === 'fade' ? activeButtonStyle : {}}> fade </Button> </View> <View style={styles.row}> <Text style={styles.rowTitle}>Transparent</Text> <Switch value={ this .state.transparent} onValueChange={ this ._toggleTransparent} /> </View> <Button onPress={ this ._setModalVisible.bind( this , true )}> Present </Button> </View> ); }, }); exports.examples = [ { title: 'Modal Presentation' , description: 'Modals can be presented with or without animation' , render: () => <ModalExample />, }, ]; var styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center' , padding: 20, }, innerContainer: { borderRadius: 10, alignItems: 'center' , }, row: { alignItems: 'center' , flex: 1, flexDirection: 'row' , marginBottom: 20, }, rowTitle: { flex: 1, fontWeight: 'bold' , }, button: { borderRadius: 5, flex: 1, height: 44, alignSelf: 'stretch' , justifyContent: 'center' , overflow: 'hidden' , }, buttonText: { fontSize: 18, margin: 5, textAlign: 'center' , }, modalButton: { marginTop: 10, }, }); |