Skip to content

Commit f1fa688

Browse files
author
Pavlo Aksonov
committed
Merge pull request #218 from sbycrosz/master
Add examples for animating modals
2 parents c5aa59c + a5d9ba9 commit f1fa688

File tree

6 files changed

+101
-7
lines changed

6 files changed

+101
-7
lines changed

Example/Example.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var {Route, Schema, Animations, Actions, TabBar} = RNRF;
1111
var Error = require('./components/Error');
1212
var Home = require('./components/Home');
1313
var TabView = require('./components/TabView');
14+
var ReactNativeModalBox = require('./components/ReactNativeModalBox');
1415

1516
// Redux stuff is optional
1617
import { createStore } from 'redux'
@@ -80,6 +81,7 @@ export default class Example extends React.Component {
8081
</Route>
8182
<Route name="register2" component={Register} title="Register2" schema="withoutAnimation"/>
8283
<Route name="error" type="modal" component={Error}/>
84+
<Route name="modalBox" type="modal" component={ReactNativeModalBox}/>
8385
<Route name="tabbar">
8486
<Router footer={TabBar} showNavigationBar={false}>
8587
<Route name="tab1" schema="tab" title="Tab #1" >

Example/components/Error.js

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,51 @@
11
'use strict';
22

33
var React = require('react-native');
4-
var {View, Text, StyleSheet} = React;
4+
var {View, Text, StyleSheet, Animated, Dimensions} = React;
55
var Button = require('react-native-button');
66
var Actions = require('react-native-router-flux').Actions;
77

8+
var {
9+
height: deviceHeight
10+
} = Dimensions.get('window');
11+
12+
813
class Error extends React.Component {
14+
constructor(props){
15+
super (props)
16+
17+
this.state = {
18+
offset: new Animated.Value(-deviceHeight)
19+
}
20+
}
21+
22+
componentDidMount() {
23+
Animated.timing(this.state.offset, {
24+
duration: 150,
25+
toValue: 0
26+
}).start();
27+
}
28+
29+
closeModal() {
30+
Animated.timing(this.state.offset, {
31+
duration: 150,
32+
toValue: -deviceHeight
33+
}).start(Actions.dismiss);
34+
}
35+
936
render(){
1037
return (
11-
<View style={[styles.container,{backgroundColor:'rgba(52,52,52,0.5)'}]}>
12-
<View style={{width:250,height:250,justifyContent: 'center',
13-
alignItems: 'center',backgroundColor:'white'}}>
14-
<Text>{this.props.data}</Text>
15-
<Button onPress={Actions.dismiss}>Close</Button>
16-
</View>
38+
<Animated.View style={[styles.container, {backgroundColor:'rgba(52,52,52,0.5)'},
39+
{transform: [{translateY: this.state.offset}]}]}>
40+
<View style={{ width:250,
41+
height:250,
42+
justifyContent: 'center',
43+
alignItems: 'center',
44+
backgroundColor:'white' }}>
45+
<Text>{this.props.data}</Text>
46+
<Button onPress={this.closeModal.bind(this)}>Close</Button>
1747
</View>
48+
</Animated.View>
1849
);
1950
}
2051
}

Example/components/Launch.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Launch extends React.Component {
1414
<Button onPress={Actions.register}>Go to Register page</Button>
1515
<Button onPress={Actions.register2}>Go to Register page without animation</Button>
1616
<Button onPress={()=>Actions.error("Error message")}>Popup error</Button>
17+
<Button onPress={Actions.modalBox}>PopUp with ReactNativeModalBox</Button>
1718
<Button onPress={Actions.tabbar}>Go to TabBar page</Button>
1819
<Button onPress={()=>Actions.showActionSheet({callback:index=>alert("Selected:"+index)})}>Show ActionSheet</Button>
1920
</View>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'use strict';
2+
3+
var React = require('react-native');
4+
var {View, Text, StyleSheet} = React;
5+
var Button = require('react-native-button');
6+
var Actions = require('react-native-router-flux').Actions;
7+
8+
var Modal = require('react-native-modalbox');
9+
10+
// Example integration with react-native-modalbox (https://github.com/maxs15/react-native-modalbox)
11+
// For those people who don't want to animate their own modal
12+
class ReactNativeModalBox extends React.Component {
13+
constructor(){
14+
super();
15+
}
16+
componentWillMount(){
17+
this.setState({isOpen: true});
18+
}
19+
render(){
20+
return (
21+
<Modal animationDuration={200}
22+
swipeThreshold={100}
23+
style={styles.modal}
24+
position={"center"}
25+
isOpen={this.state.isOpen}
26+
onClosed={Actions.dismiss}>
27+
<Text style={styles.text}>
28+
ReactNativeModalBox
29+
</Text>
30+
<Text>
31+
(swipe down to close)
32+
</Text>
33+
</Modal>
34+
);
35+
}
36+
}
37+
38+
var styles = StyleSheet.create({
39+
modal: {
40+
justifyContent: 'center',
41+
alignItems: 'center',
42+
height: 300,
43+
width: 300,
44+
},
45+
text: {
46+
color: "black",
47+
fontSize: 22
48+
},
49+
});
50+
51+
module.exports = ReactNativeModalBox;

Example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"react-native": "^0.19.0",
1010
"react-native-button": "^1.2.1",
1111
"react-native-router-flux": "^2.2.5",
12+
"react-native-modalbox": "^1.3.0",
1213
"react-redux": "^4.4.0",
1314
"redux": "^3.3.1"
1415
}

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export default class Example extends React.Component {
137137
```
138138

139139
components/Launch.js (initial screen)
140+
140141
```
141142
import React, {View, Text, StyleSheet, TouchableHighlight} from 'react-native'
142143
import Button from 'react-native-button'
@@ -168,6 +169,13 @@ var styles = StyleSheet.create({
168169
169170
module.exports = Launch;
170171
```
172+
173+
## Modals
174+
To display a modal use ```type="modal"``` for your route components.
175+
Modal type inserts its 'component' after navigator component. See the ```Examples``` folder for more details.
176+
177+
Note that **ReactNativeRouterFlux will not provide animations for modals** and you'll need to animate the modal yourself (or use a library)
178+
171179
## Sidebar/Drawer support
172180
You can easily configure react-native-router-flux to handle a sidebar/drawer for specific routes:
173181
**1.** Create a sidebar/drawer component (you can use both [react-native-drawer](https://github.com/root-two/react-native-drawer) and [react-native-side-menu](https://github.com/react-native-fellowship/react-native-side-menu)) and pass its router props to its children:

0 commit comments

Comments
 (0)