Skip to content

Convenient navigation service with using refs on navigators

Notifications You must be signed in to change notification settings

allmaxgit/react-navigation-extension

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Getting started

  1. Install package
yarn add react-navigation-extension
  1. Set navigation container
import React, {
  memo,
  useRef,
  useLayoutEffect,
} from 'react';
import {
  NavigationContainerComponent,
} from 'react-navigation';

import {
  navigationNames,
} from '~/global';
import {
  Navigation,
} from '~/navigation';
import {
  setNavigationContainer,
} from '~/components';

export const UnconnectedApp = memo<{}>(() => {
  const navigationRef = useRef<NavigationContainerComponent>(null);
  useLayoutEffect(() => {
    setNavigationContainer(navigationNames.main, navigationRef);
  }, []);
  return (
    <Navigation
      ref={navigationRef}
    />
  );
});
  1. Create navigation
import {
  createNavigation,
} from 'react-navigation-extension';

import {
  navigationNames,
} from '~/global';

export const mainNavigation = createNavigation(navigationNames.main);
  1. Navigate simple
import {
  mainNavigation,
} from '~/navigation';

mainNavigation.navigate('SIGN_UP');
mainNavigation.reset(['SIGN_IN', 'FORGOT_PASSWORD'], { email: '[email protected]' });

Available methods

navigate: (
  routeName: string,
  params?: NavigationParams,
  action?: NavigationNavigateAction,
  key?: string,
) => void,
setParams: (params: NavigationParams, key?: string) => void,
goBack: (key?: string | null) => {
  const navigator = navigatorsByName[navigationRouteName];
  if (navigator != null) {
    const action = NavigationActions.back({ key });
    navigator.dispatch(action);
  }
},
push: (
  routeName: string,
  params?: NavigationParams,
  action?: NavigationNavigateAction,
  key?: string,
) => void,
pop: (n?: number) => void,
reset: (routeName?: string | string[], params?: NavigationParams) => void,
getCanNavigateBack: () => {
  const navigator = navigatorsByName[navigationRouteName];
  if (navigator != null) {
    const {
      state: {
        nav: {
          index,
        },
      },
    } = navigator;
    return index > 0;
  }
  return false;
},
getCurrentRouteName: () => string | null,

About

Convenient navigation service with using refs on navigators

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •