2016-02-05 22:25:17 +00:00
|
|
|
/**
|
2016-03-15 22:58:38 +00:00
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
2016-02-05 22:25:17 +00:00
|
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
|
|
* evaluation purposes only.
|
|
|
|
*
|
|
|
|
* Facebook reserves all rights not expressly granted.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-03-15 22:58:38 +00:00
|
|
|
const React = require('react-native');
|
|
|
|
|
|
|
|
const {
|
2016-02-23 00:15:43 +00:00
|
|
|
Animated,
|
2016-02-05 22:25:17 +00:00
|
|
|
NavigationExperimental,
|
|
|
|
StyleSheet,
|
|
|
|
ScrollView,
|
|
|
|
} = React;
|
2016-03-15 22:58:38 +00:00
|
|
|
|
|
|
|
const NavigationExampleRow = require('./NavigationExampleRow');
|
|
|
|
|
|
|
|
const {
|
2016-02-05 22:25:17 +00:00
|
|
|
AnimatedView: NavigationAnimatedView,
|
|
|
|
Card: NavigationCard,
|
|
|
|
Header: NavigationHeader,
|
2016-03-15 22:58:38 +00:00
|
|
|
Reducer: NavigationReducer,
|
|
|
|
RootContainer: NavigationRootContainer,
|
2016-02-05 22:25:17 +00:00
|
|
|
} = NavigationExperimental;
|
|
|
|
|
|
|
|
const NavigationBasicReducer = NavigationReducer.StackReducer({
|
2016-02-23 00:15:42 +00:00
|
|
|
getPushedReducerForAction: (action) => {
|
|
|
|
if (action.type === 'push') {
|
|
|
|
return (state) => state || {key: action.key};
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
getReducerForState: (initialState) => (state) => state || initialState,
|
|
|
|
initialState: {
|
|
|
|
key: 'AnimatedExampleStackKey',
|
|
|
|
index: 0,
|
|
|
|
children: [
|
|
|
|
{key: 'First Route'},
|
|
|
|
],
|
|
|
|
},
|
2016-02-05 22:25:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
class NavigationAnimatedExample extends React.Component {
|
|
|
|
componentWillMount() {
|
2016-03-04 22:56:37 +00:00
|
|
|
this._renderNavigation = this._renderNavigation.bind(this);
|
|
|
|
this._renderCard = this._renderCard.bind(this);
|
|
|
|
this._renderScene = this._renderScene.bind(this);
|
|
|
|
this._renderHeader = this._renderHeader.bind(this);
|
2016-02-05 22:25:17 +00:00
|
|
|
}
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<NavigationRootContainer
|
|
|
|
reducer={NavigationBasicReducer}
|
2016-02-09 04:02:45 +00:00
|
|
|
ref={navRootContainer => { this.navRootContainer = navRootContainer; }}
|
2016-02-23 00:15:35 +00:00
|
|
|
persistenceKey="NavigationAnimExampleState"
|
2016-03-04 22:56:37 +00:00
|
|
|
renderNavigation={this._renderNavigation}
|
2016-02-05 22:25:17 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2016-03-03 12:20:34 +00:00
|
|
|
handleBackAction() {
|
|
|
|
return (
|
|
|
|
this.navRootContainer &&
|
|
|
|
this.navRootContainer.handleNavigation(NavigationRootContainer.getBackAction())
|
|
|
|
);
|
|
|
|
}
|
2016-03-04 22:56:37 +00:00
|
|
|
_renderNavigation(navigationState, onNavigate) {
|
2016-02-05 22:25:17 +00:00
|
|
|
if (!navigationState) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<NavigationAnimatedView
|
|
|
|
navigationState={navigationState}
|
|
|
|
style={styles.animatedView}
|
2016-03-04 22:56:37 +00:00
|
|
|
renderOverlay={this._renderHeader}
|
2016-03-09 07:31:27 +00:00
|
|
|
applyAnimation={(pos, navState) => {
|
2016-03-15 22:58:38 +00:00
|
|
|
Animated.timing(pos, {toValue: navState.index, duration: 500}).start();
|
2016-02-23 00:15:43 +00:00
|
|
|
}}
|
2016-03-04 22:56:37 +00:00
|
|
|
renderScene={this._renderCard}
|
2016-02-05 22:25:17 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2016-03-04 22:56:37 +00:00
|
|
|
|
|
|
|
_renderHeader(/*NavigationSceneRendererProps*/ props) {
|
|
|
|
return (
|
|
|
|
<NavigationHeader
|
|
|
|
{...props}
|
|
|
|
getTitle={state => state.key}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_renderCard(/*NavigationSceneRendererProps*/ props) {
|
|
|
|
return (
|
|
|
|
<NavigationCard
|
|
|
|
{...props}
|
|
|
|
key={'card_' + props.scene.navigationState.key}
|
|
|
|
renderScene={this._renderScene}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_renderScene(/*NavigationSceneRendererProps*/ props) {
|
|
|
|
return (
|
|
|
|
<ScrollView style={styles.scrollView}>
|
|
|
|
<NavigationExampleRow
|
|
|
|
text={props.scene.navigationState.key}
|
|
|
|
/>
|
|
|
|
<NavigationExampleRow
|
|
|
|
text="Push!"
|
|
|
|
onPress={() => {
|
|
|
|
props.onNavigate({
|
|
|
|
type: 'push',
|
|
|
|
key: 'Route #' + props.scenes.length,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<NavigationExampleRow
|
|
|
|
text="Exit Animated Nav Example"
|
|
|
|
onPress={this.props.onExampleExit}
|
|
|
|
/>
|
|
|
|
</ScrollView>
|
|
|
|
);
|
|
|
|
}
|
2016-02-05 22:25:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
animatedView: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
scrollView: {
|
2016-03-03 12:20:34 +00:00
|
|
|
marginTop: 64
|
2016-02-05 22:25:17 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = NavigationAnimatedExample;
|