tsconfig.json文件: { "compilerOptions": { "module":"es2015", "target": "es2015", "jsx": "react", //jsx要配置成react,默認狀況下沒有,否則jsx解析會失敗 "rootDir": "src", //入口文件夾,默認狀況下沒有src文件夾,因此還要在項目下建立一個src文件夾進行入口的編譯 "outDir": "build", //輸出文件夾,ts必須打成一個包,把ts轉成js沒法運行文件,因此先build再去run,同時加上watch每修改一次build一次 "allowSyntheticDefaultImports": true, "noImplicitAny": true, "sourceMap": true, "experimentalDecorators": true, "preserveConstEnums": true, "allowJs": true, "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, "skipLibCheck": true, "moduleResolution":"Node" }, "filesGlob": [ "typings/index.d.ts", "src/**/*.ts", "src/**/*.tsx", "node_modules/typescript/lib/lib.es6.d.ts" ], "types": [ "react", "react-dom", "react-native" ], "exclude":[ // exclude排除哪些配置項 "build", "node_modules", "jest.config.js", "App.js" ], "compileOnSave": false }
package.json文件:
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "node node_modules/jest/bin/jest.js",
"lint": "tslint src/**/*.ts",
"tsc": "tsc",
"clean": "rimraf build",
"build": "yarn run clean && yarn run tsc --",
"watch": "yarn run build -- -w",
"watchAndRunAndroid": "concurrently \"yarn run watch\" \"yarn run android\"",
"buildRunAndroid": "yarn run build && yarn run watchAndRunAndroid ",
"watchAndRunIOS": "concurrently \"yarn run watch\" \"yarn run ios\"",
"buildRunIOS": "yarn run build && yarn run watchAndRunIOS ",
"watchAndStart": "concurrently \"yarn run watch\" \"yarn run start\"",
"buildAndStart": "yarn run build && yarn run watchAndStart "
}
修改package.json中的入口文件:
"main":"./node_modules/react-native-scripts/build/bin/crna-entry.js"
此時能夠看見node_modules/react-native-scripts/build/bin/crna-entry.js文件中的 var _App = require('../../../../App');
刪除App.js的文件內容,粘貼如下內容:javascript
App.js文件:
import App from './build/App';
export default App;
建立一個src文件夾目錄,再將babel.config.js文件拖到src文件目錄下!html
配置完成,能夠直接run了 。前端
yarn buildAndStartjava
App.tsx文件:
import React from "react"
import {
View,
Text
} from "react-native"
export default class componentName extends React.Component{
render(){
return(
<View>
<Text>hello world</Text>
</View>
)
}
}
這個時候能夠聯想到nextTick,咱們應該等數據來了再渲染,你能夠試着判斷一下你的渲染數據: this.list.length>0? 渲染:"null"
import { Provider} from "mobx-react"
import { createStackNavigator } from "react-navigation
7、WebViewnode
import { WebView } from "react-native"
import { Text, View, TouchableOpacity } from 'react-native' import { Camera, Permissions } from 'expo'
import { Switch } from "react-native"
import { AsyncStorage } from "react-native"
await AsyncStorage.setItem('isShowMap', `${value}`); // 第二個參數是字符串
const isShowMap = Boolean(await AsyncStorage.getItem('isShowMap')); // 返回值是一個字符串,須要轉化爲Boolean類型
11、上拉刷新、下拉加載 -- FlatList引入 react
import { FlatList } from "react-native"
上面只規整了import引入的方式,具體代碼格式你們能夠進RN官網再去看一下,固然!文章最上頭有規整好網址,你們copy代碼就能很happy的run了。android
恩。RN就整理到這裏,但願能幫助到你們。ios