このチャプターの目次
開発に必要なパッケージをインストールします。
yarn add @react-navigation/bottom-tabs @react-navigation/native @react-navigation/stack nativewind react-native-device-info react-native-gesture-handler react-native-safe-area-context react-native-screens react-native-vector-icons react-native-video
yarn add --dev tailwindcss
スタイルは TailwindCSS を使用するために、nativewind
ライブラリを使用します。
tailwind.config.js ファイルを作成します。
npx tailwindcss init
tailwind.config.js
module.exports = {
content: ['./App.{js,jsx,ts,tsx}', './src/**/*.{js,jsx,ts,tsx}'],
theme: {
extend: {},
},
plugins: [],
}
babel.config.js
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: ['nativewind/babel'],
}
ナビゲーションはReact Navigation
を使用します。
アイコンは、react-native-vector-icons
を使用します。
Android と iOS でそれぞれ設定が必要になります。
Android
android/app/build.gradle に下記を追記します。
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
iOS
iOS の設定は下記の記事が参考になります。
動作確認
ライブラリのインストールに問題がないかもう一度起動させます。
yarn android
yarn ios
チュートリアルのライブラリのバージョン
React Native は頻繁にバージョンアップが行われるので、もし最新のバージョンで動作しない場合は、チュートリアル実施時のバージョンで動かすようにしてください。
package.json
{
"name": "reactnative_tiktok_tutorial",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"@react-navigation/bottom-tabs": "^6.4.0",
"@react-navigation/native": "^6.0.13",
"@react-navigation/stack": "^6.3.1",
"nativewind": "^2.0.11",
"react": "18.1.0",
"react-native": "0.70.2",
"react-native-device-info": "^10.2.0",
"react-native-gesture-handler": "^2.7.0",
"react-native-safe-area-context": "^4.4.1",
"react-native-screens": "^3.18.0",
"react-native-vector-icons": "^9.2.0",
"react-native-video": "^5.2.1"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"@babel/runtime": "^7.12.5",
"@react-native-community/eslint-config": "^2.0.0",
"babel-jest": "^26.6.3",
"eslint": "^7.32.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "0.72.3",
"react-test-renderer": "18.1.0",
"tailwindcss": "^3.1.8"
},
"jest": {
"preset": "react-native"
}
}
Eslint Prettier
Eslint と Prettier の設定は好みで設定してください。
セミコロンはなしで設定してあります。
.eslintrc.js
module.exports = {
root: true,
plugins: ['prettier'],
env: {
es2022: true,
},
}
.prettierrc.js
module.exports = {
arrowParens: 'avoid',
bracketSameLine: true,
bracketSpacing: false,
singleQuote: true,
trailingComma: 'all',
semi: false,
}