Skip to content

Commit 9558181

Browse files
authored
Added thunk sample, Push screen example (#49)
* Add thunk sample, push example, cleanup * Update Readme * fix lint issues
1 parent 72acb73 commit 9558181

File tree

23 files changed

+290
-116
lines changed

23 files changed

+290
-116
lines changed

README.md

+62-72
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,63 @@
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)
6+
7+
___
68

79
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.
810

911
### Supports React Native 0.63.3, React Native Navigation v7 and Flipper
1012

11-
This repo supports the latest version of React Native compatible with React Native Navigation.
12-
13-
| UPDATE | RNN | RN | React | Comments |
13+
| | RNN | RN | React | Comments |
1414
|---|---|---|---|---|
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.
15+
| 07 Oct '20 | 7.1.0 | 0.63.3 | 16.13.1 | Support for Flipper
16+
| 27 Apr '20 | 3.7.0 | 0.61.5 | 16.9.0 | Support for RN > 0.60, Android X
17+
| 02 Nov '19 | 2.26.2 | 0.59.10 | | Maintenance |
18+
| 08 Mar '19 | 2.13.1 | 0.58.6 | 16.8.4 |
19+
20+
## Introduction
21+
22+
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.
23+
24+
- Routing and Navigation
25+
- Tabbed navigation using [React Native Navigation v7](https://github.com/wix/react-native-navigation)
26+
- Side Menu support
27+
- State Management using Flux Architecture
28+
- [Redux](https://redux.js.org/introduction/getting-started)
29+
- [Redux-Thunk](https://github.com/reduxjs/redux-thunk) middleware
30+
- Widgets / Elements
31+
32+
Build your own design system with these building blocks.
33+
- **elements**: `<BUTTON_DEFAULT>` or `<CText>`. They are custom elements that have default properties like font, size and so on.
34+
- **widgets**: Any component providing a complete functionality. E.g. carousels component, banner component, etc.
35+
- Typography
36+
- Base Typography setup - Color, Font, LAYOUT, CTA, FONTS, TEXT, TEXT_INPUT
37+
- Code Lint
38+
- [Airbnb's JS](https://github.com/airbnb/javascript) Linting
2639

2740
> _Disclaimer_: This is an **opinionated** approach to building apps with RN. The project structure is inspired by multiple production apps built by the contributors.
2841
29-
#### App Screens
42+
##### App Screens
3043

3144
| ![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") |
3245
| :-------------------------------------------------------: | :---------------------------------------------------: | :---------------------------------------------------: |
3346

34-
#### Flipper Support
47+
##### Flipper Support
3548

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

3851
### Table of Contents
3952

4053
- [Project Structure](#project-structure)
41-
- [Running](#running)
42-
- [Lint](#lint)
43-
- [Unit Tests](#unit-tests)
54+
- [Getting Started](#getting-started)
4455
- [Cheat Sheet](#cheat-sheet)
4556
- [Single Screen vs Tabbed Based Navigation](#single-screen-vs-tabbed-based-navigation)
46-
- [Styles](#styles)
47-
- [Widgets / Elements](#widgets---elements)
57+
- [Renaming the App](#renaming-the-app)
4858
- [Contributing](#contributing)
4959
- [TODO](#todo)
5060

51-
#### Project Structure
61+
### Project Structure
5262

5363
```
5464
/
@@ -90,95 +100,75 @@ You might also want to [rename](https://medium.com/the-react-native-log/how-to-r
90100
```
91101

92102
`shared`
93-
Everything related to application business logic (store) resides under this directory.
103+
Everything related to application business logic. The redux store.
94104

95105
`src`
96-
Only presentation layer for the app, styles, images, icons are meant to be under this.
97-
98-
#### Running
106+
Presentation layer for the app - screens, styles, images, icons etc.
99107

100-
Make sure node version installed is `>=10.x.x`
108+
### Getting Started
101109

110+
Make sure node version installed is `>=10.x.x`. Then install using yarn (or npm):
102111
```
103112
yarn install
104113
```
105114

106-
#### Launch
107-
108-
###### iOS
109-
110-
```
111-
cd ios && pod install
112-
```
113-
114-
Launch application from XCode
115-
116-
###### Android
117-
118-
For android, run the Metro Bundler from the terminal
119-
115+
Start the Metro Bundler:
120116
```
121-
npm run start
117+
yarn start
122118
```
123119

124-
and then launch from IDE.
125-
126-
#### Lint
120+
###### iOS
127121

128-
To run lint on the application:
122+
One time. Move to `ios` folder and install pods:
129123

130124
```
131-
yarn lint
125+
cd ios && pod install
132126
```
133127

134-
Fixes most tslint issues automatically:
128+
Launch application from XCode (`Command + R`) Or launch from Terminal:
135129

136130
```
137-
yarn lint:fix
131+
yarn ios
132+
# runs the following command. change device name here
133+
# `npx react-native run-ios --simulator='iPhone 11'`
138134
```
139135

140-
#### Unit Test
141-
142-
Unit tests are under `__test__` directory at root.
143-
144-
To run unit test on the application:
136+
###### Android
145137

138+
Start an Android Simulator from:
146139
```
147-
npm run test
140+
Android Studio > Tools > AVD Manager > Run any device
148141
```
149142

150-
To find unit test coverage for the application:
151-
143+
Similarly, run from Android Studio itself Or from Terminal:
152144
```
153-
npm run test:coverage
145+
yarn android
146+
# runs the following command
147+
# react-native run-android --variant=Debug
154148
```
155149

156-
#### Cheat Sheet
150+
### Cheat Sheet
157151

158-
##### Single Screen vs Tabbed Based Navigation
152+
#### Single Screen vs Tabbed Based Navigation
159153

160154
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.
161155

162156
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.
163157

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
158+
#### Renaming the App
169159

170-
The custom components have been broken into 2 major categories, namely - **widgets**, **elements**
160+
You might also want to rename the app for your own use. Follow any of the links below.
161+
- [How to Rename A React Native App](https://medium.com/the-react-native-log/how-to-rename-a-react-native-app-dafd92161c35)
171162

172-
A Good use case would be:
163+
Or
173164

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.
165+
- NPM Package: [react-native-rename](https://www.npmjs.com/package/react-native-rename)
176166

177-
#### Contributing
167+
### Contributing
178168

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

181-
#### Authors
171+
### Authors
182172

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

package.json

+5-4
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

+8
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+
});
+8-2
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

+3-2
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

+1-2
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

+6-2
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

+15
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

+4-2
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

+10-1
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();

src/navigators/navigation.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* Application navigation stacks to be defined here.
3+
*/
14
import { Navigation } from 'react-native-navigation';
25

36
import { SCREENS } from '../constants/screen';

0 commit comments

Comments
 (0)