Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
解剖"React Native"
Search
hacusk
April 08, 2026
Technology
190
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
解剖"React Native"
React .study vol.01@sapporo
https://hokkaido-js.connpass.com/event/388202/
hacusk
April 08, 2026
More Decks by hacusk
See All by hacusk
DuckDB-Wasmを使って ブラウザ上でRDBMSを動かす
hacusk
1
550
バックエンドの技術をブラウザで動かす技術
hacusk
0
130
形なしからの脱却
hacusk
0
35
Other Decks in Technology
See All in Technology
AWS Blocks が楽しい #ゆるWeb札幌
tacck
PRO
0
120
同じWAFが、攻撃の“形”は弾く── 正当な“形”の不正は通す
kuroneko13
0
270
LLM Internals: 언어 모델의 계보와 알고리즘 진화 (2023~2026)
inureyes
PRO
1
890
属人化を叩き割れ!「制作加速」と「安定化」の矛盾を打破する:8年目プロダクトが辿り着いた「ミスが起こり得ない」アセット制作フローの全貌
gree_tech
PRO
0
370
暗号化?某ファイルストレージはどうなるの!? 3rd Partyとうまく付き合う秘密度ラベル設計
kasada
0
160
AIペネトレーションテスト・ セキュリティ検証「AgenticSec」紹介資料
laysakura
2
9.4k
あなたの知らないバージョン命名規則
sat
PRO
2
360
ソフトウェアサプライチェーンの構造的リスクとコンテナ環境の保護
kyohmizu
5
890
現場回帰したデータエンジニアが考える AI 時代のキャリア開発 / Career Development in the Age of AI Perspectives from a Hands-on Data Engineer
medley
0
320
【GCC2026】大規模言語モデルを活用した内製検索サービスの社内展開や業務活用
bandainamcostudios
PRO
0
520
作って理解するCoding Agent 〜フレームワークに頼らないピュア Python での実装〜
takapy
3
1.1k
What's new in Go 1.27?
ciarana
0
370
Featured
See All Featured
Visualization
eitanlees
152
17k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
870
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
360
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
470
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.9k
What's in a price? How to price your products and services
michaelherold
247
13k
Statistics for Hackers
jakevdp
799
230k
YesSQL, Process and Tooling at Scale
rocio
174
15k
GraphQLとの向き合い方2022年版
quramy
50
15k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Paper Plane
katiecoart
PRO
2
53k
The Pragmatic Product Professional
lauravandoore
37
7.4k
Transcript
解剖"React Native" HakataYusuke(@hacusk) 2026.04.08(Wed.) React.study vol.01@sapporo 1
$ whoami Name: はくすけ(@hacusk) / HakataYusuke Job: 株式会社モニクル SWE Language:TypeScript,
Go, PHP… FavoriteTech: MultiPlatformなもの, OSS, ネ ットワーク Love: 声優, 旅行, ライブ, アイドル, 車, モータ ースポーツ, ガジェット, 飛行機, 麻雀 Community: 函館本線沿線勉強会, フロントエ ンドカンファレンス北海道実行委員会, OSC北 海道実行委員会, 一般社団法人LOCAL Website: https://hacusk.net/ 2
What is "React Native" Learn once, write anywhere. Meta社が主に開発しているOSSのマルチプラットフォームフレームワーク Callstack,Expo,Infinite
Red,Microsoft,Software Mansion社も大きく関わっている iOS,Android,tvOS,Android TV,Vega OS,macOS,Windows(UWP),Meta Horizon OS,Webなどで動くものを作れる ※一部はReactNativeからforkされているプロジェクト(意外なことにfor macOSはMicrosoft が面倒を見ている) https://reactnative.dev/docs/out-of-tree-platforms Reactとそのネイティブ側のプラットフォームの機能を組み合わせてアプリケーションを作る 既存のネイティブコードをラップしたReactのコンポーネントを用いて,JavaScriptを介してネ イティブのAPIを実行する 3
今日話すこと ReactNativeがどのようにして実行されているのかを紐解く 各プラットフォーム上でJavaScriptを動かすための仕組み — Metro Bundler / Hermes JavaScriptとプラットフォームAPIをつなぐための仕組み —
JSI 接続を保証する仕組み — Codegen / TurboModules Reactを動かす仕組み — Fabric / Yoga 前提: iOS,Androidをターゲットとした前提で話します react-native 0.76以降で有効化されているNew Architectureの話です 4
ReactNativeのアーキテクチャ全体像 JS 側 React / App code JSX コンポーネント Hermes
JSエンジン Codegen ビルド時 · 型定義⾃動⽣成 JSI JavaScript Interface C++ · 同期 · シリアライズなし Native 側 TurboModules 初回呼び出し時に C++ インスタンス⽣成 Fabric React レンダラー · immutable な C++ ツリー Yoga Flexbox 計算 (C++ 実装) iOS APIs UIKit · SwiftUI Android APIs View · Jetpack 5
Metro Bundler コードのバンドル,最適化,バイトコードの生成 主な機能 JSX → JS 変換(Babel) モジュール解決 minify,Tree
shaking RN固有の役割 HMR(Hot Module Replacement) Platform-specific extensions Hermes向けバイトコード出力 $ pnpm expo export → JavaScript bytecode https://metrobundler.dev/ https://reactnative.dev/docs/metro 6
Hermes リリースビルド時(AOT) 1. Metroがコードをバンドル 2. HermesコンパイラがJSをバイトコード (.hbc)に変換 3. APK /
IPAに同梱して配布 実行側 バイトコードをそのまま実行(AOTコンパイル 済み) JIT不要 → 起動時のコンパイルコストがゼロ シングルスレッド・イベントループ イベントループの実行順 // HermesInternal でエンジン確認 const isHermes = !!global.HermesInternal; // true console.log('1. 同期処理'); // Call Stack Promise.resolve().then(() => { console.log('2. Microtask'); // Microtask Queue }); setTimeout(() => { console.log('3. Task'); // Task Queue }, 0); // 出力順: 1 → 2 → 3 デバッグモードではMetroからJSを配布し,JITで実行 https://reactnative.dev/docs/hermes https://reactnative.dev/architecture/bundled-hermes 7
JSI — JavaScript Interface シリアライズなし JSオブジェクトをC++ポイン タで直接参照 同期呼び出し可能 await なしでNativeから即座
に値を受け取れる Codegen連携 TSの型定義から C++,Java,ObjCのI/Fを自動生 成 // C++側: HostObjectとして公開 class NativeCalculator : public HostObject { public: Value get(Runtime& rt, const PropNameID& name) override { // JSオブジェクトをコピーなしで直接参照 return Function::createFromHostFunction(rt, ...); } }; https://reactnative.dev/architecture/landing-page 8
Codegen TSの型定義を唯一の情報源とする export interface Spec extends TurboModule { multiply(a: number,
b: number): number; fetchData(url: string): Promise<string>; } export default TurboModuleRegistry.getEnforcing<Spec>('Calculator'); ↓ Codegenが自動生成 class NativeCalculatorCxxSpec { public: virtual double multiply(jsi::Runtime& rt, double a, double b) = 0; virtual jsi::Value fetchData(jsi::Runtime& rt, jsi::String url) = 0; }; 型ズレによるランタイムクラッシュが原理的に起きにくくなる https://reactnative.dev/docs/the-new-architecture/what-is-codegen 9
TurboModules 初回呼び出し時にC++インスタンス生成 JSIのHostObjectとして登録 同期呼び出し可能(JSIのおかげ) Codegenで型安全が保証される 旧NativeModulesは起動時に全モジュールを一括登録していたため,メモリ消費や起動遅延の原因に なっていた https://reactnative.dev/docs/turbo-native-modules-introduction 10
TurboModules — Platform.constantsで読む実装の流れ① // ① JS Spec — 型の定義(Codegenの入力) //
NativePlatformConstantsIOS.js export interface Spec extends TurboModule { getConstants(): { osVersion: string; reactNativeVersion: {...}; ... }; } export default TurboModuleRegistry.getEnforcing<Spec>('PlatformConstants'); // ② iOS実装 — RCTPlatform.mm RCT_EXPORT_MODULE(PlatformConstants) // モジュール名を登録 - (ModuleConstants)getConstants { return typedConstants<JS::NativePlatformConstantsIOS::Constants>({ .osVersion = [UIDevice currentDevice].systemVersion, ... }); } 11
TurboModules — Platform.constantsで読む実装の流れ② // ③ Android実装 — AndroidInfoModule.kt @ReactModule(name =
NativePlatformConstantsAndroidSpec.NAME) class AndroidInfoModule : NativePlatformConstantsAndroidSpec(reactContext) { override fun getTypedExportedConstants() = mapOf( "Release" to Build.VERSION.RELEASE, "Model" to Build.MODEL, ... ) } https://github.com/reactwg/react-native-new-architecture/blob/main/docs/turbo-modules.md 12
Fabricのレンダリングパイプライン Phase 1 — Render(JSスレッド) ReactがElement Treeを生成 → JSI経由でC++のShadow Treeにミラーリング
Phase 2 — Commit(C++スレッド) BeforeMutation → Mutation(差分適用)→ Layout(Yoga・Flexbox計算) JSスレッドをブロックしない Phase 3 — Mount(メインスレッド) 確定した座標でiOS UIView / Android Viewを同期更新 startTransition → Renderフェーズを低優先度に Suspense → Shadow Tree構築を保留しfallbackをMount https://reactnative.dev/architecture/render-pipeline 13
YogaとShadow Tree Shadow Tree C++でReact Element Treeをミラーリング immutable — 並列に複数バージョン保持可能
これがConcurrent Featuresの土台 Yoga Flexboxレイアウトエンジン(C++実装) WebのCSSとほぼ同じAPIで計算 CommitフェーズのLayoutサブフェーズで動く // Shadow TreeはJSスレッドと同期しているので同期的に正確な座標が返る const boxRef = useRef<View>(null); boxRef.current?.measureInWindow((x, y, width, height) => { console.log(`x:${x} y:${y} w:${width} h:${height}`); }); https://reactnative.dev/architecture/glossary#react-shadow-tree-and-react-shadow-node 14
まとめ: React Nativeにおける"React" React自体はWeb版とまったく同じでコンポーネント・状態管理などがそのまま動くが, レンダラーだけ違う Webの場合 reconciler(Fiber)が差分を計算 react-dom がDOMを更新 React
Nativeの場合 reconciler(Fiber)が差分を計算(同じ) Fabric がNative UIツリーを更新 React NativeでDOMイベント等は使えないなどの制約はある https://reactnative.dev/architecture/fabric-renderer 15