react-native-roku 0.0.0-stage → 0.2.0-preview.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/CHANGELOG.md +318 -0
  2. package/CONTRIBUTING.md +34 -0
  3. package/LICENSE +21 -0
  4. package/NOTICE.md +10 -0
  5. package/README.md +66 -2
  6. package/bin/react-native-roku.mjs +91 -0
  7. package/build/assets.cjs +311 -0
  8. package/build/assets.d.cts +50 -0
  9. package/build/compatibility.d.mts +40 -0
  10. package/build/compatibility.mjs +272 -0
  11. package/build/dev.d.mts +34 -0
  12. package/build/dev.mjs +297 -0
  13. package/build/devWorkspace.d.mts +11 -0
  14. package/build/devWorkspace.mjs +86 -0
  15. package/build/device.d.mts +47 -0
  16. package/build/device.mjs +310 -0
  17. package/build/environment.d.mts +29 -0
  18. package/build/environment.mjs +144 -0
  19. package/build/esbuild.d.mts +5 -0
  20. package/build/esbuild.mjs +118 -0
  21. package/build/fontVariants.d.mts +27 -0
  22. package/build/fontVariants.mjs +424 -0
  23. package/build/frontend.d.mts +52 -0
  24. package/build/frontend.mjs +75 -0
  25. package/build/identity.mjs +45 -0
  26. package/build/index.d.mts +22 -0
  27. package/build/index.mjs +87 -0
  28. package/build/intl.mjs +121 -0
  29. package/build/metro.cjs +38 -0
  30. package/build/metro.d.cts +37 -0
  31. package/build/metroFrontend.mjs +222 -0
  32. package/build/metroMetadata.mjs +119 -0
  33. package/build/metroModules.mjs +397 -0
  34. package/build/metroRefresh.d.mts +64 -0
  35. package/build/metroRefresh.mjs +346 -0
  36. package/build/metroTransformer.cjs +146 -0
  37. package/build/nativeTextMemo.mjs +296 -0
  38. package/build/nativewind.d.mts +9 -0
  39. package/build/nativewind.mjs +92 -0
  40. package/build/project.d.mts +111 -0
  41. package/build/project.mjs +615 -0
  42. package/build/reactCompiler.mjs +113 -0
  43. package/build/reactProfile.cjs +35 -0
  44. package/build/refreshRuntime.mjs +187 -0
  45. package/build/refreshSourceMap.mjs +53 -0
  46. package/build/release.mjs +99 -0
  47. package/build/resolution.d.mts +3 -0
  48. package/build/resolution.mjs +25 -0
  49. package/build/surfaces.d.mts +1 -0
  50. package/build/surfaces.mjs +42 -0
  51. package/build/testing/node.d.mts +29 -0
  52. package/build/testing/node.mjs +106 -0
  53. package/build/yoga.d.mts +8 -0
  54. package/build/yoga.mjs +186 -0
  55. package/compatibility/public-api.json +327 -0
  56. package/compatibility/registry.json +2258 -0
  57. package/config/release.json +15 -0
  58. package/config/toolchain.json +34 -0
  59. package/docs/compatibility.md +813 -0
  60. package/docs/getting-started.md +460 -0
  61. package/docs/maintenance.md +362 -0
  62. package/docs/qualification.md +241 -0
  63. package/docs/standalone-testing.md +56 -0
  64. package/examples/hello-roku/README.md +35 -0
  65. package/examples/hello-roku/package.template.json +31 -0
  66. package/examples/hello-roku/pnpm-workspace.yaml +11 -0
  67. package/examples/hello-roku/roku.config.json +22 -0
  68. package/examples/hello-roku/src/App.tsx +54 -0
  69. package/examples/hello-roku/src/Catalog.tsx +200 -0
  70. package/examples/hello-roku/src/assets.d.ts +16 -0
  71. package/examples/hello-roku/src/catalog-cover.png +0 -0
  72. package/examples/hello-roku/tsconfig.json +1 -0
  73. package/examples/hello-roku/tsconfig.react.json +1 -0
  74. package/native/components/RNRAppControl.brs +215 -0
  75. package/native/components/RNRAppControl.xml +13 -0
  76. package/native/components/RNRDeviceFacts.brs +19 -0
  77. package/native/components/RNRDeviceFacts.xml +9 -0
  78. package/native/components/RNRDeviceFactsTask.brs +74 -0
  79. package/native/components/RNRDeviceFactsTask.xml +9 -0
  80. package/native/components/RNRTextRaster.brs +15 -0
  81. package/native/components/RNRTextRaster.xml +9 -0
  82. package/native/components/RNRTextRasterTask.brs +77 -0
  83. package/native/components/RNRTextRasterTask.xml +9 -0
  84. package/native/manifest.json +7 -0
  85. package/package.json +183 -3
  86. package/src/animation/clock.ts +10 -0
  87. package/src/animation/derivedValue.ts +163 -0
  88. package/src/animation/legacyAnimated.ts +255 -0
  89. package/src/animation/reanimated.ts +243 -0
  90. package/src/animation/sharedValue.ts +285 -0
  91. package/src/animation/worklets.ts +23 -0
  92. package/src/application/AppRegistry.ts +31 -0
  93. package/src/application/mountApplication.ts +136 -0
  94. package/src/graphics/BitmapLayer.tsx +68 -0
  95. package/src/graphics/RoundedBorder.tsx +116 -0
  96. package/src/graphics/TextRasterCache.ts +259 -0
  97. package/src/graphics/gradient.ts +37 -0
  98. package/src/graphics/inlineRaster.ts +85 -0
  99. package/src/graphics/png.ts +77 -0
  100. package/src/graphics/rasterPixels.ts +89 -0
  101. package/src/graphics/surfaces.ts +105 -0
  102. package/src/graphics/textRaster.types.ts +60 -0
  103. package/src/graphics/textRasterGeometry.ts +116 -0
  104. package/src/host/host.types.ts +57 -0
  105. package/src/index.ts +22 -0
  106. package/src/interop/nativewind.ts +2 -0
  107. package/src/layout/FontResources.ts +252 -0
  108. package/src/layout/affine.ts +89 -0
  109. package/src/layout/flexLayout.ts +398 -0
  110. package/src/layout/fontFaces.d.mts +19 -0
  111. package/src/layout/fontFaces.mjs +85 -0
  112. package/src/layout/fontVariants.d.mts +2 -0
  113. package/src/layout/fontVariants.mjs +8 -0
  114. package/src/layout/inlineParagraph.ts +158 -0
  115. package/src/layout/inlineText.ts +68 -0
  116. package/src/layout/layoutReuse.ts +117 -0
  117. package/src/layout/nativeNodeFields.ts +179 -0
  118. package/src/layout/preparedFields.ts +78 -0
  119. package/src/layout/textLayout.ts +138 -0
  120. package/src/layout/transform.ts +113 -0
  121. package/src/media/SceneGraphAudio.ts +161 -0
  122. package/src/media/SceneGraphVideo.ts +167 -0
  123. package/src/media/audioSession.ts +84 -0
  124. package/src/media/index.ts +2 -0
  125. package/src/media/videoErrorDetails.ts +40 -0
  126. package/src/media/videoSession.ts +136 -0
  127. package/src/navigation/RouterStore.ts +244 -0
  128. package/src/navigation/expoRouter.ts +115 -0
  129. package/src/react-native/NativeInput.ts +494 -0
  130. package/src/react-native/NativeSystemState.ts +95 -0
  131. package/src/react-native/accessibility.ts +265 -0
  132. package/src/react-native/activityIndicator.ts +72 -0
  133. package/src/react-native/compilerPressable.ts +26 -0
  134. package/src/react-native/createNativeRoot.ts +2126 -0
  135. package/src/react-native/directionalFocus.ts +55 -0
  136. package/src/react-native/environment.ts +275 -0
  137. package/src/react-native/flatList.ts +1001 -0
  138. package/src/react-native/flatListViewability.ts +231 -0
  139. package/src/react-native/focusEvents.ts +85 -0
  140. package/src/react-native/image.ts +247 -0
  141. package/src/react-native/index.ts +54 -0
  142. package/src/react-native/interactionManager.ts +76 -0
  143. package/src/react-native/keyboard.ts +60 -0
  144. package/src/react-native/linearGradient.ts +94 -0
  145. package/src/react-native/modal.tsx +148 -0
  146. package/src/react-native/nativeHostContext.ts +80 -0
  147. package/src/react-native/nativeModules.ts +86 -0
  148. package/src/react-native/nativeRoot.types.ts +22 -0
  149. package/src/react-native/nativeViewHandle.ts +191 -0
  150. package/src/react-native/nativewindPressable.ts +38 -0
  151. package/src/react-native/panResponder.ts +73 -0
  152. package/src/react-native/primitives.ts +685 -0
  153. package/src/react-native/safeArea.ts +76 -0
  154. package/src/react-native/scrollView.ts +289 -0
  155. package/src/react-native/styleInterop.ts +8 -0
  156. package/src/react-native/styleSheet.ts +54 -0
  157. package/src/react-native/textInput.ts +334 -0
  158. package/src/react-native/unsupported.ts +25 -0
  159. package/src/renderer/SceneRoot.ts +1006 -0
  160. package/src/scene/SdkDeviceFacts.ts +151 -0
  161. package/src/scene/SdkDeviceServices.ts +72 -0
  162. package/src/scene/SdkSceneGraph.ts +124 -0
  163. package/src/scene/SdkTextEntry.ts +321 -0
  164. package/src/scene/SdkTextMetrics.ts +136 -0
  165. package/src/scene/SdkTextRasterTransport.ts +191 -0
  166. package/src/scene/SdkWebTransport.ts +122 -0
  167. package/src/scene/createRokuHost.ts +213 -0
  168. package/src/scene/sceneGraph.types.ts +38 -0
  169. package/src/services/DeviceServices.ts +53 -0
  170. package/src/services/RegistryStorage.ts +85 -0
  171. package/src/services/RokuKeySession.ts +29 -0
  172. package/src/services/asyncStorage.ts +23 -0
  173. package/src/services/base64.ts +52 -0
  174. package/src/services/crypto.ts +18 -0
  175. package/src/services/expoConstants.ts +11 -0
  176. package/src/services/expoLinking.ts +12 -0
  177. package/src/services/expoStatusBar.ts +4 -0
  178. package/src/services/installWebRuntime.ts +105 -0
  179. package/src/services/intlEnglish.ts +54 -0
  180. package/src/services/languageRuntime.ts +65 -0
  181. package/src/services/nativeTimers.ts +96 -0
  182. package/src/services/secureStore.ts +23 -0
  183. package/src/services/textEntryRequest.ts +22 -0
  184. package/src/services/utf8.ts +57 -0
  185. package/src/services/webRuntime.ts +346 -0
  186. package/src/testing/CanvasResources.ts +141 -0
  187. package/src/testing/CanvasSceneGraph.ts +496 -0
  188. package/src/testing/CanvasTextEntry.ts +237 -0
  189. package/src/testing/PreviewTextObservations.ts +82 -0
  190. package/src/testing/RecordingSceneGraph.ts +136 -0
  191. package/src/types/normalize-colors.d.ts +4 -0
  192. package/src/vector/dynamicSvg.tsx +226 -0
  193. package/src/vector/svg.ts +222 -0
  194. package/src/vector/svg.types.ts +4 -0
  195. package/src/vector/svgElements.ts +58 -0
  196. package/src/vector/svgKey.d.mts +4 -0
  197. package/src/vector/svgKey.mjs +16 -0
  198. package/src/vector/svgPath.ts +157 -0
  199. package/src/vector/svgPixels.ts +133 -0
  200. package/tsconfig.consumer.json +29 -0
