{"id":19744,"date":"2024-01-04T11:06:27","date_gmt":"2024-01-04T03:06:27","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/?p=19744"},"modified":"2024-01-04T11:06:27","modified_gmt":"2024-01-04T03:06:27","slug":"reactnative%e5%bc%80%e5%8f%91%e5%ae%89%e5%8d%93app%e6%93%8d%e4%bd%9c%e6%96%b9%e6%b3%95%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2024\/19744\/","title":{"rendered":"reactnative\u5f00\u53d1\u5b89\u5353app\u64cd\u4f5c\u65b9\u6cd5\u4ecb\u7ecd"},"content":{"rendered":"

React Native\u662f\u4e00\u79cd\u7528JavaScript\u7f16\u5199\u624b\u673a\u5e94\u7528\u7684\u6846\u67b6\u3002\u5b83\u662fReact\u7684\u4e00\u4e2a\u6269\u5c55\uff0c\u53ef\u4ee5\u4f7f\u7528\u76f8\u540c\u7684\u601d\u60f3\u6765\u5f00\u53d1iOS\uff0cAndroid\u548cWeb\u5e94\u7528\u3002React Native\u63d0\u4f9b\u4e86\u4e00\u79cd\u53ef\u91cd\u7528\u7684UI\u5143\u7d20\uff0c\u53ef\u4ee5\u5728\u4e0d\u540c\u7684\u5e73\u53f0\u4e0a\u4f7f\u7528\uff0c\u5982\u6309\u94ae\uff0c\u8f93\u5165\u6846\uff0c\u6587\u672c\u89c6\u56fe\u7b49\uff0c\u8fd9\u4f7f\u5f97\u5f00\u53d1\u5e94\u7528\u7a0b\u5e8f\u66f4\u52a0\u7b80\u5355\u548c\u5feb\u901f\u3002<\/p>\n

React Native\u5f00\u53d1\u5b89\u5353App\u7684\u6b65\u9aa4\uff1a<\/p>\n

1. \u5b89\u88c5Node.js\u548cnpm<\/p>\n

React Native\u4f7f\u7528Node.js\u548cnpm\u6765\u7f16\u8bd1\u548c\u6784\u5efa\u5b89\u5353app\u5236\u4f5c<\/a>\u5e94\u7528\u7a0b\u5e8f\u3002\u5b89\u88c5Node.js\u548cnpm\u53ef\u4ee5\u4eceNode.js\u7f51\u7ad9\u4e0b\u8f7d\u548c\u5b89\u88c5\u3002<\/p>\n

2. \u5b89\u88c5React Native\u547d\u4ee4\u884c\u5de5\u5177<\/p>\n

React Native\u63d0\u4f9b\u4e86\u4e00\u7ec4\u547d\u4ee4\u884c\u5de5\u5177\u6765\u521b\u5efa\uff0c\u542f\u52a8\u548c\u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5React Native\u547d\u4ee4\u884c\u5de5\u5177\uff1a<\/p>\n

“`<\/p>\n

npm install -g react-native-cli<\/p>\n

“`<\/p>\n

3. \u521b\u5efa\u65b0\u7684React \u5b89\u5353app<\/a>Native\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u4f7f\u7528React Native\u547d\u4ee4\u884c\u5de5\u5177\u53ef\u4ee5\u521b\u5efa\u65b0\u7684React Native\u5e94\u7528\u7a0b\u5e8f\u3002\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

react-native init MyApp<\/p>\n

“`<\/p>\n

\u5176\u4e2d\uff0c`MyApp`\u662f\u5e94\u7528\u7a0b\u5e8f\u7684\u540d\u79f0\u3002\u8fd9\u4e2a\u547d\u4ee4\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a`MyApp`\u7684\u76ee\u5f55\uff0c\u5e76\u751f\u6210React Native\u5e94\u7528\u7a0b\u5e8f\u7684\u521d\u59cb\u4ee3\u7801\u3002<\/p>\n

4. \u8fde\u63a5Android\u8bbe\u5907\u6216\u542f\u52a8\u6a21\u62df\u5668<\/p>\n

\u5728Android\u8bbe\u5907\u4e0a\u8fd0\u884cReact Native\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u8fde\u63a5\u8bbe\u5907\u5230\u7535\u8111\uff0c\u6216\u8005\u5728\u7535\u8111\u4e0a\u542f\u52a8\u6a21\u62df\u5668\u3002\u53ef\u4ee5\u4f7f\u7528Android Studio\u6765\u542f\u52a8\u6a21\u62df\u5668\u6216\u8fde\u63a5\u8bbe\u5907\u3002<\/p>\n

5. \u542f\u52a8\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u5728\u547d\u4ee4\u884c\u4e2d\uff0c\u8fdb\u5165\u5230\u5e94\u7528\u7a0b\u5e8f\u7684\u76ee\u5f55\uff0c\u5e76\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\uff1a<\/p>\n

“`<\/p>\n

react-native run-android<\/p>\n

“`<\/p>\n

\u8fd9\u4e2a\u547d\u4ee4\u5c06\u7f16\u8bd1React Native\u5e94\u7528\u7a0b\u5e8f\u7684JavaScript\u4ee3\u7801\uff0c\u5e76\u5728\u8fde\u63a5\u7684\u8bbe\u5907\u6216\u542f\u52a8\u7684\u6a21\u62df\u5668\u4e0a\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

6. \u7f16\u5199React Native\u4ee3\u7801<\/p>\n

\u6253\u5f00\u5e94\u7528\u7a0b\u5e8f\u7684\u4ee3\u7801\uff0c\u53ef\u4ee5\u770b\u5230\u5b83\u5305\u542b\u4e86\u4e00\u4e2a\u57fa\u672c\u7684React Native\u754c\u9762\u3002\u53ef\u4ee5\u6839\u636e\u9700\u8981\u4fee\u6539\u4ee3\u7801\u6765\u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

React Native\u4f7f\u7528JavaScript\u7f16\u5199UI\uff0c\u53ef\u4ee5\u76f4\u63a5\u7f16\u8f91JavaScript\u6587\u4ef6\u6765\u66f4\u6539UI\u3002\u4f8b\u5982\uff0c\u5728`App.js`\u6587\u4ef6\u4e2d\uff0c\u4fee\u6539\u4ee3\u7801\u6765\u66f4\u6539UI\uff1a<\/p>\n

“`jsx<\/p>\n

import React from ‘react’;<\/p>\n

import { StyleSheet, Text, View } from ‘react-native’;<\/p>\n

export default function App() {<\/p>\n

return (<\/p>\n

\n

Hello, React Native!<\/p>\n<\/p>\n

);<\/p>\n

}<\/p>\n

const styles = StyleSheet.create({<\/p>\n

container: {<\/p>\n

flex:<\/p>\n

<\/figure>\n<\/p>\n

1,<\/p>\n

backgroundColor: ‘#fff’,<\/p>\n

alignItems: ‘center’,<\/p>\n

justifyContent: ‘center’,<\/p>\n

},<\/p>\n

text: {<\/p>\n

fontSize: 24,<\/p>\n

color: ‘blue’,<\/p>\n

},<\/p>\n

});<\/p>\n

“`<\/p>\n

7. \u8c03\u8bd5\u5e94\u7528\u7a0b\u5e8f<\/p>\n

React Native\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u4f7f\u7528\u8c03\u8bd5\u5de5\u5177\u6765\u8c03\u8bd5JavaScript\u4ee3\u7801\u548cUI\u3002\u5728\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528`adb logcat`\u547d\u4ee4\u6765\u67e5\u770b\u65e5\u5fd7\u3002\u540c\u65f6\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528Chrome\u6d4f\u89c8\u5668\u7684\u5f00\u53d1\u8005\u5de5\u5177\u8fdb\u884c\u8fdc\u7a0b\u8c03\u8bd5\u3002<\/p>\n

\u4ee5\u4e0a\u5c31\u662f\u7528React Native\u5f00\u53d1\u5b89\u5353App\u7684\u57fa\u672c\u6b65\u9aa4\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cReact Native\u5f00\u53d1\u5b89\u5353App\u9700\u8981\u719f\u7ec3\u638c\u63e1JavaScript\u548cReact\uff0c\u5bf9\u4e8e\u65b0\u624b\u6765\u8bf4\u9700\u8981\u66f4\u591a\u7ec3\u4e60\u548c\u5b66\u4e60\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

React Native\u662f\u4e00\u79cd\u7528JavaScript\u7f16\u5199\u624b\u673a\u5e94\u7528\u7684\u6846\u67b6\u3002\u5b83\u662fReact\u7684\u4e00\u4e2a\u6269\u5c55\uff0c\u53ef\u4ee5\u4f7f\u7528\u76f8\u540c\u7684\u601d\u60f3\u6765\u5f00\u53d1iOS\uff0cAndroid\u548cWeb\u5e94\u7528\u3002React Native\u63d0\u4f9b\u4e86\u4e00\u79cd\u53ef\u91cd\u7528<\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,625,25047,14,25046],"class_list":["post-19744","post","type-post","status-publish","format-standard","hentry","category-zuoapp","tag-81","tag-625","tag-app","tag-14"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/19744","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=19744"}],"version-history":[{"count":1,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/19744\/revisions"}],"predecessor-version":[{"id":19778,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/19744\/revisions\/19778"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=19744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=19744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=19744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}