Skip to content

Commit ce3e78f

Browse files
committed
Add thunk sample, push example, cleanup
1 parent 98a9750 commit ce3e78f

File tree

23 files changed

+290
-110
lines changed

23 files changed

+290
-110
lines changed

README.md

Lines changed: 64 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,66 @@
22

33
![Travis](https://api.travis-ci.com/AmitM30/react-native-typescript-boilerplate.svg?branch=master) [![Code Climate](https://codeclimate.com/github/AmitM30/react-native-typescript-boilerplate/badges/gpa.svg)](https://codeclimate.com/github/AmitM30/react-native-typescript-boilerplate) ![License](https://img.shields.io/github/license/AmitM30/react-native-typescript-boilerplate.svg) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](./CONTRIBUTING.md)
44

5-
### An opinionated [React Native](https://facebook.github.io/react-native/docs/getting-started) Starter Kit with [React Native Navigation](https://github.com/wix/react-native-navigation) + [Redux](https://github.com/reactjs/redux) + [Airbnb TSLint](https://github.com/airbnb/javascript) to build iOS and Android apps using [TypeScript](https://github.com/Microsoft/TypeScript-React-Native-Starter)
5+
#### An opinionated [React Native](https://facebook.github.io/react-native/docs/getting-started) Starter Kit with [React Native Navigation](https://github.com/wix/react-native-navigation) + [Redux](https://github.com/reactjs/redux) + [Airbnb TSLint](https://github.com/airbnb/javascript) to build iOS and Android apps using [TypeScript](https://github.com/Microsoft/TypeScript-React-Native-Starter)
66

77
The project has been setup based off [RN Getting Started](https://facebook.github.io/react-native/docs/getting-started) and instructions from [Microsoft's Github TypeScript React Native Starter](https://github.com/Microsoft/TypeScript-React-Native-Starter) repo.
88

99
### Supports React Native 0.63.3, React Native Navigation v7 and Flipper
1010

11-
This repo supports the latest version of React Native compatible with React Native Navigation.
12-
1311
| UPDATE | RNN | RN | React | Comments |
1412
|---|---|---|---|---|
15-
| 7th October '20 | 7.1.0 | 0.63.3 | 16.13.1 | Major Upgrade, Support for Flipper
16-
| 27th April '20 | 3.7.0 | 0.61.5 | 16.9.0 | Support for RN > 0.60
17-
| 2nd Nov '19 | 2.26.2 | 0.59.10 | | Maintenance |
18-
| 30th April '19 | 2.18.3 | 0.59.5 | 16.8.6 | Maintenance |
19-
| 8th March '19 | 2.13.1 | 0.58.6 | 16.8.4 |
20-
21-
### Who is this for?
22-
23-
Jumpstart building robust apps using React Native, with TypeScript. The base setup has been taken care of, just `yarn install` and get going from respective IDEs.
24-
25-
You might also want to [rename](https://medium.com/the-react-native-log/how-to-rename-a-react-native-app-dafd92161c35) the app for your own use.
13+
| 07 Oct '20 | 7.1.0 | 0.63.3 | 16.13.1 | Support for Flipper
14+
| 27 Apr '20 | 3.7.0 | 0.61.5 | 16.9.0 | Support for RN > 0.60, Android X
15+
| 02 Nov '19 | 2.26.2 | 0.59.10 | | Maintenance |
16+
| 30 Apr '19 | 2.18.3 | 0.59.5 | 16.8.6 | Maintenance |
17+
| 08 Mar '19 | 2.13.1 | 0.58.6 | 16.8.4 |
18+
19+
### Introduction
20+
21+
Jumpstart building robust apps using React Native and TypeScript with most commoly needed tools already setup. Just `yarn install` and get going from respective IDEs.
22+
23+
- Routing and Navigation
24+
- Tabbed navigation using [React Native Navigation v7](https://github.com/wix/react-native-navigation)
25+
- Side Menu support
26+
- State Management using Flux Architecture
27+
- [Redux](https://redux.js.org/introduction/getting-started)
28+
- [Redux-Thunk](https://github.com/reduxjs/redux-thunk) middleware
29+
- Widgets / Elements
30+
Build your own design system with these building blocks.
31+
- **elements**: `<BUTTON_DEFAULT>` or `<CText>`. They are custom elements that have default properties like font, size and so on.
32+
- **widgets**: Any component providing a complete functionality. E.g. carousels component, banner component, etc.
33+
- Typography
34+
- Base Typography setup - Color, Font, LAYOUT, CTA, FONTS, TEXT, TEXT_INPUT
35+
- Code Lint
36+
- [Airbnb's JS](https://github.com/airbnb/javascript) Linting
37+
38+
You might also want to rename the app for your own use. Follow any of the links below.
39+
- [How to Rename A React Native App](https://medium.com/the-react-native-log/how-to-rename-a-react-native-app-dafd92161c35)
40+
Or
41+
- NPM Package: [react-native-rename](https://www.npmjs.com/package/react-native-rename)
2642

2743
> _Disclaimer_: This is an **opinionated** approach to building apps with RN. The project structure is inspired by multiple production apps built by the contributors.
2844
29-
#### App Screens
45+
##### App Screens
3046

3147
| ![Splash](./src/view/assets/images/sample/1.png "Splash") | ![Home](./src/view/assets/images/sample/2.png "Home") |![Side Menu](./src/view/assets/images/sample/3.png "Side Menu") |
3248
| :-------------------------------------------------------: | :---------------------------------------------------: | :---------------------------------------------------: |
3349

34-
#### Flipper Support
50+
##### Flipper Support
3551

3652
![Flipper](./src/view/assets/images/sample/4.png "Flipper")
3753

3854
### Table of Contents
3955

4056
- [Project Structure](#project-structure)
41-
- [Running](#running)
57+
- [Getting Started](#getting-started)
4258
- [Lint](#lint)
43-
- [Unit Tests](#unit-tests)
4459
- [Cheat Sheet](#cheat-sheet)
4560
- [Single Screen vs Tabbed Based Navigation](#single-screen-vs-tabbed-based-navigation)
46-
- [Styles](#styles)
47-
- [Widgets / Elements](#widgets---elements)
4861
- [Contributing](#contributing)
4962
- [TODO](#todo)
5063

51-
#### Project Structure
64+
### Project Structure
5265

5366
```
5467
/
@@ -90,95 +103,80 @@ You might also want to [rename](https://medium.com/the-react-native-log/how-to-r
90103
```
91104

92105
`shared`
93-
Everything related to application business logic (store) resides under this directory.
106+
Everything related to application business logic. The redux store.
94107

95108
`src`
96-
Only presentation layer for the app, styles, images, icons are meant to be under this.
109+
Presentation layer for the app - screens, styles, images, icons etc.
97110

98-
#### Running
99-
100-
Make sure node version installed is `>=10.x.x`
111+
### Getting Started
101112

113+
Make sure node version installed is `>=10.x.x`. Then install using yarn (or npm):
102114
```
103115
yarn install
104116
```
105117

106-
#### Launch
118+
Start the Metro Bundler:
119+
```
120+
yarn start
121+
```
107122

108123
###### iOS
109124

125+
One time. Move to `ios` folder and install pods:
126+
110127
```
111128
cd ios && pod install
112129
```
113130

114-
Launch application from XCode
115-
116-
###### Android
117-
118-
For android, run the Metro Bundler from the terminal
131+
Launch application from XCode (`Command + R`) Or launch from Terminal:
119132

120133
```
121-
npm run start
134+
yarn ios
135+
# runs the following command. change device name here
136+
# `npx react-native run-ios --simulator='iPhone 11'`
122137
```
123138

124-
and then launch from IDE.
125-
126-
#### Lint
127-
128-
To run lint on the application:
139+
###### Android
129140

141+
Start an Android Simulator from:
130142
```
131-
yarn lint
143+
Android Studio > Tools > AVD Manager > Run any device
132144
```
133145

134-
Fixes most tslint issues automatically:
135-
146+
Similarly, run from Android Studio itself or from Terminal:
136147
```
137-
yarn lint:fix
148+
yarn android
149+
# runs the following command
150+
# react-native run-android --variant=Debug
138151
```
139152

140-
#### Unit Test
153+
### Lint
141154

142-
Unit tests are under `__test__` directory at root.
143-
144-
To run unit test on the application:
155+
To run lint on the application, run:
145156

146157
```
147-
npm run test
158+
yarn lint
148159
```
149160

150-
To find unit test coverage for the application:
161+
Fixes most tslint issues automatically:
151162

152163
```
153-
npm run test:coverage
164+
yarn lint:fix
154165
```
155166

156-
#### Cheat Sheet
167+
### Cheat Sheet
157168

158-
##### Single Screen vs Tabbed Based Navigation
169+
#### Single Screen vs Tabbed Based Navigation
159170

160171
The application launches with a splash screen, and then moves to a tabbed based navigation. Splash screen is a good place to fetch data / build application launch logic like getting user token from API or Async Store, load persist state etc.
161172

162173
For Single screen application, replace this tabbed based navigation with a single screen - just `home`, or simply use the splash screen to setup the app, may be with a burger menu.
163174

164-
##### Styles
165-
166-
The `styles` folder contains `global` style and `typography` for the application. Styles for each screen has been placed with the screen, as they are used together with the screen, unlike web.
167-
168-
##### Widgets / Elements
169-
170-
The custom components have been broken into 2 major categories, namely - **widgets**, **elements**
171-
172-
A Good use case would be:
173-
174-
- **widgets**: Any component providing a complete functionality. Like carousels component, banner component, etc.
175-
- **elements**: Smallest building blocks of application. A custom element, may be `<ButtonPrimary>` or `<CText>`, that has default font properties like font, size and so on.
176-
177-
#### Contributing
175+
### Contributing
178176

179177
Please check out [Contributing](https://github.com/AmitM30/react-native-typescript-boilerplate/blob/master/CONTRIBUTING.md).
180178

181-
#### Authors
179+
### Authors
182180

183181
- [**Anurag Chutani**](https://github.com/a7urag) - _Android Setup_
184182
- [**Brian Varley**](https://github.com/BrianJVarley) - _Windows Setup_

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"scripts": {
2727
"start": "node node_modules/react-native/local-cli/cli.js start",
2828
"test": "cross-env-shell jest",
29-
"android": "react-native run-android --variant=Debug",
29+
"ios": "npx react-native run-ios --simulator='iPhone 11'",
30+
"android": "npx react-native run-android --variant=Debug",
3031
"build:android:debug": "./gradlew assembleDebug",
3132
"build:android:release": "./gradlew assembleRelease -x bundleReleaseJsAndAssets",
3233
"lint": "cross-env-shell tslint --project ./tsconfig.json",
@@ -43,16 +44,16 @@
4344
"license": "MIT",
4445
"devDependencies": {
4546
"@babel/core": "^7.8.4",
46-
"@babel/runtime": "^7.8.4",
47-
"@react-native-community/eslint-config": "^1.1.0",
4847
"@babel/plugin-proposal-class-properties": "^7.3.0",
4948
"@babel/preset-env": "^7.3.1",
49+
"@babel/runtime": "^7.8.4",
50+
"@react-native-community/eslint-config": "^1.1.0",
5051
"@types/jest": "^24.0.23",
5152
"@types/react": "^16.7.21",
5253
"@types/react-native": "^0.57.32",
5354
"@types/react-redux": "^7.0.1",
5455
"@types/react-test-renderer": "^16.0.3",
55-
"@types/redux-logger": "^3.0.6",
56+
"@types/redux-logger": "^3.0.8",
5657
"babel-core": "^7.0.0-bridge.0",
5758
"babel-eslint": "^10.0.1",
5859
"babel-jest": "^25.1.0",

shared/redux/actions/app.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Single location for Actions dispatched at `app` level
3+
*/
4+
import { ACTION_TYPES } from '../constants/actionTypes';
5+
6+
export const splashLaunched = () => ({
7+
type: ACTION_TYPES.SPLASH.SPLASH_LAUNCHED
8+
});
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
/* Add All Action constants here */
22

33
const ACTION_TYPES = {
4-
// Splash Actions
5-
SPLASH_LAUNCHED: 'SPLASH_LAUNCHED',
4+
// Splash Screen Actions
5+
SPLASH: {
6+
SPLASH_LAUNCHED: 'SPLASH_LAUNCHED'
7+
},
8+
// Home Screen Actions
9+
HOME: {
10+
HOME_LAUNCHED: 'HOME_LAUNCHED'
11+
}
612
};
713

814
export { ACTION_TYPES };

shared/redux/reducers/app.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { ACTION_TYPES } from '../constants/actionTypes';
22

33
const initialState = {
4-
isLoading: false,
4+
isLoading: true,
55
};
66

77
export default (state = initialState, action: any) => {
88
switch (action.type) {
9-
case ACTION_TYPES.SPLASH_LAUNCHED:
9+
case ACTION_TYPES.SPLASH.SPLASH_LAUNCHED:
1010
return {
1111
...state,
12+
isLoading: false
1213
};
1314
default:
1415
return state;

shared/redux/reducers/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/**
22
* This file includes all the reducers under reducers directory,
33
* Import all and add to combineReducers to use any among whole app
4-
*
5-
* ** */
4+
*/
65
import { combineReducers } from 'redux';
76

87
import app from './app';

shared/redux/store/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { applyMiddleware, createStore } from 'redux';
22
import * as thunkMiddleware from 'redux-thunk';
3-
import { createLogger } from 'redux-logger';
43

54
import reducers from '../reducers';
65

76
let middlewares = [thunkMiddleware.default];
87
if (__DEV__) {
9-
const loggerMiddleware = createLogger();
8+
const logger = require('redux-logger');
9+
const loggerMiddleware = logger.createLogger({
10+
duration: true
11+
});
1012
middlewares = [...middlewares, loggerMiddleware];
1113
}
1214
const store = createStore(reducers, applyMiddleware(...middlewares));
1315

16+
export type AppDispatch = typeof store.dispatch;
17+
1418
export default store;

shared/redux/thunk/app.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Thunks are a great place for application business logic
3+
*/
4+
import { splashLaunched } from '../actions/app';
5+
import { AppDispatch } from '../store';
6+
7+
export const splashScreenLaunched = () => async (dispatch: AppDispatch) => {
8+
dispatch(splashLaunched());
9+
/**
10+
* Application launch Logic can go here, like
11+
* - Validating user token
12+
* - Getting data from async storage
13+
* - Making an API call needed for booting app
14+
*/
15+
};

src/constants/screen.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
// Screen ids constants
2-
1+
/**
2+
* Define screen names as constants here
3+
*/
34
const SCREENS = {
45
Splash: 'Splash',
56
Home: 'Home',
67
Settings: 'Settings',
78
Drawer: 'Drawer',
9+
Dummy: 'Dummy',
810
};
911

1012
export { SCREENS };

src/navigators/index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@ import { showSplash } from './navigation';
99
*/
1010
registerScreens({ store });
1111

12+
/**
13+
* Entry point for the app
14+
* showSplash() -> As the name suggests, shows the splash screen.
15+
* If you do not want a splash screen, directly call `tabbedNavigation()`
16+
* defined in './navigation'
17+
*/
1218
const app = () => {
1319
Navigation.events().registerAppLaunchedListener(() => {
1420
Navigation.setDefaultOptions({
15-
topBar: { visible: true },
21+
/**
22+
* Add default options right here
23+
*/
24+
topBar: { visible: true, elevation: 0 },
1625
});
1726

1827
showSplash();

0 commit comments

Comments
 (0)