创建TypeScript版本的React Native项目
https://www.npmjs.com/package/react-native-template-typescript
1.使用typescript模板创建一个react native项目
react-native init MyApp --template typescript
2.运行新项目中的 setup.js脚本
node MyApp/setup.js
3.加入 Navigation
https://reactnavigation.org/docs/zh-Hans/getting-started.html
yarn add react-navigation react-native-gesture-handler
yarn add @types/react-navigation --dev
4.链接原生依赖
react-native link react-native-gesture-handler
5.为了完成 react-native-gesture-handler在 Android 上的安装,请确保在 MainActivity.java 上完成如下修改:
package com.reactnavigation.example;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
public class MainActivity extends ReactActivity {
@Override
protected String getMainComponentName() {
return "Example";
}
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName()) {
@Override
protected ReactRootView createRootView() {
return new RNGestureHandlerEnabledRootView(MainActivity.this);
}
};
}
}
6.加入redux(根据需要加入redux-thunk 或者 redux-saga)
yarn add redux react-redux
yarn add @types/redux @types/react-redux --dev