### Running Example Apps Source: https://github.com/aksonov/react-native-router-flux/blob/master/README.md Clone the repository, navigate to an example directory, install dependencies, and start the application. ```Shell # Get the code git clone https://github.com/aksonov/react-native-router-flux.git cd react-native-router-flux/examples/[expo|react-native|redux] # Installing dependencies yarn # Run it yarn start ``` -------------------------------- ### Running the Example App with Bash Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/index.md These commands clone the React Native Router Flux repository, navigate to the example directory, install dependencies using yarn, and run the iOS app using react-native. ```bash # Get the code git clone git@github.com:aksonov/react-native-router-flux.git` cd react-native-router-flux/Example # Install dependencies yarn # Run it react-native run-ios ``` -------------------------------- ### Installing React Native Router Flux Source: https://github.com/aksonov/react-native-router-flux/blob/master/README.md Install react-native-router-flux using yarn. ```Shell yarn add react-native-router-flux ``` -------------------------------- ### Installing React Native Router Source: https://github.com/aksonov/react-native-router-flux/blob/master/README2.md Command to install the react-native-router-flux package using npm. This command adds the package to your project's dependencies. ```bash npm i react-native-router-flux --save ``` -------------------------------- ### scenesForTabBar.js Example Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/OTHER_INFO.md This example shows the content of a separate scene file (scenesForTabBar.js) that defines a tab bar with its associated scenes. This file is then required in the main scene definition to include the tab bar and its scenes. ```jsx import React from 'react-native'; import {Scene} from 'react-native-router-flux'; module.exports = // scenes here ; ``` -------------------------------- ### Installing React Native Dependencies Source: https://github.com/aksonov/react-native-router-flux/blob/master/README.md Install required dependencies for react-native-router-flux using npm or yarn. ```Shell npm install react-native-screens || yarn add react-native-screens ``` ```Shell npm install react-native-gesture-handler || yarn add react-native-gesture-handler ``` ```Shell npm install react-native-reanimated || yarn add react-native-reanimated ``` ```Shell npm install react-native-safe-area-context || yarn add react-native-react-native-safe-area-context ``` ```Shell npm install @react-native-community/masked-view || yarn add @react-native-community/masked-view ``` -------------------------------- ### Launch Component with Navigation Actions Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/DETAILED_EXAMPLE.md This component represents the initial screen and includes buttons that trigger navigation actions to different scenes. It demonstrates how to use Actions from react-native-router-flux to navigate between screens. ```jsx 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 ( Launch page ); } } var styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'transparent', } }); module.exports = Launch; ``` -------------------------------- ### Splitting Scenes Using NodeJS require Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/OTHER_INFO.md This example demonstrates how to split scenes into separate files using NodeJS's require function. This allows for better organization and modularity of the scene definitions, especially in large applications. The required scene files are then included within the Router component. ```jsx {require("./scenesForTabBar")} {require("./scenesForAnotherPart")} ``` -------------------------------- ### Calling the Modal with Props Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/OTHER_INFO.md This example shows how to call the StatusModal with specific props, including an error message and a 'hide' prop to control its initial visibility. The Actions.statusModal function is used to trigger the modal with the provided parameters. ```javascript Actions.statusModal({error: "Network failed...", hide: false}) ``` -------------------------------- ### Drawer Custom Renderer with react-native-drawer Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/OTHER_INFO.md This example demonstrates a custom drawer renderer using react-native-drawer. It includes handling open and close events and applying a tweenHandler for visual effects. The component uses Actions.refresh to update the drawer state and includes a SideMenu component as the drawer content. ```jsx import React from 'react-native'; import Drawer from 'react-native-drawer'; import SideMenu from './SideMenu'; import {Actions, DefaultRenderer} from 'react-native-router-flux'; export default class NavigationDrawer extends Component { render(){ const state = this.props.navigationState; const children = state.children; return ( Actions.refresh({key:state.key, open: true})} onClose={()=>Actions.refresh({key:state.key, open: false})} type="displace" content={} tapToClose={true} openDrawerOffset={0.2} panCloseMask={0.2} negotiatePan={true} tweenHandler={(ratio) => ({ main: { opacity:Math.max(0.54,1-ratio) } })}> ); } } ``` -------------------------------- ### Router Configuration with Scenes Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/DETAILED_EXAMPLE.md This code configures the router with different scenes, including modals, tabs, and regular scenes. It demonstrates how to define navigation properties such as titles, components, and transition types. ```jsx 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 { Scene, Router, TabBar, Modal, Schema, Actions, Reducer, ActionConst } 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 ( {this.props.title} ); } } const reducerCreate = params=>{ const defaultReducer = Reducer(params); return (state, action)=>{ console.log("ACTION:", action); return defaultReducer(state, action); } }; export default class Example extends React.Component { render() { return alert("Right button")} rightTitle="Right" /> alert("Left button!")} leftTitle="Left"/> ; ``` -------------------------------- ### Modal Implementation with React Native Router Flux Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/OTHER_INFO.md This example demonstrates how to implement a modal using React Native Router Flux. It defines a root scene with a modal component that renders other scenes as popups. The StatusModal component is defined to display a message and can be dismissed by pressing it. ```jsx import StatusModal from './components/StatusModal' ``` -------------------------------- ### Navigating Between Scenes Source: https://github.com/aksonov/react-native-router-flux/blob/master/README.md Navigate between scenes using the Actions object. This example shows how to navigate to a specific scene, go back, and refresh the current scene with new props. ```JSX // Login.js // navigate to 'home' as defined in your top-level router Actions.home(PARAMS); // go back (i.e. pop the current screen off the nav stack) Actions.pop(); // refresh the current Scene with the specified props Actions.refresh({ param1: 'hello', param2: 'world' }); ``` -------------------------------- ### Defining Routes with React Native Router Flux Source: https://github.com/aksonov/react-native-router-flux/blob/master/README.md Define routes using the Router, Stack, and Scene components. This example defines a simple routing configuration with login, register, and home scenes. ```JSX const App = () => ( ); ``` -------------------------------- ### Customizing TabBar Style Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/OTHER_INFO.md This example demonstrates how to customize the style of the TabBar in React Native Router Flux. It creates a StyleSheet with custom styles for the tab bar, including border color, background color, and opacity. The tabBarStyle prop is then used to apply these styles to the TabBar. ```javascript let style = StyleSheet.create({ tabBarStyle: { borderTopWidth : .5, borderColor : '#b7b7b7', backgroundColor: 'white', opacity : 1 } }); // in your render method ``` -------------------------------- ### Switch Component with Redux Integration Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/OTHER_INFO.md This example demonstrates how to use the Switch component with Redux to conditionally render different scenes based on the application state. The Switch component selects the scene to display based on the selector prop, which uses the profile.sessionID from the Redux store to determine whether to show the 'main' or 'signUp' scene. ```jsx ({profile:state.profile}))(Switch)} tabs={true} unmountScenes selector={props=>props.profile.sessionID ? "main" : "signUp"} > ``` -------------------------------- ### Wrapping Tabs Scene with Drawer Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/OTHER_INFO.md This example shows how to wrap a tabs scene with a Drawer component in react-native-router-flux. The NavigationDrawer component is used as the drawer's component, and the 'open' prop controls the drawer's initial state. ```jsx render() { return ( .... ); } ``` -------------------------------- ### Toggling Drawer Using Refresh Modifier Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/OTHER_INFO.md This example demonstrates how to toggle the drawer's visibility using the 'refresh' modifier in react-native-router-flux. The Actions.refresh method is used to update the 'open' state of the drawer, allowing it to be opened, hidden, or toggled programmatically. ```jsx Actions.refresh({key: 'drawer', open: value => !value }); ``` -------------------------------- ### Defining Sub-scene Actions Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/OTHER_INFO.md This example illustrates how to create sub-scene actions by nesting Scene components without a 'component' prop under a base scene. This allows for updating the base scene's state and properties based on the called sub-scene action, such as enabling edit mode or saving data. ```jsx Actions.saveAccount()} leftTitle="Cancel" onLeft={()=>Actions.viewAccount()} /> ``` -------------------------------- ### Inter Routing Example Source: https://github.com/aksonov/react-native-router-flux/blob/master/README2.md This snippet demonstrates how to navigate from one nested route to another in React Native Router Flux. It shows a router configuration with two main routes (route1 and route2) and several sub-routes. To navigate from SubRoute3Screen to SubRoute7Screen, you need to call NavigationActions for each parent route. ```JavaScript import { Actions as NavigationActions } from 'react-native-router-flux' . . . . ``` -------------------------------- ### Navigating Between Scenes with React Native Router Flux in JavaScript Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/index.md This code snippet shows how to navigate between scenes using the Actions API provided by React Native Router Flux. It includes examples of navigating to a specific scene, going back, and refreshing the current scene with new props. ```javascript // login.js // navigate to 'home' as defined in your top-level router Actions.home(PARAMS) // go back (i.e. pop the current screen off the nav stack) Actions.pop() // refresh the current Scene with the specified props Actions.refresh({param1: 'hello', param2: 'world'}) ``` -------------------------------- ### Refreshing a Scene on Tab Press Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/OTHER_INFO.md This example shows how to refresh a specific scene when a tab is pressed in React Native Router Flux. The onPress prop of the Scene is used to trigger an action that refreshes the target scene using ActionConst.REFRESH. This allows updating the scene's content when the tab is selected. ```javascript { Actions.myTab_1({type: ActionConst.REFRESH}); }} > ``` -------------------------------- ### Combining Reducers with Redux in React Native Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/REDUX_FLUX.md This example demonstrates how to combine the routing reducer with other reducers in a Redux application using `combineReducers` from Redux. It imports the routing reducer and combines it with any other reducers to create the root reducer for the application. ```JavaScript // reducers/index.js import { combineReducers } from 'redux'; import routes from './routes'; // ... other reducers export default combineReducers({ routes, // ... other reducers }); ``` -------------------------------- ### Using Lightbox Component with Scenes in React Native Router Flux Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/API.md This example demonstrates how to use the Lightbox component to render scenes on top of the current scene, allowing for transparency. The root scene is nested within the Lightbox, and the loginLightbox scene will render as a Lightbox when pushed. ```jsx {/* Lightbox components will lay over the screen, allowing transparency*/} ``` -------------------------------- ### Implementing Modals with Router and Scenes in JSX Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/API.md This code demonstrates how to implement modals using the Router and Scene components in React Native Router Flux. The Modal component is used as the root scene, rendering the first scene normally and subsequent scenes as modals. The example shows a root scene with two screens and three modal scenes. ```JSX ``` -------------------------------- ### StatusModal Component Definition Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/OTHER_INFO.md This code defines the StatusModal component, which displays a modal with a message. It uses the 'hide' prop to control the visibility of the modal and includes a dismissModal function to hide the modal when pressed. The component receives props for the error message and initial visibility. ```jsx class StatusModal extends Component { constructor(props) { super(props) // set state with passed in props this.state = { message: props.error, hide: props.hide, } // bind functions this.dismissModal = this.dismissModal.bind(this) } dismissModal() { this.setState({hide: true}) } // show or hide Modal based on 'hide' prop render() { if(this.state.hide){ return ( ) } else { return ( {this.state.message} ) } } } ``` -------------------------------- ### Accessing Routes via Context in React Native Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/REDUX_FLUX.md This example demonstrates how to access the routes object from any component using the React context. It defines the `contextTypes` property to specify that the component requires the `routes` object from the context. The component can then access the routes object via `this.context.routes` and use it to navigate to different scenes. ```JSX // components/MyComponent.js import React, { PropTypes } from 'react'; import { Text, View } from 'react-native'; import Button from 'react-native-button' class MyComponent extends React.Component { static contextTypes = { routes: PropTypes.object.isRequired, }; render () { const {routes} = this.context; return ( ); } } export default MyComponent; ``` -------------------------------- ### Accessing Component Ref via Actions in React Native Router Flux Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/API.md This example shows how to safely access a component's ref through Actions.ref within the onEnter event of a Scene. It checks if the ref is defined before accessing its properties to avoid errors during component mounting. ```javascript onEnter={() => { if(Actions.refs.your_component_ref !== undefined) { //now you can access it's properties without trouble Actios.refs.your_component_ref.selector.props.someCoolFunction(); } }} ``` -------------------------------- ### Accessing Current Scene from Connected Component in React Native Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/REDUX_FLUX.md This example demonstrates how to access the current scene information from a connected component using `react-redux`. It connects the component to the Redux store and maps the `routes` state to the component's props. The component then accesses the `scene` property from the `routes` prop to display the current scene's title. ```JSX // components/MyComponent.js import React, { Component, PropTypes } from 'react'; import { Text } from 'react-native'; import { connect } from 'react-redux'; class MyComponent extends Component { static propTypes = { routes: PropTypes.object, }; render () { return ( The current scene is titled {this.props.routes.scene.title}. ); } } export default connect(({routes}) => ({routes}))(MyComponent); ``` -------------------------------- ### Programmatically navigating back Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/MINI_TUTORIAL.md This code shows how to programmatically navigate back to the previous scene. ```javascript Actions.pop() ``` -------------------------------- ### Initializing Router and Scenes in index.js Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/MINI_TUTORIAL.md This code initializes the Router and defines the scenes for navigation. It imports necessary components from react-native-router-flux and defines two scenes, PageOne and PageTwo, within a root scene. PageOne is set as the initial scene. ```jsx import React, { Component } from 'react'; import { Router, Scene } from 'react-native-router-flux'; import PageOne from './PageOne'; import PageTwo from './PageTwo'; export default class App extends Component { render() { return ( ) } } ``` -------------------------------- ### Navigating to PageTwo from PageOne Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/MINI_TUTORIAL.md This code defines the PageOne component and sets up navigation to PageTwo using Actions.pageTwo. When the Text component is pressed, it triggers the navigation action. ```jsx import React, { Component } from 'react'; import { View, Text } from 'react-native'; import { Actions } from 'react-native-router-flux'; export default class PageOne extends Component { render() { return ( This is PageOne! ) } } ``` -------------------------------- ### Initializing Scenes with Router Component in React Native Source: https://github.com/aksonov/react-native-router-flux/blob/master/README3.md This code snippet demonstrates how to define scenes using the Scene component and pass them into the Router as children in a React Native application. It imports the Scene and Router components from the react-native-router-flux library and defines three scenes: login, register, and home. The login and register scenes have titles, while the home scene does not. ```javascript import {Scene, Router} from 'react-native-router-flux'; class App extends React.Component { render() { return } } ``` -------------------------------- ### Refreshing the current scene with new props Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/MINI_TUTORIAL.md This code shows how to refresh the current scene with new props. ```javascript Actions.refresh(PARAMS) ``` -------------------------------- ### Receiving Data in PageTwo Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/MINI_TUTORIAL.md This code shows how to receive and display data passed from PageOne in the PageTwo component. The data is accessed via this.props.text. ```jsx render() { return ( This is PageTwo! {this.props.text} ) } ``` -------------------------------- ### Configuring Drawer Routes in Router - JavaScript Source: https://github.com/aksonov/react-native-router-flux/blob/master/README2.md This snippet shows how to configure routes with a drawer using react-native-router-flux. It defines routes both inside and outside the drawer, demonstrating how to nest routers within the drawer component. ```javascript ``` -------------------------------- ### Action Constants Shorthand Usage Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/API_CONFIGURATION.md Demonstrates the shorthand string literal usage for defining scene types or action parameters in React Native Router Flux. It highlights the conversion to constant values when passed to the reducer and recommends using constants for consistency. ```JavaScript Actions.ROUTE_NAME({type: 'reset'}); ``` -------------------------------- ### Router Configuration with SideDrawer - JavaScript Source: https://github.com/aksonov/react-native-router-flux/blob/master/README2.md This snippet demonstrates a complete router configuration using react-native-router-flux and a SideDrawer component. It defines schemas for different scene configurations, routes for session and authentication screens, and nested routes within the SideDrawer for the main application content. ```javascript const hideNavBar = Platform.OS === 'android' const paddingTop = Platform.OS === 'android' ? 0 : 8 export default class Routes extends React.Component { render() { return ( ) } } ``` -------------------------------- ### Defining Scenes During Compile Time in React Native Source: https://github.com/aksonov/react-native-router-flux/blob/master/README3.md This code snippet shows how to define scenes during compile time using the Actions.create method and then pass them to the Router component. It imports Actions, Scene, and Router from react-native-router-flux. This approach allows for more dynamic scene creation and management. ```javascript import {Actions, Scene, Router} from 'react-native-router-flux'; const scenes = Actions.create( ); /* ... */ class App extends React.Component { render() { return } } ``` -------------------------------- ### Importing Actions from React Native Router Flux Source: https://github.com/aksonov/react-native-router-flux/blob/master/README3.md This code snippet demonstrates how to import the Actions object from the react-native-router-flux library. This object provides methods for navigating between scenes, refreshing the current scene, and popping the current screen from the navigation stack. ```javascript import {Actions} from 'react-native-router-flux' ``` -------------------------------- ### SideDrawer Component using react-native-drawer - JavaScript Source: https://github.com/aksonov/react-native-router-flux/blob/master/README2.md This snippet defines a SideDrawer component using the react-native-drawer library. It configures the drawer's appearance and behavior, including overlay type, tap-to-close, offset, and tween handler for opacity animation. It also clones the children to pass the route prop. ```javascript import Drawer from 'react-native-drawer' class SideDrawer extends React.Component { render() { return ( } 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 }))} ) } } ``` -------------------------------- ### Configuring Deep Linking with React Native Router Flux Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/API.md This code snippet demonstrates how to configure deep linking in React Native Router Flux using the uriPrefix and path properties. It defines a Router with a uriPrefix and several Scene components with associated paths. When a user clicks on a link matching one of the defined paths, the corresponding scene will be opened with the extracted parameters. ```JavaScript ``` -------------------------------- ### Action Constants Recommended Usage Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/API_CONFIGURATION.md Illustrates the recommended approach of using constants instead of string literals for defining scene types or action parameters in React Native Router Flux to ensure consistency. ```JavaScript Actions.ROUTE_NAME({type: ActionConst.RESET}); ``` -------------------------------- ### Passing Data from PageOne to PageTwo Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/MINI_TUTORIAL.md This code demonstrates how to pass data from PageOne to PageTwo during navigation. The Actions.pageTwo function is called with a parameter object containing the data to be passed. ```jsx render() { const goToPageTwo = () => Actions.pageTwo({text: 'Hello World!'}); return ( This is PageOne! ) } ``` -------------------------------- ### Defining Routes with React Native Router Flux in JavaScript Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/index.md This code snippet demonstrates how to define routes using React Native Router Flux. It defines a root scene containing login, register, and home scenes, each associated with a React component. ```javascript class App extends React.Component { render() { return ( ); } } ``` -------------------------------- ### JSX Scene with onBack and back props Source: https://github.com/aksonov/react-native-router-flux/blob/master/README.md This code shows the correct way to implement the onBack prop in a Scene component. The back prop must be set to true for the onBack function to be triggered when the back button is pressed. ```JSX {/*code*/}} back={true}/> ``` -------------------------------- ### Wrapping Children with Router Props in DrawerLayout - JavaScript Source: https://github.com/aksonov/react-native-router-flux/blob/master/README2.md This snippet demonstrates how to wrap the children of a DrawerLayout component with router props using React.cloneElement. This allows the child components to access the route information. ```javascript {React.Children.map(children, c => React.cloneElement(c, {route: this.props.route}))} ``` -------------------------------- ### Connecting a Route to Redux in React Native Router Flux Source: https://github.com/aksonov/react-native-router-flux/blob/master/README2.md This snippet demonstrates how to connect a Route component to Redux using the connect function. It connects the RegisterScreen component to Redux, passing the selectFnForRegister function to map state to props. ```JavaScript ``` -------------------------------- ### Overlay Support Implementation Source: https://github.com/aksonov/react-native-router-flux/blob/master/CHANGELOG.md This snippet relates to the implementation of overlay support in React Native Router Flux. It likely involves adding a new component or modifying existing ones to handle overlay rendering on top of the current scene. ```JavaScript N/A ``` -------------------------------- ### Nested Routers with Modal Screens Source: https://github.com/aksonov/react-native-router-flux/blob/master/README2.md This snippet demonstrates how to define a modal screen within nested routers. The modal screen is defined in the root router with the wrapRouter={true} property to ensure it covers the tab bar when presented. ```JavaScript ``` -------------------------------- ### Updating Component on Focus in React Native Source: https://github.com/aksonov/react-native-router-flux/blob/master/README2.md This snippet shows how to update a component when it gains focus by comparing the current and previous routes in the componentDidUpdate lifecycle method. It checks if the current route is 'payment' and the previous route was different, then triggers an action. ```JavaScript componentDidUpdate(prevProps) { const prevRoute = prevProps.global.currentRoute const currentRoute = this.props.global.currentRoute if (currentRoute === 'payment' && prevRoute !== currentRoute) { this.props.actions.doSomething() } } ``` -------------------------------- ### Adding POP_AND_REPLACE Action Constant in React Native Router Flux Source: https://github.com/aksonov/react-native-router-flux/blob/master/HISTORY.md This commit introduces a new action constant, POP_AND_REPLACE, to the React Native Router Flux library. This action allows for popping the current screen and replacing it with a new one, providing a specific navigation behavior. -------------------------------- ### Connecting React Native Router Flux with Redux Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/REDUX_FLUX.md This code snippet shows how to connect React Native Router Flux with Redux using the `connect` function from `react-redux`. It wraps the `Router` component with `connect()` to enable dispatching actions to the Redux store. It also includes the Redux `Provider` to make the store available to the Router and its children. ```JSX // app.js import React, { Component } from 'react'; import { Router } from 'react-native-router-flux'; import { connect, Provider } from 'react-redux'; import { createStore, applyMiddleware, compose } from 'redux'; const RouterWithRedux = connect()(Router); import reducers from './reducers'; // other imports... // create store... const middleware = [/* ...your middleware (i.e. thunk) */]; const store = compose( applyMiddleware(...middleware) )(createStore)(reducers); class App extends Component { render () { return ( // your scenes here ); } } export default App; ``` -------------------------------- ### Custom Tab Bar Component Implementation - JSX Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/API.md Illustrates the implementation of a custom tab bar component in React Native. It maps over the routes in the navigation state and creates a TouchableOpacity for each route, allowing navigation to the corresponding scene when pressed. It relies on Actions from react-native-router-flux for navigation. ```JSX import React from 'react'; import { Text, View, TouchableOpacity } from 'react-native'; import { Actions } from 'react-native-router-flux'; export default class CustomTabBar extends React.Component { render() { const { state } = this.props.navigation; const activeTabIndex = state.index; return ( { state.routes.map(element => ( Actions[element.key]()}> {element.key.toUpperCase()} )) } ); } } ``` -------------------------------- ### JSX Scene with onBack prop Source: https://github.com/aksonov/react-native-router-flux/blob/master/README.md This code demonstrates an incorrect way to implement the onBack prop in a Scene component. The onBack function will not be triggered unless the back prop is set to true. ```JSX {/*code*/}}/> ``` -------------------------------- ### Creating a Reducer for Routing Actions in React Native Router Flux Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/REDUX_FLUX.md This reducer handles the `FOCUS` action dispatched by React Native Router Flux when a new scene comes into focus. It updates the `scene` property in the state with the new scene object. The reducer also includes a default case to return the current state for unhandled actions. ```JavaScript // reducers/routes.js import { ActionConst } from 'react-native-router-flux'; const initialState = { scene: {}, }; export default function reducer(state = initialState, action = {}) { switch (action.type) { // focus action is dispatched when a new screen comes into focus case ActionConst.FOCUS: return { ...state, scene: action.scene, }; // ...other actions default: return state; } } ``` -------------------------------- ### Updating types per documentation Source: https://github.com/aksonov/react-native-router-flux/blob/master/CHANGELOG.md This pull request updates the TypeScript definitions to align with the documentation for React Native Router Flux. This ensures that the TypeScript types accurately reflect the available properties and their expected types, improving type safety and developer experience. ```TypeScript interface SceneProps { key?: string; // for Actions.unique(key) sceneKey?: string; component?: React.ComponentType; rightTitle?: string; leftTitle?: string; onRight?: () => void; onLeft?: () => void; title?: string; titleStyle?: StyleProp; navigationBarStyle?: StyleProp; navBarButtonColor?: string; passProps?: boolean; panHandlers?: any; //... other props } ``` -------------------------------- ### Catching Route Actions in Reducer Source: https://github.com/aksonov/react-native-router-flux/blob/master/README2.md This snippet demonstrates how to catch route actions such as AFTER_ROUTE and AFTER_POP in a Redux reducer. The reducer updates the currentRoute state based on the action's name, allowing components to react to route changes. ```JavaScript case Actions.AFTER_ROUTE: case Actions.AFTER_POP: return state.set('currentRoute', action.name) ``` -------------------------------- ### Adding POP_AND_REPLACE Action Constant in React Native Router Flux Source: https://github.com/aksonov/react-native-router-flux/blob/master/CHANGELOG.md This snippet introduces a new action constant, POP_AND_REPLACE, to the React Native Router Flux library. This action likely allows for replacing the current screen on the navigation stack, offering an alternative to standard push or pop operations. The constant would be used within the routing logic to trigger this specific navigation behavior. ```javascript const POP_AND_REPLACE ``` -------------------------------- ### Connecting Router to Redux in React Native Router Flux Source: https://github.com/aksonov/react-native-router-flux/blob/master/README2.md This snippet shows how to connect the Router component from react-native-router-flux to Redux. By connecting the Router, Redux will be informed of navigation status changes, triggering actions like BEFORE_ROUTE, AFTER_ROUTE, etc. ```JavaScript import ReactNativeRouter, { Actions, Router } from 'react-native-router-flux' const Router = connect()(ReactNativeRouter.Router) ``` -------------------------------- ### Using Custom Tab Bar Component with Tabs - JSX Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/API.md Demonstrates how to integrate a custom tab bar component with the Tabs component in React Native Router Flux. It imports the custom component and assigns it to the tabBarComponent prop within the Tabs component. The Tabs component then renders scenes associated with TabOne and TabTwo. ```JSX ``` -------------------------------- ### Router Configuration with Redux in React Native Router Flux Source: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/REDUX_FLUX.md This code demonstrates how to configure a Router component with Redux in react-native-router-flux to prevent re-renders. It includes connecting child components to Redux, pre-creating scenes using Actions.create(), and conditionally connecting the Router to Redux for dispatching actions. ```jsx import { Router, Scene, Actions, } from 'react-native-router-flux'; // --- child component can connect and listen to props they want. const myConnectedMainConponent = connect()(myMainConponent); const myConnectedLoginConponent = connect()(myLoginConponent); // --- Create it via Actions.create(), or it will be re-created for each render of your Router const scenes = Actions.create( ); // --- Create connected Router if you want dispatch() method. // --- Or you can just use vanilla Router const myConnectedRouter = connect()(Router); // --- your exported main router export default class MyExportedRouter extends React.Component { constructor(props) { super(props); }; render() { return ( ); } } ``` -------------------------------- ### Adding open prop to TS declaration Source: https://github.com/aksonov/react-native-router-flux/blob/master/CHANGELOG.md This pull request adds the `open` prop to the TypeScript declaration file for the react-native-router-flux library. This allows developers using TypeScript to properly type-check and utilize the `open` prop within their components. ```TypeScript ``` -------------------------------- ### Adding titleStyle to TypeScript definitions Source: https://github.com/aksonov/react-native-router-flux/blob/master/CHANGELOG.md This pull request adds the `titleStyle` property to the TypeScript definitions for React Native Router Flux, allowing for custom styling of the title in the navigation bar. This enhances the flexibility of styling the navigation bar title. ```TypeScript interface SceneProps { key?: string; // for Actions.unique(key) sceneKey?: string; component?: React.ComponentType; rightTitle?: string; leftTitle?: string; onRight?: () => void; onLeft?: () => void; title?: string; titleStyle?: StyleProp; navigationBarStyle?: StyleProp; navBarButtonColor?: string; passProps?: boolean; panHandlers?: any; //... other props } ``` -------------------------------- ### React Component componentDidMount with Actions.refresh Source: https://github.com/aksonov/react-native-router-flux/blob/master/README.md This code snippet demonstrates how to use Actions.refresh within the componentDidMount lifecycle method to update the onBack prop of a Scene. This allows you to execute custom logic when the back button is pressed, such as changing the component's state. ```JSX componentDidMount(){ InteractionManager.runAfterInteractions(()=> { Actions.refresh({onBack:()=>this.changeSomethingInYourComponent()}) }) } ``` -------------------------------- ### Preventing React Warning with Stateless Components Source: https://github.com/aksonov/react-native-router-flux/blob/master/CHANGELOG.md This snippet addresses a React warning related to refs and stateless functional components within React Native Router Flux. It likely involves modifying the component structure to properly handle refs or using a different type of component. ```JavaScript N/A ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.