MCPcopy Index your code
hub / github.com/aksonov/react-native-router-flux

github.com/aksonov/react-native-router-flux @4.3.1 sqlite

repository ↗ · DeepWiki ↗ · release 4.3.1 ↗
175 symbols 378 edges 80 files 3 documented · 2% 1 cross-repo links
README

React Native Router (v2.x) Join the chat at https://gitter.im/aksonov/react-native-router-flux

Router for React Native based on exNavigator

Features

  • Define your screens ("routes") and animation transitions in one central location
  • Use simple syntax to call transitions anywhere in your code (e.g. Actions.login)
  • Eliminates the need to pass navigator objects to your screens
  • Use a Schema to define common properties for a group of screens. For example, you can define a "modal" Schema for screens that animate from the bottom of the screen.
  • Ability to show/hide navigation bar (see limitations)
  • Support for managing a tab bar, using react-native-tabs (see demo)
  • Support for nested navigators. For example, each tab can have its own navigator, nested in a root navigator. Transition actions will automatically use the top navigator.

Installation

npm i react-native-router-flux --save

Usage

  1. In top-level index.js, define a Router and child Route elements for your screens.
    • If some of your screens have common attributes, consider defining a Schema element to reduce repetition
  2. In any app screen:
    • import {Actions} from 'react-native-router-flux'
    • Actions.ACTION_NAME(PARAMS) will call appropriate action and params will be passed to the route

Configuration

Router:
Property Type Default Description
header object null optional header view
footer object null optional footer view (e.g. tab bar)
hideNavBar bool false hides navigation bar for every route
Route:
Property Type Default Description
name string required Will be used to call screen transition, for example, Actions.name(params). Must be unique.
component React.Component semi-required The Component to be displayed. Not required when defining a nested Router or child, see example
type string optional Defines how the new screen is added to the navigator stack. One of push, modal,actionSheet,replace, switch, reset transitionToTop. Default is 'push'. replace tells navigator to replace current route with new route. actionSheet shows Action Sheet popup, you must pass callback as callback function, check Example for details. modal type inserts its 'component' after navigator component. It could be used for popup alerts as well for various needed processes before any navigator transitions (like login auth process).switch is used for tab screens. reset is similar to replace except it unmounts the componets in the navigator stack. modal component could be dismissed by using Actions.dismiss() transitionToTop will reset router stack ['route.name'] and with animation, if route has sceneConfig. eg <Route name="login" schema="modal" component={Login} type="transitionToTop" />
initial bool false Set to true if this is the initial screen
title string null The title to be displayed in the navigation bar
schema string optional Set this property to the name of a previously defined Schema to inherit its properties
wrapRouter bool false If true, the route is automatically nested in its own Router. Useful for modal screens. For type==switch wrapRouter will be true
sceneConfig Navigator.SceneConfigs optional Defines the transition animation.
defaultRoute string optional Defines which route to go to if this route is used as a tab and the tab is clicked on when the tab is already selected
hideNavBar bool false hides navigation bar for this route
hideTabBar bool false hides tab bar for this route (if built-in TabBar component is used as footer for parent Router, check Example)
navigationBarStyle View style optional style override for the navigation bar
titleStyle Text style optional style override for the title element
renderTitle Closure optional closure to render the title element
barButtonIconStyle Image style optional style override for icon buttons (e.g. back icon)
leftTitle string optional string to display on the left if the previous route does not provide renderBackButton prop. renderBackButton > leftTitle > title>
renderLeftButton Closure optional closure to render the left title / buttons element
renderBackButton Closure optional closure to render back text or button if this route happens to be the previous route
leftButtonStyle View style optional style override for the container of left title / buttons
leftButtonTextStyle Text style optional style override for the left title element
rightTitle string optional string to display on the right. onRight must be provided for this to appear.
renderRightButton Closure optional closure to render the right title / buttons element
rightButtonStyle View style optional style override for the container of right title / buttons
rightButtonTextStyle Text style optional style override for the right title element
Schema:
Property Type Default Description
name string required The name of the schema, to be referenced in the route as schema={"name"}
property - - A Schema can have any property that you want the Route to inherit

Example

launch

