æè¯è¿ç¨å½å
ç HBuilder + MUI æ¡æ¶å¼åï¼ä¹è¯è¿ Cordova + React for Web
å¼åãç°å¨æä¸çæAppï¼æ£å¨åæ¥ä½¿ç¨ Cordova + React å React Native åå«å¼å UI
å±ï¼é»è¾å±ä»£ç å
¬ç¨ï¼ãå½ç¶ï¼é½æ¯å°ååºç¨ï¼è¿ä¸éè¦å @æç»´ç¹ åçä¸æ ·èè页é¢åæ¢çé®é¢â¦â¦
æçç»è®ºæ¯ï¼åã好大çåãè纹大åã
æçå¦æµ
ï¼åªæ»ç»åºä»¥ä¸é®é¢ï¼
1. æ§è½é®é¢
å
æ¯å¨ç»ã
æ è®ºæ¯ CSS3 å¨ç»ãè¿æ¯ Canvas å¨ç»ï¼è¿æ¯ JavaScript æä½ DOM çå¨ç»ï¼é½å¡ï¼åè
å°¤çãé«ç«¯æºå°å¯ï¼ä½ç«¯æºæ¯å¯ä»¥å¡æå¹»ç¯ççãæå½è¿ GIFï¼ä½¿ç¨ç设å¤æ¯å°çµP88ï¼å
¨å¿ CPU ã大æ¦å°±æ¯è¿æ ·ï¼
http://zsxsoft.qiniudn.com/upload_images/2015/08/201508158461_695.gifå
¶æ¬¡ï¼æ¯ DOM æ§è½é®é¢ã
æè°¢ React 带æ¥äº Virtual DOMï¼é¨å解å³äºå±é¨åºå DOM å·æ°æ¶çæ§è½é®é¢ãä¸è¿ï¼ä¸æ¦æ¶åå°è¾å¤§åºå DOM æ´æ°ï¼ååææ´å¤§çæ§è½æèï¼æç»è®¡ç®åºæ¥çç»æè¿æ¯è¦å
¨é¨æ¿æ¢æï¼å¤åäºä¸æ¥ Diff ï¼ã
å 为æ§è½é®é¢ï¼Facebook 2012年离å¼äº HTML5 App éµè¥ï¼Facebook: âBetting on HTML5 Was a Mistakeâï¼ãä½æ¶è³ä»æ¥ï¼è¿æ¯æ²¡æä»ä¹æ¹åãä¹å享ä¸ç¯æç« ï¼å¯ä»¥ççåï¼ç§»å¨ç«¯HTML5游ææ§è½ä¼åã
è¿éæ个ä¾åï¼å¾®ä¼é¶è¡ App æ¯ Cordova + Ionic + Angularãå¾®ä¼å¾è¡appååå¡é¡¿ï¼å¤§å®¶è§å¾ä¹ï¼
2. å
¼å®¹é®é¢
å
åªç®å®æ¹ç³»ç»ãAndroidç³»ç»ç WebView ä¸è¬é Android çæ¬æ´æ°ï¼å½ç¶ï¼ä¹å¯ä»¥èªå·±å» Play Store æ´æ°ï¼ï¼æ¯ä¸ªçæ¬ææ¯æçåè½åä¸åãåçæ¯ï¼å¨å½å
çç¯å¢ä¸ï¼åºæ¬ä¸ä¼åæ´æ°äºãæçåè½ï¼å¨ PC ä¸å¯¹åºçæ¬çChrome æ¯æçï¼å°è¯¥çæ¬ WebView 就没æäºã
æ¯å¦è¯´ï¼XMLHttpRequest ç onprogress å¨ Android 4.0.4 ä¸ä¸è¢«æ¯æãäºæ¯ï¼é对è¿ç±»ç³»ç»ï¼åªè½éç¨åä¹å对 IE ç Hack ä¸æ ·ï¼ç¨ iframe æ¥æ¿ä»£è¿åº¦æ¡ã
åæ¯å¦è¯´ï¼ECMAScript 6 被é«çæ¬ WebView æ¯æãå¦æå¼åè
åæ¯äºåï¼å¼å
¥äº Symbol çï¼åå¿è®°äº polyfill ãå¨ä½çæ¬ WebView å°±ä¼åºéãå°±åæè¿æ ·ï¼<Table> doesn't support old browsers. · Issue #1685 · callemall/material-ui · GitHub
æ¥çå¢ï¼æè°¢ ROM ååä¹±æ¹ç³»ç»èªå¸¦ç WebView ï¼ä»è导è´å¨åç§å°ç»èä¸ä¸åææºçæ¾ç¤ºæææè¿ç®ç»æä¸åãæ´åéçæ¯ï¼æççè³è¿ä¼å
¨é¡µé¢æ··ä¹±ã
æä¹è§£å³ï¼ä¸ªäººè®¤ä¸ºï¼å微信é£æ ·èªå¸¦ä¸ä¸ª X5ï¼ä¹è®¸ç®æ¯ä¸ä¸ªè§£å³æ¹æ¡å§ã
è³äºå
¼å®¹é®é¢çä¾åï¼è¿æ¯å¾®ä¼é¶è¡å¥½äºï¼
https://www.v2ex.com/t/215728 ï¼ä¸æ°ç iOS 9 ç WebView ä¸å
¼å®¹ï¼
3. è°è¯é®é¢
å
å槽ï¼Android 5.0+ çç³»ç»å
ç WebView ï¼å¯ä»¥ç¨ Chrome for PC æ¥è°è¯ãä½éè¦ç¿»å¢ã
è°è¯åè°è¯ JavaScript åçé¢ä¸¤æ¹é¢ã
JavaScript
æ¹é¢ï¼å¦æ throw åºä¸ä¸ªé误ï¼å¾å¯è½å©ä¸çäºæ
ä½ é½å¹²ä¸äºäºãææºç«¯ç表ç°å°±æ¯ä»ä¹æä½é½æ²¡ç¨ï¼ä¹ä¸ä¼å´©æºéåºä¹ç±»ãå¨å¼åæ¶ï¼å¯¹äº
JavaScript æ¥éï¼MUI å Cordova åå¯ä»¥éè¿ adb logcat æ¥æ£æ¥æ¥éï¼Release åå¯å°±æ²¡åæ³æ¾ç¨æ·è¿
USB äºãweinre çå·¥å
·å¯¹äº JavaScript Debug 没å¥ç¨ã
é£ weinre å¹²å¥ç¨ï¼åªæ¯è®©ä½ ç DOM å±çº§æå¨ææ§è¡ä»£ç ç½¢äºãè¿å°±æ¯ UI æ¹é¢çè°è¯äºãè¿é¨åçè¯ï¼èèå°å
¼å®¹é®é¢ï¼èªæ±å¤ç¦å§â¦â¦
Cordova æä¾äº Rippleï¼åçç¡®æ¯ä¸ä¸ªå¾ä¸éç解å³æ¹æ¡ãä½æ¯å¹¶ä¸è½æ¶µçææçææºâ¦â¦
4. 代ç å®å
¨æ§é®é¢
æ£
å¦.apk -> .dex -> .jar -> .class -> .javaä¸ä¸å°±è½æ代ç å
¨é¨æ¿åºæ¥çä¸æ ·ï¼.apk
-> .js æ´ä¸ºæ¹ä¾¿ï¼è§£åä¸ä¸å°±å¥½äºãäºæ¯ï¼å¨ Release åï¼å¿
é¡» gulp / grunt æ建工ä½æµï¼æ uglify
ä¹ç±»å
¨é¨ä¸è¡èå¡è¿å»ãè¿é¨åååç½é¡µå端没å¥åºå«ï¼å·®å«å¤§æ¦åªæä¸éè¦èè代ç ååçï¼æ¯ç«æ²¡æç½ç»ï¼å
¨å¨æ¬å°ï¼ã
ç¶èï¼è¿æ ·ç代ç ï¼ä¿®æ¹ææ¬é常ä½ãæ¯å¦æåä¸ä¸ªä»è´¹çæ¬å°æ¸¸æï¼åªè¦ç®åå°ä¿®æ¹ä¸ä¸.jsï¼è½»è½»æ¾æ¾ç ´è§£éªè¯çåéæ°æå
åå»ï¼ç ´è§£ç游æå°±å好äºï¼æ¯ Java çç®åå¤äºãå°±ç®æ C++ï¼æ js ä¸è°ç¨ä½ ï¼ä½ åå¥æä½ï¼æ²¡ææå¡å¨éªè¯çè¯ï¼ç©èå»å§ã
5. åè½é®é¢
å¦æ没æ Native Codeï¼ä¸åHTML5 Appé½æ¯ç©ºæ¶åãæ以ï¼Java / Objective-C / C#ä»ç¶æ¯å¿
é¡»å¦ä¹ çè¯è¨ï¼Native App å¦ä½å¼åä¹ä»ç¶æ¯å¿
ä¿®ãæ¯å¦ä»¥ä¸ä»£ç ï¼å°±æ¯å¨ MUI éç¨åçæµè§å¨æå¼ä¸ä¸ªé¾æ¥ã
function openInBrowser(originalUri) {
var Intent = plus.android.importClass("android.content.Intent");
var main = plus.android.runtimeMainActivity();
var Uri = plus.android.importClass("android.net.Uri");
var uri = Uri.parse(originalUri);
var intent = new Intent(Intent.ACTION_VIEW, uri);
main.startActivity(intent);
}
å½ç¶ï¼Cordova å°±å¾å plugin äºï¼æ´ä¸ºç¹æã