@@ -0,0 +1,460 @@
1
+ # Build an independent Roku app
2
+
3
+ Use Node 24.18.1 and pnpm 11.23.0. The tested cohort is React 19.2.8,
4
+ reconciler 0.33.0, Yoga 1.10.0 and Roku SDK 2.19.1. The package ships
5
+ TypeScript source and public build adapters and requires only its declared dependencies.
6
+
7
+ ## Create and run
8
+
9
+ With the published preview, create a project directly from the registry.
10
+
11
+ ```sh
12
+ npx --yes react-native-roku@preview init my-roku-app
13
+ cd my-roku-app
14
+ pnpm install
15
+ pnpm run doctor
16
+ pnpm typecheck
17
+ pnpm dev
18
+ ```
19
+
20
+ ### Test a specific archive
21
+
22
+ To verify the exact package used in a release, download the developer-preview archive into an empty
23
+ directory. Compare its SHA-256 with the release record, then use the same steps
24
+ as for an archive supplied for review.
25
+
26
+ ```sh
27
+ npm pack react-native-roku@preview
28
+ ```
29
+
30
+ Set `archive` to the absolute path of that file:
31
+
32
+ ```sh
33
+ archive=/absolute/path/to/react-native-roku-0.2.0-preview.1.tgz
34
+ shasum -a 256 "$archive"
35
+ scratch=$(mktemp -d)
36
+ tar -xzf "$archive" -C "$scratch"
37
+ node "$scratch/package/bin/react-native-roku.mjs" init "$scratch/my-roku-app" --package="file:$archive"
38
+ cd "$scratch/my-roku-app"
39
+ pnpm install
40
+ pnpm run doctor
41
+ pnpm typecheck
42
+ pnpm dev
43
+ # Stop the preview before running the finite SDK build.
44
+ pnpm build
45
+ ```
46
+
47
+ The generator refuses an existing destination. It does not install dependencies,
48
+ commit, publish or deploy. Its template has a normal default-exported React
49
+ component in `src/App.tsx`:
50
+
51
+ ```tsx
52
+ import { View, Text } from "react-native";
53
+ export default function App() {
54
+ return (
55
+ <View>
56
+ <Text>Hello Roku</Text>
57
+ </View>
58
+ );
59
+ }
60
+ ```
61
+
62
+ `roku.config.json` owns the entry, application name, background and font assets:
63
+
64
+ ```json
65
+ {
66
+ "name": "HelloRoku",
67
+ "entry": "src/App.tsx",
68
+ "background": "#101014"
69
+ }
70
+ ```
71
+
72
+ The default font is Inter from the template's pinned `@expo-google-fonts/inter`
73
+ dependency. To override it, configure `fonts.defaultFamily` and a `fonts.assets`
74
+ map from physical face names to local paths or resolvable package asset paths.
75
+ The starter declares a logical `Inter` family with regular (400) and bold (700)
76
+ faces. Ordinary `Text` can use `fontWeight: "bold"` or `"700"` without selecting
77
+ an asset itself. Custom fonts declare `fonts.families`, for example
78
+ `{ "Body": { "normal": { "400": "BodyRegular", "700": "BodyBold" } } }`,
79
+ where both physical names exist in `fonts.assets`; set `defaultFamily: "Body"`.
80
+ Declare real italic files under `italic` in the same map. Missing requested
81
+ weights/styles fail explicitly; the host does not synthesize faces.
82
+ The starter also configures `fonts.variants: ["tabular-nums"]` and shows equal-width
83
+ digits. This prepares the font's real OpenType tabular face; it does not assume
84
+ a native font-feature field. Custom fonts must contain the admitted static
85
+ single-glyph `tnum` profile. Remove the variant example/configuration when your
86
+ app does not use it; an unconfigured or unsupported requested variant fails
87
+ explicitly. Custom pipelines can call `prepareRokuFontAssets` from the public
88
+ `build/project` export and register its returned ordinary/variant asset map and
89
+ `families` declaration. Custom SDK entry generation accepts `fontFamilies`.
90
+ Optional `viewport` defaults to 1920×1080 and `dev.port` defaults to 9389.
91
+ Application names must be identifiers containing letters, digits or underscores.
92
+
93
+ The browser Canvas host watches source and config and serializes/coalesces builds.
94
+ The default esbuild frontend reloads after a completed successful build. An error overlay retains the
95
+ last good app until the error is fixed. Configuration files remain watched after
96
+ atomic editor replacements. `ROKU_DEV_PORT` overrides the port. This is a full
97
+ page reload: React state and in-memory credentials reset. Apps may explicitly
98
+ use preview-owned `sessionStorage` for their own development credentials; the
99
+ platform does not copy credentials from another app. Native rendering, video,
100
+ focus observations and performance still need device qualification.
101
+
102
+ ```sh
103
+ pnpm build
104
+ ```
105
+
106
+ This finite official SDK build writes `dist/roku-app.zip` and a generated native
107
+ project in `.roku/`. Those paths are disposable. Do not edit generated Scene,
108
+ Main, anchor or native helper files. No command installs a channel or accesses
109
+ a device account. Retain the font dependency's redistribution license.
110
+
111
+ Finite builds default to the `production` React profile (`__DEV__` false and
112
+ `NODE_ENV` production). The development preview defaults to `development`.
113
+ Choose explicitly with `pnpm build --profile=development` or
114
+ `pnpm dev --profile=production`. Development SDK output uses `.roku/development/`
115
+ and `dist/roku-app-development.zip`; it cannot overwrite the default candidate.
116
+ Each SDK ZIP includes `build-profile.json`. SDK diagnostic/source-map output
117
+ remains enabled in both profiles; the profile selects React/application code.
118
+ Channel identity, device qualification and publication are separate decisions.
119
+
120
+ Custom consumers use `rokuBuildProfile(name)` from
121
+ `react-native-roku/build/environment` for the same validated immutable
122
+ `defines` object. Include the profile in consumer fingerprints and transform
123
+ cache keys, and use its `development` boolean when configuring Babel callers.
124
+
125
+ ## Sideload and debug on a Roku
126
+
127
+ The benchmarked device is a Roku Ultra 4850X running Roku OS 16.0.4 build 853
128
+ with Roku SDK 2.19.1. Use a Roku with RSG 2.0 developer support on the same
129
+ local network as your computer. [Roku developer-mode setup](https://developer.roku.com/dev/docs/developer-setup)
130
+
131
+ 1. Enable the Development Application Installer on the device and record its
132
+ local URL. After the reboot, open that URL and sign in as `rokudev` with the
133
+ password you set on the Roku.
134
+ 2. Save the ZIP of any development channel you need to restore. The device
135
+ has one sideload slot. Upload `dist/roku-app.zip` and choose ZIP for a
136
+ checksum-comparable installation. Save the ZIP's SHA-256 and the installer
137
+ checksum and byte count with your test notes.
138
+ 3. After launch, press Select on the focused counter and confirm it increments
139
+ once. For a navigation example with images and virtualized rows, set
140
+ `entry` to `src/Catalog.tsx` in the generated app and build again.
141
+ 4. For device debugging, run `pnpm build --profile=development` and sideload
142
+ `dist/roku-app-development.zip`. Read the developer console at port 8085.
143
+ To map a saved JavaScript stack to its source, keep the bundle from that
144
+ exact build and run this command. [Roku SDK runtime and debugging guide](https://developer.roku.com/dev/docs/rsg-sdk-standing-docs-runtime-and-debugging-rk)
145
+
146
+ ```sh
147
+ pnpm exec rk decode-stack --build-dir .roku/development/dist/sdk/bundle --file roku-console.log
148
+ ```
149
+
150
+ | Symptom | First check |
151
+ | --------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
152
+ | Doctor reports missing Roku SDK tooling | In the generated app, run `pnpm install` through your configured npm registry and rerun `pnpm run doctor`. The template declares the exact SDK cohort. |
153
+ | Installer URL fails or the login is rejected | Open the URL displayed by the device after developer-mode setup and reboot. Use the device-local `rokudev` account and the password you set for it. |
154
+ | Remote automation receives 403 or cannot inspect the tree | Confirm developer mode and enable Control by mobile apps under the Roku's advanced system settings. [Roku ECP command requirements](https://developer.roku.com/dev/docs/external-control-api) |
155
+ | Font preparation reports a missing face | Check the physical face name and asset path in `fonts.assets`, then map the requested weight and style in `fonts.families`. Run `pnpm run doctor` and rebuild. |
156
+ | Bundling reports an unsupported import | Use a public React Native entry point and compare the imported API with the [compatibility matrix](compatibility.md). Keep SDK imports in native host code. |
157
+
158
+ ## React Compiler for esbuild
159
+
160
+ For React 19 applications, set `"reactCompiler": true` in `roku.config.json` to
161
+ compile application modules under the consumer directory. Install the compiler
162
+ in that consumer using the tested versions.
163
+
164
+ ```sh
165
+ pnpm add -D --save-exact @babel/core@7.29.7 babel-plugin-react-compiler@1.0.0
166
+ ```
167
+
168
+ This option applies to the esbuild preview and device builds. For Metro, enable
169
+ the plugin through the application's Babel configuration.
170
+
171
+ Production SDK builds can also reuse equivalent React Native `Text` elements
172
+ with scalar children and inline scalar styles. The compiler checks the imported
173
+ component and JSX shape before applying this reuse. It preserves evaluation of
174
+ the current style and child expressions and honors `"use no memo"`.
175
+
176
+ ## Register an existing React application
177
+
178
+ An app can use a familiar registration entry instead of a default export:
179
+
180
+ ```tsx
181
+ import { AppRegistry } from "react-native";
182
+ import App from "./App";
183
+ AppRegistry.registerComponent("HelloRoku", () => App);
184
+ ```
185
+
186
+ Set `entry` to that file and `entryMode` to `registry`. Its registration key must
187
+ match `name`. The host binds its environment before loading the entry, mounts
188
+ the registered tree, and owns input/root disposal. This is a registration subset
189
+ of AppRegistry; it does not implement every upstream AppRegistry operation.
190
+
191
+ For an archive upgrade in an existing app, save the current dependency
192
+ manifest and lockfile, then run `pnpm add "react-native-roku@file:/absolute/path/to/candidate.tgz"`.
193
+ Run doctor, typecheck, preview and a production build again. Keep the prior ZIP
194
+ and lockfile available for rollback. To roll back, restore the saved manifest
195
+ and lockfile, run `pnpm install --frozen-lockfile`, then replace the sideloaded
196
+ channel with the saved ZIP. Confirm its installer checksum and launch state.
197
+ Track remote focus with a new observation after a list or route remount before
198
+ sending an automated Select.
199
+
200
+ The standalone catalogue fixture uses `react-native-safe-area-context` 5.8.1
201
+ with `SafeAreaProvider` and `useSafeAreaInsets`. See the
202
+ [compatibility registry](../compatibility/registry.json) for exact tested
203
+ combinations and outstanding execution environments.
204
+
205
+ ### Report a preview issue
206
+
207
+ Start with the smallest shared JSX that reproduces the behavior in a fresh
208
+ generated app. Include the dependency pins, archive SHA-256, minimal
209
+ `roku.config.json`, the production ZIP SHA-256, exact steps and expected
210
+ result. For a Roku result, include the model, firmware including build, and
211
+ whether you observed a native frame, app-tree focus or only key acknowledgement.
212
+ Attach a cropped screenshot or a short event trace when available. Remove
213
+ appliance addresses, account identifiers, credentials and private media from
214
+ reports. Keep original device logs locally.
215
+
216
+ ## Audio
217
+
218
+ Import `SceneGraphAudio` and `SceneGraphAudioRef` from `react-native-roku/media`
219
+ for a nonvisual audio resource. Supply an explicit stream format (`mp3`, `mp4`,
220
+ `flac`, `hls` or `es.aac-adts`), rather than inferring it from an opaque URL.
221
+ Use its observations for state, position, duration and decoder format. Its ref
222
+ supports seek, pause, resume, stop and mute; a submitted command is not playback
223
+ evidence. Queues, admission, progress persistence and source-time mapping belong
224
+ to the application. Playback speed and fractional volume need additional output
225
+ mechanics. See the [compatibility boundary](compatibility.md#audio-resource).
226
+
227
+ ## Existing build pipelines and Metro
228
+
229
+ React code can extend `react-native-roku/tsconfig`. The public
230
+ `rokuPlugin({root})` from `react-native-roku/build/esbuild` supplies adapter
231
+ aliases, a single React resolution, `.roku` then `.tv` then shared source
232
+ selection, pinned NativeWind corrections and Hermes-safe Yoga preparation.
233
+ Unsupported private React Native imports and SDK imports in frontend code fail
234
+ explicitly. Upstream React Native types alone do not prove implementation support.
235
+
236
+ An existing Metro configuration can use:
237
+
238
+ ```js
239
+ const { withRoku } = require("react-native-roku/metro");
240
+ module.exports = withRoku(existingConfig);
241
+ ```
242
+
243
+ Only the `roku` platform gets these aliases/source variants. Other targets keep
244
+ the existing resolver. The resolver also selects the reviewed portable
245
+ NativeWind engine's native-style leaves on Roku. To prepare its component and
246
+ preference adapters and Yoga's finite bindings for Hermes, compose your Babel
247
+ transformer in a `roku-transformer.cjs` file:
248
+
249
+ ```js
250
+ const { withRokuBabelTransformer } = require("react-native-roku/metro");
251
+ module.exports = withRokuBabelTransformer(require("@react-native/metro-babel-transformer"), {
252
+ root: __dirname,
253
+ });
254
+ ```
255
+
256
+ Set `transformer.babelTransformerPath` in your Metro config to
257
+ `require.resolve("./roku-transformer.cjs")`. Keep your existing Babel presets,
258
+ plugins and upstream transformer. The wrapper only prepares Roku dependency
259
+ source; it preserves the upstream arguments, results, errors and additional
260
+ exports. Other platforms pass through unchanged. Its cache key includes the
261
+ upstream key, installed platform implementation and Yoga preparation inputs.
262
+ A custom upstream's `getCacheKey` must cover its own configuration/dependencies.
263
+ No Metro or Babel dependency is required by the ordinary CLI/esbuild workflow.
264
+
265
+ The optional reviewed tool versions live in `config/toolchain.json` under
266
+ `optionalPackages.metro`. `pnpm test:metro` in the platform repository installs
267
+ an independent archived-package consumer and checks cold production/development
268
+ Metro output and SDK integration. Set `ROKU_HERMES_EXECUTABLE` to also execute
269
+ that output in a local host Hermes CLI. Reports retain generated source, runners,
270
+ source maps, SDK programs and ZIPs under `.local/metro-consumer-*` (or
271
+ `ROKU_QUALIFY_EVIDENCE_DIR`). Host-Hermes execution links the partitioned frontend
272
+ with esbuild for the VM; SDK builds consume the separate bounded modules.
273
+
274
+ For an independent Metro application, initialize with:
275
+
276
+ ```sh
277
+ react-native-roku init ../my-metro-app --package=file:/absolute/platform.tgz --bundler=metro
278
+ cd ../my-metro-app
279
+ pnpm install
280
+ pnpm run doctor
281
+ pnpm typecheck
282
+ pnpm build
283
+ pnpm dev
284
+ ```
285
+
286
+ The generator sets `bundler: "metro"` in `roku.config.json` and adds the optional
287
+ cohort and Babel preset. An existing app can add that field and the same tool
288
+ cohort to its dev dependencies. The CLI loads its Metro config, composes the
289
+ Roku resolver/transformer and preserves its Babel policy. Component and registry
290
+ entry modes, fonts, production/development profiles and SDK ZIP paths use the
291
+ same project builder. The SDK stage still compiles native mechanics separately.
292
+ Metro/Babel config and package manifest edits trigger full preview reloads.
293
+
294
+ Custom build systems call `buildRokuMetroModules` from `/build/frontend` with
295
+ `root`, `entry`, `outfile`, optional `profile`, `configPath` or `configuration`,
296
+ and the entry's named `exports` (default `mountApplication`). It prepares full
297
+ collation data before Metro scans files, using the same bounded static data
298
+ extractor as esbuild. It then writes ESM modules with one Metro require cache,
299
+ source maps and a default 2 MiB code limit per module. An oversized module or an
300
+ unreviewed serializer shape fails explicitly. Its returned files/hashes and
301
+ `frontend.json` are build inputs for a consumer's existing artifact policy.
302
+ The returned `metafile` attributes each source factory to its actual output
303
+ chunk and records dependency edges. `assets` contains Metro's complete asset
304
+ descriptors, including density variants and configured asset-plugin metadata,
305
+ on both cold builds and transform-cache hits. Set
306
+ `imageAssets: { generatedDirectory: "/owned/output/images" }` to use the
307
+ package's raster compiler and registry. This composes configured asset plugins,
308
+ preserves their metadata, and restores physical images on cache hits using the
309
+ complete density inventory and Metro's exact source snapshots. Embedded literals
310
+ become separate static modules before a second file-map scan, preserving their
311
+ values without exceeding the module budget. Preparation stops when the graph
312
+ settles and refuses changed source snapshots; `imagePreparationPasses` records
313
+ the finite pass count. Omitting this
314
+ option retains a custom host's existing asset registry.
315
+ The frontend retains its selected `NODE_ENV` independently of the host's
316
+ environment; an explicit development profile cannot inherit production mode.
317
+ Use a generation-owned output/work directory; caller lifetime policy retires
318
+ old generations. The raw Metro bundle and map remain in the work directory.
319
+
320
+ Metro development previews preserve React state across safe component edits.
321
+ Changing a hook signature resets that component. A changed dependency graph,
322
+ configuration, runtime, asset/font or module resource lifetime requests a full
323
+ page reload. Syntax/build failures retain the last good application; corrected
324
+ component edits can resume stateful updates. Module and render failures are
325
+ reported through the preview without creating a second Metro runtime.
326
+ Production-profile previews and the default esbuild frontend retain full reload.
327
+ Finite SDK builds and device package reload do not provide native stateful hot
328
+ reload. Native behavior and performance have separate qualification gates.
329
+
330
+ Custom preview systems can use `createRokuProjectDevServer` from
331
+ `react-native-roku/build/project` with `root`, optional `profile`, `port` and
332
+ `onBuild`; call its asynchronous `close()` to retire watchers and its owned
333
+ workspace. Lower-level integrations use `createRokuMetroRefreshSession` and
334
+ `writeRokuRefreshBootstrap` from `/build/frontend`. Keep one session and stable
335
+ entry/generated paths across builds, pass `{session,generation}` as `refresh`
336
+ to `buildRokuMetroModules`, and put the generated bootstrap before loading the
337
+ application. Stage the returned `refreshGraph` with an identity covering all
338
+ configuration, runtime, image and font bytes. Return its plan to
339
+ `createRokuDevServer` from `/build/dev`; publish the session only when that
340
+ generation is published, discard abandoned generations and dispose on close.
341
+ Configuration changes must never be represented as safe component updates.
342
+
343
+ The repository's `pnpm test:metro-development` separately qualifies the generated
344
+ Metro app's browser development loop through the same font/edit/error/fix/session
345
+ and activation journey as the default frontend. `pnpm check` and exact-archive
346
+ candidate qualification include the Metro build/reload lanes and a separate
347
+ `pnpm test:fast-refresh` installed-consumer browser journey locally.
348
+
349
+ For custom hosts, `createRokuHost` from `/sdk-host` owns SDK mechanics;
350
+ `mountRegisteredApplication` from `/application` mounts a registered React app.
351
+ React-side port types come from `/host` without SDK/Solid JSX types.
352
+ `generateSdkEntry`, `createRokuSdkConfiguration`, `readRokuConfig` and
353
+ `resolveProjectFont` from `/build/project` allow an existing canonical build to
354
+ generate the same native mechanics. A custom mount pipeline can use entryMode
355
+ `mount`; the default CLI app builder requires `component` or `registry`.
356
+ `prepareNativeComponents` from `/build` copies generic helpers into a generated
357
+ tree. SDK compilation remains separate from the React frontend typecheck.
358
+
359
+ Applications own routes, providers, queries, assets and product focus topology.
360
+ The host owns native lifecycle, key transport, fonts/raster setup, native service
361
+ adapters, retirement and exit requests. A stable `storageNamespace` keeps native
362
+ application storage separate. Never edit installed dependency sources.
363
+
364
+ ### Custom application lifetime
365
+
366
+ Custom launchers use `mountApplication` from `/application`, the same lifetime
367
+ owner used by `mountRegisteredApplication`. Content is created lazily after the
368
+ root/input and optional portable web runtime are bound:
369
+
370
+ ```tsx
371
+ import { mountApplication } from "react-native-roku/application";
372
+ const app = mountApplication(context, {
373
+ webRuntime: "host", // an explicit host fetch policy; default is portable
374
+ setup() {
375
+ const unsubscribe = subscribeApplicationFacts();
376
+ return unsubscribe;
377
+ },
378
+ createContent() {
379
+ const session = createApplicationSession();
380
+ return { element: <App session={session} />, dispose: () => session.close() };
381
+ },
382
+ });
383
+ try {
384
+ await app.whenCommitted();
385
+ } finally {
386
+ await app.dispose();
387
+ }
388
+ ```
389
+
390
+ `context` contains `scene` and the public native-root options, plus an optional
391
+ `webTransport`. The lifetime allocates its own input; `app.input` permits host
392
+ diagnostics but must not be disposed by the consumer. `remote` and
393
+ `publishSystem` stop admitting calls as soon as disposal begins. The root
394
+ and setup subscriptions retire synchronously; disposal awaits the content
395
+ callback, then releases the web leases. Resources needed by asynchronous content
396
+ cleanup belong to that content's disposer. Repeated/reentrant calls return the same promise. Every
397
+ independent cleanup is attempted and the first cleanup error rejects that
398
+ promise. A setup/content/render error remains the original synchronous error,
399
+ with any asynchronous cleanup rejection observed internally. A throwing setup
400
+ or content factory owns its own partially constructed resources until it
401
+ returns them. Handle asynchronous commit failures and dispose in `finally`.
402
+
403
+ The root owns the supplied text/raster providers after successful allocation;
404
+ allocation failure leaves those providers with the caller. Timer compatibility
405
+ is an idempotent process bootstrap, not a per-root clock lease. Overlapping
406
+ roots require the same viewport, system and device-services ports. Web leases
407
+ can retire out of order; an older async cleanup cannot clear a newer host's
408
+ globals or resurrect a retired installation. Consumer setup still owns any
409
+ additional global policy and must honor its own overlap requirements.
410
+
411
+ `examples/minimal/src/applicationOwnership.ts` is an executable packed-consumer
412
+ example with input, asynchronous disposal and original-error cleanup controls.
413
+ Run `pnpm test:consumer` in the producer to install and execute it outside the
414
+ producer checkout. It uses only public package imports and its own fixture
415
+ identities.
416
+
417
+ NativeWind className compilation still needs the app's Tailwind/CSS and Babel
418
+ configuration; aliasing alone does not compile CSS. Expo, navigation, SVG,
419
+ animation and storage integrations implement documented subsets. See the
420
+ [compatibility contract](compatibility.md).
421
+
422
+ ## Static images
423
+
424
+ The default project builders package static PNG/JPEG imports and convert WebP
425
+ to PNG. SDK builds import the prepared files; the browser preview serves those
426
+ same bytes under `/assets/`. Metro selects the first density at least as large
427
+ as the target scale, or the largest available variant, while preserving logical
428
+ width/height. The current logical-pixel host targets scale 1. Custom builds may
429
+ set `imageAssets.scale` explicitly; this is build-time selection, not adaptive
430
+ device-density switching.
431
+
432
+ Static PNG/JPEG/WebP data URI literals retain their exact authored values,
433
+ including schema-validated strings and JSX attributes. A generated registration
434
+ maps them to packaged images at the image adapter. Comments and URI-prefix
435
+ checks are untouched. Animated images and other embedded formats fail explicitly.
436
+ Host preparation and browser rendering do not establish native bitmap fidelity.
437
+
438
+ Custom build systems import `createRokuImageAssets` from
439
+ `react-native-roku/build/assets`. Its `packageImage` and `prepareEmbeddedSource`
440
+ methods compose with application-owned Babel transforms. `metroConfiguration`
441
+ provides the asset plugin/registry, `restoreMetroAssets` rematerializes a complete
442
+ Metro inventory, and `writeSdkModule` emits SDK imports for the used images.
443
+ `inventory` returns a deterministic, content-addressed file map. The optional
444
+ `esbuildPlugin` handles raster imports and embedded literals in standalone builds;
445
+ an existing Babel owner calls the preparation method before its own transform.
446
+ Use an owned output generation and retire it through your existing build policy.
447
+ `prepareEmbeddedSource` returns references to generated modules; prepare these
448
+ before starting a custom Metro file map. The public Metro frontend owns that
449
+ sequence automatically. Its optional inline mode retains literals in one module
450
+ and is suitable only when the caller separately enforces its module budget.
451
+ The compiler loads the reviewed SDK tooling's `sharp` dependency when needed.
452
+
453
+ ## Qualification
454
+
455
+ `pnpm check` in the platform repository runs both type boundaries, host/build
456
+ contracts, package hygiene, independent packed React and SDK consumers, and a
457
+ fresh-profile headless Chromium edit/reload/error/fix/activation journey. Set
458
+ `ROKU_TEST_CHROMIUM` if Chrome/Chromium is not in a standard location. Evidence
459
+ is saved under `.local/`. These checks prove the packaged development path;
460
+ firmware behavior and device performance remain unqualified.