{"id":117016,"date":"2026-10-22T10:08:06","date_gmt":"2026-10-22T02:08:06","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/117016.html"},"modified":"2026-10-22T10:08:06","modified_gmt":"2026-10-22T02:08:06","slug":"react-native-for-openharmony-%e5%ae%9e%e6%88%98%ef%bc%9a%e4%b8%89%e6%96%b9%e5%ba%93-react-native-switch-selector-%e7%9a%84%e9%b8%bf%e8%92%99%e5%8c%96%e9%80%82%e9%85%8d%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/117016.html","title":{"rendered":"React Native for OpenHarmony \u5b9e\u6218\uff1a\u4e09\u65b9\u5e93 react-native-switch-selector \u7684\u9e3f\u8499\u5316\u9002\u914d\u6307\u5357"},"content":{"rendered":"<p>        \/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/<br \/>\n        #content_views .toc,<br \/>\n        \/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/<br \/>\n        #content_views.markdown_views &gt; p:empty:has(+ .toc),<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty,<br \/>\n        \/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/<br \/>\n        #content_views.htmledit_views #main-toc,<br \/>\n        #content_views.htmledit_views #hr-toc,<br \/>\n        #content_views.htmledit_views p[id*=\\&#8221;-toc\\&#8221;] {<br \/>\n          display: none !important;<br \/>\n        }<br \/>\n        \/* \u76ee\u5f55\u53bb\u6389\u540e\uff0c\u7d27\u8ddf\u7684\u9996\u4e2a\u6807\u9898\u4e0d\u518d\u591a\u51fa\u4e00\u5757\u4e0a\u8fb9\u8ddd *\/<br \/>\n        #content_views.markdown_views &gt; .toc + h1,<br \/>\n        #content_views.markdown_views &gt; .toc + h2,<br \/>\n        #content_views.markdown_views &gt; .toc + h3,<br \/>\n        #content_views.markdown_views &gt; .toc + h4,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h1,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h2,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h3,<br \/>\n        #content_views.markdown_views &gt; .toc + p:empty + h4 {<br \/>\n          margin-top: 0 !important;<br \/>\n        }<\/p>\n<h2><\/h2>\n<p>\u672c\u6587\u8bb0\u5f55\u628a react-native-switch-selector&#xff08;\u4e8c\u9009\u4e00\u5f00\u5173 \/ \u5206\u6bb5\u5f00\u5173&#xff09;\u9002\u914d\u5230 HarmonyOS \u7684\u5b8c\u6574\u8fc7\u7a0b\u3002<\/p>\n<p>\u5b83\u662f\u4e00\u4e2a\u7eaf JS class \u7ec4\u4ef6&#xff08;index.js 336 \u884c&#xff09;&#xff0c;\u7528\u4e00\u4e2a\u4f1a\u6ed1\u52a8\u7684\u8272\u5757\u8868\u793a\u5f53\u524d\u9009\u4e2d\u9879&#xff0c;\u8fd8\u652f\u6301\u5de6\u53f3\u6ed1\u52a8\u5207\u6362\u3002\u5b83\u5e26\u6765\u4e00\u4e2a\u5f88\u5bb9\u6613\u8ba9\u4eba\u4ee5\u4e3a&#034;\u7ec4\u4ef6\u574f\u4e86&#034;\u7684\u9ed8\u8ba4\u503c&#xff1a;<\/p>\n<p>defaultProps.initial &#061; -1&#xff0c;\u800c\u6e90\u7801\u91cc<\/p>\n<p><span class=\"token function\">getBgColor<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">const<\/span> <span class=\"token punctuation\">{<\/span> selected <span class=\"token punctuation\">}<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">.<\/span>state<span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>selected <span class=\"token operator\">&#061;&#061;&#061;<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#039;transparent&#039;<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span>   <span class=\"token comment\">\/\/ \u2190 \u6ed1\u5757\u53d8\u900f\u660e<\/span><br \/>\n  <span class=\"token keyword\">return<\/span> options<span class=\"token punctuation\">[<\/span>selected<span class=\"token punctuation\">]<\/span><span class=\"token operator\">?.<\/span>activeColor <span class=\"token operator\">||<\/span> buttonColor<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u21d2 \u4e0d\u4f20 initial&#xff08;\u4e5f\u4e0d\u4f20 value&#xff09;\u65f6&#xff0c;\u6ed1\u5757\u662f\u900f\u660e\u7684 \u2014\u2014 \u5c4f\u6155\u4e0a\u53ea\u770b\u5f97\u5230\u6587\u5b57\u548c\u8fb9\u6846&#xff0c;\u770b\u4e0d\u5230\u90a3\u4e2a\u4f1a\u52a8\u7684\u8272\u5757&#xff0c;\u800c\u4e14\u4e0d\u62a5\u9519\u3001\u4e0d\u8b66\u544a\u3002<\/p>\n<p>\u5b9e\u6d4b&#xff08;\u6ed1\u5757\u989c\u8272\u662f buttonColor: &#039;#BCD635&#039;&#xff0c;\u9ec4\u7eff&#xff09;&#xff1a;\u4e0d\u4f20 initial \u7684\u5b9e\u4f8b&#xff0c;\u6309\u8be5\u989c\u8272\u626b\u5168\u5c4f\u662f 0 \u4e2a\u50cf\u7d20 \u2713<\/p>\n<p>\u53e6\u4e00\u4e2a\u5f88\u9002\u5408\u505a\u91cf\u5316\u9a8c\u8bc1\u7684\u70b9&#xff1a;\u6ed1\u5757\u7684\u51e0\u4f55\u53ef\u4ee5\u7cbe\u786e\u7b97\u51fa\u6765\u3002hasPadding&#061;false\u3001buttonMargin&#061;0 \u65f6&#xff1a;<\/p>\n<p>\u6ed1\u5757\u5bbd\u5ea6 &#061; width \/ options.length<br \/>\ntranslateX &#061; (k \/ options.length) \u00b7 width      \u2190 animatedValue &#061; k\/N \u63d2\u503c\u5230 [0, width]<br \/>\n\u21d2 \u6ed1\u5757\u5de6\u8fb9\u754c &#061; (k\/N)\u00b7width&#xff0c;\u5bbd &#061; width\/N \u21d2 \u6b63\u597d\u8986\u76d6\u7b2c k \u683c<\/p>\n<p>\u5b9e\u6d4b&#xff08;\u5bb9\u5668\u5bbd 1248px\u3001N&#061;2&#xff09;\u4e09\u4e2a\u5b9e\u4f8b&#xff1a;<\/p>\n<table>\n<tr>\u5b9e\u4f8b\u914d\u7f6e\u9884\u671f\u6ed1\u5757 x\u5b9e\u6d4b\u6ed1\u5757 x<\/tr>\n<tbody>\n<tr>\n<td>W1<\/td>\n<td>initial&#061;{0}<\/td>\n<td>36\u2026660&#xff08;\u5de6\u534a&#xff09;<\/td>\n<td>37\u2026658 \u2713<\/td>\n<\/tr>\n<tr>\n<td>W2<\/td>\n<td>initial&#061;{1}<\/td>\n<td>660\u20261284&#xff08;\u53f3\u534a&#xff09;<\/td>\n<td>661\u20261282 \u2713<\/td>\n<\/tr>\n<tr>\n<td>W3<\/td>\n<td>\u4e0d\u4f20 initial<\/td>\n<td>\u65e0\u6ed1\u5757<\/td>\n<td>0 \u50cf\u7d20\u5339\u914d \u2713\u2713<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u800c\u4e14\u4ea4\u4e92\u4e5f\u4e00\u5e76\u9a8c\u5230\u4e86&#xff1a;\u70b9\u53f3\u4fa7\u9009\u9879 \u21d2 PRESS W1 onPress(off)&#xff08;\u62ff\u5230\u7684\u662f\u8be5\u9009\u9879\u7684 value&#xff09;\u2713<\/p>\n<p>\u8bbe\u5907\u4fa7\u65ad\u8a00 34 \/ 34 \u5168\u90e8\u901a\u8fc7\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261022020759-6ad96fff18416.jpg\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<hr \/>\n<h3>\u4e00\u3001\u5148\u8bf4\u7ed3\u8bba<\/h3>\n<table>\n<tr>\u9879\u7ed3\u679c<\/tr>\n<tbody>\n<tr>\n<td>\u4e0a\u6e38\u6700\u65b0\u7248<\/td>\n<td>2.3.0&#xff1b;license: MIT&#xff1b;\u4e0a\u6e38 star 46<\/td>\n<\/tr>\n<tr>\n<td>\u5e93\u7c7b\u578b<\/td>\n<td>\u7eaf JS \u5355\u7ec4\u4ef6\u5e93&#xff1a;SwitchSelector&#xff08;class \u7ec4\u4ef6&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u662f\u5426\u9700\u8981\u539f\u751f\u9002\u914d<\/td>\n<td>\u4e0d\u9700\u8981&#xff08;\u65e0 harmony\/\u3001\u65e0 NativeModules&#xff1b;import \u56fe\u53ea\u6709 prop-types \/ react \/ react-native&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u8fd0\u884c\u65f6\u4f9d\u8d56<\/td>\n<td>\u26a0\ufe0f \u6709&#xff1a;prop-types&#064;^15.7.2 \u21d2 \u76ee\u5f55\/file: \u63a5\u5165\u4e0d\u4f1a\u81ea\u52a8\u88c5\u5b83&#xff08;\u672c\u8f6e\u5bbf\u4e3b\u91cc\u6070\u597d\u5df2\u6709 15.8.1&#xff0c;\u6240\u4ee5\u6ca1\u88ab\u54ac\u5230&#xff1b;\u6362\u5e72\u51c0\u5bbf\u4e3b\u4f1a\u76f4\u63a5\u5d29&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>prepare \/ prepublish<\/td>\n<td>\u90fd\u6ca1\u6709&#xff08;\u53ea\u6709 lint \/ test&#xff09;\u21d2 \u5b89\u88c5\u8def\u5f84\u5e72\u51c0<\/td>\n<\/tr>\n<tr>\n<td>main<\/td>\n<td>index.js&#xff08;\u6e90\u7801&#xff0c;\u4e0d\u662f\u4ea7\u7269&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u5bfc\u51fa\u5f62\u6001<\/td>\n<td>export default class SwitchSelector \u21d2 \u6709 default \u5bfc\u51fa&#xff0c;\u662f class<\/td>\n<\/tr>\n<tr>\n<td>\u9700\u8981 HAR \/ \u6743\u9650 \/ ohpm<\/td>\n<td>\u274c \u90fd\u4e0d\u9700\u8981<\/td>\n<\/tr>\n<tr>\n<td>\u8bbe\u5907\u4fa7\u65ad\u8a00<\/td>\n<td>\u2705 34 \/ 34 \u5168\u90e8\u901a\u8fc7&#xff08;A 25 &#043; B 8 &#043; C 1&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u2605\u2605 \u6700\u91cd\u8981\u7684\u5751<\/td>\n<td>initial \u9ed8\u8ba4 -1 \u21d2 \u6ed1\u5757\u989c\u8272 transparent \u21d2 \u5c4f\u4e0a\u5b8c\u5168\u770b\u4e0d\u5230\u6ed1\u5757&#xff08;\u4e0d\u62a5\u9519&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u2605 \u50cf\u7d20\u5224\u636e<\/td>\n<td>\u2705 \u6ed1\u5757 #BCD635&#xff1a;W1 \u5de6\u534a 37\u2026658\u3001W2 \u53f3\u534a 661\u20261282\u3001W3 \u65e0<\/td>\n<\/tr>\n<tr>\n<td>\u2605 \u4ea4\u4e92<\/td>\n<td>\u2705 \u70b9\u9009\u9879 \u21d2 onPress(off)&#xff08;\u62ff\u5230 value&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u4e8c\u3001\u5224\u5b9a\u4e0e\u63a5\u5165<\/h3>\n<table>\n<tr>\u6b65\u505a\u6cd5\u7ed3\u679c<\/tr>\n<tbody>\n<tr>\n<td>\u2460<\/td>\n<td>package.json \u91cc\u6709\u6ca1\u6709 harmony.autolinking<\/td>\n<td>\u6ca1\u6709<\/td>\n<\/tr>\n<tr>\n<td>\u2461<\/td>\n<td>\u4ed3\u5e93\u91cc\u6709\u6ca1\u6709 harmony\/<\/td>\n<td>\u6ca1\u6709<\/td>\n<\/tr>\n<tr>\n<td>\u2462<\/td>\n<td>\u4ee3\u7801\u91cc\u6709\u6ca1\u6709 NativeModules \/ requireNativeComponent<\/td>\n<td>\u5168\u65e0<\/td>\n<\/tr>\n<tr>\n<td>\u2463<\/td>\n<td>import \u56fe\u4f53\u68c0<\/td>\n<td>\u53ea\u6709 prop-types \/ react \/ react-native \u2713<\/td>\n<\/tr>\n<tr>\n<td>\u2464<\/td>\n<td>scripts \u626b prepare \u5bb6\u65cf<\/td>\n<td>\u6ca1\u6709 \u2713<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span class=\"token function\">npm<\/span> <span class=\"token function\">install<\/span> <span class=\"token string\">&#034;git&#043;https:\/\/atomgit.com\/oh-react-native\/react-native-switch-selector.git#2.3.0-ohos-1.0.0&#034;<\/span> &#8211;ignore-scripts<\/p>\n<p><span class=\"token comment\"># \u26a0\ufe0f \u5b83\u81ea\u5e26\u8fd0\u884c\u65f6\u4f9d\u8d56 prop-types&#xff0c;\u76ee\u5f55\/\u8f6f\u94fe\u63a5\u5165\u4e0d\u4f1a\u81ea\u52a8\u88c5<\/span><br \/>\n<span class=\"token function\">npm<\/span> <span class=\"token function\">install<\/span> prop-types &#8211;ignore-scripts<\/p>\n<p><span class=\"token comment\">\/\/ metro.config.js<\/span><br \/>\n<span class=\"token literal-property property\">watchFolders<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span> path<span class=\"token punctuation\">.<\/span><span class=\"token function\">resolve<\/span><span class=\"token punctuation\">(<\/span>__dirname<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;..\/react-native-switch-selector&#039;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><\/p>\n<p><span class=\"token keyword\">import<\/span> SwitchSelectorTestApp <span class=\"token keyword\">from<\/span> <span class=\"token string\">&#039;.\/SwitchSelectorTestApp&#039;<\/span><span class=\"token punctuation\">;<\/span><br \/>\nAppRegistry<span class=\"token punctuation\">.<\/span><span class=\"token function\">registerComponent<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;SwitchSelectorTestApp&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> SwitchSelectorTestApp<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>hdc shell aa force-stop com.rnoh084.demo<br \/>\nhdc shell aa start <span class=\"token parameter variable\">-b<\/span> com.rnoh084.demo <span class=\"token parameter variable\">-a<\/span> EntryAbility <span class=\"token parameter variable\">&#8211;ps<\/span> rnAppKey SwitchSelectorTestApp<\/p>\n<p>\u4e0d\u9700\u8981 HAR\u3001\u6743\u9650\u3001ohpm\u3001link-harmony\u3002<\/p>\n<hr \/>\n<h3>\u4e09\u3001\u8bfb\u6e90\u7801\u53d6\u5230\u7684\u771f\u503c&#xff08;index.js&#xff0c;336 \u884c&#xff09;<\/h3>\n<h4>3.1 \u7ec4\u4ef6\u5f62\u6001<\/h4>\n<p><span class=\"token keyword\">export<\/span> <span class=\"token keyword\">default<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">SwitchSelector<\/span> <span class=\"token keyword\">extends<\/span> <span class=\"token class-name\">Component<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  \u2026<br \/>\n  <span class=\"token comment\">\/\/ \u26a0\ufe0f \u4e0b\u9762\u4e09\u4e2a\u662f\u3010\u7bad\u5934\u51fd\u6570\u7684\u7c7b\u5b57\u6bb5\u3011\u21d2 \u6302\u5728\u3010\u5b9e\u4f8b\u3011\u4e0a&#xff0c;\u4e0d\u5728 prototype \u4e0a<\/span><br \/>\n  <span class=\"token function-variable function\">responderEnd<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token parameter\">evt<span class=\"token punctuation\">,<\/span> gestureState<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span> \u2026 <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token function-variable function\">animate<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token parameter\">value<span class=\"token punctuation\">,<\/span> last<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span> \u2026 <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token function-variable function\">toggleItem<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token parameter\">index<span class=\"token punctuation\">,<\/span> callOnPress <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">true<\/span><\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span> \u2026 <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\nSwitchSelector<span class=\"token punctuation\">.<\/span>defaultProps <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span> \u2026 <span class=\"token number\">30<\/span> \u4e2a\u952e \u2026 <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\nSwitchSelector<span class=\"token punctuation\">.<\/span>propTypes    <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span> \u2026 <span class=\"token number\">30<\/span> \u4e2a\u952e \u2026 <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8981\u70b9&#xff1a;<\/p>\n<li>class \u7ec4\u4ef6&#xff08;render \u5728 prototype \u4e0a&#xff09;\u21d2 defaultProps \u5728 React 19 \u4e0b\u4ecd\u7136\u751f\u6548 \u2713 \u800c\u4e14\u5b83\u6709 propTypes&#xff08;30 \u952e&#xff09;&#xff1b;<\/li>\n<li>\u26a0\ufe0f responderEnd \/ animate \/ toggleItem \u662f\u7bad\u5934\u51fd\u6570\u7c7b\u5b57\u6bb5 \u21d2 SwitchSelector.prototype.toggleItem &#061;&#061;&#061; undefined&#xff08;\u672c\u8f6e\u6211\u5728\u8fd9\u91cc\u5199\u9519\u8fc7\u65ad\u8a00&#xff0c;\u89c1\u7b2c\u516d\u8282&#xff09;&#xff1b;<\/li>\n<li>\u9ed8\u8ba4\u5bfc\u51fa\u662f class&#xff0c;\u53ef\u4ee5\u76f4\u63a5 import SwitchSelector from &#039;\u2026&#039;\u3002<\/li>\n<h4>3.2 \u2605\u2605 defaultProps \u91cc\u7684\u4e24\u4e2a&#034;\u9677\u9631\u9ed8\u8ba4\u503c&#034;<\/h4>\n<p>SwitchSelector<span class=\"token punctuation\">.<\/span>defaultProps <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token literal-property property\">options<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">textColor<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#039;#000000&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">selectedColor<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#039;#FFFFFF&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">fontSize<\/span><span class=\"token operator\">:<\/span> <span class=\"token number\">14<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">backgroundColor<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#039;#FFFFFF&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">borderColor<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#039;#C9C9C9&#039;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">borderRadius<\/span><span class=\"token operator\">:<\/span> <span class=\"token number\">50<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">borderWidth<\/span><span class=\"token operator\">:<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">hasPadding<\/span><span class=\"token operator\">:<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">valuePadding<\/span><span class=\"token operator\">:<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">height<\/span><span class=\"token operator\">:<\/span> <span class=\"token number\">40<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">bold<\/span><span class=\"token operator\">:<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">buttonMargin<\/span><span class=\"token operator\">:<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">buttonColor<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#039;#BCD635&#039;<\/span><span class=\"token punctuation\">,<\/span>      <span class=\"token comment\">\/\/ \u2605 \u6ed1\u5757\u7684\u9ed8\u8ba4\u989c\u8272<\/span><br \/>\n  <span class=\"token literal-property property\">returnObject<\/span><span class=\"token operator\">:<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">animationDuration<\/span><span class=\"token operator\">:<\/span> <span class=\"token number\">100<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">disabled<\/span><span class=\"token operator\">:<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">disableValueChangeOnPress<\/span><span class=\"token operator\">:<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">initial<\/span><span class=\"token operator\">:<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span>                 <span class=\"token comment\">\/\/ \u2605\u2605 \u9ed8\u8ba4 -1 \u21d2 \u6ed1\u5757\u900f\u660e&#xff01;<\/span><br \/>\n  <span class=\"token literal-property property\">value<\/span><span class=\"token operator\">:<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span>                    <span class=\"token comment\">\/\/ \u26a0\ufe0f \u5b83\u8fd8\u6709\u4e2a value \u9ed8\u8ba4\u503c&#xff08;\u53d7\u63a7\u7528&#xff09;<\/span><br \/>\n  <span class=\"token literal-property property\">onPress<\/span><span class=\"token operator\">:<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">accessibilityLabel<\/span><span class=\"token operator\">:<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">testID<\/span><span class=\"token operator\">:<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">touchableProps<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  \u2026<br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<table>\n<tr>\u9677\u9631\u8868\u73b0<\/tr>\n<tbody>\n<tr>\n<td>initial: -1<\/td>\n<td>state.selected &#061; -1 \u21d2 getBgColor() \u8fd4\u56de &#039;transparent&#039; \u21d2 \u6ed1\u5757\u4e0d\u53ef\u89c1&#xff08;\u5b9e\u6d4b&#xff1a;\u8be5\u989c\u8272 0 \u50cf\u7d20&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>value: 1<\/td>\n<td>componentDidUpdate \u91cc if (prevProps.value !&#061;&#061; value) toggleItem(value, \u2026) \u21d2 \u9996\u5e27\u540e\u5982\u679c value \u53d8\u5316\u4f1a\u9a71\u52a8\u9009\u4e2d\u9879&#xff1b;\u4e0d\u4f20 value \u65f6\u5b83\u662f 1&#xff0c;\u4e0e initial \u672a\u5fc5\u4e00\u81f4<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>3.3 \u2605 \u6ed1\u5757\u51e0\u4f55&#xff08;\u53ef\u7cbe\u786e\u9884\u8a00&#xff09;<\/h4>\n<p><span class=\"token comment\">\/\/ \u8f68\u9053 onLayout&#xff1a;<\/span><br \/>\n<span class=\"token keyword\">this<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">setState<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">{<\/span> <span class=\"token literal-property property\">sliderWidth<\/span><span class=\"token operator\">:<\/span> width <span class=\"token operator\">&#8211;<\/span> <span class=\"token punctuation\">(<\/span>hasPadding <span class=\"token operator\">?<\/span> <span class=\"token number\">2<\/span> <span class=\"token operator\">:<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u6ed1\u5757&#xff1a;<\/span><br \/>\n<span class=\"token literal-property property\">width<\/span><span class=\"token operator\">:<\/span> sliderWidth <span class=\"token operator\">\/<\/span> options<span class=\"token punctuation\">.<\/span>length <span class=\"token operator\">&#8211;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span>hasPadding <span class=\"token operator\">?<\/span> valuePadding <span class=\"token operator\">:<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#043;<\/span> buttonMargin <span class=\"token operator\">*<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token literal-property property\">transform<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">{<\/span> <span class=\"token literal-property property\">translateX<\/span><span class=\"token operator\">:<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">.<\/span>animatedValue<span class=\"token punctuation\">.<\/span><span class=\"token function\">interpolate<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token literal-property property\">inputRange<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  <span class=\"token literal-property property\">outputRange<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span>hasPadding <span class=\"token operator\">?<\/span> valuePadding <span class=\"token operator\">:<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> sliderWidth <span class=\"token operator\">&#8211;<\/span> <span class=\"token punctuation\">(<\/span>hasPadding <span class=\"token operator\">?<\/span> valuePadding <span class=\"token operator\">:<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u52a8\u753b&#xff1a;<\/span><br \/>\n<span class=\"token keyword\">this<\/span><span class=\"token punctuation\">.<\/span>animatedValue <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Animated<span class=\"token punctuation\">.<\/span>Value<\/span><span class=\"token punctuation\">(<\/span>initial <span class=\"token operator\">?<\/span> initial <span class=\"token operator\">\/<\/span> options<span class=\"token punctuation\">.<\/span>length <span class=\"token operator\">:<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function-variable function\">animate<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token parameter\">value<span class=\"token punctuation\">,<\/span> last<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">.<\/span>animatedValue<span class=\"token punctuation\">.<\/span><span class=\"token function\">setValue<\/span><span class=\"token punctuation\">(<\/span>last<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n  Animated<span class=\"token punctuation\">.<\/span><span class=\"token function\">timing<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">this<\/span><span class=\"token punctuation\">.<\/span>animatedValue<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token literal-property property\">toValue<\/span><span class=\"token operator\">:<\/span> value<span class=\"token punctuation\">,<\/span> <span class=\"token literal-property property\">duration<\/span><span class=\"token operator\">:<\/span> animationDuration<span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token literal-property property\">easing<\/span><span class=\"token operator\">:<\/span> Easing<span class=\"token punctuation\">.<\/span>cubic<span class=\"token punctuation\">,<\/span> <span class=\"token literal-property property\">useNativeDriver<\/span><span class=\"token operator\">:<\/span> <span class=\"token boolean\">true<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">start<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ toggleItem \u91cc&#xff1a;this.animate(index \/ options.length, selected \/ options.length)<\/span><\/p>\n<p>\u21d2 hasPadding&#061;false, buttonMargin&#061;0 \u65f6&#xff1a;\u6ed1\u5757\u5bbd\u5ea6 &#061; width\/N\u3001\u5de6\u8fb9\u754c &#061; (k\/N)\u00b7width \u21d2 \u6b63\u597d\u8986\u76d6\u7b2c k \u683c\u3002<\/p>\n<p>\u26a0\ufe0f useNativeDriver: true \u21d2 \u6ed1\u5757\u4f4d\u79fb\u662f transform &#043; \u539f\u751f\u9a71\u52a8 \u21d2 \u5e03\u5c40 dump \u8bfb\u4e0d\u5230 \u21d2 \u5fc5\u987b\u8d70\u50cf\u7d20\u3002<\/p>\n<h4>3.4 \u4ea4\u4e92\u4e0e\u8fb9\u754c<\/h4>\n<p><span class=\"token function-variable function\">toggleItem<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token parameter\">index<span class=\"token punctuation\">,<\/span> callOnPress <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">true<\/span><\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>options<span class=\"token punctuation\">.<\/span>length <span class=\"token operator\">&lt;&#061;<\/span> <span class=\"token number\">1<\/span> <span class=\"token operator\">||<\/span> index <span class=\"token operator\">&#061;&#061;&#061;<\/span> <span class=\"token keyword\">null<\/span> <span class=\"token operator\">||<\/span> <span class=\"token function\">isNaN<\/span><span class=\"token punctuation\">(<\/span>index<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span><span class=\"token punctuation\">;<\/span>    <span class=\"token comment\">\/\/ \u2605 \u8fb9\u754c\u2460<\/span><br \/>\n  <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">animate<\/span><span class=\"token punctuation\">(<\/span>\u2026<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>callOnPress <span class=\"token operator\">&amp;&amp;<\/span> onPress<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token function\">onPress<\/span><span class=\"token punctuation\">(<\/span>returnObject <span class=\"token operator\">?<\/span> options<span class=\"token punctuation\">[<\/span>index<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">:<\/span> options<span class=\"token punctuation\">[<\/span>index<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">.<\/span>value<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n  <span class=\"token keyword\">else<\/span> <span class=\"token punctuation\">{<\/span> console<span class=\"token punctuation\">.<\/span><span class=\"token function\">log<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;Call onPress with value: &#039;<\/span><span class=\"token punctuation\">,<\/span> options<span class=\"token punctuation\">[<\/span>index<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">.<\/span>value<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span>   <span class=\"token comment\">\/\/ \u2605 \u6ca1 onPress \u65f6\u6253\u65e5\u5fd7<\/span><br \/>\n  <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">setState<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">{<\/span> <span class=\"token literal-property property\">selected<\/span><span class=\"token operator\">:<\/span> index <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u2605 \u8fb9\u754c\u2461&#xff1a;value \u53d8\u5316\u65f6<\/span><br \/>\n<span class=\"token function\">componentDidUpdate<\/span><span class=\"token punctuation\">(<\/span><span class=\"token parameter\">prevProps<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">const<\/span> <span class=\"token punctuation\">{<\/span> value<span class=\"token punctuation\">,<\/span> disableValueChangeOnPress <span class=\"token punctuation\">}<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">.<\/span>props<span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>prevProps<span class=\"token punctuation\">.<\/span>value <span class=\"token operator\">!&#061;&#061;<\/span> value<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">toggleItem<\/span><span class=\"token punctuation\">(<\/span>value<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">!<\/span>disableValueChangeOnPress<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u2605 \u8fb9\u754c\u2462&#xff1a;\u62d6\u52a8\u5207\u6362&#xff08;PanResponder&#xff09;<\/span><br \/>\n<span class=\"token function-variable function\">shouldSetResponder<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token parameter\">evt<span class=\"token punctuation\">,<\/span> g<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> evt<span class=\"token punctuation\">.<\/span>nativeEvent<span class=\"token punctuation\">.<\/span>touches<span class=\"token punctuation\">.<\/span>length <span class=\"token operator\">&#061;&#061;&#061;<\/span> <span class=\"token number\">1<\/span><br \/>\n  <span class=\"token operator\">&amp;&amp;<\/span> <span class=\"token operator\">!<\/span><span class=\"token punctuation\">(<\/span>Math<span class=\"token punctuation\">.<\/span><span class=\"token function\">abs<\/span><span class=\"token punctuation\">(<\/span>g<span class=\"token punctuation\">.<\/span>dx<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">5<\/span> <span class=\"token operator\">&amp;&amp;<\/span> Math<span class=\"token punctuation\">.<\/span><span class=\"token function\">abs<\/span><span class=\"token punctuation\">(<\/span>g<span class=\"token punctuation\">.<\/span>dy<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">5<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>          <span class=\"token comment\">\/\/ \u9700\u8981\u771f\u7684\u62d6\u52a8<\/span><br \/>\n<span class=\"token function-variable function\">getSwipeDirection<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token parameter\">g<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">(<\/span>Math<span class=\"token punctuation\">.<\/span><span class=\"token function\">abs<\/span><span class=\"token punctuation\">(<\/span>g<span class=\"token punctuation\">.<\/span>vx<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0.1<\/span> <span class=\"token operator\">&amp;&amp;<\/span> Math<span class=\"token punctuation\">.<\/span><span class=\"token function\">abs<\/span><span class=\"token punctuation\">(<\/span>g<span class=\"token punctuation\">.<\/span>dy<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">80<\/span><span class=\"token punctuation\">)<\/span><br \/>\n  <span class=\"token operator\">?<\/span> <span class=\"token punctuation\">(<\/span>g<span class=\"token punctuation\">.<\/span>dx <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span> <span class=\"token operator\">?<\/span> <span class=\"token string\">&#039;RIGHT&#039;<\/span> <span class=\"token operator\">:<\/span> <span class=\"token string\">&#039;LEFT&#039;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">:<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">;<\/span>                  <span class=\"token comment\">\/\/ 0.1 \u901f\u5ea6\u9608\u503c<\/span><\/p>\n<hr \/>\n<h3>\u56db\u3001\u9a8c\u8bc1\u8bbe\u8ba1<\/h3>\n<table>\n<tr>\u5224\u636e\u5185\u5bb9<\/tr>\n<tbody>\n<tr>\n<td>\u2460 \u6ed1\u5757\u4f4d\u7f6e<\/td>\n<td>\u626b\u63cf\u6ed1\u5757\u989c\u8272 #BCD635&#xff0c;\u5176 x \u533a\u95f4\u5e94\u4e3a [\u5bb9\u5668\u5de6 &#043; (k\/N)\u00b7W, \u5bb9\u5668\u5de6 &#043; ((k&#043;1)\/N)\u00b7W]<\/td>\n<\/tr>\n<tr>\n<td>\u2461 \u6ed1\u5757\u6709\u65e0<\/td>\n<td>\u4e0d\u4f20 initial \u65f6&#xff0c;\u8be5\u989c\u8272\u5e94\u5b8c\u5168\u626b\u4e0d\u5230<\/td>\n<\/tr>\n<tr>\n<td>\u2462 \u9009\u9879\u547d\u4e2d\u533a<\/td>\n<td>\u6bcf\u4e2a\u9009\u9879\u7684 TouchableOpacity \u5e94\u5404\u5360 W\/N<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u4e94\u3001\u5b9e\u6d4b\u7ed3\u679c<\/h3>\n<h4>5.1 \u65ad\u8a00 34 \/ 34<\/h4>\n<table>\n<tr>\u7ec4\u5185\u5bb9\u7ed3\u679c<\/tr>\n<tbody>\n<tr>\n<td>A \u5951\u7ea6<\/td>\n<td>class \/ render \u5728 prototype\u3001\u4e09\u4e2a\u7bad\u5934\u51fd\u6570\u7c7b\u5b57\u6bb5\u4e0d\u5728 prototype\u3001defaultProps 30 \u952e\u4e0e\u5173\u952e\u503c&#xff08;initial -1\u3001buttonColor #BCD635\u2026&#xff09;\u3001propTypes 30 \u952e\u3001prop-types \u53ef\u52a0\u8f7d<\/td>\n<td>25\/25<\/td>\n<\/tr>\n<tr>\n<td>B \u6e32\u67d3\u4e0e\u51e0\u4f55<\/td>\n<td>5 \u4e2a\u5b9e\u4f8b\u6e32\u67d3\u672a\u629b\u9519\u3001\u6807\u9898\u4e0d\u4e0e\u72b6\u6001\u680f\u91cd\u5408\u3001\u5b9e\u4f8b\u5c3a\u5bf8\u3001\u5224\u636e\u8bf4\u660e<\/td>\n<td>8\/8<\/td>\n<\/tr>\n<tr>\n<td>C \u8fb9\u754c<\/td>\n<td>\u4e8b\u4ef6\u8bb0\u5f55\u683c\u5f0f &#043; \u56db\u6761\u8fb9\u754c\u8bf4\u660e<\/td>\n<td>1\/1<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>\u5408\u8ba1<\/td>\n<td>34\/34<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>5.2 \u2605\u2605 \u6ed1\u5757\u50cf\u7d20\u5224\u636e&#xff08;\u672c\u8f6e\u6838\u5fc3&#xff09;<\/h4>\n<p>\u5bb9\u5668\u5bbd 1248px\u3001\u5de6\u8fb9\u754c 36px\u3001N&#061;2 \u21d2 \u6bcf\u683c 624px&#xff1a;<\/p>\n<table>\n<tr>\u5b9e\u4f8b\u9884\u671f\u5b9e\u6d4b&#xff08;#BCD635 \u626b\u63cf&#xff09;\u5224\u5b9a<\/tr>\n<tbody>\n<tr>\n<td>W1&#xff08;initial&#061;0&#xff09;<\/td>\n<td>\u6ed1\u5757 x &#061; 36\u2026660<\/td>\n<td>37\u2026658<\/td>\n<td>\u2713<\/td>\n<\/tr>\n<tr>\n<td>W2&#xff08;initial&#061;1&#xff09;<\/td>\n<td>\u6ed1\u5757 x &#061; 660\u20261284<\/td>\n<td>661\u20261282<\/td>\n<td>\u2713<\/td>\n<\/tr>\n<tr>\n<td>W3&#xff08;\u4e0d\u4f20 initial&#xff09;<\/td>\n<td>\u65e0\u6ed1\u5757<\/td>\n<td>0 \u50cf\u7d20\u5339\u914d&#xff08;\u8fde\u7eed 5 \u884c\u90fd\u662f 0&#xff09;<\/td>\n<td>\u2713\u2713<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u21d2 \u201c\u4f20 initial \u5c31\u6709\u6ed1\u5757\u3001\u4f4d\u7f6e\u6b63\u786e&#xff1b;\u4e0d\u4f20\u5c31\u5b8c\u5168\u6ca1\u6709\u201d \u4e24\u4e2a\u7ed3\u8bba\u90fd\u6210\u7acb\u3002<\/p>\n<h4>5.3 \u2605 \u4ea4\u4e92\u4e0e\u9009\u9879\u547d\u4e2d\u533a<\/h4>\n<p>\u4ece\u5e03\u5c40 dump \u91cf W1 \u7684\u4e24\u4e2a\u9009\u9879&#xff1a;<\/p>\n<p>y&#061;901..950  x&#061;36..660  (w&#061;624)   \u2190 \u5de6\u4fa7\u9009\u9879<br \/>\ny&#061;901..950  x&#061;660..1284 (w&#061;624)  \u2190 \u53f3\u4fa7\u9009\u9879<\/p>\n<p>\u21d2 \u5404\u5360 624px &#061; W\/2 \u2713&#xff08;\u4e0e\u6ed1\u5757\u5bbd\u5ea6\u9884\u8a00\u4e00\u81f4&#xff09;\u3002<\/p>\n<p>\u70b9\u51fb\u53f3\u4fa7\u9009\u9879&#xff08;75% \u5904&#xff0c;\u5750\u6807 (990, 925)&#xff09;\u21d2 \u65e5\u5fd7&#xff1a;<\/p>\n<p>PRESS W1 onPress(off)<\/p>\n<p>\u21d2 onPress \u89e6\u53d1&#xff0c;\u4e14\u62ff\u5230\u7684\u662f\u8be5\u9009\u9879\u7684 value&#xff08;&#039;off&#039;&#xff09; \u2713&#xff08;returnObject \u4e3a false \u65f6\u7684\u884c\u4e3a&#xff09;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261022020801-6ad97001400b2.jpg\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261022020802-6ad97002a9c06.jpg\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>5.4 UI&#xff1a;\u6807\u9898\u4e0d\u4e0e\u72b6\u6001\u680f\u91cd\u5408<\/h4>\n<p>TITLE measureInWindow y&#061;420   &#xff08;\u72b6\u6001\u680f\u9ad8 117&#xff09;   \u21d2 420 &gt; 117&#xff0c;\u4e0d\u91cd\u5408 \u2713<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261022020803-6ad97003d62e4.jpg\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<hr \/>\n<h3>\u516d\u3001\u6211\u81ea\u5df1\u7684\u4e00\u4e2a\u5931\u8bef<\/h3>\n<p>\u6211\u628a toggleItem \/ animate \/ responderEnd \u5f53\u6210\u539f\u578b\u65b9\u6cd5\u53bb\u65ad\u8a00&#xff0c;\u7ed3\u679c\u4e09\u6761\u5168\u6302&#xff1a;<\/p>\n<p>\u2717 [A] \u539f\u578b\u4e0a\u6709 toggleItem&#xff5c;\u671f\u671b function&#xff5c;\u5b9e\u9645 undefined<br \/>\n\u2717 [A] \u539f\u578b\u4e0a\u6709 animate&#xff5c;\u671f\u671b function&#xff5c;\u5b9e\u9645 undefined<br \/>\n\u2717 [A] \u539f\u578b\u4e0a\u6709 responderEnd&#xff5c;\u671f\u671b function&#xff5c;\u5b9e\u9645 undefined<\/p>\n<p>\u8bfb\u6e90\u7801\u540e\u786e\u8ba4&#xff1a;\u5b83\u4eec\u662f\u7bad\u5934\u51fd\u6570\u7684\u7c7b\u5b57\u6bb5&#xff08;toggleItem &#061; (index, callOnPress &#061; true) &#061;&gt; {\u2026}&#xff09;\u2014\u2014 \u7ecf Babel \u7684 class-properties \u8f6c\u6362\u540e&#xff0c;\u5b83\u4eec\u88ab\u8d4b\u503c\u5230\u5b9e\u4f8b\u4e0a&#xff0c;\u800c\u4e0d\u5728 prototype \u4e0a\u3002<\/p>\n<p>\u7ea0\u6b63&#xff1a;\u65ad\u8a00\u6539\u4e3a typeof SS.prototype.toggleItem &#061;&#061;&#061; &#039;undefined&#039;&#xff08;\u5e76\u4fdd\u7559 prototype.render &#061;&#061;&#061; &#039;function&#039; \u4f5c\u4e3a&#034;\u5b83\u786e\u5b9e\u662f class&#034;\u7684\u8bc1\u636e&#xff09;\u3002<\/p>\n<p>\u6559\u8bad&#xff1a;&#034;\u5199\u5728 class \u4f53\u91cc\u7684\u65b9\u6cd5&#034;\u672a\u5fc5\u5728 prototype \u4e0a \u2014\u2014 \u7bad\u5934\u51fd\u6570\u5f62\u5f0f\u7684\u7c7b\u5b57\u6bb5\u6302\u5728\u5b9e\u4f8b\u4e0a\u3002\u21d2 \u8981\u5224\u65ad&#034;\u662f\u4e0d\u662f\u539f\u578b\u65b9\u6cd5&#034;&#xff0c;\u5f97\u770b\u5199\u6cd5&#xff08;method() {} vs field &#061; () &#061;&gt; {}&#xff09;&#xff0c;\u6216\u8005\u5e72\u8106\u7528 typeof proto.x \u5b9e\u6d4b\u3002<\/p>\n<hr \/>\n<h3>\u4e03\u3001\u5df2\u77e5\u9650\u5236\u4e0e\u672c\u6b21\u9a8c\u8bc1\u8fb9\u754c<\/h3>\n<h4>7.1 \u7528\u8fd9\u4e2a\u5e93\u8981\u77e5\u9053\u7684<\/h4>\n<table>\n<tr>\u4e8b\u9879\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u4e0d\u4f20 initial \u21d2 \u770b\u4e0d\u5230\u6ed1\u5757<\/td>\n<td>\u9ed8\u8ba4 -1 \u21d2 \u989c\u8272 transparent&#xff1b;\u4e0d\u62a5\u9519\u3002\u60f3\u6709\u6ed1\u5757\u5c31\u4f20 initial&#xff08;\u6216\u53d7\u63a7\u4f20 value&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>value \u9ed8\u8ba4\u662f 1<\/td>\n<td>componentDidUpdate \u91cc value \u53d8\u5316\u4f1a\u9a71\u52a8\u9009\u4e2d\u9879&#xff1b;\u4e0e initial \u4e0d\u662f\u4e00\u56de\u4e8b<\/td>\n<\/tr>\n<tr>\n<td>onPress \u62ff\u5230\u7684\u662f value<\/td>\n<td>\u4f20 returnObject \u624d\u62ff\u5230\u6574\u4e2a\u9009\u9879\u5bf9\u8c61<\/td>\n<\/tr>\n<tr>\n<td>\u6ca1\u4f20 onPress \u65f6\u4f1a\u6253 console.log<\/td>\n<td>Call onPress with value:  \u2026&#xff08;\u4e0d\u662f\u62a5\u9519&#xff0c;\u4f46\u65e5\u5fd7\u91cc\u4f1a\u770b\u5230&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>options.length &lt;&#061; 1 \u65f6\u70b9\u51fb\u65e0\u6548<\/td>\n<td>toggleItem \u76f4\u63a5 return<\/td>\n<\/tr>\n<tr>\n<td>\u62d6\u52a8\u5207\u6362\u6709\u9608\u503c<\/td>\n<td>\u9700 |dx|\u22655 \u6216 |dy|\u22655 \u624d\u63a5\u7ba1\u624b\u52bf&#xff1b;|vx|&gt;0.1 &amp;&amp; |dy|&lt;80 \u624d\u7b97\u5de6\u53f3\u6ed1\u52a8<\/td>\n<\/tr>\n<tr>\n<td>\u6ed1\u5757\u7528 useNativeDriver: true<\/td>\n<td>\u4f4d\u79fb\u662f transform \u21d2 \u5e03\u5c40 dump \u8bfb\u4e0d\u5230 \u21d2 \u53ea\u80fd\u50cf\u7d20\u9a8c<\/td>\n<\/tr>\n<tr>\n<td>\u6709\u8fd0\u884c\u65f6\u4f9d\u8d56 prop-types<\/td>\n<td>\u76ee\u5f55\/file: \u63a5\u5165\u8981\u624b\u52a8\u8865\u88c5<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>7.2 \u672c\u6b21\u9a8c\u8bc1\u7684\u8fb9\u754c<\/h4>\n<li>\u62d6\u52a8\/\u6ed1\u52a8\u5207\u6362&#xff08;PanResponder&#xff09;\u672a\u9a8c\u8bc1&#xff1a;\u53ea\u9a8c\u8bc1\u4e86\u70b9\u51fb\u9009\u9879\u7ed9\u56de\u8c03&#xff1b;getSwipeDirection \u7684 |vx|&gt;0.1 &amp;&amp; |dy|&lt;80 \u9608\u503c\u884c\u4e3a\u672a\u5b9e\u6d4b&#xff1b;<\/li>\n<li>disableValueChangeOnPress \u8fb9\u754c\u672a\u5b9e\u6d4b&#xff08;\u53ea\u4ece\u6e90\u7801\u786e\u8ba4\u8bed\u4e49&#xff1a;value \u53d8\u5316\u65f6\u53ea\u52a8\u4e0d\u7ed9\u56de\u8c03&#xff09;&#xff1b;<\/li>\n<li>options.length &lt;&#061; 1 \u7684\u8fb9\u754c\u672a\u5b9e\u6d4b&#xff08;\u53ea\u6e32\u67d3\u4e86 1 \u9009\u9879\u5b9e\u4f8b&#xff0c;\u6ca1\u6709\u53bb\u70b9\u5b83&#xff09;&#xff1b;<\/li>\n<li>returnObject \u672a\u5b9e\u6d4b&#xff08;W4 \u4f20\u4e86 returnObject \u4f46\u6ca1\u70b9\u5b83\u56de\u8bfb\u5bf9\u8c61&#xff09;&#xff1b;<\/li>\n<li>options[].activeColor&#xff08;\u6bcf\u9879\u72ec\u7acb\u6fc0\u6d3b\u8272&#xff09;\u672a\u6d4b&#xff1b;<\/li>\n<li>hasPadding \/ valuePadding \/ buttonMargin \u975e\u9ed8\u8ba4\u503c\u7684\u51e0\u4f55\u672a\u6d4b&#xff08;\u53ea\u9a8c\u8bc1\u4e86 hasPadding&#061;false, buttonMargin&#061;0 \u8fd9\u4e00\u7ec4&#xff09;&#xff1b;<\/li>\n<li>animationDuration \u7684\u4e2d\u95f4\u6001\u672a\u9a8c\u8bc1&#xff08;\u53ea\u5728\u52a8\u753b\u7ed3\u675f\u540e\u6d4b\u91cf&#xff09;&#xff1b;<\/li>\n<li>RTL&#xff08;I18nManager.isRTL&#xff09;\u5206\u652f\u672a\u6d4b&#xff1b;<\/li>\n<li>imageIcon \/ customIcon \u56fe\u6807\u6e32\u67d3\u672a\u6d4b&#xff08;assets\/*.gif \u53ea\u662f\u6587\u6863\u8d44\u6e90&#xff09;&#xff1b;<\/li>\n<li>\u53ea\u5728\u4e00\u53f0\u6a21\u62df\u5668\u4e0a\u9a8c\u8bc1&#xff08;Pura X View&#xff0c;density 3&#xff0c;1320\u00d72232&#xff09;&#xff0c;\u6ca1\u6709\u771f\u673a&#xff1b;\u672a\u505a\u8de8\u5e73\u53f0\u5bf9\u7167\u3002<\/li>\n<p>\u672a\u6539\u52a8\u5e93\u4ee3\u7801\u3002<\/p>\n<hr \/>\n<h3>\u516b\u3001\u5e38\u89c1\u95ee\u9898<\/h3>\n<p>Q1&#xff1a;\u6211\u7528\u4e86\u8fd9\u4e2a\u7ec4\u4ef6&#xff0c;\u4f46\u770b\u4e0d\u5230\u90a3\u4e2a\u4f1a\u6ed1\u52a8\u7684\u8272\u5757&#xff1f;<\/p>\n<p>\u5927\u6982\u7387\u662f\u6ca1\u4f20 initial\u3002 \u5b83\u7684\u9ed8\u8ba4\u503c\u662f -1&#xff0c;\u800c\u6e90\u7801\u91cc&#xff1a;<\/p>\n<p><span class=\"token function\">getBgColor<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">const<\/span> <span class=\"token punctuation\">{<\/span> selected <span class=\"token punctuation\">}<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">.<\/span>state<span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>selected <span class=\"token operator\">&#061;&#061;&#061;<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#039;transparent&#039;<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n  <span class=\"token keyword\">return<\/span> options<span class=\"token punctuation\">[<\/span>selected<span class=\"token punctuation\">]<\/span><span class=\"token operator\">?.<\/span>activeColor <span class=\"token operator\">||<\/span> buttonColor<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u21d2 \u6ed1\u5757\u88ab\u8bbe\u6210\u900f\u660e\u3002\u4f20 initial&#061;{0}&#xff08;\u6216\u53d7\u63a7\u5730\u4f20 value&#xff09;\u5373\u53ef&#xff1a;<\/p>\n<p>&lt;SwitchSelector initial&#061;{0} options&#061;{[{label:&#039;\u5f00&#039;,value:&#039;on&#039;},{label:&#039;\u5173&#039;,value:&#039;off&#039;}]} \/&gt;<\/p>\n<p>\u5b9e\u6d4b&#xff1a;\u4e0d\u4f20 initial \u7684\u5b9e\u4f8b&#xff0c;\u6309\u6ed1\u5757\u989c\u8272 #BCD635 \u626b\u5168\u5c4f 0 \u50cf\u7d20\u3002<\/p>\n<p>Q2&#xff1a;\u6ed1\u5757\u989c\u8272\/\u4f4d\u7f6e\u600e\u4e48\u7b97&#xff1f;<\/p>\n<ul>\n<li>\u989c\u8272&#xff1a;buttonColor&#xff08;\u9ed8\u8ba4 #BCD635&#xff09;&#xff0c;\u6216\u67d0\u4e2a\u9009\u9879\u7684 activeColor&#xff1b;<\/li>\n<li>\u4f4d\u7f6e&#xff08;hasPadding&#061;false, buttonMargin&#061;0&#xff09;&#xff1a;\u5de6\u8fb9\u754c &#061; (k\/N)\u00b7width\u3001\u5bbd &#061; width\/N&#xff0c;\u6b63\u597d\u8986\u76d6\u7b2c k \u683c&#xff08;\u5b9e\u6d4b N&#061;2 \u65f6 37\u2026658 \u4e0e 661\u20261282&#xff09;\u3002<\/li>\n<\/ul>\n<p>Q3&#xff1a;onPress \u7ed9\u7684\u662f\u4ec0\u4e48&#xff1f;<\/p>\n<p>\u9ed8\u8ba4\u7ed9\u8be5\u9009\u9879\u7684 value&#xff08;returnObject: false&#xff09;\u3002\u4f20 returnObject \u5219\u7ed9\u6574\u4e2a\u9009\u9879\u5bf9\u8c61\u3002<\/p>\n<p>onPress&#061;{(v) &#061;&gt; console.log(v)}            \/\/ &#039;off&#039;<br \/>\nonPress&#061;{(v) &#061;&gt; console.log(v.label)}      \/\/ \u9700\u8981 returnObject<\/p>\n<p>\u26a0\ufe0f \u4e0d\u4f20 onPress \u65f6\u6e90\u7801\u4f1a console.log(&#039;Call onPress with value: &#039;, \u2026)&#xff08;\u4e0d\u662f\u62a5\u9519&#xff09;\u3002<\/p>\n<p>Q4&#xff1a;\u4e3a\u4ec0\u4e48\u6211\u6539 value \u4e4b\u540e\u754c\u9762\u52a8\u4e86&#xff0c;\u4f46 onPress \u6ca1\u89e6\u53d1&#xff1f;<\/p>\n<p>\u56e0\u4e3a componentDidUpdate \u662f&#xff1a;this.toggleItem(value, !disableValueChangeOnPress) \u2014\u2014 disableValueChangeOnPress: true \u65f6\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f false&#xff0c;\u4e8e\u662f\u53ea\u505a\u52a8\u753b &#043; setState&#xff0c;\u4e0d\u7ed9\u56de\u8c03\u3002<\/p>\n<p>Q5&#xff1a;\u4e3a\u4ec0\u4e48\u70b9\u7b2c 1 \u4e2a\u9009\u9879\u6ca1\u53cd\u5e94&#xff1f;<\/p>\n<p>\u5982\u679c options.length &lt;&#061; 1&#xff0c;toggleItem \u4f1a\u76f4\u63a5 return&#xff08;\u6e90\u7801\u7b2c\u4e00\u884c\u5b88\u536b&#xff09;\u3002\u53e6\u5916 disabled \u6216 options[i].disabled \u4e5f\u4f1a\u8ba9\u8be5\u9009\u9879\u4e0d\u53ef\u70b9\u3002<\/p>\n<p>Q6&#xff1a;\u80fd\u5de6\u53f3\u6ed1\u52a8\u5207\u6362\u5417&#xff1f;<\/p>\n<p>\u80fd&#xff08;PanResponder&#xff09;\u3002\u4f46\u8981\u6ce8\u610f\u9608\u503c&#xff1a;shouldSetResponder \u8981\u6c42\u4f4d\u79fb \u22655&#xff0c;getSwipeDirection \u8981\u6c42 |vx| &gt; 0.1 \u4e14 |dy| &lt; 80 \u21d2 \u8f7b\u8f7b\u4e00\u78b0\u4e0d\u4f1a\u5207&#xff0c;\u5f97\u662f\u6709\u70b9\u901f\u5ea6\u7684\u6a2a\u5411\u62d6\u52a8\u3002&#xff08;\u672c\u8f6e\u672a\u5b9e\u6d4b\u8fd9\u6761\u3002&#xff09;<\/p>\n<p>Q7&#xff1a;npm install \u4e4b\u540e\u62a5\u627e\u4e0d\u5230 prop-types&#xff1f;<\/p>\n<p>\u56e0\u4e3a\u5b83\u5e26\u4e86\u8fd0\u884c\u65f6\u4f9d\u8d56 prop-types&#064;^15.7.2&#xff0c;\u800c\u76ee\u5f55\/file: \u63a5\u5165\u4e0d\u4f1a\u5b89\u88c5\u76ee\u6807\u5305\u81ea\u5df1\u7684 dependencies&#xff1a;<\/p>\n<p><span class=\"token function\">npm<\/span> <span class=\"token function\">install<\/span> prop-types &#8211;ignore-scripts<\/p>\n<p>&#xff08;\u8d70 .tgz \u5b89\u88c5\u4f1a\u88ab\u81ea\u52a8\u5e26\u4e0a\u3002&#xff09;<\/p>\n<p>Q8&#xff1a;\u8fd9\u4e2a\u5e93\u9700\u8981\u9e3f\u8499\u4fa7\u505a\u4ec0\u4e48\u7279\u6b8a\u5904\u7406\u5417&#xff1f;<\/p>\n<p>\u4e0d\u9700\u8981\u3002 \u7eaf JS\u3001\u65e0\u539f\u751f\u6a21\u5757\u3001\u4e0d\u9700\u8981 HAR \/ \u6743\u9650 \/ ohpm\u3002\u552f\u4e00\u8981\u6ce8\u610f\u7684\u662f\u4e0a\u6587\u90a3\u6761 initial \u9ed8\u8ba4\u503c\u548c prop-types \u4f9d\u8d56\u3002<\/p>\n<hr \/>\n<h3>\u5c0f\u7ed3<\/h3>\n<p>react-native-switch-selector \u662f\u7eaf JS class \u7ec4\u4ef6&#xff08;index.js 336 \u884c&#xff09;&#xff0c;\u96f6\u539f\u751f\u63a5\u7ebf\u3002\u8bbe\u5907\u4fa7 34 \/ 34 \u65ad\u8a00\u901a\u8fc7\u3002<\/p>\n<p>\u6700\u503c\u5f97\u8bb0\u4e0b\u6765\u7684\u662f\u8fd9\u51e0\u6761&#xff1a;<\/p>\n<li>\n<p>\u2605\u2605 &#034;\u9ed8\u8ba4\u503c&#034;\u672c\u8eab\u53ef\u80fd\u5c31\u662f\u5751\u3002 initial \u9ed8\u8ba4 -1 \u21d2 getBgColor() \u8fd4\u56de transparent \u21d2 \u6ed1\u5757\u5b8c\u5168\u4e0d\u53ef\u89c1&#xff0c;\u800c\u4e14\u4e0d\u62a5\u9519\u3002\u21d2 \u63a5\u4e00\u4e2a\u7ec4\u4ef6\u65f6&#xff0c;\u628a defaultProps \u9010\u4e2a\u8fc7\u4e00\u904d&#xff0c;\u7279\u522b\u662f\u6709&#034;\u54e8\u5175\u503c&#034;&#xff08;-1 \/ null \/ &#039;&#039;&#xff09;\u7684\u5b57\u6bb5 \u2014\u2014 \u5b83\u4eec\u5f80\u5f80\u4ee3\u8868&#034;\u672a\u521d\u59cb\u5316&#034;\u72b6\u6001&#xff0c;\u4f1a\u6539\u53d8\u6e32\u67d3\u7ed3\u679c\u3002&#xff08;\u8fd9\u4e0e&#034;\u67d0\u7c7b\u4f9d\u8d56\u7f3a\u5931\u5bfc\u81f4\u6548\u679c\u9759\u9ed8\u6d88\u5931&#034;\u5c5e\u4e8e\u540c\u4e00\u65cf\u95ee\u9898&#xff1a;\u5171\u540c\u70b9\u662f\u4e0d\u62a5\u9519\u3002&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u2605 \u6ed1\u5757\u51e0\u4f55\u6709\u95ed\u5f0f\u516c\u5f0f \u21d2 \u76f4\u63a5\u5f53\u5224\u636e\u3002 \u6ed1\u5757\u5de6\u8fb9\u754c &#061; (k\/N)\u00b7width\u3001\u5bbd &#061; width\/N \u21d2 \u5b9e\u6d4b N&#061;2 \u65f6 37\u2026658 \/ 661\u20261282&#xff0c;\u7b2c\u4e09\u4e2a\u5b9e\u4f8b 0 \u50cf\u7d20&#xff08;\u56e0\u4e3a\u4e0d\u4f20 initial&#xff09;\u3002\u21d2 \u4e09\u4e2a\u5b9e\u4f8b\u4e00\u6b21\u628a&#034;\u4f4d\u7f6e\u5bf9\u4e0d\u5bf9&#034;\u548c&#034;\u6709\u6ca1\u6709&#034;\u90fd\u9a8c\u6389\u4e86\u3002<\/p>\n<\/li>\n<li>\n<p>\u2605 &#034;\u5199\u5728 class \u91cc\u7684\u65b9\u6cd5&#034;\u672a\u5fc5\u5728 prototype \u4e0a\u3002 toggleItem &#061; (&#8230;) &#061;&gt; {} \u8fd9\u79cd\u7bad\u5934\u51fd\u6570\u7c7b\u5b57\u6bb5\u88ab\u8d4b\u5230\u5b9e\u4f8b\u4e0a \u21d2 prototype.toggleItem &#061;&#061;&#061; undefined\u3002\u6211\u6309\u539f\u578b\u65b9\u6cd5\u5199\u65ad\u8a00&#xff0c;\u4e00\u6b21\u6302\u4e09\u6761\u3002\u21d2 \u5224\u65ad\u8981\u770b\u5199\u6cd5&#xff08;m(){} vs f &#061; () &#061;&gt; {}&#xff09;&#xff0c;\u6216\u7528 typeof proto.x \u5b9e\u6d4b\u3002<\/p>\n<\/li>\n<li>\n<p>\u9009\u9879\u547d\u4e2d\u533a\u4e5f\u80fd\u5f53\u514d\u8d39\u5224\u636e\u3002 \u4ece dump \u91cf\u5230\u4e24\u4e2a\u9009\u9879\u5404\u5360 624px &#061; W\/2&#xff0c;\u4e0e\u6ed1\u5757\u5bbd\u5ea6\u9884\u8a00\u4e92\u76f8\u5370\u8bc1&#xff1b;\u518d\u52a0\u4e00\u6b21\u70b9\u51fb\u62ff\u5230 onPress(off)&#xff0c;\u5c31\u540c\u65f6\u8986\u76d6\u4e86&#034;\u5e03\u5c40&#034;\u548c&#034;\u4ea4\u4e92&#034;\u3002<\/p>\n<\/li>\n<hr \/>\n<h3>\u672c\u7bc7\u7528\u5230\u7684\u5e93<\/h3>\n<table>\n<tr>\u9879\u5185\u5bb9<\/tr>\n<tbody>\n<tr>\n<td>\u4e09\u65b9\u5e93<\/td>\n<td>react-native-switch-selector&#xff08;\u4e0a\u6e38 2.3.0 \u7684\u9e3f\u8499\u9002\u914d\u7248&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u9002\u914d\u4ed3\u5e93<\/td>\n<td>https:\/\/atomgit.com\/oh-react-native\/react-native-switch-selector<\/td>\n<\/tr>\n<tr>\n<td>\u9002\u914d TAG<\/td>\n<td>2.3.0-ohos-1.0.0<\/td>\n<\/tr>\n<tr>\n<td>\u9700\u8981 HAR \/ \u6743\u9650 \/ ohpm<\/td>\n<td>\u90fd\u4e0d\u9700\u8981&#xff08;\u7eaf JS&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u5e93\u7c7b\u578b<\/td>\n<td>\u7eaf JS \u5355\u7ec4\u4ef6\u5e93&#xff1a;\u4e8c\u9009\u4e00\u5f00\u5173 \/ \u5206\u6bb5\u5f00\u5173&#xff08;\u5e26\u6ed1\u52a8\u5207\u6362&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u8fd0\u884c\u65f6\u4f9d\u8d56<\/td>\n<td>\u26a0\ufe0f prop-types&#064;^15.7.2 \u21d2 \u76ee\u5f55\/file: \u63a5\u5165\u987b\u624b\u52a8\u8865\u88c5<\/td>\n<\/tr>\n<tr>\n<td>prepare \/ prepublish<\/td>\n<td>\u90fd\u6ca1\u6709<\/td>\n<\/tr>\n<tr>\n<td>\u8bb8\u53ef\u8bc1<\/td>\n<td>MIT<\/td>\n<\/tr>\n<tr>\n<td>\u4e0a\u6e38\u4ed3\u5e93<\/td>\n<td>https:\/\/github.com\/jkdrangel\/react-native-switch-selector&#xff08;\u260546&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u5bbf\u4e3b\u5de5\u7a0b<\/td>\n<td>RNOH084Demo&#xff08;\u6d4b\u8bd5\u9875 rnAppKey &#061; SwitchSelectorTestApp&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span class=\"token comment\"># \u4ece\u9002\u914d\u4ed3\u5e93\u5b89\u88c5<\/span><br \/>\n<span class=\"token function\">npm<\/span> <span class=\"token function\">install<\/span> <span class=\"token string\">&#034;git&#043;https:\/\/atomgit.com\/oh-react-native\/react-native-switch-selector.git#2.3.0-ohos-1.0.0&#034;<\/span> &#8211;ignore-scripts<\/p>\n<p><span class=\"token comment\"># \u672c\u5730\u76ee\u5f55\u63a5\u5165&#xff08;\u5f00\u53d1\u5e38\u7528&#xff09;&#xff1a;\u5fc5\u987b\u8865 prop-types<\/span><br \/>\n<span class=\"token function\">npm<\/span> <span class=\"token function\">install<\/span> <span class=\"token punctuation\">..<\/span>\/react-native-switch-selector &#8211;ignore-scripts<br \/>\n<span class=\"token function\">npm<\/span> <span class=\"token function\">install<\/span> prop-types &#8211;ignore-scripts<\/p>\n<p><span class=\"token comment\">\/\/ metro.config.js<\/span><br \/>\n<span class=\"token literal-property property\">watchFolders<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span> path<span class=\"token punctuation\">.<\/span><span class=\"token function\">resolve<\/span><span class=\"token punctuation\">(<\/span>__dirname<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;..\/react-native-switch-selector&#039;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><\/p>\n<p>import SwitchSelector from &#039;react-native-switch-selector&#039;;<\/p>\n<p>\/\/ \u2705 \u6b63\u786e&#xff1a;\u4f20 initial&#xff08;\u5426\u5219\u6ed1\u5757\u900f\u660e&#xff0c;\u5c4f\u4e0a\u770b\u4e0d\u5230&#xff09;<br \/>\n&lt;SwitchSelector<br \/>\n  initial&#061;{0}<br \/>\n  options&#061;{[<br \/>\n    {label: &#039;\u5f00&#039;, value: &#039;on&#039;},<br \/>\n    {label: &#039;\u5173&#039;, value: &#039;off&#039;},<br \/>\n  ]}<br \/>\n  onPress&#061;{(value) &#061;&gt; console.log(&#039;\u9009\u4e2d&#039;, value)}      \/\/ \u9ed8\u8ba4\u62ff\u5230 value<br \/>\n\/&gt;<\/p>\n<p>\/\/ \u53d7\u63a7 &#043; \u60f3\u8981\u6574\u4e2a\u9009\u9879\u5bf9\u8c61<br \/>\nconst [v, setV] &#061; useState(0);<br \/>\n&lt;SwitchSelector<br \/>\n  initial&#061;{0}<br \/>\n  value&#061;{v}<br \/>\n  returnObject<br \/>\n  options&#061;{[{label:&#039;A&#039;,value:&#039;a&#039;},{label:&#039;B&#039;,value:&#039;b&#039;},{label:&#039;C&#039;,value:&#039;c&#039;}]}<br \/>\n  onPress&#061;{(opt) &#061;&gt; setV(opt.value &#061;&#061;&#061; &#039;b&#039; ? 1 : opt.value &#061;&#061;&#061; &#039;c&#039; ? 2 : 0)}<br \/>\n\/&gt;<\/p>\n<p>\/\/ \u81ea\u5b9a\u4e49\u5916\u89c2&#xff08;\u542b\u6ed1\u5757\u989c\u8272&#xff09;<br \/>\n&lt;SwitchSelector<br \/>\n  initial&#061;{1}<br \/>\n  options&#061;{[{label:&#039;\u662f&#039;,value:&#039;y&#039;},{label:&#039;\u5426&#039;,value:&#039;n&#039;}]}<br \/>\n  buttonColor&#061;&#034;#BCD635&#034;          \/\/ \u6ed1\u5757\u989c\u8272<br \/>\n  selectedColor&#061;&#034;#FFFFFF&#034;        \/\/ \u9009\u4e2d\u9879\u6587\u5b57\u8272<br \/>\n  textColor&#061;&#034;#000000&#034;<br \/>\n  backgroundColor&#061;&#034;#FFFFFF&#034;<br \/>\n  borderColor&#061;&#034;#C9C9C9&#034;<br \/>\n  borderRadius&#061;{50}<br \/>\n  height&#061;{40}<br \/>\n  animationDuration&#061;{100}<br \/>\n\/&gt;<\/p>\n<p><span class=\"token comment\"># \u6362\u9875\u542f\u52a8\u6d4b\u8bd5\u9875&#xff08;force-stop \u4e0d\u80fd\u7701&#xff0c;\u6362\u9875\u53c2\u6570\u53ea\u5728\u51b7\u542f\u52a8\u751f\u6548&#xff09;<\/span><br \/>\nhdc shell aa force-stop com.rnoh084.demo<br \/>\nhdc shell aa start <span class=\"token parameter variable\">-b<\/span> com.rnoh084.demo <span class=\"token parameter variable\">-a<\/span> EntryAbility <span class=\"token parameter variable\">&#8211;ps<\/span> rnAppKey SwitchSelectorTestApp<\/p>\n<h4>\u50cf\u7d20\u5224\u636e\u7684\u590d\u73b0\u65b9\u5f0f<\/h4>\n<p><span class=\"token comment\"># \u6ed1\u5757\u989c\u8272 &#061; buttonColor&#xff08;\u9ed8\u8ba4 #BCD635 &#061; RGB 188,214,53&#xff09;<\/span><br \/>\n<span class=\"token function\">Add-Type<\/span> <span class=\"token operator\">&#8211;<\/span>AssemblyName System<span class=\"token punctuation\">.<\/span>Drawing<br \/>\n<span class=\"token variable\">$b<\/span> &#061; <span class=\"token function\">New-Object<\/span> System<span class=\"token punctuation\">.<\/span>Drawing<span class=\"token punctuation\">.<\/span>Bitmap<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;shot.jpeg&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token variable\">$xs<\/span> &#061; &#064;<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token variable\">$x<\/span> &#061; 0<span class=\"token punctuation\">;<\/span> <span class=\"token variable\">$x<\/span> <span class=\"token operator\">-lt<\/span> <span class=\"token variable\">$b<\/span><span class=\"token punctuation\">.<\/span>Width<span class=\"token punctuation\">;<\/span> <span class=\"token variable\">$x<\/span><span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token variable\">$p<\/span> &#061; <span class=\"token variable\">$b<\/span><span class=\"token punctuation\">.<\/span>GetPixel<span class=\"token punctuation\">(<\/span><span class=\"token variable\">$x<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token variable\">$trackMidY<\/span><span class=\"token punctuation\">)<\/span><br \/>\n  <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token namespace\">[Math]<\/span>::Abs<span class=\"token punctuation\">(<\/span><span class=\"token variable\">$p<\/span><span class=\"token punctuation\">.<\/span>R-188<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">-lt<\/span> 26 <span class=\"token operator\">-and<\/span> <span class=\"token namespace\">[Math]<\/span>::Abs<span class=\"token punctuation\">(<\/span><span class=\"token variable\">$p<\/span><span class=\"token punctuation\">.<\/span>G-214<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">-lt<\/span> 26 <span class=\"token operator\">-and<\/span> <span class=\"token namespace\">[Math]<\/span>::Abs<span class=\"token punctuation\">(<\/span><span class=\"token variable\">$p<\/span><span class=\"token punctuation\">.<\/span>B-53<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">-lt<\/span> 26<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token variable\">$xs<\/span> <span class=\"token operator\">&#043;&#061;<\/span> <span class=\"token variable\">$x<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token comment\"># N&#061;2 \u65f6&#xff1a;k&#061;0 \u21d2 \u5de6\u534a&#xff1b;k&#061;1 \u21d2 \u53f3\u534a&#xff1b;\u4e0d\u4f20 initial \u21d2 \u4e00\u4e2a\u50cf\u7d20\u90fd\u626b\u4e0d\u5230<\/span><\/p>\n<h3>\u9a8c\u8bc1\u73af\u5883<\/h3>\n<table>\n<tr>\u9879\u7248\u672c<\/tr>\n<tbody>\n<tr>\n<td>React Native<\/td>\n<td>0.84.1<\/td>\n<\/tr>\n<tr>\n<td>React<\/td>\n<td>19.2.3<\/td>\n<\/tr>\n<tr>\n<td>RNOH&#xff08;npm \/ ohpm&#xff09;<\/td>\n<td>&#064;react-native-oh\/react-native-harmony \/ &#064;rnoh\/react-native-openharmony 0.84.3<\/td>\n<\/tr>\n<tr>\n<td>Node.js \/ npm<\/td>\n<td>v24.14.0 \/ 11.9.0<\/td>\n<\/tr>\n<tr>\n<td>DevEco Studio<\/td>\n<td>26.0.0.621<\/td>\n<\/tr>\n<tr>\n<td>HarmonyOS SDK<\/td>\n<td>API 26&#xff08;26.0.0.32&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u8bbe\u5907<\/td>\n<td>HarmonyOS 7.0.0(26.0.0) Beta2 \u6a21\u62df\u5668 Pura X View&#xff08;ohos-x64&#xff09;&#xff0c;1320\u00d72232&#xff0c;density 3<\/td>\n<\/tr>\n<tr>\n<td>\u672c\u673a\u72b6\u6001\u680f\u9ad8\u5ea6<\/td>\n<td>117px&#xff08;\u9875\u9762\u7559\u767d\u53d6 48vp&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u5bbf\u4e3b prop-types<\/td>\n<td>15.8.1&#xff08;\u5df2\u5b58\u5728 \u21d2 \u672c\u8f6e\u672a\u88ab\u4f9d\u8d56\u5751\u54ac\u5230&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u5bbf\u4e3b HAP \u4ea7\u7269<\/td>\n<td>entry-default-signed.hap<\/td>\n<\/tr>\n<tr>\n<td>\u672c\u6b21\u6784\u5efa<\/td>\n<td>assembleHap 3 \u5206 37 \u79d2&#xff1b;\u6539\u65ad\u8a00\u540e\u91cd\u7f16 3 \u5206 52 \u79d2<\/td>\n<\/tr>\n<tr>\n<td>\u9a8c\u8bc1\u89c4\u6a21<\/td>\n<td>\u8bbe\u5907\u4fa7 34 \/ 34 \u65ad\u8a00&#xff1b;\u6ed1\u5757\u50cf\u7d20\u5224\u636e 3 \u4e2a\u5b9e\u4f8b&#xff08;\u5de6\u534a 37\u2026658 \/ \u53f3\u534a 661\u20261282 \/ \u4e0d\u4f20 initial \u4e3a 0 \u50cf\u7d20&#xff09;&#xff1b;\u9009\u9879\u547d\u4e2d\u533a 2 \u5904&#xff08;\u5404 624px&#xff09;&#xff1b;\u4ea4\u4e92 1 \u6b21&#xff08;onPress(off)&#xff09;&#xff1b;UI \u5b89\u5168\u533a 1 \u9879<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u76f8\u5173\u793e\u533a\u4e0e\u9879\u76ee\u5730\u5740<\/h3>\n<table>\n<tr>\u9879\u76ee\u5730\u5740<\/tr>\n<tbody>\n<tr>\n<td>React Native \u9e3f\u8499\u5b98\u65b9\u793e\u533a&#xff08;CPF-RN&#xff09;<\/td>\n<td>https:\/\/atomgit.com\/CPF-RN<\/td>\n<\/tr>\n<tr>\n<td>RNOH \u6846\u67b6\u4ed3\u5e93<\/td>\n<td>https:\/\/atomgit.com\/openharmony-RN\/ohos_react_native<\/td>\n<\/tr>\n<tr>\n<td>RNOH \u4e09\u65b9\u5e93\u4f7f\u7528\u6587\u6863<\/td>\n<td>https:\/\/atomgit.com\/OpenHarmony-RN\/usage-docs<\/td>\n<\/tr>\n<tr>\n<td>React Native for OpenHarmony \u7ec4\u7ec7<\/td>\n<td>https:\/\/atomgit.com\/oh-react-native<\/td>\n<\/tr>\n<tr>\n<td>RN \u4e09\u65b9\u5e93\u9e3f\u8499\u9002\u914d\u6e05\u5355<\/td>\n<td>https:\/\/atomgit.com\/oh-react-native\/rn-ohos-adaptation-overview<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6b22\u8fce\u52a0\u5165 CPF-RN \u9e3f\u8499\u793e\u533a&#xff1a;https:\/\/atomgit.com\/CPF-RN<\/p>\n<p>React Native for OpenHarmony \u7ec4\u7ec7&#xff1a;https:\/\/atomgit.com\/oh-react-native<\/p>\n<p>RN \u4e09\u65b9\u5e93\u9e3f\u8499\u9002\u914d\u6e05\u5355&#xff1a;https:\/\/atomgit.com\/oh-react-native\/rn-ohos-adaptation-overview<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/#content_views .toc,\/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/#content_views.markdown_views &gt; p:empty:has(+ .toc),#content_views.markdown_views &gt; .toc + p:empty,\/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/#content<\/p>\n","protected":false},"author":2,"featured_media":117012,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[6800,280,187,524,67],"topic":[],"class_list":["post-117016","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-react-native","tag-harmonyos","tag-javascript","tag-react-js","tag-67"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>React Native for OpenHarmony \u5b9e\u6218\uff1a\u4e09\u65b9\u5e93 react-native-switch-selector \u7684\u9e3f\u8499\u5316\u9002\u914d\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/117016.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"React Native for OpenHarmony \u5b9e\u6218\uff1a\u4e09\u65b9\u5e93 react-native-switch-selector \u7684\u9e3f\u8499\u5316\u9002\u914d\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/#content_views .toc,\/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/#content_views.markdown_views &gt; p:empty:has(+ .toc),#content_views.markdown_views &gt; .toc + p:empty,\/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/#content\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/117016.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-22T02:08:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261022020759-6ad96fff18416.jpg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/117016.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/117016.html\",\"name\":\"React Native for OpenHarmony \u5b9e\u6218\uff1a\u4e09\u65b9\u5e93 react-native-switch-selector \u7684\u9e3f\u8499\u5316\u9002\u914d\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-22T02:08:06+00:00\",\"dateModified\":\"2026-10-22T02:08:06+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/117016.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/117016.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/117016.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"React Native for OpenHarmony \u5b9e\u6218\uff1a\u4e09\u65b9\u5e93 react-native-switch-selector \u7684\u9e3f\u8499\u5316\u9002\u914d\u6307\u5357\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"React Native for OpenHarmony \u5b9e\u6218\uff1a\u4e09\u65b9\u5e93 react-native-switch-selector \u7684\u9e3f\u8499\u5316\u9002\u914d\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/117016.html","og_locale":"zh_CN","og_type":"article","og_title":"React Native for OpenHarmony \u5b9e\u6218\uff1a\u4e09\u65b9\u5e93 react-native-switch-selector \u7684\u9e3f\u8499\u5316\u9002\u914d\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\/* MD \/ \u5bcc\u6587\u672c\u4e2d\u7684 .toc\uff08\u542b\u535a\u5ba2\u56ed\u642c\u5bb6\u7b49\u5d4c\u5957\u7ed3\u6784\uff09\uff1b.toc-box \u5728\u4fa7\u680f\uff0c\u4e0d\u53d7\u5f71\u54cd *\/#content_views .toc,\/* \u7f16\u8f91\u5668\u5e38\u5728\u76ee\u5f55\u524d\u540e\u63d2\u5165\u7a7a p\uff08:empty \u4ecd\u5360 20px\uff09\uff0c\u4e00\u5e76\u53bb\u6389\u907f\u514d\u9876\u7a7a\u9699 *\/#content_views.markdown_views &gt; p:empty:has(+ .toc),#content_views.markdown_views &gt; .toc + p:empty,\/* \u5bcc\u6587\u672c\u65e7\u7248\u76ee\u5f55\u6807\u8bb0 *\/#content","og_url":"https:\/\/www.wsisp.com\/helps\/117016.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-22T02:08:06+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261022020759-6ad96fff18416.jpg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/117016.html","url":"https:\/\/www.wsisp.com\/helps\/117016.html","name":"React Native for OpenHarmony \u5b9e\u6218\uff1a\u4e09\u65b9\u5e93 react-native-switch-selector \u7684\u9e3f\u8499\u5316\u9002\u914d\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-22T02:08:06+00:00","dateModified":"2026-10-22T02:08:06+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/117016.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/117016.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/117016.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"React Native for OpenHarmony \u5b9e\u6218\uff1a\u4e09\u65b9\u5e93 react-native-switch-selector \u7684\u9e3f\u8499\u5316\u9002\u914d\u6307\u5357"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/117016","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=117016"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/117016\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/117012"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=117016"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=117016"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=117016"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=117016"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}