Skip to content

Commit

Permalink
Merge pull request #34 from simpleweb/remove-rnrf
Browse files Browse the repository at this point in the history
Removes the RNRF code
  • Loading branch information
benjaminreid authored Mar 14, 2018
2 parents 499bf7a + bba7b63 commit a0462bb
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 279 deletions.
101 changes: 30 additions & 71 deletions generators/base/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,9 @@ module.exports = class extends Generator {
message: 'Create a local git repo?',
default: true,
},
{
type: 'list',
name: 'router',
message: 'Which router would you like to use?',
default: 'react-native-router-flux@3.41.0',
choices: ['react-native-router-flux@3.41.0', 'react-navigation'],
},
]).then((answers) => {
this.nodeVersion = answers.nodeVersion;
this.createGit = answers.createGit;
this.router = answers.router;
this.flowVerison = answers.flowVerison;
});
}
Expand All @@ -55,42 +47,25 @@ module.exports = class extends Generator {
this.fs.delete('App.js');

// copy root app file that the entry points use
if (this.router === 'react-navigation') {
this.fs.copyTpl(
this.templatePath('App/App.react-navigation.js'),
this.destinationPath(`App/${this.name}.js`),
{ name: this.name }
);
} else {
this.fs.copyTpl(
this.templatePath('App/App.js'),
this.destinationPath(`App/${this.name}.js`),
{ name: this.name }
);
}
this.fs.copyTpl(
this.templatePath('App/App.js'),
this.destinationPath(`App/${this.name}.js`),
{ name: this.name }
);

// copy router
if (this.router === 'react-navigation') {
this.fs.copyTpl(
this.templatePath('App/Router.react-navigation.js'),
this.destinationPath('App/Router.js'),
{ name: this.name }
);
} else {
this.fs.copyTpl(
this.templatePath('App/Router.js'),
this.destinationPath('App/Router.js'),
{ name: this.name }
);
}
this.fs.copyTpl(
this.templatePath('App/Router.js'),
this.destinationPath('App/Router.js'),
{ name: this.name }
);

// copy scenes
this.fs.copyTpl(
this.templatePath('App/Scenes'),
this.destinationPath('App/Scenes'),
{
name: this.name,
router: this.router,
}
);

Expand All @@ -114,38 +89,24 @@ module.exports = class extends Generator {
this.destinationPath('App/Store/Middleware/Buffer.js'),
{ name: this.name }
);
if (this.router === 'react-navigation') {
this.fs.copyTpl(
this.templatePath('App/Store/Middleware/index.react-navigation.js'),
this.destinationPath('App/Store/Middleware/index.js'),
{ name: this.name }
);
} else {
this.fs.copyTpl(
this.templatePath('App/Store/Middleware/index.js'),
this.destinationPath('App/Store/Middleware/index.js'),
{ name: this.name }
);
}

this.fs.copyTpl(
this.templatePath('App/Store/Middleware/index.js'),
this.destinationPath('App/Store/Middleware/index.js'),
{ name: this.name }
);

this.fs.copyTpl(
this.templatePath('App/Store/Middleware/Saga.js'),
this.destinationPath('App/Store/Middleware/Saga.js'),
{ name: this.name }
);
if (this.router === 'react-navigation') {
this.fs.copyTpl(
this.templatePath('App/Store/Middleware/Logger.react-navigation.js'),
this.destinationPath('App/Store/Middleware/Logger.js'),
{ name: this.name }
);
} else {
this.fs.copyTpl(
this.templatePath('App/Store/Middleware/Logger.js'),
this.destinationPath('App/Store/Middleware/Logger.js'),
{ name: this.name }
);
}

this.fs.copyTpl(
this.templatePath('App/Store/Middleware/Logger.js'),
this.destinationPath('App/Store/Middleware/Logger.js'),
{ name: this.name }
);

// copy reducers
this.fs.copyTpl(
Expand All @@ -159,17 +120,15 @@ module.exports = class extends Generator {
this.destinationPath('App/Reducers/index.js'),
{
name: this.name,
reducers: (this.router === 'react-navigation') ? ['App', 'Nav'] : ['App'],
reducers: ['App', 'Nav'],
}
);

if (this.router === 'react-navigation') {
this.fs.copyTpl(
this.templatePath('App/Reducers/Nav.js'),
this.destinationPath('App/Reducers/Nav.js'),
{ name: this.name }
);
}
this.fs.copyTpl(
this.templatePath('App/Reducers/Nav.js'),
this.destinationPath('App/Reducers/Nav.js'),
{ name: this.name }
);

// copy actions
this.fs.copyTpl(
Expand Down Expand Up @@ -280,8 +239,8 @@ module.exports = class extends Generator {
this.yarnInstall([
'axios',
'react-native-dotenv',
this.router,
...(this.router === 'react-navigation' ? ['react-navigation-redux-helpers'] : []),
'react-navigation',
'react-navigation-redux-helpers',
'react-redux',
'redux',
'redux-action-buffer',
Expand Down
7 changes: 3 additions & 4 deletions generators/base/templates/App/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// @flow
import * as React from 'react';
import { Actions } from 'react-native-router-flux';
import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/src/integration/react';
import Router, { Routes, RouterWithRedux } from '<%= name %>/App/Router';
import { PersistGate } from 'redux-persist/lib/integration/react'
import Router, { RouterWithRedux } from '<%= name %>/App/Router';
import { configureStore } from '<%= name %>/App/Store';
import { runSagaMiddleware } from '<%= name %>/App/Store/Middleware/Saga';
import App from '<%= name %>/App/Components/App';
Expand Down Expand Up @@ -34,7 +33,7 @@ export default class <%= name %> extends React.Component<{}> {
onBeforeLift={this._onBeforeLift}
persistor={persistor}
>
<RouterWithRedux scenes={Routes}/>
<RouterWithRedux />
</PersistGate>
</Provider>
</App>
Expand Down
42 changes: 0 additions & 42 deletions generators/base/templates/App/App.react-navigation.js

This file was deleted.

64 changes: 49 additions & 15 deletions generators/base/templates/App/Router.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,50 @@
// @flow
import React from 'react';
import { Linking } from 'react-native';
import { Scene, Actions, Router, ActionConst } from 'react-native-router-flux';
import { connect } from 'react-redux';
import type { Store as ReduxStore } from 'redux';
import {
StackNavigator,
NavigationActions,
addNavigationHelpers
} from 'react-navigation';
import {
createReactNavigationReduxMiddleware,
createReduxBoundAddListener
} from 'react-navigation-redux-helpers';
import Scenes from '<%= name %>/App/Scenes';

const Routes = Actions.create(
<Scene key="modal">
<Scene key="root">
<Scene key="launch" component={Scenes.Launch}/>
<Scene key="main">
<Scene key="main_index" component={Scenes.Main}/>
</Scene>
<Scene key="styleguide" component={Scenes.Styleguide}/>
</Scene>
</Scene>
const key = "root";

// Note: createReactNavigationReduxMiddleware must be run before createReduxBoundAddListener
export const RouterMiddleware = createReactNavigationReduxMiddleware(
key,
state => state.nav,
);

const RouterWithRedux = connect()(Router);
const addListener = createReduxBoundAddListener(key);

const RootNavigator = StackNavigator({
Launch: {
screen: Scenes.Launch,
navigationOptions: {
header: null
}
},
Main: {
screen: Scenes.Main,
},
Styleguide: {
screen: Scenes.Styleguide,
},
});

const Router = ({ dispatch, nav: state }) => {
const navigation = addNavigationHelpers({ dispatch, state, addListener });
return <RootNavigator navigation={ navigation }/>
};

const RouterWithRedux = connect(({ nav }) => ({ nav }))(Router);

const handleURL = ({ url }: { url: string }) => {
console.log('handleURL', url)
Expand All @@ -43,10 +70,17 @@ const getInitialURL = async () => {
});
};

const root = async () => {
const root = async (store: ReduxStore) => {
const url : string|null = await getInitialURL();

Actions.main({ type: ActionConst.RESET });
store.dispatch(
NavigationActions.reset({
index: 0,
actions: [
NavigationActions.navigate({ routeName: 'Main' }),
],
})
);

if (url) {
handleURL({ url });
Expand All @@ -58,4 +92,4 @@ export default {
removeDeepLinkListener,
root,
};
export { Routes, RouterWithRedux };
export { RootNavigator, RouterWithRedux };
Loading

0 comments on commit a0462bb

Please sign in to comment.