@react-navigation/core
Advanced tools
Comparing version 3.0.0-alpha.6 to 3.0.0-alpha.7
@@ -0,1 +1,3 @@ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
/* | ||
@@ -38,3 +40,3 @@ * This is used to extract one children's worth of events from a stream of navigation action events | ||
const emit = (type, payload) => { | ||
const payloadWithType = { ...payload, type }; | ||
const payloadWithType = _extends({}, payload, { type }); | ||
const subscribers = getChildSubscribers(type); | ||
@@ -41,0 +43,0 @@ subscribers && subscribers.forEach(subs => { |
@@ -0,1 +1,3 @@ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
import getChildEventSubscriber from './getChildEventSubscriber'; | ||
@@ -37,8 +39,3 @@ import getChildRouter from './getChildRouter'; | ||
const actionCreators = { | ||
...navigation.actions, | ||
...navigation.router.getActionCreators(childRoute, navigation.state.key), | ||
...(childRouter ? childRouter.getActionCreators(focusedGrandChildRoute, childRoute.key) : {}), | ||
...getNavigationActionCreators(childRoute) | ||
}; | ||
const actionCreators = _extends({}, navigation.actions, navigation.router.getActionCreators(childRoute, navigation.state.key), childRouter ? childRouter.getActionCreators(focusedGrandChildRoute, childRoute.key) : {}, getNavigationActionCreators(childRoute)); | ||
@@ -55,5 +52,3 @@ const actionHelpers = {}; | ||
if (children[childKey]) { | ||
children[childKey] = { | ||
...children[childKey], | ||
...actionHelpers, | ||
children[childKey] = _extends({}, children[childKey], actionHelpers, { | ||
state: childRoute, | ||
@@ -63,3 +58,3 @@ router: childRouter, | ||
getParam: createParamGetter(childRoute) | ||
}; | ||
}); | ||
return children[childKey]; | ||
@@ -70,4 +65,3 @@ } | ||
children[childKey] = { | ||
...actionHelpers, | ||
children[childKey] = _extends({}, actionHelpers, { | ||
@@ -102,3 +96,3 @@ state: childRoute, | ||
addListener: childSubscriber.addListener | ||
}; | ||
}); | ||
return children[childKey]; | ||
@@ -105,0 +99,0 @@ } |
@@ -0,1 +1,3 @@ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
import getNavigationActionCreators from './routers/getNavigationActionCreators'; | ||
@@ -35,6 +37,3 @@ import getChildNavigation from './getChildNavigation'; | ||
const actionCreators = { | ||
...getNavigationActionCreators(navigation.state), | ||
...actions | ||
}; | ||
const actionCreators = _extends({}, getNavigationActionCreators(navigation.state), actions); | ||
@@ -41,0 +40,0 @@ Object.keys(actionCreators).forEach(actionName => { |
@@ -0,1 +1,3 @@ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
import React from 'react'; | ||
@@ -7,9 +9,10 @@ import { polyfill } from 'react-lifecycles-compat'; | ||
class Navigator extends React.Component { | ||
static router = router; | ||
static navigationOptions = navigationConfig.navigationOptions; | ||
constructor(...args) { | ||
var _temp; | ||
state = { | ||
descriptors: {}, | ||
screenProps: this.props.screenProps | ||
}; | ||
return _temp = super(...args), this.state = { | ||
descriptors: {}, | ||
screenProps: this.props.screenProps | ||
}, _temp; | ||
} | ||
@@ -49,6 +52,13 @@ static getDerivedStateFromProps(nextProps, prevState) { | ||
render() { | ||
return <NavigatorView {...this.props} screenProps={this.state.screenProps} navigation={this.props.navigation} navigationConfig={navigationConfig} descriptors={this.state.descriptors} />; | ||
return React.createElement(NavigatorView, _extends({}, this.props, { | ||
screenProps: this.state.screenProps, | ||
navigation: this.props.navigation, | ||
navigationConfig: navigationConfig, | ||
descriptors: this.state.descriptors | ||
})); | ||
} | ||
} | ||
Navigator.router = router; | ||
Navigator.navigationOptions = navigationConfig.navigationOptions; | ||
return polyfill(Navigator); | ||
@@ -55,0 +65,0 @@ } |
@@ -0,1 +1,3 @@ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
import invariant from '../utils/invariant'; | ||
@@ -8,15 +10,8 @@ | ||
if (typeof configurer === 'function') { | ||
return { | ||
...navigationOptions, | ||
...configurer({ | ||
...configProps, | ||
navigationOptions | ||
}) | ||
}; | ||
return _extends({}, navigationOptions, configurer(_extends({}, configProps, { | ||
navigationOptions | ||
}))); | ||
} | ||
if (typeof configurer === 'object') { | ||
return { | ||
...navigationOptions, | ||
...configurer | ||
}; | ||
return _extends({}, navigationOptions, configurer); | ||
} | ||
@@ -23,0 +18,0 @@ return navigationOptions; |
@@ -0,1 +1,3 @@ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
/* eslint-disable import/no-commonjs */ | ||
@@ -28,6 +30,3 @@ | ||
return paramsOut; | ||
}, { | ||
// start with the input(query string) params, which will get overridden by path params | ||
...inputParams | ||
}); | ||
}, _extends({}, inputParams)); | ||
return params; | ||
@@ -171,3 +170,3 @@ }; | ||
path: subPath ? `${subPath}/${child.path}` : child.path, | ||
params: child.params ? { ...nonPathParams, ...child.params } : nonPathParams | ||
params: child.params ? _extends({}, nonPathParams, child.params) : nonPathParams | ||
}; | ||
@@ -174,0 +173,0 @@ } |
@@ -0,1 +1,3 @@ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
const POP = 'Navigation/POP'; | ||
@@ -8,31 +10,25 @@ const POP_TO_TOP = 'Navigation/POP_TO_TOP'; | ||
const pop = payload => ({ | ||
type: POP, | ||
...payload | ||
}); | ||
const pop = payload => _extends({ | ||
type: POP | ||
}, payload); | ||
const popToTop = payload => ({ | ||
type: POP_TO_TOP, | ||
...payload | ||
}); | ||
const popToTop = payload => _extends({ | ||
type: POP_TO_TOP | ||
}, payload); | ||
const push = payload => ({ | ||
type: PUSH, | ||
...payload | ||
}); | ||
const push = payload => _extends({ | ||
type: PUSH | ||
}, payload); | ||
const reset = payload => ({ | ||
type: RESET, | ||
...payload | ||
}); | ||
const reset = payload => _extends({ | ||
type: RESET | ||
}, payload); | ||
const replace = payload => ({ | ||
type: REPLACE, | ||
...payload | ||
}); | ||
const replace = payload => _extends({ | ||
type: REPLACE | ||
}, payload); | ||
const completeTransition = payload => ({ | ||
type: COMPLETE_TRANSITION, | ||
...payload | ||
}); | ||
const completeTransition = payload => _extends({ | ||
type: COMPLETE_TRANSITION | ||
}, payload); | ||
@@ -39,0 +35,0 @@ export default { |
@@ -0,1 +1,3 @@ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
import NavigationActions from '../NavigationActions'; | ||
@@ -63,8 +65,8 @@ import StackActions from './StackActions'; | ||
index: 0, | ||
routes: [{ | ||
params: action.params, | ||
...childState, | ||
routes: [_extends({ | ||
params: action.params | ||
}, childState, { | ||
key: action.key || generateKey(), | ||
routeName: action.routeName | ||
}] | ||
})] | ||
}; | ||
@@ -79,14 +81,8 @@ } | ||
} | ||
const params = (route.params || action.params || initialRouteParams) && { | ||
...(route.params || {}), | ||
...(action.params || {}), | ||
...(initialRouteParams || {}) | ||
}; | ||
const params = (route.params || action.params || initialRouteParams) && _extends({}, route.params || {}, action.params || {}, initialRouteParams || {}); | ||
const { initialRouteKey } = stackConfig; | ||
route = { | ||
...route, | ||
...(params ? { params } : {}), | ||
route = _extends({}, route, params ? { params } : {}, { | ||
routeName: initialRouteName, | ||
key: action.key || initialRouteKey || generateKey() | ||
}; | ||
}); | ||
return { | ||
@@ -122,8 +118,6 @@ key: 'StackRouterRoot', | ||
getActionCreators(route, navStateKey) { | ||
return { | ||
...getCustomActionCreators(route, navStateKey), | ||
pop: (n, params) => StackActions.pop({ | ||
n, | ||
...params | ||
}), | ||
return _extends({}, getCustomActionCreators(route, navStateKey), { | ||
pop: (n, params) => StackActions.pop(_extends({ | ||
n | ||
}, params)), | ||
popToTop: params => StackActions.popToTop(params), | ||
@@ -159,3 +153,3 @@ push: (routeName, params, action) => StackActions.push({ | ||
}) | ||
}; | ||
}); | ||
}, | ||
@@ -194,6 +188,5 @@ | ||
const newState = StateUtils.replaceAndPrune(state, nextRouteState ? nextRouteState.key : childRoute.key, nextRouteState ? nextRouteState : childRoute); | ||
return { | ||
...newState, | ||
return _extends({}, newState, { | ||
isTransitioning: state.index !== newState.index ? action.immediate !== true : state.isTransitioning | ||
}; | ||
}); | ||
} | ||
@@ -234,17 +227,12 @@ } | ||
const route = state.routes[lastRouteIndex]; | ||
routes[lastRouteIndex] = { | ||
...route, | ||
params: { | ||
...route.params, | ||
...action.params | ||
} | ||
}; | ||
routes[lastRouteIndex] = _extends({}, route, { | ||
params: _extends({}, route.params, action.params) | ||
}); | ||
} | ||
// Return state with new index. Change isTransitioning only if index has changed | ||
return { | ||
...state, | ||
return _extends({}, state, { | ||
isTransitioning: state.index !== lastRouteIndex ? action.immediate !== true : state.isTransitioning, | ||
index: lastRouteIndex, | ||
routes | ||
}; | ||
}); | ||
} | ||
@@ -254,9 +242,8 @@ | ||
const childAction = action.action || NavigationActions.init({ params: action.params }); | ||
route = { | ||
params: action.params, | ||
// merge the child state in this order to allow params override | ||
...childRouter.getStateForAction(childAction), | ||
route = _extends({ | ||
params: action.params | ||
}, childRouter.getStateForAction(childAction), { | ||
routeName: action.routeName, | ||
key: action.key || generateKey() | ||
}; | ||
}); | ||
} else { | ||
@@ -269,6 +256,5 @@ route = { | ||
} | ||
return { | ||
...StateUtils.push(state, route), | ||
return _extends({}, StateUtils.push(state, route), { | ||
isTransitioning: action.immediate !== true | ||
}; | ||
}); | ||
} else if (action.type === StackActions.PUSH && childRouters[action.routeName] === undefined) { | ||
@@ -299,11 +285,9 @@ // Return the state identity to bubble the action up | ||
if (routeToPush) { | ||
const route = { | ||
...routeToPush, | ||
const route = _extends({}, routeToPush, { | ||
routeName: childRouterName, | ||
key: action.key || generateKey() | ||
}; | ||
return { | ||
...StateUtils.push(state, route), | ||
}); | ||
return _extends({}, StateUtils.push(state, route), { | ||
isTransitioning: action.immediate !== true | ||
}; | ||
}); | ||
} | ||
@@ -325,8 +309,7 @@ } | ||
if (state.index > 0) { | ||
return { | ||
...state, | ||
return _extends({}, state, { | ||
isTransitioning: action.immediate !== true, | ||
index: 0, | ||
routes: [state.routes[0]] | ||
}; | ||
}); | ||
} | ||
@@ -356,10 +339,9 @@ return state; | ||
const routes = [...state.routes]; | ||
routes[routeIndex] = { | ||
params: action.params, | ||
// merge the child state in this order to allow params override | ||
...childState, | ||
routes[routeIndex] = _extends({ | ||
params: action.params | ||
}, childState, { | ||
routeName: action.routeName, | ||
key: action.newKey || generateKey() | ||
}; | ||
return { ...state, routes }; | ||
}); | ||
return _extends({}, state, { routes }); | ||
} | ||
@@ -370,6 +352,5 @@ } | ||
if (action.type === StackActions.COMPLETE_TRANSITION && (action.key == null || action.key === state.key) && state.isTransitioning) { | ||
return { | ||
...state, | ||
return _extends({}, state, { | ||
isTransitioning: false | ||
}; | ||
}); | ||
} | ||
@@ -381,15 +362,10 @@ | ||
if (lastRoute) { | ||
const params = { | ||
...lastRoute.params, | ||
...action.params | ||
}; | ||
const params = _extends({}, lastRoute.params, action.params); | ||
const routes = [...state.routes]; | ||
routes[state.routes.indexOf(lastRoute)] = { | ||
...lastRoute, | ||
routes[state.routes.indexOf(lastRoute)] = _extends({}, lastRoute, { | ||
params | ||
}; | ||
return { | ||
...state, | ||
}); | ||
return _extends({}, state, { | ||
routes | ||
}; | ||
}); | ||
} | ||
@@ -407,4 +383,3 @@ } | ||
return { | ||
...state, | ||
return _extends({}, state, { | ||
routes: newStackActions.map(newStackAction => { | ||
@@ -421,11 +396,11 @@ const router = childRouters[newStackAction.routeName]; | ||
return { | ||
params: newStackAction.params, | ||
...childState, | ||
return _extends({ | ||
params: newStackAction.params | ||
}, childState, { | ||
routeName: newStackAction.routeName, | ||
key: newStackAction.key || generateKey() | ||
}; | ||
}); | ||
}), | ||
index: action.index | ||
}; | ||
}); | ||
} | ||
@@ -446,8 +421,7 @@ | ||
if (backRouteIndex > 0) { | ||
return { | ||
...state, | ||
return _extends({}, state, { | ||
routes: state.routes.slice(0, backRouteIndex), | ||
index: backRouteIndex - 1, | ||
isTransitioning: immediate !== true | ||
}; | ||
}); | ||
} | ||
@@ -454,0 +428,0 @@ } |
@@ -0,1 +1,3 @@ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
import invariant from '../utils/invariant'; | ||
@@ -55,8 +57,7 @@ import getScreenForRouteName from './getScreenForRouteName'; | ||
const childAction = NavigationActions.init(); | ||
return { | ||
...childRouter.getStateForAction(childAction), | ||
return _extends({}, childRouter.getStateForAction(childAction), { | ||
key: routeName, | ||
routeName, | ||
params | ||
}; | ||
}); | ||
} | ||
@@ -81,6 +82,5 @@ return { | ||
return { | ||
...possibleNextState, | ||
return _extends({}, possibleNextState, { | ||
routes: nextRoutes | ||
}; | ||
}); | ||
} else { | ||
@@ -110,3 +110,3 @@ nextState = possibleNextState; | ||
getStateForAction(action, inputState) { | ||
let prevState = inputState ? { ...inputState } : inputState; | ||
let prevState = inputState ? _extends({}, inputState) : inputState; | ||
let state = inputState || getInitialState(); | ||
@@ -122,9 +122,4 @@ let activeChildIndex = state.index; | ||
if (params) { | ||
state.routes = state.routes.map(route => ({ | ||
...route, | ||
params: { | ||
...route.params, | ||
...params, | ||
...(route.routeName === initialRouteName ? initialRouteParams : null) | ||
} | ||
state.routes = state.routes.map(route => _extends({}, route, { | ||
params: _extends({}, route.params, params, route.routeName === initialRouteName ? initialRouteParams : null) | ||
})); | ||
@@ -145,6 +140,5 @@ } | ||
routes[state.index] = activeChildState; | ||
return getNextState(prevState, { | ||
...state, | ||
return getNextState(prevState, _extends({}, state, { | ||
routes | ||
}); | ||
})); | ||
} | ||
@@ -181,9 +175,5 @@ } | ||
} else if (!action.action && action.params) { | ||
newChildState = { | ||
...childState, | ||
params: { | ||
...(childState.params || {}), | ||
...action.params | ||
} | ||
}; | ||
newChildState = _extends({}, childState, { | ||
params: _extends({}, childState.params || {}, action.params) | ||
}); | ||
} | ||
@@ -194,7 +184,6 @@ | ||
routes[activeChildIndex] = newChildState; | ||
return getNextState(prevState, { | ||
...state, | ||
return getNextState(prevState, _extends({}, state, { | ||
routes, | ||
index: activeChildIndex | ||
}); | ||
})); | ||
} else if (!newChildState && state.index === activeChildIndex && prevState) { | ||
@@ -210,15 +199,10 @@ return null; | ||
if (lastRoute) { | ||
const params = { | ||
...lastRoute.params, | ||
...action.params | ||
}; | ||
const params = _extends({}, lastRoute.params, action.params); | ||
const routes = [...state.routes]; | ||
routes[state.routes.indexOf(lastRoute)] = { | ||
...lastRoute, | ||
routes[state.routes.indexOf(lastRoute)] = _extends({}, lastRoute, { | ||
params | ||
}; | ||
return getNextState(prevState, { | ||
...state, | ||
}); | ||
return getNextState(prevState, _extends({}, state, { | ||
routes | ||
}); | ||
})); | ||
} | ||
@@ -228,10 +212,9 @@ } | ||
if (activeChildIndex !== state.index) { | ||
return getNextState(prevState, { | ||
...state, | ||
return getNextState(prevState, _extends({}, state, { | ||
index: activeChildIndex | ||
}); | ||
})); | ||
} else if (didNavigate && !inputState) { | ||
return state; | ||
} else if (didNavigate) { | ||
return { ...state }; | ||
return _extends({}, state); | ||
} | ||
@@ -273,7 +256,6 @@ | ||
if (index !== state.index || routes !== state.routes) { | ||
return getNextState(prevState, { | ||
...state, | ||
return getNextState(prevState, _extends({}, state, { | ||
index, | ||
routes | ||
}); | ||
})); | ||
} | ||
@@ -280,0 +262,0 @@ return state; |
@@ -0,1 +1,3 @@ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
import SwitchRouter from './SwitchRouter'; | ||
@@ -5,3 +7,3 @@ import withDefaultValue from '../utils/withDefaultValue'; | ||
export default ((routeConfigs, config = {}) => { | ||
config = { ...config }; | ||
config = _extends({}, config); | ||
config = withDefaultValue(config, 'resetOnBlur', false); | ||
@@ -8,0 +10,0 @@ config = withDefaultValue(config, 'backBehavior', 'initialRoute'); |
@@ -0,1 +1,3 @@ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
import invariant from './utils/invariant'; | ||
@@ -46,7 +48,6 @@ | ||
return { | ||
...state, | ||
return _extends({}, state, { | ||
index: routes.length - 1, | ||
routes | ||
}; | ||
}); | ||
}, | ||
@@ -65,7 +66,6 @@ | ||
const routes = state.routes.slice(0, -1); | ||
return { | ||
...state, | ||
return _extends({}, state, { | ||
index: routes.length - 1, | ||
routes | ||
}; | ||
}); | ||
}, | ||
@@ -83,6 +83,5 @@ | ||
return { | ||
...state, | ||
return _extends({}, state, { | ||
index | ||
}; | ||
}); | ||
}, | ||
@@ -125,6 +124,5 @@ | ||
return { | ||
...replaced, | ||
return _extends({}, replaced, { | ||
routes: replaced.routes.slice(0, index + 1) | ||
}; | ||
}); | ||
}, | ||
@@ -162,7 +160,6 @@ | ||
return { | ||
...state, | ||
return _extends({}, state, { | ||
index, | ||
routes | ||
}; | ||
}); | ||
}, | ||
@@ -189,7 +186,6 @@ | ||
return { | ||
...state, | ||
return _extends({}, state, { | ||
index: nextIndex, | ||
routes | ||
}; | ||
}); | ||
} | ||
@@ -196,0 +192,0 @@ }; |
@@ -14,2 +14,18 @@ import React from 'react'; | ||
class NavigationEvents extends React.Component { | ||
constructor(...args) { | ||
var _temp; | ||
return _temp = super(...args), this.addListener = eventName => { | ||
const listener = this.props[EventNameToPropName[eventName]]; | ||
if (listener) { | ||
this.subscriptions[eventName] = this.props.navigation.addListener(eventName, listener); | ||
} | ||
}, this.removeListener = eventName => { | ||
if (this.subscriptions[eventName]) { | ||
this.subscriptions[eventName].remove(); | ||
this.subscriptions[eventName] = undefined; | ||
} | ||
}, _temp; | ||
} | ||
componentDidMount() { | ||
@@ -34,16 +50,2 @@ this.subscriptions = {}; | ||
addListener = eventName => { | ||
const listener = this.props[EventNameToPropName[eventName]]; | ||
if (listener) { | ||
this.subscriptions[eventName] = this.props.navigation.addListener(eventName, listener); | ||
} | ||
}; | ||
removeListener = eventName => { | ||
if (this.subscriptions[eventName]) { | ||
this.subscriptions[eventName].remove(); | ||
this.subscriptions[eventName] = undefined; | ||
} | ||
}; | ||
render() { | ||
@@ -50,0 +52,0 @@ return null; |
@@ -7,6 +7,8 @@ import React from 'react'; | ||
const { screenProps, component: Component, navigation } = this.props; | ||
return <NavigationProvider value={navigation}> | ||
<Component screenProps={screenProps} navigation={navigation} /> | ||
</NavigationProvider>; | ||
return React.createElement( | ||
NavigationProvider, | ||
{ value: navigation }, | ||
React.createElement(Component, { screenProps: screenProps, navigation: navigation }) | ||
); | ||
} | ||
} |
@@ -11,4 +11,8 @@ import React from 'react'; | ||
return <SceneView component={ChildComponent} navigation={descriptor.navigation} screenProps={this.props.screenProps} />; | ||
return React.createElement(SceneView, { | ||
component: ChildComponent, | ||
navigation: descriptor.navigation, | ||
screenProps: this.props.screenProps | ||
}); | ||
} | ||
} |
@@ -0,1 +1,3 @@ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
import React from 'react'; | ||
@@ -8,17 +10,22 @@ import hoistStatics from 'hoist-non-react-statics'; | ||
class ComponentWithNavigation extends React.Component { | ||
static displayName = `withNavigation(${Component.displayName || Component.name})`; | ||
render() { | ||
const navigationProp = this.props.navigation; | ||
return <NavigationConsumer> | ||
{navigationContext => { | ||
return React.createElement( | ||
NavigationConsumer, | ||
null, | ||
navigationContext => { | ||
const navigation = navigationProp || navigationContext; | ||
invariant(!!navigation, 'withNavigation can only be used on a view hierarchy of a navigator. The wrapped component is unable to get access to navigation from props or context.'); | ||
return <Component {...this.props} navigation={navigation} ref={this.props.onRef} />; | ||
}} | ||
</NavigationConsumer>; | ||
return React.createElement(Component, _extends({}, this.props, { | ||
navigation: navigation, | ||
ref: this.props.onRef | ||
})); | ||
} | ||
); | ||
} | ||
} | ||
ComponentWithNavigation.displayName = `withNavigation(${Component.displayName || Component.name})`; | ||
return hoistStatics(ComponentWithNavigation, Component); | ||
} |
@@ -0,1 +1,3 @@ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
import React from 'react'; | ||
@@ -8,3 +10,2 @@ import hoistStatics from 'hoist-non-react-statics'; | ||
class ComponentWithNavigationFocus extends React.Component { | ||
static displayName = `withNavigationFocus(${Component.displayName || Component.name})`; | ||
@@ -31,7 +32,11 @@ constructor(props) { | ||
render() { | ||
return <Component {...this.props} isFocused={this.state.isFocused} ref={this.props.onRef} />; | ||
return React.createElement(Component, _extends({}, this.props, { | ||
isFocused: this.state.isFocused, | ||
ref: this.props.onRef | ||
})); | ||
} | ||
} | ||
ComponentWithNavigationFocus.displayName = `withNavigationFocus(${Component.displayName || Component.name})`; | ||
return hoistStatics(withNavigation(ComponentWithNavigationFocus), Component); | ||
} |
{ | ||
"name": "@react-navigation/core", | ||
"version": "3.0.0-alpha.6", | ||
"version": "3.0.0-alpha.7", | ||
"description": "Core utilities for the react-navigation framework", | ||
@@ -17,3 +17,3 @@ "main": "dist/index.js", | ||
"format": "eslint . --fix", | ||
"build": "babel --no-babelrc --plugins=syntax-jsx,syntax-class-properties,syntax-object-rest-spread,transform-flow-strip-types src --copy-files --out-dir dist --ignore '**/__tests__/**'", | ||
"build": "babel --no-babelrc --plugins=transform-react-jsx,transform-class-properties,transform-object-rest-spread,transform-flow-strip-types src --copy-files --out-dir dist --ignore '**/__tests__/**'", | ||
"prepare": "yarn build", | ||
@@ -52,5 +52,5 @@ "release": "release-it" | ||
"babel-jest": "^22.4.1", | ||
"babel-plugin-syntax-class-properties": "^6.13.0", | ||
"babel-plugin-syntax-jsx": "^6.18.0", | ||
"babel-plugin-syntax-object-rest-spread": "^6.13.0", | ||
"babel-plugin-transform-class-properties": "^6.13.0", | ||
"babel-plugin-transform-react-jsx": "^6.18.0", | ||
"babel-plugin-transform-object-rest-spread": "^6.13.0", | ||
"babel-plugin-transform-flow-strip-types": "^6.22.0", | ||
@@ -57,0 +57,0 @@ "babel-preset-react-native": "^4.0.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
304302
0
9103