@@ -19,6 +19,7 @@ var React = require('react-native');
1919var {
2020 Modal,
2121 StyleSheet,
22+ SwitchIOS,
2223 Text,
2324 TouchableHighlight,
2425 View,
@@ -29,53 +30,98 @@ exports.framework = 'React';
2930exports . title = '<Modal>' ;
3031exports . description = 'Component for presenting modal views.' ;
3132
33+ var Button = React . createClass ( {
34+ getInitialState ( ) {
35+ return {
36+ active : false ,
37+ } ;
38+ } ,
39+
40+ _onHighlight ( ) {
41+ this . setState ( { active : true } ) ;
42+ } ,
43+
44+ _onUnhighlight ( ) {
45+ this . setState ( { active : false } ) ;
46+ } ,
47+
48+ render ( ) {
49+ var colorStyle = {
50+ color : this . state . active ? '#fff' : '#000' ,
51+ } ;
52+ return (
53+ < TouchableHighlight
54+ onHideUnderlay = { this . _onUnhighlight }
55+ onPress = { this . props . onPress }
56+ onShowUnderlay = { this . _onHighlight }
57+ style = { [ styles . button , this . props . style ] }
58+ underlayColor = "#a9d9d4" >
59+ < Text style = { [ styles . buttonText , colorStyle ] } > { this . props . children } </ Text >
60+ </ TouchableHighlight >
61+ ) ;
62+ }
63+ } ) ;
64+
3265var ModalExample = React . createClass ( {
33- getInitialState : function ( ) {
66+ getInitialState ( ) {
3467 return {
35- openModal : null ,
68+ animated : true ,
69+ modalVisible : false ,
70+ transparent : false ,
3671 } ;
3772 } ,
3873
39- _closeModal : function ( ) {
40- this . setState ( { openModal : null } ) ;
74+ _setModalVisible ( visible ) {
75+ this . setState ( { modalVisible : visible } ) ;
4176 } ,
4277
43- _openAnimatedModal : function ( ) {
44- this . setState ( { openModal : ' animated' } ) ;
78+ _toggleAnimated ( ) {
79+ this . setState ( { animated : ! this . state . animated } ) ;
4580 } ,
4681
47- _openNotAnimatedModal : function ( ) {
48- this . setState ( { openModal : 'not-animated' } ) ;
82+ _toggleTransparent ( ) {
83+ this . setState ( { transparent : ! this . state . transparent } ) ;
4984 } ,
5085
51- render : function ( ) {
86+ render ( ) {
87+ var modalBackgroundStyle = {
88+ backgroundColor : this . state . transparent ? 'rgba(0, 0, 0, 0.5)' : '#f5fcff' ,
89+ } ;
90+ var innerContainerTransparentStyle = this . state . transparent
91+ ? { backgroundColor : '#fff' , padding : 20 }
92+ : null ;
93+
5294 return (
5395 < View >
54- < Modal animated = { true } visible = { this . state . openModal === 'animated' } >
55- < View style = { styles . container } >
56- < Text > This modal was presented with animation.</ Text >
57- < TouchableHighlight underlayColor = "#a9d9d4" onPress = { this . _closeModal } >
58- < Text > Close</ Text >
59- </ TouchableHighlight >
96+ < Modal
97+ animated = { this . state . animated }
98+ transparent = { this . state . transparent }
99+ visible = { this . state . modalVisible } >
100+ < View style = { [ styles . container , modalBackgroundStyle ] } >
101+ < View style = { [ styles . innerContainer , innerContainerTransparentStyle ] } >
102+ < Text > This modal was presented { this . state . animated ? 'with' : 'without' } animation.</ Text >
103+ < Button
104+ onPress = { this . _setModalVisible . bind ( this , false ) }
105+ style = { styles . modalButton } >
106+ Close
107+ </ Button >
108+ </ View >
60109 </ View >
61110 </ Modal >
62111
63- < Modal visible = { this . state . openModal === 'not-animated' } >
64- < View style = { styles . container } >
65- < Text > This modal was presented immediately, without animation.</ Text >
66- < TouchableHighlight underlayColor = "#a9d9d4" onPress = { this . _closeModal } >
67- < Text > Close</ Text >
68- </ TouchableHighlight >
69- </ View >
70- </ Modal >
112+ < View style = { styles . row } >
113+ < Text style = { styles . rowTitle } > Animated</ Text >
114+ < SwitchIOS value = { this . state . animated } onValueChange = { this . _toggleAnimated } />
115+ </ View >
71116
72- < TouchableHighlight underlayColor = "#a9d9d4" onPress = { this . _openAnimatedModal } >
73- < Text > Present Animated</ Text >
74- </ TouchableHighlight >
117+ < View style = { styles . row } >
118+ < Text style = { styles . rowTitle } > Transparent</ Text >
119+ < SwitchIOS value = { this . state . transparent } onValueChange = { this . _toggleTransparent } />
120+ </ View >
75121
76- < TouchableHighlight underlayColor = "#a9d9d4" onPress = { this . _openNotAnimatedModal } >
77- < Text > Present Without Animation </ Text >
78- </ TouchableHighlight >
122+ < Button onPress = { this . _setModalVisible . bind ( this , true ) } >
123+ Present
124+ </ Button >
79125 </ View >
80126 ) ;
81127 } ,
@@ -91,9 +137,36 @@ exports.examples = [
91137
92138var styles = StyleSheet . create ( {
93139 container : {
140+ flex : 1 ,
141+ justifyContent : 'center' ,
142+ padding : 20 ,
143+ } ,
144+ innerContainer : {
145+ borderRadius : 10 ,
146+ } ,
147+ row : {
94148 alignItems : 'center' ,
95- backgroundColor : '#f5fcff' ,
96149 flex : 1 ,
150+ flexDirection : 'row' ,
151+ marginBottom : 20 ,
152+ } ,
153+ rowTitle : {
154+ flex : 1 ,
155+ fontWeight : 'bold' ,
156+ } ,
157+ button : {
158+ borderRadius : 5 ,
159+ flex : 1 ,
160+ height : 44 ,
97161 justifyContent : 'center' ,
162+ overflow : 'hidden' ,
163+ } ,
164+ buttonText : {
165+ fontSize : 18 ,
166+ margin : 5 ,
167+ textAlign : 'center' ,
168+ } ,
169+ modalButton : {
170+ marginTop : 10 ,
98171 } ,
99172} ) ;
0 commit comments