Code Monkey home page Code Monkey logo

victorkvarghese / react-native-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
600.0 22.0 209.0 1.01 MB

๐Ÿš€ Type Based Architecture for developing React Native Apps using react, redux, sagas and hooks with auth flow

License: MIT License

JavaScript 3.70% Java 18.39% Ruby 2.86% Objective-C 13.32% Starlark 1.78% TypeScript 59.96%
react react-native react-native-app react-navigation react-navigation-redux redux redux-saga redux-persist react-redux react-redux-boilerplate react-native-boilerplate

react-native-boilerplate's Introduction

๐Ÿš€ React Native Boilerplate - March 2022

React Native React Navigation V5

React Native Boilerplate is a starting point for React Native application. This project is configured with redux, redux saga and redux persist. Uses latest version of react-navigation (v6.0)

Redux Logo

Redux Logo

Redux Logo

UPDATE

If you want something simple, un opinionated and scalable with no boilerplate: React-Native-Query-Zusatnd-BoilerPlate

Scalability Factor

This Type based Architecture scales smoothly for small - medium apps. If you guys are building a very large application I would suggest using the following feature based architecture which will be more developer friendly with ease of scaling.

React-Native-Feature-BoilerPlate

Projects using this BoilerPlate

Features

How this looks

Prerequisites

Getting Started

  1. Clone this repo, git clone https://github.com/victorkvarghese/react-native-boilerplate.git <your project name>

  2. Go to project's root directory, cd <your project name>

  3. Remove .git folder, rm -rf .git

  4. Use React Native Rename to update project name $ npx react-native-rename <newName>

  5. Run yarn to install dependencies

  6. Start the packager with yarn start

  7. Connect a mobile device to your development machine

  8. Run the test application:

  • On Android:
    • Run react-native run-android or Use Android Studio (Recommended)
  • On iOS:
    • Open ios/YourReactProject.xcworkspace in Xcode
    • Hit Run after selecting the desired device
  1. Enjoy!!!

Contributing

PRs are welcome

react-native-boilerplate's People

Contributors

angelk90 avatar dependabot[bot] avatar shibilyts avatar victor-varghese avatar victorkvarghese avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-boilerplate's Issues

Missing Nav Types

Not really an issue I would say, just a couple types missing.

Adding these allows for typescript to recognize navigation and routes as well as avoid typescript not liking the options={homeOptions} object we're passing in.

Other than that I'd say this is the best boiler plate I've seen so far. Simple and to the point allowing a man to work quickly, great job!!

const AuthStack = createStackNavigator<AuthParamList>();
const AppStack = createStackNavigator<AppParamList>();

type AppParamList = {
  Home: undefined;
};

export type AppNavProps<T extends keyof AppParamList> = {
  navigation: StackNavigationProp<AppParamList, T>;
  route: RouteProp<AppParamList, T>;
};

type AuthParamList = {
  Login: undefined;
  ForgotPassword: undefined;
};

export type AuthNavProps<T extends keyof AuthParamList> = {
  navigation: StackNavigationProp<AuthParamList, T>;
  route: RouteProp<AuthParamList, T>;
};

interface HomeOptions {
  title: 'Home';
  headerTitleStyle: {
    fontWeight: 'bold';
  };
  headerRight: () => JSX.Element;
}

const homeOptions: HomeOptions = {
  title: 'Home',
  headerTitleStyle: {
    fontWeight: 'bold',
  },
  headerRight: () => <ThemeController />,
};

Unable to convert the JS version of this repo to redux tool kit

While trying to convert the JS version of this great project, I kept running into this problem

"t is not a function. (In 't(i,c)', 't' is an instance of Object)"

while trying to convert

createStore

to

configureStore

This is the

configureStore.js

import { configureStore } from '@reduxjs/toolkit'
import {  persistStore,  persistReducer,  FLUSH,  REHYDRATE,  PAUSE,  PERSIST,  PURGE,  REGISTER,} from 'redux-persist'
import AsyncStorage from '@react-native-community/async-storage';
import { createLogger } from 'redux-logger';
import createSagaMiddleware from 'redux-saga';

//import sagas from 'app/sagas';
import {
  loginReducer,
  paymentReducer,
  signupReducer
} from '../reducer';

const config = {
  key: 'root',
  storage: AsyncStorage,
  blacklist: ['loadingReducer'],
  debug: true, //to get useful logging
};

const middleware = [];
const sagaMiddleware = createSagaMiddleware();

middleware.push(sagaMiddleware);

if (__DEV__) {
  middleware.push(createLogger());
}
const reducers = persistReducer(config, {reducer:{
    loginReducer,
    signupReducer,
    paymentReducer
  }})

const store = configureStore({
  reducer: reducers,
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware({
      serializableCheck: {
        ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
      },
      thunk: false,
      ...middleware
    }),
})

let persistor = persistStore(store);
const myStore = () => {
  return { persistor, store };
};

export default myStore
//sagaMiddleware.run(sagas);

export const store = configureStore({
  reducer: {},
})

while this is

App.js

import React from 'react';
import { ActivityIndicator } from 'react-native';
import { Provider } from 'react-redux';
import storage from 'redux-persist/lib/storage'
import { PersistGate } from 'redux-persist/integration/react'
import { DefaultTheme, Provider as PaperProvider } from 'react-native-paper';
import 'react-native-gesture-handler';
import Navigator from './app/navigation';
import myStore from './app/store/configureStore';
import { enableScreens } from 'react-native-screens';
enableScreens();

