2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2015-03-23 20:35:08 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-02-20 04:10:52 +00:00
|
|
|
*
|
2018-05-11 02:06:46 +00:00
|
|
|
* @format
|
2015-03-25 19:55:10 +00:00
|
|
|
* @flow
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2018-05-11 02:06:46 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-03-03 23:04:46 +00:00
|
|
|
const EventEmitter = require('EventEmitter');
|
|
|
|
const Image = require('Image');
|
|
|
|
const RCTNavigatorManager = require('NativeModules').NavigatorManager;
|
|
|
|
const React = require('React');
|
|
|
|
const PropTypes = require('prop-types');
|
|
|
|
const ReactNative = require('ReactNative');
|
|
|
|
const StaticContainer = require('StaticContainer.react');
|
|
|
|
const StyleSheet = require('StyleSheet');
|
|
|
|
const TVEventHandler = require('TVEventHandler');
|
|
|
|
const View = require('View');
|
|
|
|
const ViewPropTypes = require('ViewPropTypes');
|
|
|
|
|
|
|
|
const createReactClass = require('create-react-class');
|
|
|
|
const invariant = require('fbjs/lib/invariant');
|
|
|
|
const requireNativeComponent = require('requireNativeComponent');
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2017-09-06 10:25:01 +00:00
|
|
|
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
|
|
|
|
* found when Flow v0.54 was deployed. To see the error delete this comment and
|
|
|
|
* run Flow. */
|
2016-09-09 00:53:55 +00:00
|
|
|
const keyMirror = require('fbjs/lib/keyMirror');
|
|
|
|
|
2018-03-03 23:04:46 +00:00
|
|
|
const TRANSITIONER_REF = 'transitionerRef';
|
2015-03-09 16:28:51 +00:00
|
|
|
|
2018-03-03 23:04:46 +00:00
|
|
|
let __uid = 0;
|
2015-03-09 16:28:51 +00:00
|
|
|
function getuid() {
|
|
|
|
return __uid++;
|
|
|
|
}
|
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class NavigatorTransitionerIOS extends React.Component<$FlowFixMeProps> {
|
2016-12-19 14:26:07 +00:00
|
|
|
requestSchedulingNavigation(cb) {
|
2015-03-17 10:08:46 +00:00
|
|
|
RCTNavigatorManager.requestSchedulingJavaScriptNavigation(
|
2016-04-08 02:43:49 +00:00
|
|
|
ReactNative.findNodeHandle(this),
|
2018-05-11 02:06:46 +00:00
|
|
|
cb,
|
2015-03-09 16:28:51 +00:00
|
|
|
);
|
2016-12-19 14:26:07 +00:00
|
|
|
}
|
2015-03-09 16:28:51 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2018-05-11 02:06:46 +00:00
|
|
|
return <RCTNavigator {...this.props} />;
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-09 16:28:51 +00:00
|
|
|
|
2016-09-09 00:53:55 +00:00
|
|
|
const SystemIconLabels = {
|
|
|
|
done: true,
|
|
|
|
cancel: true,
|
|
|
|
edit: true,
|
|
|
|
save: true,
|
|
|
|
add: true,
|
|
|
|
compose: true,
|
|
|
|
reply: true,
|
|
|
|
action: true,
|
|
|
|
organize: true,
|
|
|
|
bookmarks: true,
|
|
|
|
search: true,
|
|
|
|
refresh: true,
|
|
|
|
stop: true,
|
|
|
|
camera: true,
|
|
|
|
trash: true,
|
|
|
|
play: true,
|
|
|
|
pause: true,
|
|
|
|
rewind: true,
|
|
|
|
'fast-forward': true,
|
|
|
|
undo: true,
|
|
|
|
redo: true,
|
|
|
|
'page-curl': true,
|
|
|
|
};
|
|
|
|
const SystemIcons = keyMirror(SystemIconLabels);
|
|
|
|
|
|
|
|
type SystemButtonType = $Enum<typeof SystemIconLabels>;
|
|
|
|
|
2015-03-25 19:55:10 +00:00
|
|
|
type Route = {
|
2016-06-23 15:27:29 +00:00
|
|
|
component: Function,
|
|
|
|
title: string,
|
|
|
|
titleImage?: Object,
|
|
|
|
passProps?: Object,
|
|
|
|
backButtonTitle?: string,
|
|
|
|
backButtonIcon?: Object,
|
|
|
|
leftButtonTitle?: string,
|
|
|
|
leftButtonIcon?: Object,
|
2016-12-19 14:26:07 +00:00
|
|
|
leftButtonSystemIcon?: SystemButtonType,
|
2016-06-23 15:27:29 +00:00
|
|
|
onLeftButtonPress?: Function,
|
|
|
|
rightButtonTitle?: string,
|
|
|
|
rightButtonIcon?: Object,
|
2016-12-19 14:26:07 +00:00
|
|
|
rightButtonSystemIcon?: SystemButtonType,
|
2016-06-23 15:27:29 +00:00
|
|
|
onRightButtonPress?: Function,
|
|
|
|
wrapperStyle?: any,
|
2015-03-25 19:55:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
type State = {
|
2016-06-23 15:27:29 +00:00
|
|
|
idStack: Array<number>,
|
|
|
|
routeStack: Array<Route>,
|
|
|
|
requestedTopOfStack: number,
|
|
|
|
observedTopOfStack: number,
|
|
|
|
progress: number,
|
|
|
|
fromIndex: number,
|
|
|
|
toIndex: number,
|
|
|
|
makingNavigatorRequest: boolean,
|
|
|
|
updatingAllIndicesAtOrBeyond: ?number,
|
2018-05-11 02:06:46 +00:00
|
|
|
};
|
2015-03-25 19:55:10 +00:00
|
|
|
|
|
|
|
type Event = Object;
|
2015-03-09 16:28:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Think of `<NavigatorIOS>` as simply a component that renders an
|
2015-03-17 10:08:46 +00:00
|
|
|
* `RCTNavigator`, and moves the `RCTNavigator`'s `requestedTopOfStack` pointer
|
|
|
|
* forward and backward. The `RCTNavigator` interprets changes in
|
2015-03-09 16:28:51 +00:00
|
|
|
* `requestedTopOfStack` to be pushes and pops of children that are rendered.
|
|
|
|
* `<NavigatorIOS>` always ensures that whenever the `requestedTopOfStack`
|
|
|
|
* pointer is moved, that we've also rendered enough children so that the
|
2015-03-17 10:08:46 +00:00
|
|
|
* `RCTNavigator` can carry out the push/pop with those children.
|
2015-03-09 16:28:51 +00:00
|
|
|
* `<NavigatorIOS>` also removes children that will no longer be needed
|
|
|
|
* (after the pop of a child has been fully completed/animated out).
|
|
|
|
*/
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2016-06-29 12:16:37 +00:00
|
|
|
* `NavigatorIOS` is a wrapper around
|
|
|
|
* [`UINavigationController`](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/),
|
|
|
|
* enabling you to implement a navigation stack. It works exactly the same as it
|
|
|
|
* would on a native app using `UINavigationController`, providing the same
|
2017-07-29 14:57:53 +00:00
|
|
|
* animations and behavior from UIKit.
|
2016-06-29 12:16:37 +00:00
|
|
|
*
|
|
|
|
* As the name implies, it is only available on iOS. Take a look at
|
2017-04-12 23:09:48 +00:00
|
|
|
* [`React Navigation`](https://reactnavigation.org/) for a cross-platform
|
2017-03-21 22:13:04 +00:00
|
|
|
* solution in JavaScript, or check out either of these components for native
|
|
|
|
* solutions: [native-navigation](http://airbnb.io/native-navigation/),
|
|
|
|
* [react-native-navigation](https://github.com/wix/react-native-navigation).
|
2015-02-20 04:10:52 +00:00
|
|
|
*
|
2016-06-23 19:47:36 +00:00
|
|
|
* To set up the navigator, provide the `initialRoute` prop with a route
|
|
|
|
* object. A route object is used to describe each scene that your app
|
|
|
|
* navigates to. `initialRoute` represents the first route in your navigator.
|
2015-02-20 04:10:52 +00:00
|
|
|
*
|
|
|
|
* ```
|
2017-08-10 06:47:48 +00:00
|
|
|
* import PropTypes from 'prop-types';
|
|
|
|
* import React, { Component } from 'react';
|
2016-06-23 19:47:36 +00:00
|
|
|
* import { NavigatorIOS, Text } from 'react-native';
|
|
|
|
*
|
2016-06-29 12:16:37 +00:00
|
|
|
* export default class NavigatorIOSApp extends Component {
|
2016-06-23 19:47:36 +00:00
|
|
|
* render() {
|
|
|
|
* return (
|
|
|
|
* <NavigatorIOS
|
|
|
|
* initialRoute={{
|
2016-06-29 12:16:37 +00:00
|
|
|
* component: MyScene,
|
|
|
|
* title: 'My Initial Scene',
|
2016-06-23 19:47:36 +00:00
|
|
|
* }}
|
|
|
|
* style={{flex: 1}}
|
|
|
|
* />
|
|
|
|
* );
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
2016-06-29 12:16:37 +00:00
|
|
|
* class MyScene extends Component {
|
|
|
|
* static propTypes = {
|
|
|
|
* title: PropTypes.string.isRequired,
|
|
|
|
* navigator: PropTypes.object.isRequired,
|
|
|
|
* }
|
|
|
|
*
|
2016-10-21 09:40:40 +00:00
|
|
|
* _onForward = () => {
|
2016-06-29 12:16:37 +00:00
|
|
|
* this.props.navigator.push({
|
|
|
|
* title: 'Scene ' + nextIndex,
|
|
|
|
* });
|
|
|
|
* }
|
|
|
|
*
|
2016-06-23 19:47:36 +00:00
|
|
|
* render() {
|
2016-06-29 12:16:37 +00:00
|
|
|
* return (
|
|
|
|
* <View>
|
|
|
|
* <Text>Current Scene: { this.props.title }</Text>
|
|
|
|
* <TouchableHighlight onPress={this._onForward}>
|
|
|
|
* <Text>Tap me to load the next scene</Text>
|
|
|
|
* </TouchableHighlight>
|
|
|
|
* </View>
|
|
|
|
* )
|
2016-06-23 19:47:36 +00:00
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*
|
2016-06-29 12:16:37 +00:00
|
|
|
* In this code, the navigator renders the component specified in initialRoute,
|
|
|
|
* which in this case is `MyScene`. This component will receive a `route` prop
|
|
|
|
* and a `navigator` prop representing the navigator. The navigator's navigation
|
|
|
|
* bar will render the title for the current scene, "My Initial Scene".
|
2016-06-23 19:47:36 +00:00
|
|
|
*
|
|
|
|
* You can optionally pass in a `passProps` property to your `initialRoute`.
|
|
|
|
* `NavigatorIOS` passes this in as props to the rendered component:
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* initialRoute={{
|
2016-06-29 12:16:37 +00:00
|
|
|
* component: MyScene,
|
|
|
|
* title: 'My Initial Scene',
|
2016-06-23 19:47:36 +00:00
|
|
|
* passProps: { myProp: 'foo' }
|
|
|
|
* }}
|
2015-02-20 04:10:52 +00:00
|
|
|
* ```
|
|
|
|
*
|
2016-06-29 12:16:37 +00:00
|
|
|
* You can then access the props passed in via `{this.props.myProp}`.
|
2015-02-20 04:10:52 +00:00
|
|
|
*
|
2016-06-23 19:47:36 +00:00
|
|
|
* #### Handling Navigation
|
2015-03-09 16:28:51 +00:00
|
|
|
*
|
2016-06-23 19:47:36 +00:00
|
|
|
* To trigger navigation functionality such as pushing or popping a view, you
|
|
|
|
* have access to a `navigator` object. The object is passed in as a prop to any
|
|
|
|
* component that is rendered by `NavigatorIOS`. You can then call the
|
|
|
|
* relevant methods to perform the navigation action you need:
|
2015-02-20 04:10:52 +00:00
|
|
|
*
|
|
|
|
* ```
|
2016-06-23 19:47:36 +00:00
|
|
|
* class MyView extends Component {
|
|
|
|
* _handleBackPress() {
|
2015-02-20 04:10:52 +00:00
|
|
|
* this.props.navigator.pop();
|
2016-06-23 19:47:36 +00:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* _handleNextPress(nextRoute) {
|
2015-02-20 04:10:52 +00:00
|
|
|
* this.props.navigator.push(nextRoute);
|
2016-06-23 19:47:36 +00:00
|
|
|
* }
|
|
|
|
*
|
|
|
|
* render() {
|
|
|
|
* const nextRoute = {
|
|
|
|
* component: MyView,
|
|
|
|
* title: 'Bar That',
|
|
|
|
* passProps: { myProp: 'bar' }
|
|
|
|
* };
|
|
|
|
* return(
|
|
|
|
* <TouchableHighlight onPress={() => this._handleNextPress(nextRoute)}>
|
|
|
|
* <Text style={{marginTop: 200, alignSelf: 'center'}}>
|
|
|
|
* See you on the other nav {this.props.myProp}!
|
|
|
|
* </Text>
|
|
|
|
* </TouchableHighlight>
|
|
|
|
* );
|
|
|
|
* }
|
|
|
|
* }
|
2015-02-20 04:10:52 +00:00
|
|
|
* ```
|
|
|
|
*
|
2016-06-23 19:47:36 +00:00
|
|
|
* You can also trigger navigator functionality from the `NavigatorIOS`
|
|
|
|
* component:
|
2015-02-20 04:10:52 +00:00
|
|
|
*
|
|
|
|
* ```
|
2016-06-23 19:47:36 +00:00
|
|
|
* class NavvyIOS extends Component {
|
|
|
|
* _handleNavigationRequest() {
|
|
|
|
* this.refs.nav.push({
|
|
|
|
* component: MyView,
|
|
|
|
* title: 'Genius',
|
|
|
|
* passProps: { myProp: 'genius' },
|
|
|
|
* });
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* render() {
|
|
|
|
* return (
|
|
|
|
* <NavigatorIOS
|
|
|
|
* ref='nav'
|
|
|
|
* initialRoute={{
|
|
|
|
* component: MyView,
|
|
|
|
* title: 'Foo This',
|
|
|
|
* passProps: { myProp: 'foo' },
|
|
|
|
* rightButtonTitle: 'Add',
|
|
|
|
* onRightButtonPress: () => this._handleNavigationRequest(),
|
|
|
|
* }}
|
|
|
|
* style={{flex: 1}}
|
|
|
|
* />
|
|
|
|
* );
|
|
|
|
* }
|
|
|
|
* }
|
2015-02-20 04:10:52 +00:00
|
|
|
* ```
|
|
|
|
*
|
2016-06-23 19:47:36 +00:00
|
|
|
* The code above adds a `_handleNavigationRequest` private method that is
|
|
|
|
* invoked from the `NavigatorIOS` component when the right navigation bar item
|
|
|
|
* is pressed. To get access to the navigator functionality, a reference to it
|
|
|
|
* is saved in the `ref` prop and later referenced to push a new scene into the
|
|
|
|
* navigation stack.
|
|
|
|
*
|
|
|
|
* #### Navigation Bar Configuration
|
|
|
|
*
|
|
|
|
* Props passed to `NavigatorIOS` will set the default configuration
|
2016-01-04 15:41:46 +00:00
|
|
|
* for the navigation bar. Props passed as properties to a route object will set
|
|
|
|
* the configuration for that route's navigation bar, overriding any props
|
2016-06-23 19:47:36 +00:00
|
|
|
* passed to the `NavigatorIOS` component.
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* _handleNavigationRequest() {
|
|
|
|
* this.refs.nav.push({
|
|
|
|
* //...
|
|
|
|
* passProps: { myProp: 'genius' },
|
|
|
|
* barTintColor: '#996699',
|
|
|
|
* });
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* render() {
|
|
|
|
* return (
|
|
|
|
* <NavigatorIOS
|
|
|
|
* //...
|
|
|
|
* style={{flex: 1}}
|
|
|
|
* barTintColor='#ffffcc'
|
|
|
|
* />
|
|
|
|
* );
|
|
|
|
* }
|
|
|
|
* ```
|
2016-01-04 15:41:46 +00:00
|
|
|
*
|
2016-06-23 19:47:36 +00:00
|
|
|
* In the example above the navigation bar color is changed when the new route
|
|
|
|
* is pushed.
|
2016-06-29 12:16:37 +00:00
|
|
|
*
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2018-03-03 23:04:46 +00:00
|
|
|
const NavigatorIOS = createReactClass({
|
2017-07-07 21:24:25 +00:00
|
|
|
displayName: 'NavigatorIOS',
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* NavigatorIOS uses `route` objects to identify child views, their props,
|
|
|
|
* and navigation bar configuration. Navigation operations such as push
|
|
|
|
* operations expect routes to look like this the `initialRoute`.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
initialRoute: PropTypes.shape({
|
|
|
|
/**
|
|
|
|
* The React Class to render for this route
|
|
|
|
*/
|
|
|
|
component: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* The title displayed in the navigation bar and the back button for this
|
|
|
|
* route.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
title: PropTypes.string.isRequired,
|
|
|
|
|
2016-06-23 15:27:29 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* If set, a title image will appear instead of the text title.
|
2016-06-23 15:27:29 +00:00
|
|
|
*/
|
|
|
|
titleImage: Image.propTypes.source,
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* Use this to specify additional props to pass to the rendered
|
|
|
|
* component. `NavigatorIOS` will automatically pass in `route` and
|
2018-01-13 06:03:51 +00:00
|
|
|
* `navigator` props to the component.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
passProps: PropTypes.object,
|
|
|
|
|
2015-05-07 14:16:59 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* If set, the left navigation button image will be displayed using this
|
|
|
|
* source. Note that this doesn't apply to the header of the current
|
|
|
|
* view, but to those views that are subsequently pushed.
|
2015-05-07 14:16:59 +00:00
|
|
|
*/
|
|
|
|
backButtonIcon: Image.propTypes.source,
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* If set, the left navigation button text will be set to this. Note that
|
|
|
|
* this doesn't apply to the left button of the current view, but to
|
|
|
|
* those views that are subsequently pushed
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
backButtonTitle: PropTypes.string,
|
|
|
|
|
2015-05-07 14:16:59 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* If set, the left navigation button image will be displayed using
|
|
|
|
* this source.
|
2015-05-07 14:16:59 +00:00
|
|
|
*/
|
|
|
|
leftButtonIcon: Image.propTypes.source,
|
|
|
|
|
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* If set, the left navigation button will display this text.
|
2015-05-07 14:16:59 +00:00
|
|
|
*/
|
|
|
|
leftButtonTitle: PropTypes.string,
|
|
|
|
|
2016-09-09 00:53:55 +00:00
|
|
|
/**
|
|
|
|
* If set, the left header button will appear with this system icon
|
|
|
|
*
|
|
|
|
* Supported icons are `done`, `cancel`, `edit`, `save`, `add`,
|
|
|
|
* `compose`, `reply`, `action`, `organize`, `bookmarks`, `search`,
|
|
|
|
* `refresh`, `stop`, `camera`, `trash`, `play`, `pause`, `rewind`,
|
|
|
|
* `fast-forward`, `undo`, `redo`, and `page-curl`
|
|
|
|
*/
|
|
|
|
leftButtonSystemIcon: PropTypes.oneOf(Object.keys(SystemIcons)),
|
|
|
|
|
2015-05-07 14:16:59 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* This function will be invoked when the left navigation bar item is
|
|
|
|
* pressed.
|
2015-05-07 14:16:59 +00:00
|
|
|
*/
|
|
|
|
onLeftButtonPress: PropTypes.func,
|
|
|
|
|
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* If set, the right navigation button image will be displayed using
|
|
|
|
* this source.
|
2015-05-07 14:16:59 +00:00
|
|
|
*/
|
|
|
|
rightButtonIcon: Image.propTypes.source,
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* If set, the right navigation button will display this text.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
rightButtonTitle: PropTypes.string,
|
|
|
|
|
2016-09-09 00:53:55 +00:00
|
|
|
/**
|
|
|
|
* If set, the right header button will appear with this system icon
|
|
|
|
*
|
|
|
|
* See leftButtonSystemIcon for supported icons
|
|
|
|
*/
|
|
|
|
rightButtonSystemIcon: PropTypes.oneOf(Object.keys(SystemIcons)),
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* This function will be invoked when the right navigation bar item is
|
|
|
|
* pressed.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
onRightButtonPress: PropTypes.func,
|
|
|
|
|
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* Styles for the navigation item containing the component.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2017-03-24 07:22:57 +00:00
|
|
|
wrapperStyle: ViewPropTypes.style,
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2016-01-04 15:41:46 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* Boolean value that indicates whether the navigation bar is hidden.
|
2016-01-04 15:41:46 +00:00
|
|
|
*/
|
|
|
|
navigationBarHidden: PropTypes.bool,
|
|
|
|
|
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* Boolean value that indicates whether to hide the 1px hairline
|
|
|
|
* shadow.
|
2016-01-04 15:41:46 +00:00
|
|
|
*/
|
|
|
|
shadowHidden: PropTypes.bool,
|
|
|
|
|
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* The color used for the buttons in the navigation bar.
|
2016-01-04 15:41:46 +00:00
|
|
|
*/
|
|
|
|
tintColor: PropTypes.string,
|
|
|
|
|
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* The background color of the navigation bar.
|
2016-01-04 15:41:46 +00:00
|
|
|
*/
|
|
|
|
barTintColor: PropTypes.string,
|
|
|
|
|
2017-08-25 07:03:17 +00:00
|
|
|
/**
|
|
|
|
* The style of the navigation bar. Supported values are 'default', 'black'.
|
|
|
|
* Use 'black' instead of setting `barTintColor` to black. This produces
|
|
|
|
* a navigation bar with the native iOS style with higher translucency.
|
|
|
|
*/
|
|
|
|
barStyle: PropTypes.oneOf(['default', 'black']),
|
|
|
|
|
2018-05-11 02:06:46 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* The text color of the navigation bar title.
|
2016-01-04 15:41:46 +00:00
|
|
|
*/
|
|
|
|
titleTextColor: PropTypes.string,
|
|
|
|
|
2018-05-11 02:06:46 +00:00
|
|
|
/**
|
2017-06-13 15:29:46 +00:00
|
|
|
* Boolean value that indicates whether the navigation bar is
|
2016-06-23 19:47:36 +00:00
|
|
|
* translucent.
|
2016-01-04 15:41:46 +00:00
|
|
|
*/
|
|
|
|
translucent: PropTypes.bool,
|
2015-02-20 04:10:52 +00:00
|
|
|
}).isRequired,
|
|
|
|
|
2015-04-09 15:52:25 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* Boolean value that indicates whether the navigation bar is hidden
|
|
|
|
* by default.
|
2015-04-09 15:52:25 +00:00
|
|
|
*/
|
|
|
|
navigationBarHidden: PropTypes.bool,
|
|
|
|
|
2015-07-16 11:18:12 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* Boolean value that indicates whether to hide the 1px hairline shadow
|
|
|
|
* by default.
|
2015-07-16 11:18:12 +00:00
|
|
|
*/
|
|
|
|
shadowHidden: PropTypes.bool,
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
|
|
|
* The default wrapper style for components in the navigator.
|
2016-06-23 19:47:36 +00:00
|
|
|
* A common use case is to set the `backgroundColor` for every scene.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2017-03-24 07:22:57 +00:00
|
|
|
itemWrapperStyle: ViewPropTypes.style,
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* The default color used for the buttons in the navigation bar.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
tintColor: PropTypes.string,
|
|
|
|
|
2015-04-23 13:22:16 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* The default background color of the navigation bar.
|
2015-04-23 13:22:16 +00:00
|
|
|
*/
|
|
|
|
barTintColor: PropTypes.string,
|
|
|
|
|
2017-08-25 07:03:17 +00:00
|
|
|
/**
|
|
|
|
* The style of the navigation bar. Supported values are 'default', 'black'.
|
|
|
|
* Use 'black' instead of setting `barTintColor` to black. This produces
|
|
|
|
* a navigation bar with the native iOS style with higher translucency.
|
|
|
|
*/
|
|
|
|
barStyle: PropTypes.oneOf(['default', 'black']),
|
|
|
|
|
2015-04-23 13:22:16 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* The default text color of the navigation bar title.
|
2015-04-23 13:22:16 +00:00
|
|
|
*/
|
|
|
|
titleTextColor: PropTypes.string,
|
|
|
|
|
2015-06-26 14:06:51 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* Boolean value that indicates whether the navigation bar is
|
|
|
|
* translucent by default
|
2015-06-26 14:06:51 +00:00
|
|
|
*/
|
|
|
|
translucent: PropTypes.bool,
|
|
|
|
|
2016-05-06 10:17:28 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* Boolean value that indicates whether the interactive pop gesture is
|
|
|
|
* enabled. This is useful for enabling/disabling the back swipe navigation
|
|
|
|
* gesture.
|
|
|
|
*
|
|
|
|
* If this prop is not provided, the default behavior is for the back swipe
|
|
|
|
* gesture to be enabled when the navigation bar is shown and disabled when
|
|
|
|
* the navigation bar is hidden. Once you've provided the
|
|
|
|
* `interactivePopGestureEnabled` prop, you can never restore the default
|
|
|
|
* behavior.
|
2016-05-06 10:17:28 +00:00
|
|
|
*/
|
|
|
|
interactivePopGestureEnabled: PropTypes.bool,
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
|
2015-03-25 19:55:10 +00:00
|
|
|
navigator: (undefined: ?Object),
|
|
|
|
|
2018-02-08 18:26:45 +00:00
|
|
|
UNSAFE_componentWillMount: function() {
|
2015-02-20 04:10:52 +00:00
|
|
|
// Precompute a pack of callbacks that's frequently generated and passed to
|
|
|
|
// instances.
|
|
|
|
this.navigator = {
|
|
|
|
push: this.push,
|
|
|
|
pop: this.pop,
|
|
|
|
popN: this.popN,
|
|
|
|
replace: this.replace,
|
2016-11-11 20:54:48 +00:00
|
|
|
replaceAtIndex: this.replaceAtIndex,
|
2015-02-20 04:10:52 +00:00
|
|
|
replacePrevious: this.replacePrevious,
|
|
|
|
replacePreviousAndPop: this.replacePreviousAndPop,
|
|
|
|
resetTo: this.resetTo,
|
|
|
|
popToRoute: this.popToRoute,
|
|
|
|
popToTop: this.popToTop,
|
|
|
|
};
|
2015-07-02 16:34:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount: function() {
|
2016-12-19 14:26:07 +00:00
|
|
|
this._enableTVEventHandler();
|
2015-07-02 16:34:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
2016-12-19 14:26:07 +00:00
|
|
|
this._disableTVEventHandler();
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
|
2015-12-08 11:29:08 +00:00
|
|
|
getDefaultProps: function(): Object {
|
|
|
|
return {
|
|
|
|
translucent: true,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-03-25 19:55:10 +00:00
|
|
|
getInitialState: function(): State {
|
2015-02-20 04:10:52 +00:00
|
|
|
return {
|
|
|
|
idStack: [getuid()],
|
|
|
|
routeStack: [this.props.initialRoute],
|
|
|
|
// The navigation index that we wish to push/pop to.
|
|
|
|
requestedTopOfStack: 0,
|
|
|
|
// The last index that native has sent confirmation of completed push/pop
|
|
|
|
// for. At this point, we can discard any views that are beyond the
|
|
|
|
// `requestedTopOfStack`. A value of `null` means we have not received
|
|
|
|
// any confirmation, ever. We may receive an `observedTopOfStack` without
|
|
|
|
// ever requesting it - native can instigate pops of its own with the
|
|
|
|
// backswipe gesture.
|
|
|
|
observedTopOfStack: 0,
|
|
|
|
progress: 1,
|
|
|
|
fromIndex: 0,
|
|
|
|
toIndex: 0,
|
|
|
|
// Whether or not we are making a navigator request to push/pop. (Used
|
|
|
|
// for performance optimization).
|
|
|
|
makingNavigatorRequest: false,
|
|
|
|
// Whether or not we are updating children of navigator and if so (not
|
|
|
|
// `null`) which index marks the beginning of all updates. Used for
|
|
|
|
// performance optimization.
|
|
|
|
updatingAllIndicesAtOrBeyond: 0,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-03-25 19:55:10 +00:00
|
|
|
_toFocusOnNavigationComplete: (undefined: any),
|
|
|
|
|
|
|
|
_handleFocusRequest: function(item: any) {
|
2015-02-20 04:10:52 +00:00
|
|
|
if (this.state.makingNavigatorRequest) {
|
|
|
|
this._toFocusOnNavigationComplete = item;
|
|
|
|
} else {
|
|
|
|
this._getFocusEmitter().emit('focus', item);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-03-25 19:55:10 +00:00
|
|
|
_focusEmitter: (undefined: ?EventEmitter),
|
|
|
|
|
|
|
|
_getFocusEmitter: function(): EventEmitter {
|
|
|
|
// Flow not yet tracking assignments to instance fields.
|
2018-03-03 23:04:46 +00:00
|
|
|
let focusEmitter = this._focusEmitter;
|
2015-03-25 19:55:10 +00:00
|
|
|
if (!focusEmitter) {
|
|
|
|
focusEmitter = new EventEmitter();
|
|
|
|
this._focusEmitter = focusEmitter;
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
2015-03-25 19:55:10 +00:00
|
|
|
return focusEmitter;
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
|
2015-03-25 19:55:10 +00:00
|
|
|
getChildContext: function(): {
|
2016-06-23 15:27:29 +00:00
|
|
|
onFocusRequested: Function,
|
|
|
|
focusEmitter: EventEmitter,
|
2015-03-25 19:55:10 +00:00
|
|
|
} {
|
2015-02-20 04:10:52 +00:00
|
|
|
return {
|
|
|
|
onFocusRequested: this._handleFocusRequest,
|
|
|
|
focusEmitter: this._getFocusEmitter(),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
childContextTypes: {
|
2017-04-12 23:09:48 +00:00
|
|
|
onFocusRequested: PropTypes.func,
|
|
|
|
focusEmitter: PropTypes.instanceOf(EventEmitter),
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
|
2015-03-25 19:55:10 +00:00
|
|
|
_tryLockNavigator: function(cb: () => void) {
|
2015-02-20 04:10:52 +00:00
|
|
|
this.refs[TRANSITIONER_REF].requestSchedulingNavigation(
|
2018-05-11 02:06:46 +00:00
|
|
|
acquiredLock => acquiredLock && cb(),
|
2015-02-20 04:10:52 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-03-25 19:55:10 +00:00
|
|
|
_handleNavigatorStackChanged: function(e: Event) {
|
2018-03-03 23:04:46 +00:00
|
|
|
const newObservedTopOfStack = e.nativeEvent.stackLength - 1;
|
2015-07-02 16:34:34 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
invariant(
|
|
|
|
newObservedTopOfStack <= this.state.requestedTopOfStack,
|
2018-05-11 02:06:46 +00:00
|
|
|
'No navigator item should be pushed without JS knowing about it %s %s',
|
|
|
|
newObservedTopOfStack,
|
|
|
|
this.state.requestedTopOfStack,
|
2015-02-20 04:10:52 +00:00
|
|
|
);
|
2018-03-03 23:04:46 +00:00
|
|
|
const wasWaitingForConfirmation =
|
2015-02-20 04:10:52 +00:00
|
|
|
this.state.requestedTopOfStack !== this.state.observedTopOfStack;
|
|
|
|
if (wasWaitingForConfirmation) {
|
|
|
|
invariant(
|
|
|
|
newObservedTopOfStack === this.state.requestedTopOfStack,
|
|
|
|
'If waiting for observedTopOfStack to reach requestedTopOfStack, ' +
|
2018-05-11 02:06:46 +00:00
|
|
|
'the only valid observedTopOfStack should be requestedTopOfStack.',
|
2015-02-20 04:10:52 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
// Mark the most recent observation regardless of if we can lock the
|
|
|
|
// navigator. `observedTopOfStack` merely represents what we've observed
|
|
|
|
// and this first `setState` is only executed to update debugging
|
|
|
|
// overlays/navigation bar.
|
|
|
|
// Also reset progress, toIndex, and fromIndex as they might not end
|
|
|
|
// in the correct states for a two possible reasons:
|
|
|
|
// Progress isn't always 0 or 1 at the end, the system rounds
|
|
|
|
// If the Navigator is offscreen these values won't be updated
|
|
|
|
// TOOD: Revisit this decision when no longer relying on native navigator.
|
2018-03-03 23:04:46 +00:00
|
|
|
const nextState = {
|
2015-02-20 04:10:52 +00:00
|
|
|
observedTopOfStack: newObservedTopOfStack,
|
|
|
|
makingNavigatorRequest: false,
|
|
|
|
updatingAllIndicesAtOrBeyond: null,
|
|
|
|
progress: 1,
|
|
|
|
toIndex: newObservedTopOfStack,
|
|
|
|
fromIndex: newObservedTopOfStack,
|
|
|
|
};
|
|
|
|
this.setState(nextState, this._eliminateUnneededChildren);
|
|
|
|
},
|
|
|
|
|
|
|
|
_eliminateUnneededChildren: function() {
|
|
|
|
// Updating the indices that we're deleting and that's all. (Truth: Nothing
|
|
|
|
// even uses the indices in this case, but let's make this describe the
|
|
|
|
// truth anyways).
|
2018-03-03 23:04:46 +00:00
|
|
|
const updatingAllIndicesAtOrBeyond =
|
2018-05-11 02:06:46 +00:00
|
|
|
this.state.routeStack.length > this.state.observedTopOfStack + 1
|
|
|
|
? this.state.observedTopOfStack + 1
|
|
|
|
: null;
|
2015-02-20 04:10:52 +00:00
|
|
|
this.setState({
|
|
|
|
idStack: this.state.idStack.slice(0, this.state.observedTopOfStack + 1),
|
2018-05-11 02:06:46 +00:00
|
|
|
routeStack: this.state.routeStack.slice(
|
|
|
|
0,
|
|
|
|
this.state.observedTopOfStack + 1,
|
|
|
|
),
|
2015-02-20 04:10:52 +00:00
|
|
|
// Now we rerequest the top of stack that we observed.
|
|
|
|
requestedTopOfStack: this.state.observedTopOfStack,
|
|
|
|
makingNavigatorRequest: true,
|
|
|
|
updatingAllIndicesAtOrBeyond: updatingAllIndicesAtOrBeyond,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-04-09 18:12:46 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* Navigate forward to a new route.
|
|
|
|
* @param route The new route to navigate to.
|
2016-04-09 18:12:46 +00:00
|
|
|
*/
|
2015-03-25 19:55:10 +00:00
|
|
|
push: function(route: Route) {
|
2015-02-20 04:10:52 +00:00
|
|
|
invariant(!!route, 'Must supply route to push');
|
|
|
|
// Make sure all previous requests are caught up first. Otherwise reject.
|
|
|
|
if (this.state.requestedTopOfStack === this.state.observedTopOfStack) {
|
|
|
|
this._tryLockNavigator(() => {
|
2018-03-03 23:04:46 +00:00
|
|
|
const nextStack = this.state.routeStack.concat([route]);
|
|
|
|
const nextIDStack = this.state.idStack.concat([getuid()]);
|
2015-02-20 04:10:52 +00:00
|
|
|
this.setState({
|
|
|
|
// We have to make sure that we've also supplied enough views to
|
|
|
|
// satisfy our request to adjust the `requestedTopOfStack`.
|
|
|
|
idStack: nextIDStack,
|
|
|
|
routeStack: nextStack,
|
|
|
|
requestedTopOfStack: nextStack.length - 1,
|
|
|
|
makingNavigatorRequest: true,
|
|
|
|
updatingAllIndicesAtOrBeyond: nextStack.length - 1,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-04-09 18:12:46 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* Go back N scenes at once. When N=1, behavior matches `pop()`.
|
|
|
|
* @param n The number of scenes to pop.
|
2016-04-09 18:12:46 +00:00
|
|
|
*/
|
2015-03-25 19:55:10 +00:00
|
|
|
popN: function(n: number) {
|
2015-02-20 04:10:52 +00:00
|
|
|
if (n === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Make sure all previous requests are caught up first. Otherwise reject.
|
|
|
|
if (this.state.requestedTopOfStack === this.state.observedTopOfStack) {
|
|
|
|
if (this.state.requestedTopOfStack > 0) {
|
|
|
|
this._tryLockNavigator(() => {
|
2018-03-03 23:04:46 +00:00
|
|
|
const newRequestedTopOfStack = this.state.requestedTopOfStack - n;
|
2015-07-02 16:34:34 +00:00
|
|
|
invariant(newRequestedTopOfStack >= 0, 'Cannot pop below 0');
|
2015-02-20 04:10:52 +00:00
|
|
|
this.setState({
|
2015-07-02 16:34:34 +00:00
|
|
|
requestedTopOfStack: newRequestedTopOfStack,
|
2015-02-20 04:10:52 +00:00
|
|
|
makingNavigatorRequest: true,
|
2016-01-03 06:51:02 +00:00
|
|
|
updatingAllIndicesAtOrBeyond: this.state.requestedTopOfStack - n,
|
2015-02-20 04:10:52 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-04-09 18:12:46 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* Pop back to the previous scene.
|
2016-04-09 18:12:46 +00:00
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
pop: function() {
|
|
|
|
this.popN(1);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replace a route in the navigation stack.
|
|
|
|
*
|
2016-06-23 19:47:36 +00:00
|
|
|
* @param route The new route that will replace the specified one.
|
|
|
|
* @param index The route into the stack that should be replaced.
|
|
|
|
* If it is negative, it counts from the back of the stack.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2015-03-25 19:55:10 +00:00
|
|
|
replaceAtIndex: function(route: Route, index: number) {
|
2015-02-20 04:10:52 +00:00
|
|
|
invariant(!!route, 'Must supply route to replace');
|
|
|
|
if (index < 0) {
|
|
|
|
index += this.state.routeStack.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.state.routeStack.length <= index) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// I don't believe we need to lock for a replace since there's no
|
|
|
|
// navigation actually happening
|
2018-03-03 23:04:46 +00:00
|
|
|
const nextIDStack = this.state.idStack.slice();
|
|
|
|
const nextRouteStack = this.state.routeStack.slice();
|
2015-02-20 04:10:52 +00:00
|
|
|
nextIDStack[index] = getuid();
|
|
|
|
nextRouteStack[index] = route;
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
idStack: nextIDStack,
|
|
|
|
routeStack: nextRouteStack,
|
|
|
|
makingNavigatorRequest: false,
|
|
|
|
updatingAllIndicesAtOrBeyond: index,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* Replace the route for the current scene and immediately
|
2016-04-09 18:12:46 +00:00
|
|
|
* load the view for the new route.
|
2016-06-23 19:47:36 +00:00
|
|
|
* @param route The new route to navigate to.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2015-03-25 19:55:10 +00:00
|
|
|
replace: function(route: Route) {
|
2015-02-20 04:10:52 +00:00
|
|
|
this.replaceAtIndex(route, -1);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* Replace the route/view for the previous scene.
|
|
|
|
* @param route The new route to will replace the previous scene.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2015-03-25 19:55:10 +00:00
|
|
|
replacePrevious: function(route: Route) {
|
2015-02-20 04:10:52 +00:00
|
|
|
this.replaceAtIndex(route, -2);
|
|
|
|
},
|
|
|
|
|
2016-04-09 18:12:46 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* Go back to the topmost item in the navigation stack.
|
2016-04-09 18:12:46 +00:00
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
popToTop: function() {
|
|
|
|
this.popToRoute(this.state.routeStack[0]);
|
|
|
|
},
|
|
|
|
|
2016-04-09 18:12:46 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* Go back to the item for a particular route object.
|
|
|
|
* @param route The new route to navigate to.
|
2016-04-09 18:12:46 +00:00
|
|
|
*/
|
2015-03-25 19:55:10 +00:00
|
|
|
popToRoute: function(route: Route) {
|
2018-03-03 23:04:46 +00:00
|
|
|
const indexOfRoute = this.state.routeStack.indexOf(route);
|
2015-02-20 04:10:52 +00:00
|
|
|
invariant(
|
|
|
|
indexOfRoute !== -1,
|
2018-05-11 02:06:46 +00:00
|
|
|
"Calling pop to route for a route that doesn't exist!",
|
2015-02-20 04:10:52 +00:00
|
|
|
);
|
2018-03-03 23:04:46 +00:00
|
|
|
const numToPop = this.state.routeStack.length - indexOfRoute - 1;
|
2015-02-20 04:10:52 +00:00
|
|
|
this.popN(numToPop);
|
|
|
|
},
|
|
|
|
|
2016-04-09 18:12:46 +00:00
|
|
|
/**
|
|
|
|
* Replaces the previous route/view and transitions back to it.
|
2016-06-23 19:47:36 +00:00
|
|
|
* @param route The new route that replaces the previous scene.
|
2016-04-09 18:12:46 +00:00
|
|
|
*/
|
2015-03-25 19:55:10 +00:00
|
|
|
replacePreviousAndPop: function(route: Route) {
|
2015-02-20 04:10:52 +00:00
|
|
|
// Make sure all previous requests are caught up first. Otherwise reject.
|
|
|
|
if (this.state.requestedTopOfStack !== this.state.observedTopOfStack) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this.state.routeStack.length < 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._tryLockNavigator(() => {
|
|
|
|
this.replacePrevious(route);
|
|
|
|
this.setState({
|
|
|
|
requestedTopOfStack: this.state.requestedTopOfStack - 1,
|
|
|
|
makingNavigatorRequest: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-04-09 18:12:46 +00:00
|
|
|
/**
|
2016-06-23 19:47:36 +00:00
|
|
|
* Replaces the top item and pop to it.
|
|
|
|
* @param route The new route that will replace the topmost item.
|
2016-04-09 18:12:46 +00:00
|
|
|
*/
|
2015-03-25 19:55:10 +00:00
|
|
|
resetTo: function(route: Route) {
|
2015-02-20 04:10:52 +00:00
|
|
|
invariant(!!route, 'Must supply route to push');
|
|
|
|
// Make sure all previous requests are caught up first. Otherwise reject.
|
|
|
|
if (this.state.requestedTopOfStack !== this.state.observedTopOfStack) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.replaceAtIndex(route, 0);
|
|
|
|
this.popToRoute(route);
|
|
|
|
},
|
|
|
|
|
2016-04-09 18:12:46 +00:00
|
|
|
_handleNavigationComplete: function(e: Event) {
|
2016-10-17 17:26:20 +00:00
|
|
|
// Don't propagate to other NavigatorIOS instances this is nested in:
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
if (this._toFocusOnNavigationComplete) {
|
|
|
|
this._getFocusEmitter().emit('focus', this._toFocusOnNavigationComplete);
|
|
|
|
this._toFocusOnNavigationComplete = null;
|
|
|
|
}
|
|
|
|
this._handleNavigatorStackChanged(e);
|
|
|
|
},
|
|
|
|
|
2016-02-02 01:13:08 +00:00
|
|
|
_routeToStackItem: function(routeArg: Route, i: number) {
|
2018-03-03 23:04:46 +00:00
|
|
|
const {component, wrapperStyle, passProps, ...route} = routeArg;
|
|
|
|
const {itemWrapperStyle, ...props} = this.props;
|
|
|
|
const shouldUpdateChild =
|
2016-01-06 18:32:23 +00:00
|
|
|
this.state.updatingAllIndicesAtOrBeyond != null &&
|
2015-02-20 04:10:52 +00:00
|
|
|
this.state.updatingAllIndicesAtOrBeyond >= i;
|
2018-03-03 23:04:46 +00:00
|
|
|
const Component = component;
|
2015-02-20 04:10:52 +00:00
|
|
|
return (
|
|
|
|
<StaticContainer key={'nav' + i} shouldUpdate={shouldUpdateChild}>
|
2015-03-17 10:08:46 +00:00
|
|
|
<RCTNavigatorItem
|
2015-12-08 11:29:08 +00:00
|
|
|
{...props}
|
2016-01-04 15:41:46 +00:00
|
|
|
{...route}
|
2018-05-11 02:06:46 +00:00
|
|
|
style={[styles.stackItem, itemWrapperStyle, wrapperStyle]}>
|
|
|
|
<Component navigator={this.navigator} route={route} {...passProps} />
|
2015-03-17 10:08:46 +00:00
|
|
|
</RCTNavigatorItem>
|
2015-02-20 04:10:52 +00:00
|
|
|
</StaticContainer>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2016-04-09 18:12:46 +00:00
|
|
|
_renderNavigationStackItems: function() {
|
2018-03-03 23:04:46 +00:00
|
|
|
const shouldRecurseToNavigator =
|
2015-02-20 04:10:52 +00:00
|
|
|
this.state.makingNavigatorRequest ||
|
|
|
|
this.state.updatingAllIndicesAtOrBeyond !== null;
|
|
|
|
// If not recursing update to navigator at all, may as well avoid
|
|
|
|
// computation of navigator children.
|
2018-05-11 02:06:46 +00:00
|
|
|
const items = shouldRecurseToNavigator
|
|
|
|
? this.state.routeStack.map(this._routeToStackItem)
|
|
|
|
: null;
|
2015-02-20 04:10:52 +00:00
|
|
|
return (
|
|
|
|
<StaticContainer shouldUpdate={shouldRecurseToNavigator}>
|
|
|
|
<NavigatorTransitionerIOS
|
|
|
|
ref={TRANSITIONER_REF}
|
|
|
|
style={styles.transitioner}
|
2017-03-05 03:29:24 +00:00
|
|
|
// $FlowFixMe(>=0.41.0)
|
2015-02-20 04:10:52 +00:00
|
|
|
vertical={this.props.vertical}
|
|
|
|
requestedTopOfStack={this.state.requestedTopOfStack}
|
2016-05-06 10:17:28 +00:00
|
|
|
onNavigationComplete={this._handleNavigationComplete}
|
2018-05-11 02:06:46 +00:00
|
|
|
interactivePopGestureEnabled={
|
|
|
|
this.props.interactivePopGestureEnabled
|
|
|
|
}>
|
2015-02-20 04:10:52 +00:00
|
|
|
{items}
|
|
|
|
</NavigatorTransitionerIOS>
|
|
|
|
</StaticContainer>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2016-12-19 14:26:07 +00:00
|
|
|
_tvEventHandler: (undefined: ?TVEventHandler),
|
|
|
|
|
|
|
|
_enableTVEventHandler: function() {
|
|
|
|
this._tvEventHandler = new TVEventHandler();
|
|
|
|
this._tvEventHandler.enable(this, function(cmp, evt) {
|
|
|
|
if (evt && evt.eventType === 'menu') {
|
|
|
|
cmp.pop();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_disableTVEventHandler: function() {
|
|
|
|
if (this._tvEventHandler) {
|
|
|
|
this._tvEventHandler.disable();
|
|
|
|
delete this._tvEventHandler;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
render: function() {
|
|
|
|
return (
|
2017-03-05 03:29:24 +00:00
|
|
|
// $FlowFixMe(>=0.41.0)
|
2018-05-11 02:06:46 +00:00
|
|
|
<View style={this.props.style}>{this._renderNavigationStackItems()}</View>
|
2015-02-20 04:10:52 +00:00
|
|
|
);
|
2015-07-02 16:34:34 +00:00
|
|
|
},
|
2015-02-20 04:10:52 +00:00
|
|
|
});
|
|
|
|
|
2018-03-03 23:04:46 +00:00
|
|
|
const styles = StyleSheet.create({
|
2015-02-20 04:10:52 +00:00
|
|
|
stackItem: {
|
|
|
|
backgroundColor: 'white',
|
|
|
|
overflow: 'hidden',
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
bottom: 0,
|
|
|
|
},
|
|
|
|
transitioner: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-03-03 23:04:46 +00:00
|
|
|
const RCTNavigator = requireNativeComponent('RCTNavigator');
|
|
|
|
const RCTNavigatorItem = requireNativeComponent('RCTNavItem');
|
2015-07-25 01:31:55 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
module.exports = NavigatorIOS;
|