import React, {AppRegistry, Navigator, StyleSheet, Text, View} from 'react-native'
import Launch from './components/Launch'
import Register from './components/Register'
import Login from './components/Login'
import Login2 from './components/Login2'
import {Router, Route, Schema, Animations, TabBar} from 'react-native-router-flux'
import Error from './components/Error'
import Home from './components/Home'
import TabView from './components/TabView'

class TabIcon extends React.Component {
    render(){
        return (
            <Text style={{color: this.props.selected ? 'red' :'black'}}>{this.props.title}</Text>
        );
    }
}

export default class Example extends React.Component {
    render() {
        return (
            <Router hideNavBar={true}>
                <Schema name="modal" sceneConfig={Navigator.SceneConfigs.FloatFromBottom}/>
                <Schema name="default" sceneConfig={Navigator.SceneConfigs.FloatFromRight}/>
                <Schema name="withoutAnimation"/>
                <Schema name="tab" type="switch" icon={TabIcon} />

                <Route name="launch" component={Launch} initial={true} wrapRouter={true} title="Launch"/>
                <Route name="register" component={Register} title="Register"/>
                <Route name="home" component={Home} title="Replace" type="replace"/>
                <Route name="login" schema="modal">
                    <Router>
                        <Route name="loginModal" component={Login} title="Login" schema="modal"/>
                        <Route name="loginModal2" component={Login2} title="Login2"/>
                    </Router>
                </Route>
                <Route name="error" component={Error} title="Error"  type="modal"/>
                <Route name="register2" component={Register} title="Register2"  schema="withoutAnimation"/>
                <Route name="tabbar">
                    <Router footer={TabBar} hideNavBar={true} tabBarStyle={{borderTopColor:'#00bb00',borderTopWidth:1,backgroundColor:'white'}}>
                        <Route name="tab1" schema="tab" title="Tab #1" defaultRoute='tab1_1'>
                            <Router>
                                <Route name="tab1_1" component={TabView} title="Tab #1_1" />
                                <Route name="tab1_2" component={TabView} title="Tab #1_2" />
                            </Router>
                        </Route>
                        <Route name="tab2" schema="tab" title="Tab #2" hideNavBar={true}>
                            <Router onPop={()=>{console.log("onPop is called!"); return true} }>
                                <Route name="tab2_1" component={TabView} title="Tab #2_1" />
                                <Route name="tab2_2" component={TabView} title="Tab #2_2" />
                            </Router>
                        </Route>
                        <Route name="tab3" schema="tab" title="Tab #3" component={TabView} hideTabBar={true}/>
                        <Route name="tab4" schema="tab" title="Tab #4" component={TabView} />
                        <Route name="tab5" schema="tab" title="Tab #5" component={TabView} />
                    </Router>
                </Route>
            </Router>
        );
    }
}

components/Launch.js (initial screen)

import React, {View, Text, StyleSheet, TouchableHighlight} from 'react-native'
import Button from 'react-native-button'
import {Actions} from 'react-native-router-flux'

class Launch extends React.Component {
    render(){
        return (
            <View style={styles.container}>
                <Text>Launch page</Text>
                <Button onPress={()=>Actions.login({data:"Custom data", title:'Custom title' })}>Go to Login page</Button>
                <Button onPress={Actions.register}>Go to Register page</Button>
                <Button onPress={Actions.register2}>Go to Register page without animation</Button>
                <Button onPress={Actions.error('error message')}>Show error popup</Button>
                <Button onPress={Actions.tabbar}>Go to TabBar page</Button>
            </View>
        );
    }
}

var styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: 'transparent',
    }
});

module.exports = Launch;

Modals

To display a modal use type="modal" for your route components. Modal type inserts its 'component' after navigator component. See the Examples folder for more details.

Note that ReactNativeRouterFlux will not provide animations for modals and you'll need to animate the modal yourself (or use a library)

Sidebar/Drawer support

You can easily configure react-native-router-flux to handle a sidebar/drawer for specific routes:
1. Create a sidebar/drawer component (you can use both react-native-drawer and react-native-side-menu) and pass its router props to its children:

<DrawerLayout>
   {React.Children.map(children, c => React.cloneElement(c, {route: this.props.route}))}
</DrawerLayout>

2. In you router component add the sidebar/drawer and nested routes following this pattern:

