Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(props) {
super(props);
validateProps(props);
this._initialAction = NavigationActions.init();
if (
this._isStateful() &&
BackHandler &&
typeof BackHandler.addEventListener === 'function'
) {
this.subs = BackHandler.addEventListener('hardwareBackPress', () => {
if (!this._isMounted) {
this.subs && this.subs.remove();
} else {
// dispatch returns true if the action results in a state change,
// and false otherwise. This maps well to what BackHandler expects
// from a callback -- true if handled, false if not handled
return this.dispatch(NavigationActions.back());
}
});
export default function handleServerRequest(
Router,
pathWithLeadingSlash,
query
) {
const path = pathWithLeadingSlash.slice(1);
// Get initial action from the URL
const navigationAction =
Router.getActionForPathAndParams(path, query) || NavigationActions.init();
// Get state from reducer
const navigationState = Router.getStateForAction(navigationAction);
const actionSubscribers = new Set();
// Prepare top-level navigation prop
let navigation = null;
function getCurrentNavigation() {
return navigation;
}
navigation = getNavigation(
Router,
navigationState,
() => {},
// @flow
import type { NavigationAction, NavigationState } from '@react-navigation/core';
import type { Reducer } from 'redux';
import type { Navigator, ReducerState } from './types'
import { NavigationActions } from '@react-navigation/core';
const initAction = NavigationActions.init();
function createNavigationReducer(navigator: Navigator): Reducer<*, *> {
const initialState = navigator.router.getStateForAction(initAction, null);
return (
state: ReducerState = initialState,
action: NavigationAction,
): ReducerState => {
return navigator.router.getStateForAction(action, state) || state;
};
};
export {
createNavigationReducer,
initAction,
};
componentDidCatch(e) {
if (_reactNavigationIsHydratingState) {
_reactNavigationIsHydratingState = false;
console.warn(
'Uncaught exception while starting app from persisted navigation state! Trying to render again with a fresh navigation state...'
);
this.dispatch(NavigationActions.init());
} else {
throw e;
}
}
constructor(props: any) {
super(props)
this.initialAction = NavigationActions.init()
this.state = {nav: Component.router.getStateForAction(this.initialAction)}
}
export default function createBrowserApp(App, { history: historyOption } = {}) {
const history = getHistory(historyOption);
let currentPathAndParams = getPathAndParamsFromLocation(history.location);
const initAction =
App.router.getActionForPathAndParams(
currentPathAndParams.path,
currentPathAndParams.params
) || NavigationActions.init();
const setHistoryListener = dispatch => {
history.listen(location => {
const pathAndParams = getPathAndParamsFromLocation(location);
if (matchPathAndParams(pathAndParams, currentPathAndParams)) {
return;
}
currentPathAndParams = pathAndParams;
const action = App.router.getActionForPathAndParams(
pathAndParams.path,
pathAndParams.params
);
if (action) {
dispatch(action);
} else {
dispatch(initAction);
constructor(props: any) {
super(props)
this._initialAction = NavigationActions.init()
this.state = {nav: Component.router.getStateForAction(this._initialAction)}
}