This repository is about initial Development Environment Settings.
react
: 16.5.0react-native
: 0.57.4
-
react-native init
-
use
typescript
-
use
eslint
-
use
mobx
andmobx-react
-
connect with
code-push
-
connect with
firebase
(TODO)
- add assets/font
- use
react-native-splash-screen
- use
react-native-fast-image
- use
react-navigation
orreact-native-navigation
$ npm install -g react-native-cli
$ react-native init MyProject
$ cd MyProject
$ yarn add --dev typescript
$ yarn add --dev react-native-typescript-transformer
$ yarn tsc --init --pretty --jsx react
$ touch rn-cli.config.js
$ yarn add --dev @types/react @types/react-native
module.exports = {
getTransformModulePath() {
return require.resolve("react-native-typescript-transformer");
},
getSourceExts() {
return ["ts", "tsx"];
}
};
yarn add --dev ts-jest
"jest": {
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"^.+\\.(js)$": "<rootDir>/node_modules/babel-jest",
"\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"testPathIgnorePatterns": [
"\\.snap$",
"<rootDir>/node_modules/"
],
"cacheDirectory": ".jest/cache"
}
npm install --save-dev eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
],
};
{
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
]
}
{
"compilerOptions": {
…
"baseUrl": ".",
"paths": {
"~/*": ["src/*"]
}
},
…
}
npm install --save mobx mobx-react
{
"presets": [
"module:metro-react-native-babel-preset"
],
"plugins": [
"transform-decorators-legacy"
]
}
if you have error like this
error: bundling failed: Error: The 'decorators' plugin requires a 'decoratorsBeforeExport' option, whose value must be a boolean. If you are migrating from Babylon/Babel 6 or want to use the old decorators proposal, you should use the 'decorators-legacy' plugin instead of 'decorators'.
npm install --save-dev @babel/plugin-proposal-decorators
{
...
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
]
}
{
"compilerOptions": {
...
"experimentalDecorators": true
...
}
}
npm install -g code-push-cli
code-push register
code-push app add <AppName-Android>
code-push app add <AppName-iOS>
code-push app list
npm install --save react-native-code-push@latest
react-native link react-native-code-push
<key>CodePushDeploymentKey</key>
<string><Staging Deployment Key></string>
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new CodePush("<Staging Deployment Key>", getApplicationContext(), BuildConfig.DEBUG)
);
}
npm install --save react-native-firebase
react-native link react-native-firebase
create your project in Firebase
install GoogleService-Info.plist
and move to ios/[YOUR APP NAME]
directory
in AppDelegate.m
#import <Firebase.h>
[FIRApp configure];
in PodFile
# Required by RNFirebase
pod 'Firebase/Core', '~> 5.9.0'
pod install
install google-services.json
and move to android/app
directory
write this code in app.gradle
(project level)
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:4.0.1'
}
}
write this code very bottom in app.gradle
(app level)
apply plugin: 'com.google.gms.google-services'
dependencies {
// This should be here already
implementation project(':react-native-firebase')
// Firebase dependencies
implementation "com.google.android.gms:play-services-base:15.0.1"
implementation "com.google.firebase:firebase-core:16.0.3"
...
firebase.analytics().logEvent(eventName, params);
// eventName: string, params: object
When you build react-native application in Xcode
Xcode 10: Build input file double-conversion cannot be found
$ cd node_modules/react-native/scripts && ./ios-install-third-party.sh && cd ../../../
$ cd node_modules/react-native/third-party/glog-0.3.5/ && ../../scripts/ios-configure-glog.sh && cd ../../../../
reference: facebook/react-native#21168
error (when pod install
)
In Podfile:
React/CxxBridge (from `../node_modules/react-native`) was resolved to 0.57.2, which depends on
Folly (= 2016.10.31.00)
write this code in Podfile
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
reference: https://facebook.github.io/react-native/docs/integration-with-existing-apps.html
yarn add --dev styled-components
import * as styledComponents from "styled-components";
const {
default: styled,
css,
injectGlobal,
ThemeProvider
} = styledComponents as styledComponents.ThemedStyledComponentsModule<
IThemeInterface
>;
export interface IThemeInterface {
primaryColor: string;
}
export const theme = {
primaryColor: "#e9e9eb"
};
export default styled;
export { css, injectGlobal, ThemeProvider };
In
react-native
, you cannot use keyframes. You should useAnimated
API supported byreact-native
.
// in App.tsx
const ContainerView = styled(View)`
flex: 1;
justify-content: center;
align-items: center;
background-color: #F5FCFF;
`;
class App extends Component {
render() {
return (
<ContainerView>
// ...
</ContainerView>
);
}
}