2016-03-04 22:56:37 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-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.
|
|
|
|
*
|
|
|
|
* @providesModule NavigationPropTypes
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-03-24 22:48:27 +00:00
|
|
|
import type {
|
|
|
|
NavigationSceneRendererProps,
|
|
|
|
} from 'NavigationTypeDefinition';
|
|
|
|
|
2016-03-04 22:56:37 +00:00
|
|
|
/**
|
|
|
|
* React component PropTypes Definitions. Consider using this as a supplementary
|
|
|
|
* measure with `NavigationTypeDefinition`. This helps to capture the propType
|
|
|
|
* error at run-time, where as `NavigationTypeDefinition` capture the flow
|
|
|
|
* type check errors at build time.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const Animated = require('Animated');
|
2016-04-09 03:36:40 +00:00
|
|
|
const React = require('React');
|
2016-03-04 22:56:37 +00:00
|
|
|
|
|
|
|
const {PropTypes} = React;
|
|
|
|
|
|
|
|
/* NavigationAction */
|
|
|
|
const action = PropTypes.shape({
|
|
|
|
type: PropTypes.string.isRequired,
|
|
|
|
});
|
|
|
|
|
|
|
|
/* NavigationAnimatedValue */
|
|
|
|
const animatedValue = PropTypes.instanceOf(Animated.Value);
|
|
|
|
|
2016-05-20 21:24:24 +00:00
|
|
|
/* NavigationRoute */
|
2016-05-21 01:09:57 +00:00
|
|
|
const navigationRoute = PropTypes.shape({
|
2016-03-04 22:56:37 +00:00
|
|
|
key: PropTypes.string.isRequired,
|
|
|
|
});
|
|
|
|
|
2016-05-21 01:09:57 +00:00
|
|
|
/* navigationRoute */
|
|
|
|
const navigationState = PropTypes.shape({
|
2016-03-04 22:56:37 +00:00
|
|
|
index: PropTypes.number.isRequired,
|
2016-05-22 23:27:53 +00:00
|
|
|
routes: PropTypes.arrayOf(navigationRoute),
|
2016-03-04 22:56:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/* NavigationLayout */
|
|
|
|
const layout = PropTypes.shape({
|
|
|
|
height: animatedValue,
|
|
|
|
initHeight: PropTypes.number.isRequired,
|
|
|
|
initWidth: PropTypes.number.isRequired,
|
2016-04-19 22:56:33 +00:00
|
|
|
isMeasured: PropTypes.bool.isRequired,
|
2016-03-04 22:56:37 +00:00
|
|
|
width: animatedValue,
|
|
|
|
});
|
|
|
|
|
|
|
|
/* NavigationScene */
|
|
|
|
const scene = PropTypes.shape({
|
|
|
|
index: PropTypes.number.isRequired,
|
2016-06-27 19:03:51 +00:00
|
|
|
isActive: PropTypes.bool.isRequired,
|
2016-03-04 22:56:37 +00:00
|
|
|
isStale: PropTypes.bool.isRequired,
|
2016-03-24 22:48:27 +00:00
|
|
|
key: PropTypes.string.isRequired,
|
2016-05-21 01:09:57 +00:00
|
|
|
route: navigationRoute.isRequired,
|
2016-03-04 22:56:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/* NavigationSceneRendererProps */
|
2016-05-18 20:01:13 +00:00
|
|
|
const SceneRendererProps = {
|
2016-03-04 22:56:37 +00:00
|
|
|
layout: layout.isRequired,
|
2016-05-21 01:09:57 +00:00
|
|
|
navigationState: navigationState.isRequired,
|
2016-03-04 22:56:37 +00:00
|
|
|
position: animatedValue.isRequired,
|
2016-05-18 20:32:52 +00:00
|
|
|
progress: animatedValue.isRequired,
|
2016-03-04 22:56:37 +00:00
|
|
|
scene: scene.isRequired,
|
|
|
|
scenes: PropTypes.arrayOf(scene).isRequired,
|
|
|
|
};
|
|
|
|
|
2016-05-18 20:01:13 +00:00
|
|
|
const SceneRenderer = PropTypes.shape(SceneRendererProps);
|
|
|
|
|
2016-03-15 22:58:38 +00:00
|
|
|
/* NavigationPanPanHandlers */
|
|
|
|
const panHandlers = PropTypes.shape({
|
|
|
|
onMoveShouldSetResponder: PropTypes.func.isRequired,
|
|
|
|
onMoveShouldSetResponderCapture: PropTypes.func.isRequired,
|
|
|
|
onResponderEnd: PropTypes.func.isRequired,
|
|
|
|
onResponderGrant: PropTypes.func.isRequired,
|
|
|
|
onResponderMove: PropTypes.func.isRequired,
|
|
|
|
onResponderReject: PropTypes.func.isRequired,
|
|
|
|
onResponderRelease: PropTypes.func.isRequired,
|
|
|
|
onResponderStart: PropTypes.func.isRequired,
|
|
|
|
onResponderTerminate: PropTypes.func.isRequired,
|
|
|
|
onResponderTerminationRequest: PropTypes.func.isRequired,
|
|
|
|
onStartShouldSetResponder: PropTypes.func.isRequired,
|
|
|
|
onStartShouldSetResponderCapture: PropTypes.func.isRequired,
|
|
|
|
});
|
|
|
|
|
2016-03-24 22:48:27 +00:00
|
|
|
/**
|
|
|
|
* Helper function that extracts the props needed for scene renderer.
|
|
|
|
*/
|
|
|
|
function extractSceneRendererProps(
|
|
|
|
props: NavigationSceneRendererProps,
|
|
|
|
): NavigationSceneRendererProps {
|
|
|
|
return {
|
|
|
|
layout: props.layout,
|
|
|
|
navigationState: props.navigationState,
|
|
|
|
position: props.position,
|
2016-05-18 20:32:52 +00:00
|
|
|
progress: props.progress,
|
2016-03-24 22:48:27 +00:00
|
|
|
scene: props.scene,
|
|
|
|
scenes: props.scenes,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-03-04 22:56:37 +00:00
|
|
|
module.exports = {
|
2016-03-24 22:48:27 +00:00
|
|
|
// helpers
|
|
|
|
extractSceneRendererProps,
|
|
|
|
|
|
|
|
// Bundled propTypes.
|
2016-05-18 20:01:13 +00:00
|
|
|
SceneRendererProps,
|
2016-03-24 22:48:27 +00:00
|
|
|
|
|
|
|
// propTypes
|
2016-05-21 01:09:57 +00:00
|
|
|
SceneRenderer,
|
2016-03-04 22:56:37 +00:00
|
|
|
action,
|
|
|
|
navigationState,
|
2016-05-21 01:09:57 +00:00
|
|
|
navigationRoute,
|
2016-03-15 22:58:38 +00:00
|
|
|
panHandlers,
|
2016-03-04 22:56:37 +00:00
|
|
|
};
|