-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.ios.js
181 lines (162 loc) · 4.41 KB
/
index.ios.js
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
173
174
175
176
177
178
179
180
181
/**
* Sample React Native Modal Dialog Example App
*
* @see - https://github.com/facebook/react-native
* @see - https://github.com/Kureev/react-native-navbar
*/
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Navigator,
TouchableHighlight,
Text,
View,
} = React;
// react-native has a navigationBar object, but is seemed a bit cumbersome to utilize.
// I found the simplicity of https://github.com/Kureev/react-native-navbar much better
// and it seems to get the job done for my specific needs
//
// @see https://github.com/Kureev/react-native-navbar
//
var NavigationBar = require('react-native-navbar');
//
// The Modal View that will be presented using the default IOS slide up animation.
// this is accomplished by setting the animation on the sceneConfig options
//
var modalView = React.createClass({
_closeModal: function() {
// this.props.navigator - this object is passed along by default if you look at the
// code in renderScene you will see the property being set
this.props.navigator.pop()
},
render: function() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
THIS IS THE MODAL VIEW
</Text>
<TouchableHighlight
style={[styles.button]}
onPress={this._closeModal}>
<Text style={styles.buttonLabel}>
Click To Close Modal
</Text>
</TouchableHighlight>
</View>
);
}
});
var ModalSampleMainView = React.createClass({
/**
* called when the user clicks the button to close the window
*/
_openModal: function() {
//
// this.props.navigator - this object is passed along by default if you look at the
// code in renderScene you will see the property being set
//
// we are again adding the NavigationBar to the window, but notice that we are hiding the
// default back button, since we want to manage that interaction ourselves
this.props.navigator.push({
sceneConfig: Navigator.SceneConfigs.FloatFromBottom,
navigationBar: <NavigationBar title="Modal View Title"
hidePrev="true" />,
component: modalView,
passProps: {}
})
},
render: function() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native Modal Dialog Sample!
</Text>
<Text style={styles.instructions}>
We are using the react-native-navbar, module which can be found in npm
</Text>
<TouchableHighlight
underlayColor={'gray'}
style={[styles.button]}
onPress={this._openModal}>
<Text style={styles.buttonLabel}>
Click To Open Modal
</Text>
</TouchableHighlight>
</View>
);
}
});
//
// MAIN APPLICATION COMPONENT
//
var modalSample = React.createClass({
renderScene(route, navigator) {
var Component = route.component;
var navBar = route.navigationBar;
if (navBar) {
navBar = React.addons.cloneWithProps(navBar, {navigator, route});
}
return (
<View style={styles.view}>
{navBar}
<Component {...route.passProps} navigator={navigator} route={route}/>
</View>
);
},
render() {
return (
<Navigator
ref="nav"
style={styles.nav}
renderScene={this.renderScene}
configureScene={(route) => {
if (route.sceneConfig) {
return route.sceneConfig;
}
return Navigator.SceneConfigs.FloatFromBottom;
}}
tintColor="#ED6063"
initialRoute={{
navigationBar: <NavigationBar title="Initial View"/>,
title: "Modal View Sample App",
component: ModalSampleMainView,
passProps : {}
}}/>);
}
});
var styles = StyleSheet.create({
navBar: {
backgroundColor: 'white',
},
nav: {
flex: 1,
},
button: {
flexDirection: 'row',
margin : 30,
width : 200,
padding: 10,
justifyContent: 'center',
borderWidth : .5
},
container: {
flex: 1,
padding: 20,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('modalSample', () => modalSample);