<Router>
  <Route name="without-drawer"/>
  <Route name="main">
   <Drawer>
      <Router>
        <Route name="with-drawer-a"/>
        <Route name="with-drawer-b"/>
      </Router>
    </Drawer>
  </Route>
</Router>

There is an example which is worked together with react-native-drawer.

Also here is another complete example of a working drawer using a common app with: - A session screen that just checks if the user is already logged-in on startup (SessionScreen) - An auth screen that handles signin/signup (AuthScreen) - Many other screens that show the true content of the app, all using the sidebar

SideDrawer.js (I'm using 'react-native-drawer')

import Drawer from 'react-native-drawer'

class SideDrawer extends React.Component {
  render() {
    return (
      <Drawer
        type="overlay"
        content={<SideDrawerContent />}
        tapToClose={true}
        openDrawerOffset={0.2} 
        panCloseMask={0.2}
        closedDrawerOffset={-3}
        styles={{ drawer: drawerStyle, main: mainStyle }}
        tweenHandler={(ratio) => ({ main: { opacity: (2 - ratio) / 2 } })}
      >
        {React.Children.map(this.props.children, c => React.cloneElement(c, {
          route: this.props.route
        }))}
      </Drawer>
    )
  }
}

Router.js ```javascript const hideNavBar = Platform.OS === 'android' const paddingTop = Platform.OS === 'android' ? 0 : 8

export default class Routes extends React.Component { render() { return (

    <Route schema='boot' component={SessionScreen} name='session' initial={true} />
    <Route schema='boot' component={AuthScreen} name='auth' />

    <Route name='main' hideNavBar={true} type='reset'>
      <SideDrawer>
        <Router
          sceneStyle={styles.scene}
          navigationBarStyle={styles.navigationBar}
          titleStyle={styles.title}
          barButtonIconStyle={styles.barButtonIcon}
          barButtonTextStyle={styles.barButtonText}
        >
          <Route schema='main' component={PlaceScreen} name='place' title='Places' />
          <Route schema='main' component={PaymentScreen} name='payment' title='Payment' header={Toolbar} />
        </Router>

Extension points exported contracts — how you extend this code

RouterProps (Interface)
(no doc)
index.d.ts
RouterStatic (Interface)
(no doc)
index.d.ts
SceneProps (Interface)
(no doc)
index.d.ts
TabSceneProps (Interface)
(no doc)
index.d.ts
SceneStatic (Interface)
(no doc)
index.d.ts

Core symbols most depended-on inside this repo

getValue
called by 20
src/Store.js
filterParam
called by 9
src/Store.js
createNavigationOptions
called by 7
src/Store.js
getActiveState
called by 6
src/State.js
assert
called by 3
src/Util.js
createReducer
called by 2
src/Reducer.js
getParent
called by 2
src/State.js
createTabBarOptions
called by 2
src/Store.js

Shape

Function 56
Class 54
Method 46
Interface 19

Languages

TypeScript87%
Java13%

Modules by API surface

src/Store.js23 symbols
index.d.ts19 symbols
src/State.js7 symbols
examples/react-native/components/Login3.js7 symbols
examples/react-native/android/app/src/main/java/com/example/MainApplication.java7 symbols
examples/redux/android/app/src/main/java/com/rnrfreduxsample/MainApplication.java6 symbols
examples/redux/src/page.js5 symbols
examples/redux/src/app.js5 symbols
examples/react-native/components/MessageBar.js5 symbols
examples/react-native/android/app/src/debug/java/com/example/ReactNativeFlipper.java5 symbols
examples/expo/navigation/AppNavigator.js5 symbols
examples/redux/src/home.js4 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

Dependencies from manifests, versioned

@babel/cli7.0.0-beta.47 · 1×
@babel/code-frame7.0.0-beta.47 · 1×
@babel/core7.6.0 · 1×
@babel/plugin-proposal-decorators7.0.0-beta.47 · 1×
@babel/plugin-proposal-optional-chaining7.0.0-beta.47 · 1×
@babel/runtime7.6.0 · 1×
@expo/samples2.1.1 · 1×
@react-native-community/masked-view0.1.10 · 1×
@types/react16.4.12 · 1×
@types/react-native0.56.14 · 1×
add2.0.6 · 1×

For agents

$ claude mcp add react-native-router-flux \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact