ããªã§çºè¡¨ããã¦ããReactåããããã¯ãããã¾ãã«ãæªæ¥ã«çãã¦ãã¦è奮ããã®ã§ãç´¹ä»ããã¦ãã ããã
ç®æ¬¡
- ç®æ¬¡
- ãã®è¨äºã®ã´ã¼ã«
- æ³å®èªè
- ã¯ããã«
- ä»åãã¼ã¹ã¨ããã½ã¼ã¹ã³ã¼ã
- React Nativeã¯ä½ããããã¼ã«ã
- Reactã¯ä½ããããã¼ã«ã
- React DOMã¨React Nativeã®éã
- React Native DOMã¯ã©ããReact Nativeãªã®ã
- React Native DOMã®ãã°ãã¨ãã6é£çº
- Reactããã¯React Nativeã«è¦ãã¦ãã®ããã°ã
- Objective-Cå®è£ ãJavaScriptã«æ¸ãç´ãã¦ã¦ãã°ã
- Web Workerã¾ã§ä½¿ã£ã¦2ã¹ã¬ããå¶ãåç¾ãã¦ãã®ããã°ã
- Yogaãwasmåãã«ãã¼ãã£ã³ã°ãã¦ãã®ããã°ã
- React DOMã使ã£ã¦ãªãã®ããã°ã
- å®ã¯WebComponentsãæç»ãã¦ãã®ããã°ã
- React Native DOMã¯ãã°ã
- Donation Welcome!
ãã®è¨äºã®ã´ã¼ã«
ãã®è¨äºã§ã¯ãReact Nativeã®å é¨å®è£ ã«é¢ããäºåç¥èãã»ã¨ãã©ãªã人ããReact Nativeãå ã ã©ããããã®ãªã®ãããµãããã¨ç解ããä¸ã§ãReact Native DOMãã©ã®ããã«å¤æ ãã¤æªæ¥ã«çãã¦ããã®ããåãã£ãã¤ããã«ãªã£ã¦ããããã¨ãç®çã¨ãã¾ãã
æ³å®èªè
- ReactããããJavaScriptã¨ã³ã¸ãã¢
- JavaScriptã®ãã«ãã¹ã¬ããå¦çã®å®ä¾ã«èå³ãããæ¹
- WebAssemblyã®å®ä¾ã«èå³ãããæ¹
- React Nativeã®ã½ã¼ã¹ã³ã¼ããèªãã§ã¿ãããã©ãJavaScriptãªãã¨ãããJavaãObjective-Cãèªãã®ã¯ã¡ãã£ã¨ã»ã»ã»ã¨å°»è¾¼ã¿ãã¦ããæ¹
ã¯ããã«
5æ17, 18æ¥ã«ãããªã§React Europeãéå¬ããã¾ããã
Reactã«é¢ããæ§ã ãªç¥è¦ãå ¬éãããããã§ãããã¹ã±ã¸ã¥ã¼ã«ãè¦ãéãã§ã¯React Nativeã«é¢ããã»ãã·ã§ã³ãå¤ããªããã«æããã¾ããã
ä¸ã§ãç§ã®ç®ãå¼ããã»ãã·ã§ã³ã¯ãVincent Riemerããï¼[twitter:@vincentriemer]ï¼ã® "Bridging React Native Back to its Roots" ã§ãããåç»âã¨ã¹ã©ã¤ããããããå ¬éããã¦ãã¾ãã
ãã®ã»ãã·ã§ã³ã¯ãReact Native DOMã¨ãããããã¯ããä½ã£ã¦ã¿ãã®ã§ãã¢ããã¼ã·ã§ã³ã¨è¨è¨æ¹éã®ç´¹ä»ããããããã¢ãããããã¨ããã¿ã¤ãã®ãã¤ã§ããã
åé¢ãããªãã¨ãªãæ³åã§ãããã¨æãã¾ãããReact Native DOMã¯ãReact Nativeã³ã¼ãããã©ã¦ã¶ä¸ã§åããããã®ã©ã¤ãã©ãªãã§ãã
ãã®ã¸ãã®ã¦ã¼ã¹ã±ã¼ã¹ã«èå³ããã£ã¦èª¿ã¹ããã¨ãããæ¹ã¯ããã£ãããReact Native for Webã¨ä½ãéãã®ï¼ãã¨æããããã¨ã§ããããã¯ããç§ãããæãã¾ããã
ã¡ããã©ãCheap Dive into React Nativeãæ¸ãããããã§React Nativeã®ã½ã¼ã¹ãèªãã®ã«ãèªä¿¡ãã¤ãã¦ããã¨ãããªã®ã§ããã¾ãã©ããYet Another React Native for Webã§ãããã¨æããªããReact Native DOMã®ã½ã¼ã¹ãèªã¿å§ããã®ã§ãã
ããããã¾ãã¾ã¨åº¦èãæãããã®ã§ãããããã¿ããªã«ã©ãã ãããããä¼ãã«ãããããã¨ããããªè¨äºãæ¸ãå§ãã次第ã§ãã
é·æã§åææ¡ä»¶ããç´°ããæ¸ãã¦ããã®ã§ãã²ã¨ã¾ãæ¦è¦ãç¥ãããæ¹ã¯Qiitaã®è¨äºã¸ã©ããã
react-native-dom の何がすごいのか - Qiita
ã¾ããReact Nativeã®ãã¨ã¯ããããã£ã¦ãããã¨ããæ¹ã¯ãReact Native DOMã¯ã©ããReact Nativeãªã®ããã®è¦åºããæ¤ç´¢ãã¦ããããããèªã¿ãã ããã
ä»åãã¼ã¹ã¨ããã½ã¼ã¹ã³ã¼ã
æ¬è¨äºã®ä¸ã§ã½ã¼ã¹ã³ã¼ãã¸ã®ãªã³ã¯ã¾ãã¯å¼ç¨ãè¡ãå ´åãä¸è¨ã®ãã¼ã¸ã§ã³ãæãã¾ãã
- React v16.4.0
- React Native v0.55.4
- React Native DOM v0.1.2
React Nativeã¯ä½ããããã¼ã«ã
React Nativeã¯æ§ã ãªå´é¢ãæã¤ãã¼ã«ã§ããããè¤æ°ã®ãã©ãããã©ã¼ã ã«ããããã¤ãã£ãViewãæ½è±¡åãã¦è¨è¿°ããããã®ãã®ãã¨ããå´é¢ããããã¨ã¯å¤ãã®äººã«è³åããã ããã¨æãã¾ãã
JavaScriptå´ã§ <ScrollView>
ã³ã³ãã¼ãã³ãã使ãã°ãAndroidã®ãã¤ãã£ãUIã«ScrollView
ãæç»ãããiOSã®ãã¤ãã£ãUIã«UIScrollView
ãæç»ããã¾ããåãã©ãããã©ã¼ã ã«åå¨ãããç»é¢ãã¹ã¯ãã¼ã«ãããViewãã <ScrollView>
ã¨ãã¦æ½è±¡åãã¦ãããã¨ãããã¨ãã§ããã§ãããã
GUIã¢ããªã±ã¼ã·ã§ã³ãæ§ç¯ãã¦ããä¸ã§ãã©ããªãã¶ã¤ã³ã¬ã¤ãã©ã¤ã³ã«æ²¿ã£ã¦ããã«ãã¦ãæä½éå¿ ãå¿ è¦ã«ãªãã§ãããUIãã¼ãããReact Nativeã¯æ½è±¡åãããã³ã³ãã¼ãã³ãã¨ãã¦æä¾ãã¦ãã¾ãã
Reactã¯ä½ããããã¼ã«ã
Reactãæ§ã ãªæèã§èªãããã¡ãªãã¼ã«ã§ãããçè ã¯æ¬¡ã®2ã¤ã ããå¼·ãç¹å¾´ã¨ãã¦èªèãã¦ãã¾ãã
- ã³ã³ãã¼ãã³ããçµã¿åããã¦UIãæ§ç¯ããããã®ãã¼ã«ï¼ã³ã³ãã¼ãã³ãã®ããã®ãã¼ã«ï¼
- ãã¼ã¿å¤æ´ã«ä¼´ã£ã¦UIãæ´æ°ããéã«ãåå¾ã®UIã®å·®åãäºåã«è¨ç®ãã¦ãå®éã«æ´æ°ããViewãæå°éã«æãããã¨ã§ç»é¢æ´æ°ãå¹çåããããã®ãã¼ã«ï¼å·®åæ´æ°ã®ããã®ãã¼ã«ï¼
ä¸ææã¯Virtual DOMã¨ããè¨èã°ãããç¬ãæ©ããã¦ããæãããã¾ãããä¸è¨ã®ããã«Reactãèªèããä¸ã§ã¯ãç¸ã®ä¸ã®åæã¡ã¨ãã¦è¦ã¦ãããã»ããããã®ã ãããªãã¨ããã®ãæè¿ã®çè ã®èªèã§ãã
ããã ãã¨ããã°ããã ãã§ã¯ããã¾ãããå·®åãViewã«é©ç¨ããããã»ã¹ãæ½è±¡åããããã« react-reconciler
ã¨ããããã±ã¼ã¸ãç¨æããã¦ãå®è£
ã react-dom
ã® ReactDOMHostConfig.js
ã react-native-renderer
ã® ReactNativeHostConfig.js
ãæ
å½ãã¦ãã¨ãã£ãåã¿ã®ããä»çµã¿ãæ´ãããã¦ããã®ãè¦ãã¨ããã¯ãReactãå¼·ãé¢å¿ãæã£ã¦ããåéã§ãããã¨ã¯ééããªããªãã¨æãã¨ããã§ãã
React DOMã¨React Nativeã®éã
ãã¦ãReactã®å½¹å²ã¯ãªãã¨ãªããããã¾ããããReact Native DOMã®ãã¨ãç解ããããããããã«ãã¾ãReact DOMã¨React Nativeã®éããè¦ã¦ããã¾ãããã
Reactã¢ããªã±ã¼ã·ã§ã³ãæç»ãããã®ãã¡
React DOMã¨React Nativeã®å ±éç¹ãæãããªãã° React製ã®ã¢ããªã±ã¼ã·ã§ã³ããã©ãããã©ã¼ã ä¸ã«æç»ãã ã¨ãããã®ãããã¨çè ã¯èãã¦ãã¾ãã
ä¸æ¹ã§ããã©ãããã©ã¼ã ã«å¯¾ããåãåãæ¹ãéãããã«ãReact DOMã¨React Nativeã®å½¹å²ã¯å¤§ããéã£ã¦ãã¾ããããããã«ã¤ãã¦èª¬æãã¦ããã¾ãã
React DOMã®å½¹å²
React DOMã¯ãã®åã®ã¨ãããVirtual DOMã®å·®åãDOMã«é©ç¨ããã®ã責åã§ããReactDOMFiberComponent.jsã®ä¸ã§createElementãupdatePropertiesã«å®è£ ããã¦ãããããªå½¢ã§DOM APIãã´ãªã´ãªå©ããã¨ã«ãããæ´æ°ãå®ç¾ãã¦ãã¾ãã
ã¾ããreact-reconcilerã«è§¦ã£ã¦ãããããã®å ¥ãå£ã¨ãã¦ã¯ãReactDOMHostConfig.jsã®ä¸ã«ãViewããªã¼ã«ãã¼ãã追å ããããã®createInstanceãæ¢åã®ãã¼ãã«æ´æ°ãè¡ãcommitUpdateãªã©ãç¨æããã¦ãã¾ãã
ã¨ããã§ãDOMããªã¼ã«å¯¾ãã¦ã¯å¼·ãé¢å¿ãæã£ã¦ããReactã§ãããã¹ã¿ã¤ã«ã«ã¤ãã¦ã¯æå¤ã¨é¢å¿ãæã£ã¦ãã¾ãããCSS in JSã§æ¸ãããstyleã¯ãCSSPropertyOperations.jsã®ä¸»å°ã§ãpxãä»ãããããããã¤ãã³ãä»ããããããããã®ã®ãã»ã¼ãã®ã¾ã¾DOMã«å¯¾ãã¦æ¸¡ããã¾ãããããã©ããªç¹è²ãæã£ãã¹ã¿ã¤ã«ã§ãããã«ã¯ãé¢ç¥ãã¾ãããã¹ã¿ã¤ã«ã®è§£éã¨ã¬ã³ããªã³ã°ã¯ãã©ã¦ã¶ã®é åãªã®ã§ãå½ç¶ã¨ããã°å½ç¶ã§ããã
React Nativeã®å½¹å²
React Nativeã¨ãããã¼ã«ã®å ·ä½çãªå½¹å²ã¯ãã²ã¨ãã¨ã§ã¯è¡¨ç¾ã§ãã¾ãããããã¤ãã®å½¹å²ã®éããã¼ã«ãçµã¿åããã£ã¦åãã¦ããããã§ãã大å¥ããã¨æ¬¡ã®3ã¤ã«åé¡ã§ãã¾ãã
- ãã¤ãã£ãå¦çç³»ã®ä¸ã§JavaScriptå¦çç³»ãåããããã®ä»çµã¿
- Reactãåããããã®ä»çµã¿ï¼React Nativeçã®React DOMï¼
- Reactãã渡ãããå·®åããã¤ãã£ãViewã«é©ç¨ããããã®ä»çµã¿
React Native DOMã®çé«ãç解ããä¸ã§ã¯ãã©ããéè¦ãªè¦ç´ ã«ãªãã¾ãã®ã§ããããã説æãã¦ããã¾ãã
1. ãã¤ãã£ãå¦çç³»ã®ä¸ã§JavaScriptå¦çç³»ãåãã
Android SDK/NDKãiOS SDKãç¨ãã¦ãã¸ãã¯ãè¨è¿°ããéã«ã¯ã次ã®è¨èªãå ¬å¼ã«ãµãã¼ãããã¦ãã¾ãã
- Android
- Java
- Kotlin
- C++
- iOS
- Objective-C
- Objective-C++
- Swift
ããã以å¤ã®è¨èªãåããããå ´åã«ã¯ãä¸å·¥å¤«ãå¿ è¦ã«ãªãããã§ãã
React Nativeã¯ãAndroidã¨iOSã®ä¸ã§JavaScriptã®ï¼ã§ããã ãåãï¼å¦çç³»ãåããããã«ãWebKitï¼âSafariï¼ã®JavaScriptã¨ã³ã¸ã³ã§ããJavaScriptCoreï¼JSCï¼ãæ¡ç¨ãã¾ãããJSCãªãiOS SDKã«ã¯JavaScriptCore.frameworkã¨ãã¦ä½¿ãã¾ãããAndroidåãã«ã¯å°ããã«ãæ¹æ³ãå¼ã£ã¦ãfacebook/android-jscã¨ããå½¢ã«ãã¼ãã£ã³ã°ãããã¨ã§ãAndroid NDKä¸ã§ã®åä½ãå®ç¾ã§ãã¦ãã¾ããåè¿°ã®è¨èªç¾¤ã®ä¸ã§è¨ãã°ãC++å¦çç³»ã®ä¸ã§JavaScriptã®å¦çç³»ãåãããã¨ã«ããããã§ãã
JavaScriptCoreãã©ãã¾ã§ã§ããã®ãã¨ããç¹ã«ã¤ãã¦ã¯ã以ä¸ã®è³æã詳ããã§ãã
www.slideshare.net
React Nativeçã«ã¯ãJavaScriptã¨ãã¦ã¯å¤§é¨åãåå
¨ã«åã*1ãã©ãæµç³ã«DOM APIã¯ãªãã window.document
ãåå¨ããªãããã¨ããã¨ãããææ¡ã§ãã¦ããã°ããã®ããªã¨æãã¾ãã
ãã¦ãJSCã¯ããã¯ã°ã©ã¦ã³ãã¹ã¬ãããã²ã¨ã¤å æ ããå½¢ã§å®è¡ããã¾ãããã®ã¹ã¬ãããJavaScriptã«ã¨ã£ã¦ã®ã¡ã¤ã³ã¹ã¬ããï¼JavaScriptã¯ã·ã³ã°ã«ã¹ã¬ãããªã®ã§ãå¯ä¸ã®ã¹ã¬ããï¼ã«ãªãã¾ããAndroidãiOSã®UIã¹ã¬ããã¨ã¯å¥ã«JavaScriptãå®è¡ããããã®ã¹ã¬ãããåãã¦ããã¨ãç解ãã ããã
ã¾ããäºåã«ãã¤ãã£ãå´ããJSCã«å¯¾ãã¦è¨å®ãè¡ããã¨ã§ãJavaScriptã§å¼ã³åºãé¢æ°ããã¤ãã£ãå®è£ ã«ãããã¨ãã§ãã¾ãããããããã¤ãã£ãã¢ã¸ã¥ã¼ã«ã®ä»çµã¿ã§ãããã®è¾ºã®é°å²æ°ã¯å ¬å¼ããã¥ã¡ã³ããèªãã§ããã ããã»ããæ©ããã§ãããReact Native DOMã®è©±ããã¦ããä¸ã§ã¯æ¬¡ã®ãµã³ãã«ãé常ã«éè¦ã§ãã
// Objective-C #import "CalendarManager.h" #import <React/RCTLog.h> @implementation CalendarManager RCT_EXPORT_MODULE(); RCT_EXPORT_METHOD(addEvent:(NSString *)name location:(NSString *)location) { RCTLogInfo(@"Pretending to create an event %@ at %@", name, location); }
Objective-Cå´ã® RCT_EXPORT_METHOD()
ãã¯ãã«ãã£ã¦å®ç¾©ããã addEvent
ã¡ã½ããã¯ãæçµçã«JavaScriptCoreã«èªã¿è¾¼ã¾ããJavaScriptå´ã§ã¯ä»¥ä¸ã®ãããªã³ã¼ãã§å¼ã³åºããããã«ãªãã¾ãã
// JavaScript import {NativeModules} from 'react-native'; var CalendarManager = NativeModules.CalendarManager; CalendarManager.addEvent('Birthday Party', '4 Privet Drive, Surrey');
ä¸è¨ã®JavaScriptã³ã¼ããå®è¡ãããã¨ãObjective-Cå´ã® RCTLogInfo()
ãå®è¡ããã¦ããã°ãåºåãããã¨ãã寸æ³ã§ãã
RCT_EXPORT_METHOD
ã¨ããè¨èãããè¦ãã¦ããã¦ãã ããããã¹ãã«åºã¾ãã
2. Reactãåãã
DOM APIã¯å©ããªããªãããJavaScriptã¯ã¡ããã¨åããã¨ãããã¨ã¯ãReactã¢ããªã±ã¼ã·ã§ã³å ã®ç¶æ æ´æ°ã«å¿ãããVirtual DOMã«ããå·®åã®ç®åºããããã¾ã§ã¯React DOMã®ã¨ãã¨åãããã«ã§ããã¯ãã§ãã
ãã®ã¸ãã¯react-reconcilerã«ããæ½è±¡åã®ç¯å²ã«ãªã£ã¦ãããå ±éã®ã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ãè¨ãããã¦ãã¾ããreact-native-rendererã®ReactNativeHostConfig.jsã«ã¯ãReact DOMã¨åæ§ã«createInstanceãcommitUpdateãå®åããã¦ãã¾ããreact-reconcilerããè¦ãã°ãReact DOMãªã®ãReact Nativeãªã®ãã¯ç¹ã«èããã«ãã¨ããããVirtual DOMã®å·®åãæãã¤ããã°OKãã¨ããä½ãã«ããããã§ãã
å·®åã®ç®åºã¨ãæ´æ°ã®ä¾é ¼ããããã¾ã§ã®æèã§ããã°ãReact DOMã¨React Nativeï¼å³å¯ã«ã¯React Native Rendererï¼ã¯åºå¥ãªãæ±ãããã¨ãããã¨ãè¦ãã¦ããã¦ãã ããã
3. Reactãã渡ãããå·®åããã¤ãã£ãViewã«é©ç¨ãã
ãã¦ãreact-reconcilerãReact DOMã¨åãè¦é ã§React Native Rendererã«æ´æ°ä¾é ¼ãæãã¤ãã¦ãããã¨ãåããã¾ããããããããããã¯åãè¦é ã¨ããããã«ã¯ããã¾ããããã©ã¦ã¶ã®å ´åã¯React DOMãreact-reconcilerãUIã¹ã¬ããä¸ã§åãã¦ããã®ã§ãReactDOMHostConfigãéãã¦æ´æ°ä¾é ¼ãè¡ã£ãå ´åã«ãããã®ã¾ã¾DOM APIãå©ãã¦ããªã¼ã«æ¸ãè¾¼ããã¨ãã§ãã¾ãããããããReact Nativeã®JavaScriptCoreå ã§åãreact-reconcilerã¨ãã¤ãã£ãViewã®éã«ã¯ã大ããªå£ã2ã¤ç«ã¡ãµããã£ã¦ãã¾ããè¨èªã¨ã¹ã¬ããã§ãã
è¨èªã¯è¨ãããããªã§ãJavaScriptããObjective-C/Javaã®å¦çç³»ã¸ã¨å¦çã渡ããªããã°ãªãã¾ãããããã¯ã1. ãã¤ãã£ãå¦çç³»ã®ä¸ã§JavaScriptå¦çç³»ãåãããã§è¿°ã¹ãã¨ããããã¤ãã£ãã¢ã¸ã¥ã¼ã«ã®ä»çµã¿ãç¨ãã¦çªç ´ã§ãã¾ãã
åé¡ãªã®ã¯ã¹ã¬ããã§ããã1. ãã¤ãã£ãå¦çç³»ã®ä¸ã§JavaScriptå¦çç³»ãåãããã§è¿°ã¹ãã¨ãããReact Nativeã®JavaScriptå¦çç³»ã¯ãããã¯ã°ã©ã¦ã³ãã¹ã¬ããã§åä½ãã¦ãã¾ããä¸æ¹ã ãã¤ãã£ãViewã¯UIã¹ã¬ããããããæ´æ°ãããã¨ãã§ãã¾ããã ä½ã¨ããã¦ãreact-reconcilerãçºä»¤ããæ´æ°ä¾é ¼ãããã¤ãã£ãViewã¾ã§ä¼ããå¿ è¦ãããã¾ãã
ããã§React Nativeã¯ã¦ã«ãã©Cãçºæãã¾ããããã¤ãã£ãå´ã«DOMããªã¼ã®ä»£ãããä½ã£ãã®ã§ãã次ã®å³ã¯ãããã¯ã°ã©ã¦ã³ãã¹ã¬ããã§è¡ãããæ´æ°å¦çã®æµãã§ãã
å¦çã®æµããçªå·ã«æ²¿ã£ã¦èª¬æãã¾ãã¨ã次ã®ããã«ãªãã¾ãã
- react-reconcilerãVirtual DOMã®å·®åãèªèããï¼ä»åã®ä¾ã§ã¯ãã¼ãã®è¿½å ï¼
- react-reconcilerãReact Native Rendererã®
createInstance
é¢æ°ãéãã¦ãReact Nativeã«Viewã®æ´æ°ãä¾é ¼ãã createInstance
ã¯UIManager
ã¢ã¸ã¥ã¼ã«ã®createView
é¢æ°ã«Viewã®æ´æ°ãä¾é ¼ããUIManager
ã¢ã¸ã¥ã¼ã«ã¯ãã¤ãã£ãã¢ã¸ã¥ã¼ã«ã§ãããiOSã«ããã¦ã¯RCTUIManager.m
ãAndroidã«ããã¦ã¯UIManagerModule.java
ã¨ããå®ä½ãæã¡ã¾ãï¼ä»¥éã¯åã«UIManagerã¨å¼ã³ã¾ãï¼- 以éã®è§£èª¬ã¯iOSçããã¼ã¹ã«è¡ã*2ãã¨ã«ãã¾ã
createView
ã¯RCTShadowView
ã¨ããããªã¼ç¶ã®ãã¼ã¿æ§é ã«å¯¾ãã¦ã追å å¦çãè¡ã- å®éã«ãã¤ãã£ãViewã«æ¸ãè¾¼ã段éã§å®æ½ãããæ´æ°å½ä»¤ããããã¯ï¼é¢æ°ãªãã¸ã§ã¯ãï¼ã«è©°ãè¾¼ãã§ã
addUIBlock
ãå¼ã³åºã - UIManagerã®ã¤ã³ã¹ã¿ã³ã¹å¤æ°ã§ãã
_pendingUIBlocks
ã«ãã¥ã¼ã¨ãã¦ä¿åãã
ã²ã¨ã¾ãããã§ä¸åº¦å¦çãè½ã¡çãã¾ãã
ãã©ã¦ã¶ã§ããã¨ããã®DOMããªã¼ã«è©²å½ããShadowViewããªã¼ãç¨æãããã¨ã§ãReact Native Rendererããã®æ´æ°ä¾é ¼ã«å¯¾ãã¦ãDOMã®æ´æ°ã«è¿ãå½¢ã§ãã¤ãã£ãå´ã®åãå ¥ããæåããã¦ãã¾ããããã«ãããè¤éã«ãªããããªãã£ã è¨èªã®å£ãè¶ ãã ã¨ãã大æããæ¯è¼çç´ ç´ãªå½¢ã§æ¸ã¾ãã¦ãã¾ãã
çè ãã¾ããVirtual DOMã®ãããªãã®ããã¤ãã£ãå´ã«ãããã¨ã¯æã£ã¦ããªãã£ãã®ã§ãåãã¦è¦ãã¨ãã«ã¯é©ãã¾ããããreact-reconcilerã¨ã®å ¼ãåããèããã¨æªããªãããã«ãæãã¾ãããShadowViewã®å é¨å®è£ ãè¦ãã¨Yogaã®ã¬ã¤ã¢ã¦ãè¨ç®ã«ãæ´»ç¨ããã¦ããããããã¨ãè¦ã¦åããã®ã§ããªããªãéè¦ãªå½¹å²ãæããã¦ããããã§ãã
ãã¦ãããã¾ã§ã§ã¯ã¾ã ã¹ã¬ããã®å£ãè¶ãããã¦ãã¾ãããè¶ãã¦ã¯ãã¾ããããå£ãè¶ãããã¨ã«ãããããã¨ããããã¯ï¼é¢æ°ãªãã¸ã§ã¯ãï¼ã®å½¢ã«ãã¦ãã¥ã¼ã«å ¥ãããã¨ãã§ãã¾ããããã¨ã¯å£ã®åããå´ã§ãã¥ã¼ããåãåºãã ãã§ããUIã¹ã¬ããå´ã®å¦çã¯æ¬¡ã®å³ã®ããã«ãªãã¾ãã
ã¾ãé ã追ã£ã¦è§£èª¬ãã¾ãã
- UIã¹ã¬ããããUIManagerã®ã¡ã½ãããå¼ã°ãã*3
- ããããã¨çµè·¯ãéã£ã¦ãæçµçã«
flushUIBlocksWithCompletion
ã¡ã½ãããå¼ã°ãã- Yogaã®è©ä¾¡ã¯ãã®ç´åãããã«ShadowViewã«å¯¾ãã¦è¡ããã¦ãã¾ãã
- ãã¥ã¼ãã²ã¨ã¤ãã¤å®è¡ãã
- ãã¥ã¼ã«ç»é²ããã¦ãããããã¯ï¼é¢æ°ãªãã¸ã§ã¯ãï¼ãå®è¡ãã¦ããã¤ãã£ãViewãæ´æ°ãã
- ãã¤ãã£ãViewãæ´æ°æ¸ã¿ã§ãããã¨ãShadowViewã«éç¥ãã
ãã®ãããªæµãã§ãã¤ãã£ãViewã«å¤æ´ãé©ç¨ãã¦ãã¾ããJavaã®å ´åãï¼é¢æ°ãªãã¸ã§ã¯ãç¸å½ã®è¨èªæ©è½ããªãã®ã§ã¡ãã£ã¨é°å²æ°ã¯éãã¾ããï¼ä¼¼ããããªä»çµã¿ã«ãªã£ã¦ãã¾ãã
ã¹ã¬ããã®è¦³ç¹ã§ã¯ããã®æ´æ°ã®ä»çµã¿ã¯æ¬¡ã®ããã«ã¾ã¨ãããã¨ãã§ãã¾ãã
- JavaScriptå´ã®react-reconcilerã¯å®¹èµ¦ãªã次ã ã¨æ´æ°ä¾é ¼ãåºãç¶ãã
- ãã¤ãã£ãå´ã¯åãåã£ãæ´æ°ä¾é ¼ã®å 容ãShadowViewããªã¼ã¨ãã¥ã¼ã®å½¢ã§ä¿æãã¦ãä¸åº¦ããã¯ã°ã©ã¦ã³ãã¹ã¬ããã§ã®å¦çãçµãããã
- UIã¹ã¬ããã®é½åãããã¨ãã«ãã¥ã¼ãéæå®è¡ãã¦ãã
çè ã¯ãã®æµããè¯ããã©ã³ã¹ã§ã§ãã¦ããããã«æãããã¦ãã¨ã¦ã好ãã§ãï¼å人ã®ææ³ã§ãï¼ã
React Native DOMã¯ã©ããReact Nativeãªã®ã
ãã¦ãReact Nativeã®ãããããã§ãã¾ããã®ã§ãããããReact Native DOMã®è©±ãã§ãã¾ããçµè«ããè¨ã£ã¦ãã¾ãã¨ãReact Native DOM㯠DOMããªã¼ããã¤ãã£ãViewã¨è¦ãªãã¦ä½ããããReact Nativeã®ãµã¼ããã¼ãã£å®è£ ã§ãã
æ¢ã«ãããµã¼ããã¼ãã£å®è£ ã¨ãã¦ã¯Windowsåãã¨macOSåããæåã§ããããã
ç¹ã«Windowsåãã®å®è£ ã¯Microsoftãæãããã¡ã³ããã³ã¹ãè¡ã£ã¦ãããã¨ããSkypeãã¼ã ãé å¼µã£ã¦ããã¨ããåã®ReactXPã®åºå¹¹æè¡ã«ããªã£ã¦ããã¨ãããã¨ã§ãä¸ææ注ç®ããã¾ãããReact Native DOMã¯ããããã¨ååã®ãã®ã§ãã
é¡ä¼¼åã¨ãã¦React Native for Webãããã¾ãããããã¯ãã¾ãã¾React Nativeã¨æåãè¿ãUIã©ã¤ãã©ãªãªã®ã§ãã©ã¡ããã¨ããã¨material-uiãªã©ã®è¦ªæã§ã*4ã
React Native DOMã®ãã°ãã¨ãã6é£çº
ããã§ã¯React Native DOMã®ä½ããã°ãã®ããè¦ã¦ããã¾ãããã
Reactããã¯React Nativeã«è¦ãã¦ãã®ããã°ã
ã¾ãã¯åºã®å£ããããµã¼ããã¼ãã£å®è£ ã¨ãã¦æç«ãã¦ããã®ã§å½ç¶ã¨ããã°å½ç¶ã§ãããreact-reconcilerãReact Native Rendererããã¯æ®éã®React Nativeã«è¦ãã¦ãã¾ãã
ããã¯ã©ããããã¨ãã¨ããã¨ãReact Nativeåãã®UIã©ã¤ãã©ãªãå種ã¢ã¸ã¥ã¼ã«ãããã©ã¦ã¶ä¸ã§ãåãå¯è½æ§ã示åãã¦ãã¾ãã
react-native-paperã®ãããªç´ æ´ãããUIã©ã¤ãã©ãªãã¢ãã¤ã«Webã®æèã§ã使ãããã¨æãã¨ãå¦ãå¿ã§ããã³ã·ã§ã³ãä¸ããã¨ãããã®ã§ãã*5
Objective-Cå®è£ ãJavaScriptã«æ¸ãç´ãã¦ã¦ãã°ã
React Native Rendererãããæ®éã®React Nativeã¨åãããã«è¦ãã¦ããã¨ãããã¨ã¯ãUIManagerã使ã£ã¦ããã¯ãã§ãããã¤ãã£ãå®è£ ã§ããã°UI Moduleã®ä¸èº«ã¯JavaãObjective-Cã§æ¸ãã¦ãã£ãããã§ãããReact Native DOMã§ã¯ã©ããªã£ã¦ããã®ã§ããããã
RCTUIManager.jsã§ãï¼ï¼ï¼
大äºãªãã¨ãªã®ã§äºåè¨ãã¾ããã
å¯ãã®ããçæ§ã¯ãAndroidã¨ã³ã¸ãã¢ã®çè ããä½æ ããããObjective-Cçã®å®è£ ã使ã£ã¦è§£èª¬ãããã®ãããããããæ°ä»ãã®é ã§ã¯ãªãã§ããããã
æããããã¨ã«ãReact Native DOMã§ã¯ãObjective-Cçã®ã¯ã©ã¹ç¾¤ããã»ã¼ãã®ã¾ã¾JavaScriptã«ãã¼ãã£ã³ã°ãã¦ããã®ã§ãã
ãã£ã¬ã¯ããªæ§é ãã¯ã©ã¹åããã¡ã½ããåã¾ã§çäºã¤ãå¤å°ã®ãã¤ãã¼ãã§ã³ã¸ãçºããã¦ããç®æãããã¾ãããã¾ã誤差ã®ç¯å²ã§ãã
æµç³ã«@RCT_EXPORT_METHOD
ãã³ã¬ã¼ã¿ã¼ãå®è£
ããã¦ããã®ãè¦ãã¨ãã«ã¯è
¹ãæ±ãã¦ç¬ãã¾ããã
// JavaScript @RCT_EXPORT_METHOD(RCTFunctionTypeNormal) createView( reactTag: number, viewName: string, rootTag: number, props: Object ) {
ã¡ããã¨ãã¤ãã£ãã¢ã¸ã¥ã¼ã«ãå ¬éããããã«ä½¿ã£ã¦ãããããã¨ãããä¾®ããªãã»ã»ã»
Web Workerã¾ã§ä½¿ã£ã¦2ã¹ã¬ããå¶ãåç¾ãã¦ãã®ããã°ã
React Native DOMã¯React Nativeã®ãã¤ãã£ãå´ãå·®ãæ¿ãããµã¼ããã¼ãã£å®è£ ã§ãããã®èª¬æã«å½ãã¯ããã¾ããã
æ¬å®¶React Native㯠UIã¹ã¬ããã¨å¥ã«JavaScriptãå®è¡ããããã®ããã¯ã°ã©ã¦ã³ãã¹ã¬ãããæã£ã¦ãã¾ããã Androidå®è£ ãiOSå®è£ ãããã§ãã以ä¸ã React Native DOMãããããã¹ãã ãã¨ããä½è ã®ã¡ãã»ã¼ã¸ãçè ã«ã¯èããã¾ãã
React Native DOM㯠Web Workerã®ä¸ã§Reactã¢ããªã±ã¼ã·ã§ã³ãåãã ãã¨ã§ããã©ã¦ã¶ä¸ã§ããã«ãé¢ãããReact Nativeã®2ã¹ã¬ããå¶ãå®å ¨åç¾ãã¦ãã¾ããReact Nativeã®ã¹ã¬ããã®èª¬æã«å½ã¦ã¯ãããªãã°ã次ã®ãããªåæ ã§ãã
RCTBridge.jsã«åºã¦ãã Worker
ã thread
ãªã©ã®æè¨ã¯Web Workeré¢é£ã®å®è£
ãªã®ã§ãæ°ã«ãªã£ãæ¹ã¯çºãã¦ã¿ãã¨ããã§ãããã
Yogaãwasmåãã«ãã¼ãã£ã³ã°ãã¦ãã®ããã°ã
å
ã»ã©ã®ãã¡ã¤ã«ä¸è¦§ã«ãåãè¾¼ãã§ãã¾ããããå½ç¶ã®ããã« RCTShadowView.js
ãåå¨ãã¦ãã¾ãããShadowViewããªã¼ãæ§ç¯ããã¦ãã¾ãã
ãã¦ãShadowViewããªã¼ã¯ããã¯ã°ã©ã¦ã³ãã®JavaScriptããæ¥ãæ´æ°ä¾é ¼ãDOMã®ä»£ããã«åãä»ããã¨ãã責å以å¤ã«ããããã²ã¨ã¤ã®è²¬åãããã¾ãããYogaã®ã¬ã¤ã¢ã¦ãè¨ç®ã®å¯¾è±¡ã«ãªããã¨ã§ãã
ãããããã§ããèãã¦ã¿ã¾ããããYogaã¯AndroidãiOSã¨ãã£ããã©ãããã©ã¼ã ä¸ã§ãFlexboxã®ææ³ã«ããã¬ã¤ã¢ã¦ãè¨ç®ãè¡ãããã®ãã®ã§ããã確ãã«AndroidãiOSã®ãã¤ãã£ãViewãFlexboxã§é ç½®ããä¸ã§ã¯å¿ è¦ãªãã¼ã«ã ã£ãã¨æãã¾ããã§ããFlexboxãæ¨æºæè¼ãã¦ãããã¨ãå¤ãè¿ä»£çãªãã©ã¦ã¶ã«å¯¾ãã¦ãããããYogaã使ãå¿ è¦ã¯ããã§ããããï¼ãããããC++ã§å®è£ ããã¦ãããã®ããã©ã¦ã¶ã§åããã®ã¯ç¡ççã§ã¯ï¼
ãã®çåã«å¯¾ããåçã¨ãã¦ã¯ ãããããã®ã¯ã©ãã§ãããã俺ã¯Yogaãåç¾ããã ã ã£ãããã§ãã
ããããã¨ããã®ä½è ãYogaããã¼ãã£ã³ã°ããyoga-domã¨ããã©ã¤ãã©ãªãä½ããããã¾ãã¦ãWeb Assemblyã§åãããã«ãã¦ãã¾ã£ãã®ã§ãã
RCTShadowView.jsãçºããã¨ãJavaScriptãWeb Assemblyã®æ©è½ãimportãã¦ä½¿ã£ã¦ãããç©çããå æ¯ãè¦ããã¨ãã§ãã¾ãã
// JavaScript import * as YG from "yoga-dom";
// JavaScript module.exports = (async () => { const Yoga: YG.Module = (await require("yoga-dom"): any);
ããããã§ã¯ã»ã»ã»ï¼ãã¨ããæ°æã¡ãããã¾ãããæ¬å®¶ã¨æåãæããããã«ã¯ãããå¾ãªãæªç½®ã ã£ãã®ã§ãããããã£ã¨ããã«éããªããï¼èªåã«è¨ãèãããï¼
React DOMã使ã£ã¦ãªãã®ããã°ã
ã¾ãããããªãããªã§ææ°æè¡ããããã使ã£ã¦ããReact Native DOMã§ããããããã«ãã¤ãã£ãViewã§ããDOMã¸ã®ã¢ã¯ã»ã¹ã«ã¯ãReact DOMããã使ã£ã¦ãã§ããâ¦â¦
ã¨ããããã§ããã¤ãã£ãã³ã³ãã¼ãã³ããè¦ãã¦ã¿ã¾ããããæ¬å®¶React Nativeãªãã°ãRCTViewã«ã¯ãã¤ãã£ãã®Viewãæç»ããããã®ã³ã¼ããæ¸ãã¦ããã®ã§ãReact DOMã¨ãã®ãããããã£ã½ããã®ãæ¸ãã¦ããã¯ãã»ã»ã»
// JavaScript /** * @providesModule RCTView * @flow */ import type { Frame } from "InternalLib"; import UIView from "UIView"; import type RCTBridge from "RCTBridge"; import RCTEventEmitter from "RCTNativeEventEmitter"; import CustomElement from "CustomElement"; @CustomElement("rct-view") class RCTView extends UIView { bridge: RCTBridge; onLayout: ?Function; constructor(bridge: RCTBridge) { super(); this.bridge = bridge; } get frame(): Frame { return super.frame; } set frame(value: Frame) { super.frame = value; if (this.onLayout) { this.onLayout({ layout: { x: value.left, y: value.top, width: value.width, height: value.height } }); } } // TODO: Renable when I have a plan for focus styling // set accessible(value: boolean) { // this.tabIndex = 0; // } } export default RCTView;
ãããããæç»ãã¦ãã£ã½ãã¨ãããä½ããªãã»ã»ã»ã¨ãããã¹ã¼ãã¼ã¯ã©ã¹ã«ãªã£ã¦ãUIViewã£ã¦ãªãã§ããããiOS SDKã®UIKitã®åºåºViewã®ååããªãã§ãããªã¨ããã«ã»ã»ã»ã¡ãã£ã¨è¦ã¦ã¿ã¾ãããã
// JavaScript @CustomElement("ui-view") class UIView extends HTMLElement implements RCTComponent { _top: number = 0; _left: number = 0;
ããã£ã¨ãHTMLElementãåºã¦ããã¨ãããã¨ã¯ãããåºã§ããããã§ãããããããUIViewã¨ããååãã¤ãã¦ããã¨ããã®ã¯ãiOS SDKå´ã®ã¯ã©ã¹ã¾ã§åç¾ã®å¯¾è±¡ã«å ¥ã£ã¦ãã¾ã£ã¦ããã¨ãããã¨ã§ãæ¥ãæ·±ããªã£ã¦ãã¾ãããã»ã»ã»
å°ãªãã¨ãReact DOMã¯ä½¿ã£ã¦ããªããããªãã¨ãåããã¾ãããã¾ããReact Native Rendererã¨åæ ¼ã®ãã¼ã«ãªã®ã§ããããªæ·±ãã¨ããã§ä½¿ããããªãã§ããã¨ãã話ã§ããã
å®ã¯WebComponentsãæç»ãã¦ãã®ããã°ã
ããããã°ãçµå±ä½å¦ã§DOMã«æç»ãã¦ããã®ããã¾ã ããã£ã¦ãã¾ããããã©ããã«createElement
ãããã¯ãããããªãã®ã§ãããã¡ãã£ã¨ããã§ã @CustomElement("ui-view")
ã¨ããè¨è¿°ãæ°ã«ãªã£ãã®ã§ä¸èº«ãè¦ã¦ã¿ã¾ãããã
// JavaScript export default function CustomElement(name: string) { return function(target: Function) { customElements.define(name, target); }; }
ãã£ãã¿ã°ä½ã£ã¦ãï¼ç¢ºä¿¡ï¼ã
Custom Elementsã£ã¦ãæ¬å½ã«ãã®Web Componentsã®Custom Elementsããï¼ï¼
ã¡ãã£ã¨å ¬å¼ãµã³ãã«ãè¦ã¦ã¿ã¾ãããã
å®å ¨ã«Custom Elementsã§ããã»ã»ã»çãä½å°ãªãã£ãã§ããã»ã»ã»
React Native DOMã¯ãã°ã
React Native DOMã¯ãã°ããDOMããã¤ãã£ãViewã ã¨è¨ãå¼µã£ã¦ãä½ããã£ã¦ãã¾ã£ããããã¯RNã·ãªã¼ãºã®ä¸è§ãå¼µãã®ã«æ¥ããªãä½ãããã¦ããã¨ãçè ã¯èãã¦ãã¾ãããã®ããã®ãªã®ã§ã¡ã³ããã³ã¹ã¯å¤§å¤ããã ãã©ããªãã¨ãçãæ®ã£ã¦ãããã¨é¢ç½ãã¨æãã
ææ°æè¡ãããã§ããã¨çãè¾¼ãã§ããã®ãé常ã«é¢ç½ãã§ããã
- Web Worker
- Web Assembly
- Web Components
ã©ããå¤ãã®ãã©ã¦ã¶ã«å®è£ ã¯ããã¦ãã¦ãããã®ã®ãã¾ã ãã¾ãæ´»ç¨äºä¾ããªããã®ã°ããã§ãé常ã«åå¼·ã«ãªãã¾ããããã®ä¸ã§ããWeb Workerã使ã£ãç¹ã«ã¤ãã¦ãçè ã¯é«ãè©ä¾¡ãã¦ãã¾ãã
React Native DOMã§ä½ã£ãã¢ããªã±ã¼ã·ã§ã³ã§ã¯ãUIã¹ã¬ãããåãç¨äºã¯Yogaã®ã¬ã¤ã¢ã¦ãè¨ç®ã¨ãDOMã®æç»ããããããªãããã§ããç§ãã¡ãã¯ã½éãå¦çãæ¸ãæ£ãããã¦ããReactã¢ããªã±ã¼ã·ã§ã³ã¯ãå¥ã¹ã¬ããã«éããã¦ãããããªã®ã§ãæ®éã«é«éåããããªæ°ããã¾ãã
React Native DOMã®ã¢ãªãã·ã¨ã¯å¥ã«ãDOMã触ããªããããªãã¸ãã¹ãã¸ãã¯ã®å¦çãWeb Workerã«éãããã©ãã¤ã ã¯ãä»å¾ã®ã¹ã¿ã³ãã¼ãã«ãªãããå¨åãæã¤ããã«æãã¾ããã
We're in 2018 while @vincentriemer is in 2040
— Rubén Sospedra ð (@sospedra_r) 2018å¹´5æ19æ¥
俺ãã¡ã¯2018å¹´ã«çãã¦ããã©ãã´ã£ã³ã»ã³ãã¯2040å¹´ã«çãã¦ãã
ã¿ããªreact-native-domãèªãã§2040å¹´ã«è¡ããã
Donation Welcome!
æãã®å¤ãã¨ãã§ããªãå å®ããè¨äºã«ãªã£ã¦ãã¾ã£ãã®ã§ãæ°ãåãããæãéãã ãã*6*7ã
*1:Babelãæã¾ã£ã¦ããã®ã§ãé¢æ°ãææ³ã®æä¾å ãJSCãªã®ãPolyfillãªã®ãåããã¥ãããã¨ã¯ããã¾ã
*2:æ¬å½ã¯Javaãèªã¿ããã£ãã®ã ããã©ãReact Native DOMã®è§£èª¬ãããã«ã¯Objective-Cã®ã»ããé©åã ã£ãã®ã§æ³£ãæ³£ãObjective-Cãèªãã§ã¾ãã
*3:UIã¹ã¬ããã§ã¯ãªãã¨ããããå¼ã°ãããã¨ãæ³å®ãã¦ããå®è£ ã«ã¯ãªã£ã¦ãã¾ãããåºæ¬çã«ã¯UIã¹ã¬ããããå¼ã°ããã¯ã
*4:ãããªãã¨ããã¨necolasã«å±ããããã§ãã
*5:React Native for Webã«react-native-paperãé©ç¨ãããã¨ãã¦ææ²ããç§æ¨ãããã¾ã
*6:39åæãã¦ãµã³ãã¥ã¼ã£ã¦ããã®ããã£ã¦ã¿ããã ã
*7:æè¿ã®æµè¡ããèãããnoteã§èª²éããã¹ããªã®ãããããªããã©ãnoteã«æè¡è¨äºæ¸ãã®ããã©ãããªãã ããªãã»ã»ã»