How to use the @react-navigation/core.NavigationActions.init function in @react-navigation/core

To help you get started, we’ve selected a few @react-navigation/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github react-navigation / native / src / createAppContainer.js View on Github external
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());
          }
        });
github react-navigation / web / src / handleServerRequest.js View on Github external
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,
    () => {},
github react-navigation / redux-helpers / src / reducer.js View on Github external
// @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,
};
github react-navigation / native / src / createAppContainer.js View on Github external
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;
      }
    }
github keybase / client / shared / router-v2 / router.desktop.tsx View on Github external
constructor(props: any) {
      super(props)
      this.initialAction = NavigationActions.init()
      this.state = {nav: Component.router.getStateForAction(this.initialAction)}
    }
github react-navigation / web / src / createBrowserApp.js View on Github external
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);
github keybase / client / shared / router-v2 / router.desktop.js View on Github external
constructor(props: any) {
      super(props)
      this._initialAction = NavigationActions.init()
      this.state = {nav: Component.router.getStateForAction(this._initialAction)}
    }