const { persistor, store } = myStore();

const theme = {
  ...DefaultTheme,
  roundness: 2,
  colors: {
    ...DefaultTheme.colors,
    // primary: '#3498db',
    // accent: '#f1c40f',
  },
};

export default function Entrypoint() {
  return (
    <Provider store={store}>
      <PersistGate loading={null} persistor={persistor}>
        <PaperProvider theme={theme}>
          <Navigator />
        </PaperProvider>
      </PersistGate>
    </Provider>
  );
}

What am i doing wrong Sir?

Request to add helper components directory

Would be nice to have a helper components directory, with a sample sub directory including a component. Would containers go with that as well? Or a separate directory for helper component's containers?

I am proposing adding a components directory.

Borrowing from https://hackernoon.com/structuring-projects-and-naming-components-in-react-1261b6e18d76
it seems that it may be wise to put both containers and components under the components directory, while keeping screens directory separate. Screens will use helper components.

So, the structure would look something like this:

โ”œโ”€โ”€ Entrypoint.js
โ”œโ”€โ”€ actions
โ”œโ”€โ”€ api
โ”œโ”€โ”€ config
โ”œโ”€โ”€ components
ย  โ””โ”€โ”€ Form
ย      โ”œโ”€โ”€ FormView.js
ย      โ”œโ”€โ”€ FormContainer.js
ย      โ”œโ”€โ”€ index.js
ย      โ””โ”€โ”€ styles.js
โ”œโ”€โ”€ actions
โ”œโ”€โ”€ lib
โ”œโ”€โ”€ navigation
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ reducers
โ”œโ”€โ”€ sagas
โ”œโ”€โ”€ screens
โ”œโ”€โ”€ store
โ””โ”€โ”€ utils

Would like some feedback on this approach.

Future features

Hi @victorkvarghese ,

congratulations for the project, it would be possible to implement the following features:

  • i18n
  • Typescript
  • Axios
  • Check darkMode (the first time the app is started, it takes the value of the device if the device uses darkmode is set if it does not use it no, then this state is saved, if the user through the switch decides to change this value, then set the new value is not taken into consideration if the device is in dark mode or not)
  • Example login page using SafeAreaView
  • Manage the different endpoints for dev, staging, production
  • In the structure add a part relating to the Assets
  • Manage themes, for example if the device uses dark mode use the dark theme
  • Examples of screens using react native paper, I have seen that it is used in the rn-coffee project
  • Obfuscate code
  • react-native-animated-tabbar
  • react-native-app-tour
  • Use of Pinned ShortCuts

Can't integrate with Firebase

Hi,

I have an issue, when i trying to integrate firebase authentication.

Seems it has to update more Packages, While i upgrading one by one it not running

Have you upgrade to latest version ?

Add Example for call API and change state.

Hi, I'm new to redux-saga and I don't know how to change the state and call the API use Redux and Redux-saga.
Can you add some example in your project?
Thank you! ๐Ÿ˜„

Unable to resolve modules

trying to run the app from a fresh clone but i keep getting this error

error: Error: Unable to resolve module `app/navigation` from `app\Entrypoint.tsx`: app/navigation could not be found within the project.

error Failed to install the app.

when I try to run the app with react-native run-android the output is:

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

There is no android and ios folders

In this case though we can have them using react-native upgrade but the newly created android is not configured according to the react native navigation

Specify initial route.

Very nice structure - Thanks @victorkvarghese

After I ran the app, I wanted to check which screen is rendered first, that took me a minute to figure it out. Because in the NavigationStack.js I couldn't see which one is the initial route.

I understand now what you place as a first property to the config object that you pass to the createStackNavigator, becomes the first route that renders. However, passing another object with initialRouteName property makes it easier to read and understand.

I am new to RN, let me know if that does/n't matter.

How is Deep Linking done?

It works in the structure I installed with react-navigation but it doesn't work in your boilerplate. Can you share a document on this subject? I can run as myapp:// but I can't run as myapp://routename.

How to write test cases ?

Can you please provide one example for write testcases for login page? I have written below test case for login page but it not executes. Can you please help me on that ?

import React from 'react';
import Enzyme, { mount } from 'Enzyme';
import EnzymeAdapter from 'enzyme-adapter-react-16';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import reducer from '../app/reducers/loginReducer';
import Login from '../app/src/crust/containers/Login'

Enzyme.configure({ adapter: new EnzymeAdapter() });

describe(' test', () => {
const mockStore = createStore(reducer, {count: 0});
const getWrapper = () => mount(



);

it('should add to count and display the correct # of counts', () => {
const wrapper = getWrapper();
expect(wrapper.find('Text').text()).toEqual('Count: 0');
wrapper.find('Button').simulate('onPress');
expect(wrapper.find('Text').text()).toEqual('Count: 1');
});
});

Adding redux on navigation

Hi,
I am using the boilerplate for one of my project. It's good.
you can add redux navigation.
In the saga the navigation action is throwing error.
yield put(navigationActions.navigateToHomeScreen({}));
Can you show a working example?

Redux saga action is not defined.

Hi @victorkvarghese
Thanks for supporting this boilerplate.
I like this one and determined to start with this boilerplate for my project.
I have issue using redux-saga for api integration.
Just now enabled your commented login saga and test but have above issue.
Looking forward to your feedback asap.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.