react-native-roku 0.0.0-stage → 0.2.0-preview.3
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.
- package/CHANGELOG.md +328 -0
- package/CONTRIBUTING.md +34 -0
- package/LICENSE +21 -0
- package/NOTICE.md +10 -0
- package/README.md +66 -2
- package/bin/react-native-roku.mjs +91 -0
- package/build/assets.cjs +311 -0
- package/build/assets.d.cts +50 -0
- package/build/compatibility.d.mts +40 -0
- package/build/compatibility.mjs +272 -0
- package/build/dev.d.mts +34 -0
- package/build/dev.mjs +297 -0
- package/build/devWorkspace.d.mts +11 -0
- package/build/devWorkspace.mjs +86 -0
- package/build/device.d.mts +47 -0
- package/build/device.mjs +310 -0
- package/build/environment.d.mts +29 -0
- package/build/environment.mjs +144 -0
- package/build/esbuild.d.mts +5 -0
- package/build/esbuild.mjs +118 -0
- package/build/fontVariants.d.mts +27 -0
- package/build/fontVariants.mjs +424 -0
- package/build/frontend.d.mts +52 -0
- package/build/frontend.mjs +75 -0
- package/build/identity.mjs +45 -0
- package/build/index.d.mts +22 -0
- package/build/index.mjs +87 -0
- package/build/intl.mjs +121 -0
- package/build/metro.cjs +38 -0
- package/build/metro.d.cts +37 -0
- package/build/metroFrontend.mjs +222 -0
- package/build/metroMetadata.mjs +119 -0
- package/build/metroModules.mjs +397 -0
- package/build/metroRefresh.d.mts +64 -0
- package/build/metroRefresh.mjs +346 -0
- package/build/metroTransformer.cjs +146 -0
- package/build/nativeTextMemo.mjs +296 -0
- package/build/nativewind.d.mts +9 -0
- package/build/nativewind.mjs +92 -0
- package/build/project.d.mts +111 -0
- package/build/project.mjs +615 -0
- package/build/reactCompiler.mjs +113 -0
- package/build/reactProfile.cjs +35 -0
- package/build/refreshRuntime.mjs +187 -0
- package/build/refreshSourceMap.mjs +53 -0
- package/build/release.mjs +99 -0
- package/build/resolution.d.mts +3 -0
- package/build/resolution.mjs +25 -0
- package/build/surfaces.d.mts +1 -0
- package/build/surfaces.mjs +42 -0
- package/build/testing/node.d.mts +29 -0
- package/build/testing/node.mjs +106 -0
- package/build/yoga.d.mts +8 -0
- package/build/yoga.mjs +186 -0
- package/compatibility/public-api.json +327 -0
- package/compatibility/registry.json +2258 -0
- package/config/release.json +15 -0
- package/config/toolchain.json +34 -0
- package/docs/compatibility.md +813 -0
- package/docs/getting-started.md +460 -0
- package/docs/maintenance.md +368 -0
- package/docs/qualification.md +241 -0
- package/docs/standalone-testing.md +56 -0
- package/examples/hello-roku/README.md +35 -0
- package/examples/hello-roku/package.template.json +31 -0
- package/examples/hello-roku/pnpm-workspace.yaml +11 -0
- package/examples/hello-roku/roku.config.json +22 -0
- package/examples/hello-roku/src/App.tsx +54 -0
- package/examples/hello-roku/src/Catalog.tsx +200 -0
- package/examples/hello-roku/src/assets.d.ts +16 -0
- package/examples/hello-roku/src/catalog-cover.png +0 -0
- package/examples/hello-roku/tsconfig.json +1 -0
- package/examples/hello-roku/tsconfig.react.json +1 -0
- package/native/components/RNRAppControl.brs +215 -0
- package/native/components/RNRAppControl.xml +13 -0
- package/native/components/RNRDeviceFacts.brs +19 -0
- package/native/components/RNRDeviceFacts.xml +9 -0
- package/native/components/RNRDeviceFactsTask.brs +74 -0
- package/native/components/RNRDeviceFactsTask.xml +9 -0
- package/native/components/RNRTextRaster.brs +15 -0
- package/native/components/RNRTextRaster.xml +9 -0
- package/native/components/RNRTextRasterTask.brs +77 -0
- package/native/components/RNRTextRasterTask.xml +9 -0
- package/native/manifest.json +7 -0
- package/package.json +183 -3
- package/src/animation/clock.ts +10 -0
- package/src/animation/derivedValue.ts +163 -0
- package/src/animation/legacyAnimated.ts +255 -0
- package/src/animation/reanimated.ts +243 -0
- package/src/animation/sharedValue.ts +285 -0
- package/src/animation/worklets.ts +23 -0
- package/src/application/AppRegistry.ts +31 -0
- package/src/application/mountApplication.ts +136 -0
- package/src/graphics/BitmapLayer.tsx +68 -0
- package/src/graphics/RoundedBorder.tsx +116 -0
- package/src/graphics/TextRasterCache.ts +259 -0
- package/src/graphics/gradient.ts +37 -0
- package/src/graphics/inlineRaster.ts +85 -0
- package/src/graphics/png.ts +77 -0
- package/src/graphics/rasterPixels.ts +89 -0
- package/src/graphics/surfaces.ts +105 -0
- package/src/graphics/textRaster.types.ts +60 -0
- package/src/graphics/textRasterGeometry.ts +116 -0
- package/src/host/host.types.ts +57 -0
- package/src/index.ts +22 -0
- package/src/interop/nativewind.ts +2 -0
- package/src/layout/FontResources.ts +252 -0
- package/src/layout/affine.ts +89 -0
- package/src/layout/flexLayout.ts +398 -0
- package/src/layout/fontFaces.d.mts +19 -0
- package/src/layout/fontFaces.mjs +85 -0
- package/src/layout/fontVariants.d.mts +2 -0
- package/src/layout/fontVariants.mjs +8 -0
- package/src/layout/inlineParagraph.ts +158 -0
- package/src/layout/inlineText.ts +68 -0
- package/src/layout/layoutReuse.ts +117 -0
- package/src/layout/nativeNodeFields.ts +179 -0
- package/src/layout/preparedFields.ts +78 -0
- package/src/layout/textLayout.ts +138 -0
- package/src/layout/transform.ts +113 -0
- package/src/media/SceneGraphAudio.ts +161 -0
- package/src/media/SceneGraphVideo.ts +167 -0
- package/src/media/audioSession.ts +84 -0
- package/src/media/index.ts +2 -0
- package/src/media/videoErrorDetails.ts +40 -0
- package/src/media/videoSession.ts +136 -0
- package/src/navigation/RouterStore.ts +244 -0
- package/src/navigation/expoRouter.ts +115 -0
- package/src/react-native/NativeInput.ts +494 -0
- package/src/react-native/NativeSystemState.ts +95 -0
- package/src/react-native/accessibility.ts +265 -0
- package/src/react-native/activityIndicator.ts +72 -0
- package/src/react-native/compilerPressable.ts +26 -0
- package/src/react-native/createNativeRoot.ts +2126 -0
- package/src/react-native/directionalFocus.ts +55 -0
- package/src/react-native/environment.ts +275 -0
- package/src/react-native/flatList.ts +1001 -0
- package/src/react-native/flatListViewability.ts +231 -0
- package/src/react-native/focusEvents.ts +85 -0
- package/src/react-native/image.ts +247 -0
- package/src/react-native/index.ts +54 -0
- package/src/react-native/interactionManager.ts +76 -0
- package/src/react-native/keyboard.ts +60 -0
- package/src/react-native/linearGradient.ts +94 -0
- package/src/react-native/modal.tsx +148 -0
- package/src/react-native/nativeHostContext.ts +80 -0
- package/src/react-native/nativeModules.ts +86 -0
- package/src/react-native/nativeRoot.types.ts +22 -0
- package/src/react-native/nativeViewHandle.ts +191 -0
- package/src/react-native/nativewindPressable.ts +38 -0
- package/src/react-native/panResponder.ts +73 -0
- package/src/react-native/primitives.ts +685 -0
- package/src/react-native/safeArea.ts +76 -0
- package/src/react-native/scrollView.ts +289 -0
- package/src/react-native/styleInterop.ts +8 -0
- package/src/react-native/styleSheet.ts +54 -0
- package/src/react-native/textInput.ts +334 -0
- package/src/react-native/unsupported.ts +25 -0
- package/src/renderer/SceneRoot.ts +1006 -0
- package/src/scene/SdkDeviceFacts.ts +151 -0
- package/src/scene/SdkDeviceServices.ts +72 -0
- package/src/scene/SdkSceneGraph.ts +124 -0
- package/src/scene/SdkTextEntry.ts +321 -0
- package/src/scene/SdkTextMetrics.ts +136 -0
- package/src/scene/SdkTextRasterTransport.ts +191 -0
- package/src/scene/SdkWebTransport.ts +122 -0
- package/src/scene/createRokuHost.ts +213 -0
- package/src/scene/sceneGraph.types.ts +38 -0
- package/src/services/DeviceServices.ts +53 -0
- package/src/services/RegistryStorage.ts +85 -0
- package/src/services/RokuKeySession.ts +29 -0
- package/src/services/asyncStorage.ts +23 -0
- package/src/services/base64.ts +52 -0
- package/src/services/crypto.ts +18 -0
- package/src/services/expoConstants.ts +11 -0
- package/src/services/expoLinking.ts +12 -0
- package/src/services/expoStatusBar.ts +4 -0
- package/src/services/installWebRuntime.ts +105 -0
- package/src/services/intlEnglish.ts +54 -0
- package/src/services/languageRuntime.ts +65 -0
- package/src/services/nativeTimers.ts +96 -0
- package/src/services/secureStore.ts +23 -0
- package/src/services/textEntryRequest.ts +22 -0
- package/src/services/utf8.ts +57 -0
- package/src/services/webRuntime.ts +346 -0
- package/src/testing/CanvasResources.ts +141 -0
- package/src/testing/CanvasSceneGraph.ts +496 -0
- package/src/testing/CanvasTextEntry.ts +237 -0
- package/src/testing/PreviewTextObservations.ts +82 -0
- package/src/testing/RecordingSceneGraph.ts +136 -0
- package/src/types/normalize-colors.d.ts +4 -0
- package/src/vector/dynamicSvg.tsx +226 -0
- package/src/vector/svg.ts +222 -0
- package/src/vector/svg.types.ts +4 -0
- package/src/vector/svgElements.ts +58 -0
- package/src/vector/svgKey.d.mts +4 -0
- package/src/vector/svgKey.mjs +16 -0
- package/src/vector/svgPath.ts +157 -0
- package/src/vector/svgPixels.ts +133 -0
- package/tsconfig.consumer.json +29 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { RokuHostError } from "../scene/sceneGraph.types";
|
|
2
|
+
import { rokuColor } from "../react-native/styleSheet";
|
|
3
|
+
import { animationClock, type AnimationClock } from "./clock";
|
|
4
|
+
|
|
5
|
+
export type Animatable = number | string;
|
|
6
|
+
export type Animation =
|
|
7
|
+
| {
|
|
8
|
+
readonly kind: "timing";
|
|
9
|
+
readonly to: Animatable;
|
|
10
|
+
readonly duration: number;
|
|
11
|
+
readonly easing: (value: number) => number;
|
|
12
|
+
readonly callback?: (finished: boolean, value: Animatable) => void;
|
|
13
|
+
}
|
|
14
|
+
| {
|
|
15
|
+
readonly kind: "delay";
|
|
16
|
+
readonly duration: number;
|
|
17
|
+
readonly animation: Animation;
|
|
18
|
+
}
|
|
19
|
+
| { readonly kind: "sequence"; readonly animations: readonly Animation[] }
|
|
20
|
+
| {
|
|
21
|
+
readonly kind: "repeat";
|
|
22
|
+
readonly animation: Animation;
|
|
23
|
+
readonly count: number;
|
|
24
|
+
readonly reverse: boolean;
|
|
25
|
+
readonly callback?: (finished: boolean) => void;
|
|
26
|
+
};
|
|
27
|
+
export interface SharedValue<T> {
|
|
28
|
+
get value(): T;
|
|
29
|
+
set value(value: T | Animation);
|
|
30
|
+
get(): T;
|
|
31
|
+
set(value: T | Animation | ((previous: T) => T | Animation)): void;
|
|
32
|
+
modify(modifier?: (value: T) => T): void;
|
|
33
|
+
addListener(id: number, listener: (value: T) => void): void;
|
|
34
|
+
removeListener(id: number): void;
|
|
35
|
+
}
|
|
36
|
+
export interface MutableValue<T> extends SharedValue<T> {
|
|
37
|
+
readonly version: number;
|
|
38
|
+
subscribe(listener: () => void): () => void;
|
|
39
|
+
cancel(): void;
|
|
40
|
+
}
|
|
41
|
+
let collecting: Set<MutableValue<unknown>> | undefined;
|
|
42
|
+
export function collectValues<T>(work: () => T): {
|
|
43
|
+
value: T;
|
|
44
|
+
dependencies: Set<MutableValue<unknown>>;
|
|
45
|
+
} {
|
|
46
|
+
const previous = collecting,
|
|
47
|
+
dependencies = new Set<MutableValue<unknown>>();
|
|
48
|
+
collecting = dependencies;
|
|
49
|
+
try {
|
|
50
|
+
return { value: work(), dependencies };
|
|
51
|
+
} finally {
|
|
52
|
+
collecting = previous;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export function isAnimation(value: unknown): value is Animation {
|
|
56
|
+
return (
|
|
57
|
+
!!value &&
|
|
58
|
+
typeof value === "object" &&
|
|
59
|
+
"kind" in value &&
|
|
60
|
+
["timing", "delay", "sequence", "repeat"].includes(String(value.kind))
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
function mix(from: Animatable, to: Animatable, progress: number): Animatable {
|
|
64
|
+
if (progress >= 1) return to;
|
|
65
|
+
if (typeof from === "number" && typeof to === "number") return from + (to - from) * progress;
|
|
66
|
+
if (typeof from === "string" && typeof to === "string") {
|
|
67
|
+
const left = /^(-?\d+(?:\.\d+)?)(%|px|deg|rad)?$/.exec(from),
|
|
68
|
+
right = /^(-?\d+(?:\.\d+)?)(%|px|deg|rad)?$/.exec(to);
|
|
69
|
+
if (left && right && left[2] === right[2])
|
|
70
|
+
return `${Number(left[1]) + (Number(right[1]) - Number(left[1])) * progress}${left[2] ?? ""}`;
|
|
71
|
+
try {
|
|
72
|
+
const a = Number(rokuColor(from)),
|
|
73
|
+
b = Number(rokuColor(to));
|
|
74
|
+
let result = 0;
|
|
75
|
+
for (const shift of [24, 16, 8, 0])
|
|
76
|
+
result =
|
|
77
|
+
result * 256 +
|
|
78
|
+
Math.round(
|
|
79
|
+
((a >>> shift) & 255) + (((b >>> shift) & 255) - ((a >>> shift) & 255)) * progress,
|
|
80
|
+
);
|
|
81
|
+
return `#${result.toString(16).padStart(8, "0")}`;
|
|
82
|
+
} catch {
|
|
83
|
+
/* Report the actual unsupported interpolation below. */
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
throw new RokuHostError(
|
|
87
|
+
"C06_ANIMATION_VALUE",
|
|
88
|
+
`Cannot interpolate ${String(from)} to ${String(to)}`,
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
type Step = {
|
|
92
|
+
duration: number;
|
|
93
|
+
sample: (elapsed: number) => Animatable;
|
|
94
|
+
finish?: (finished: boolean, value: Animatable) => void;
|
|
95
|
+
target: Animatable;
|
|
96
|
+
};
|
|
97
|
+
function steps(animation: Animation, initial: Animatable): Step[] {
|
|
98
|
+
if (animation.kind === "timing")
|
|
99
|
+
return [
|
|
100
|
+
{
|
|
101
|
+
duration: animation.duration,
|
|
102
|
+
sample: (elapsed) =>
|
|
103
|
+
mix(
|
|
104
|
+
initial,
|
|
105
|
+
animation.to,
|
|
106
|
+
animation.easing(animation.duration ? Math.min(1, elapsed / animation.duration) : 1),
|
|
107
|
+
),
|
|
108
|
+
target: animation.to,
|
|
109
|
+
finish: animation.callback,
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
if (animation.kind === "delay")
|
|
113
|
+
return [
|
|
114
|
+
{ duration: animation.duration, sample: () => initial, target: initial },
|
|
115
|
+
...steps(animation.animation, initial),
|
|
116
|
+
];
|
|
117
|
+
if (animation.kind === "sequence") {
|
|
118
|
+
const result: Step[] = [];
|
|
119
|
+
let current = initial;
|
|
120
|
+
for (const child of animation.animations) {
|
|
121
|
+
const next = steps(child, current);
|
|
122
|
+
result.push(...next);
|
|
123
|
+
if (next.length) current = next[next.length - 1].target;
|
|
124
|
+
}
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
// Repetitions are expanded one cycle at a time by the runner, keeping infinite loops bounded.
|
|
128
|
+
return steps(animation.animation, initial);
|
|
129
|
+
}
|
|
130
|
+
export function makeMutable<T>(
|
|
131
|
+
initial: T,
|
|
132
|
+
clock: AnimationClock = animationClock,
|
|
133
|
+
): MutableValue<T> {
|
|
134
|
+
let current = initial,
|
|
135
|
+
version = 0,
|
|
136
|
+
generation = 0,
|
|
137
|
+
cancelRun: (() => void) | undefined;
|
|
138
|
+
const listeners = new Set<() => void>(),
|
|
139
|
+
identified = new Map<number, (value: T) => void>();
|
|
140
|
+
const publish = (value: T) => {
|
|
141
|
+
if (Object.is(current, value)) return;
|
|
142
|
+
current = value;
|
|
143
|
+
version++;
|
|
144
|
+
const publication = version;
|
|
145
|
+
for (const listener of [...listeners]) {
|
|
146
|
+
if (version !== publication) return;
|
|
147
|
+
listener();
|
|
148
|
+
}
|
|
149
|
+
for (const listener of [...identified.values()]) {
|
|
150
|
+
if (version !== publication) return;
|
|
151
|
+
listener(value);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const mutable: MutableValue<T> = {
|
|
155
|
+
get value(): T {
|
|
156
|
+
collecting?.add(mutable as MutableValue<unknown>);
|
|
157
|
+
return current;
|
|
158
|
+
},
|
|
159
|
+
set value(value: T | Animation) {
|
|
160
|
+
const request = ++generation;
|
|
161
|
+
const previous = cancelRun;
|
|
162
|
+
cancelRun = undefined;
|
|
163
|
+
previous?.();
|
|
164
|
+
// Cancellation callbacks may synchronously admit a newer request. That
|
|
165
|
+
// request owns the clock; the interrupted setter must not orphan it.
|
|
166
|
+
if (request !== generation) return;
|
|
167
|
+
if (!isAnimation(value)) {
|
|
168
|
+
publish(value);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (typeof current !== "string" && typeof current !== "number")
|
|
172
|
+
throw new RokuHostError(
|
|
173
|
+
"C06_ANIMATION_VALUE",
|
|
174
|
+
"Animated values must be numbers, compatible unit strings, or colors",
|
|
175
|
+
);
|
|
176
|
+
const initialValue = current as Animatable,
|
|
177
|
+
repeat = value.kind === "repeat" ? value : undefined;
|
|
178
|
+
let plan = steps(value, initialValue),
|
|
179
|
+
index = 0,
|
|
180
|
+
cycle = 0,
|
|
181
|
+
start = clock.now(),
|
|
182
|
+
frame: unknown,
|
|
183
|
+
canceled = false;
|
|
184
|
+
if (!plan.length) {
|
|
185
|
+
repeat?.callback?.(true);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const originalTarget = plan[plan.length - 1].target;
|
|
189
|
+
const stop = () => {
|
|
190
|
+
if (canceled) return;
|
|
191
|
+
canceled = true;
|
|
192
|
+
if (frame != null) clock.cancel(frame);
|
|
193
|
+
plan[index]?.finish?.(false, current as Animatable);
|
|
194
|
+
repeat?.callback?.(false);
|
|
195
|
+
};
|
|
196
|
+
cancelRun = stop;
|
|
197
|
+
const tick = () => {
|
|
198
|
+
if (canceled || request !== generation) return;
|
|
199
|
+
const now = clock.now();
|
|
200
|
+
// A blocked JS turn catches up to time rather than stretching the animation indefinitely.
|
|
201
|
+
let transitions = 0;
|
|
202
|
+
while (index < plan.length && now - start >= plan[index].duration) {
|
|
203
|
+
const step = plan[index++];
|
|
204
|
+
publish(step.target as T);
|
|
205
|
+
step.finish?.(true, step.target);
|
|
206
|
+
if (canceled) return;
|
|
207
|
+
start += step.duration;
|
|
208
|
+
if (
|
|
209
|
+
index === plan.length &&
|
|
210
|
+
repeat &&
|
|
211
|
+
(++cycle, repeat.count <= 0 || cycle < repeat.count)
|
|
212
|
+
) {
|
|
213
|
+
const target = repeat.reverse && cycle % 2 === 1 ? initialValue : originalTarget;
|
|
214
|
+
const base = repeat.animation;
|
|
215
|
+
if (repeat.reverse && base.kind !== "timing")
|
|
216
|
+
throw new RokuHostError(
|
|
217
|
+
"C06_ANIMATION_REPEAT",
|
|
218
|
+
"Reverse repetition requires a timing animation",
|
|
219
|
+
);
|
|
220
|
+
if (!repeat.reverse) publish(initialValue as T);
|
|
221
|
+
plan = steps(
|
|
222
|
+
repeat.reverse
|
|
223
|
+
? {
|
|
224
|
+
...(base as Extract<Animation, { kind: "timing" }>),
|
|
225
|
+
to: target,
|
|
226
|
+
}
|
|
227
|
+
: base,
|
|
228
|
+
current as Animatable,
|
|
229
|
+
);
|
|
230
|
+
index = 0;
|
|
231
|
+
}
|
|
232
|
+
if (++transitions > 10_000)
|
|
233
|
+
throw new RokuHostError(
|
|
234
|
+
"C06_ANIMATION_LOOP",
|
|
235
|
+
"Zero-duration infinite animation cannot make progress",
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
if (index === plan.length) {
|
|
239
|
+
canceled = true;
|
|
240
|
+
cancelRun = undefined;
|
|
241
|
+
repeat?.callback?.(true);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const sample = plan[index].sample(now - start) as T;
|
|
245
|
+
// A user easing function can replace/cancel this request while sampled.
|
|
246
|
+
if (canceled || request !== generation) return;
|
|
247
|
+
publish(sample);
|
|
248
|
+
if (!canceled) frame = clock.request(tick);
|
|
249
|
+
};
|
|
250
|
+
tick();
|
|
251
|
+
},
|
|
252
|
+
get version() {
|
|
253
|
+
return version;
|
|
254
|
+
},
|
|
255
|
+
get() {
|
|
256
|
+
return mutable.value;
|
|
257
|
+
},
|
|
258
|
+
set(value) {
|
|
259
|
+
mutable.value =
|
|
260
|
+
typeof value === "function" ? (value as (previous: T) => T | Animation)(current) : value;
|
|
261
|
+
},
|
|
262
|
+
modify(modifier) {
|
|
263
|
+
if (modifier) mutable.value = modifier(current);
|
|
264
|
+
},
|
|
265
|
+
addListener(id, listener) {
|
|
266
|
+
identified.set(id, listener);
|
|
267
|
+
},
|
|
268
|
+
removeListener(id) {
|
|
269
|
+
identified.delete(id);
|
|
270
|
+
},
|
|
271
|
+
subscribe(listener) {
|
|
272
|
+
listeners.add(listener);
|
|
273
|
+
return () => {
|
|
274
|
+
listeners.delete(listener);
|
|
275
|
+
};
|
|
276
|
+
},
|
|
277
|
+
cancel() {
|
|
278
|
+
generation++;
|
|
279
|
+
const cancel = cancelRun;
|
|
280
|
+
cancelRun = undefined;
|
|
281
|
+
cancel?.();
|
|
282
|
+
},
|
|
283
|
+
};
|
|
284
|
+
return mutable;
|
|
285
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** SceneGraph and React share one JS runtime; these calls execute on that runtime. */
|
|
2
|
+
export function runOnUISync<TArgs extends unknown[], TResult>(
|
|
3
|
+
work: (...args: TArgs) => TResult,
|
|
4
|
+
...args: TArgs
|
|
5
|
+
): TResult {
|
|
6
|
+
return work(...args);
|
|
7
|
+
}
|
|
8
|
+
export function scheduleOnRN<TArgs extends unknown[]>(
|
|
9
|
+
work: (...args: TArgs) => void,
|
|
10
|
+
...args: TArgs
|
|
11
|
+
): void {
|
|
12
|
+
work(...args);
|
|
13
|
+
}
|
|
14
|
+
export function runOnJS<TArgs extends unknown[], TResult>(
|
|
15
|
+
work: (...args: TArgs) => TResult,
|
|
16
|
+
): (...args: TArgs) => TResult {
|
|
17
|
+
return work;
|
|
18
|
+
}
|
|
19
|
+
export function runOnUI<TArgs extends unknown[]>(
|
|
20
|
+
work: (...args: TArgs) => void,
|
|
21
|
+
): (...args: TArgs) => void {
|
|
22
|
+
return work;
|
|
23
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createElement, type ComponentType, type ReactElement } from "react";
|
|
2
|
+
import { RokuHostError } from "../scene/sceneGraph.types";
|
|
3
|
+
const applications = new Map<string, () => ComponentType<Record<string, unknown>>>();
|
|
4
|
+
/** Registration-compatible React Native entry API. Native roots remain host-owned. */
|
|
5
|
+
export const AppRegistry = Object.freeze({
|
|
6
|
+
registerComponent<Props extends object>(
|
|
7
|
+
key: string,
|
|
8
|
+
provider: () => ComponentType<Props>,
|
|
9
|
+
): string {
|
|
10
|
+
if (!key.trim() || typeof provider !== "function")
|
|
11
|
+
throw new RokuHostError(
|
|
12
|
+
"R01_APP_REGISTRY",
|
|
13
|
+
"An application needs a name and component provider",
|
|
14
|
+
);
|
|
15
|
+
applications.set(key, provider as unknown as () => ComponentType<Record<string, unknown>>);
|
|
16
|
+
return key;
|
|
17
|
+
},
|
|
18
|
+
getAppKeys: () => [...applications.keys()],
|
|
19
|
+
getRunnable: (key: string) =>
|
|
20
|
+
applications.has(key) ? { componentProvider: applications.get(key)! } : undefined,
|
|
21
|
+
unregisterComponent: (key: string) => applications.delete(key),
|
|
22
|
+
});
|
|
23
|
+
export function registeredApplication(
|
|
24
|
+
key: string,
|
|
25
|
+
initialProps: Record<string, unknown> = {},
|
|
26
|
+
): ReactElement {
|
|
27
|
+
const provider = applications.get(key);
|
|
28
|
+
if (!provider)
|
|
29
|
+
throw new RokuHostError("R01_APP_REGISTRY", `Application ${key} has not been registered`);
|
|
30
|
+
return createElement(provider(), initialProps);
|
|
31
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { createNativeRoot } from "../react-native/createNativeRoot";
|
|
2
|
+
import { NativeInput } from "../react-native/NativeInput";
|
|
3
|
+
import { NativeSystemState } from "../react-native/NativeSystemState";
|
|
4
|
+
import { installNativeAnimationFrames } from "../services/nativeTimers";
|
|
5
|
+
import { installWebRuntime } from "../services/installWebRuntime";
|
|
6
|
+
import type { RokuHostContext, MountedRokuApplication } from "../host/host.types";
|
|
7
|
+
import { registeredApplication } from "./AppRegistry";
|
|
8
|
+
import type { ReactNode } from "react";
|
|
9
|
+
import type { NativeRootOptions } from "../react-native/nativeRoot.types";
|
|
10
|
+
import type { SceneRoot } from "../renderer/SceneRoot";
|
|
11
|
+
import type { SceneGraphPort } from "../scene/sceneGraph.types";
|
|
12
|
+
import type { WebTransport } from "../services/webRuntime";
|
|
13
|
+
|
|
14
|
+
export interface RokuApplicationContent {
|
|
15
|
+
readonly element: ReactNode;
|
|
16
|
+
dispose?(): void | Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface RokuApplicationContext extends Omit<NativeRootOptions, "input"> {
|
|
20
|
+
readonly scene: SceneGraphPort;
|
|
21
|
+
readonly webTransport?: WebTransport;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface RokuApplicationOptions<Content extends RokuApplicationContent> {
|
|
25
|
+
/** Runs after host allocation, before lazy content creation. A throwing setup
|
|
26
|
+
* owns rollback of resources it has not yet returned to this lifetime.
|
|
27
|
+
* Return a synchronous retirement callback; resources needed by asynchronous
|
|
28
|
+
* content disposal belong to the content's own disposer. */
|
|
29
|
+
setup?(): void | (() => void);
|
|
30
|
+
createContent(): Content;
|
|
31
|
+
/** Host mode preserves the caller's fetch/global policy. */
|
|
32
|
+
webRuntime?: "portable" | "host";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface MountedApplication<
|
|
36
|
+
Content extends RokuApplicationContent,
|
|
37
|
+
> extends MountedRokuApplication {
|
|
38
|
+
readonly content: Content;
|
|
39
|
+
/** Diagnostics and host input transport; this lifetime owns its disposal. */
|
|
40
|
+
readonly input: NativeInput;
|
|
41
|
+
dispose(): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** One React root/input lifetime for registered and custom application entries.
|
|
45
|
+
* The root owns text/raster providers; the SDK host may separately retry their
|
|
46
|
+
* idempotent disposal. Timer compatibility is process-scoped and idempotent. */
|
|
47
|
+
export function mountApplication<Content extends RokuApplicationContent>(
|
|
48
|
+
context: RokuApplicationContext,
|
|
49
|
+
options: RokuApplicationOptions<Content>,
|
|
50
|
+
): MountedApplication<Content> {
|
|
51
|
+
installNativeAnimationFrames();
|
|
52
|
+
const input = new NativeInput();
|
|
53
|
+
const system = context.system ?? new NativeSystemState({ appState: "active" });
|
|
54
|
+
let root: SceneRoot | undefined, content: Content | undefined;
|
|
55
|
+
let releaseWeb: (() => void) | undefined, releaseSetup: (() => void) | void;
|
|
56
|
+
let retired = false,
|
|
57
|
+
disposal: Promise<void> | undefined;
|
|
58
|
+
const dispose = (): Promise<void> => {
|
|
59
|
+
if (disposal) return disposal;
|
|
60
|
+
// Publish the transaction before invoking consumer or React cleanup, both
|
|
61
|
+
// of which may synchronously reenter disposal.
|
|
62
|
+
let resolve!: () => void, reject!: (error: unknown) => void;
|
|
63
|
+
disposal = new Promise<void>((done, fail) => {
|
|
64
|
+
resolve = done;
|
|
65
|
+
reject = fail;
|
|
66
|
+
});
|
|
67
|
+
retired = true;
|
|
68
|
+
const failures: unknown[] = [];
|
|
69
|
+
const attempt = (work: () => void) => {
|
|
70
|
+
try {
|
|
71
|
+
work();
|
|
72
|
+
} catch (error) {
|
|
73
|
+
failures.push(error);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
attempt(() => root?.unmount());
|
|
77
|
+
attempt(() => input.dispose());
|
|
78
|
+
// Subscriptions lose authority before consumer cleanup can yield or mount
|
|
79
|
+
// another root. Global web leases remain available for that cleanup's IO.
|
|
80
|
+
attempt(() => releaseSetup?.());
|
|
81
|
+
let consumer: void | Promise<void>;
|
|
82
|
+
attempt(() => {
|
|
83
|
+
consumer = content?.dispose?.();
|
|
84
|
+
});
|
|
85
|
+
void Promise.resolve(consumer!)
|
|
86
|
+
.catch((error) => {
|
|
87
|
+
failures.push(error);
|
|
88
|
+
})
|
|
89
|
+
.then(() => {
|
|
90
|
+
attempt(() => releaseWeb?.());
|
|
91
|
+
if (failures.length) reject(failures[0]);
|
|
92
|
+
else resolve();
|
|
93
|
+
});
|
|
94
|
+
return disposal;
|
|
95
|
+
};
|
|
96
|
+
try {
|
|
97
|
+
root = createNativeRoot(context.scene, { ...context, system, input });
|
|
98
|
+
if (options.webRuntime !== "host") releaseWeb = installWebRuntime(context.webTransport);
|
|
99
|
+
releaseSetup = options.setup?.();
|
|
100
|
+
content = options.createContent();
|
|
101
|
+
root.render(content.element);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
// Startup remains synchronous. Observe asynchronous cleanup without
|
|
104
|
+
// replacing the allocation/setup/content/render error that the caller sees.
|
|
105
|
+
void dispose().catch(() => undefined);
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
content,
|
|
110
|
+
input,
|
|
111
|
+
remote: (event) => !retired && input.dispatch(event),
|
|
112
|
+
publishSystem: (snapshot) => {
|
|
113
|
+
if (!retired) root!.runSync(() => system.publish(snapshot));
|
|
114
|
+
},
|
|
115
|
+
whenCommitted: () => (retired ? Promise.resolve() : root!.whenCommitted()),
|
|
116
|
+
dispose,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function mountRegisteredApplication(
|
|
121
|
+
context: RokuHostContext,
|
|
122
|
+
options: {
|
|
123
|
+
appKey: string;
|
|
124
|
+
load(): void;
|
|
125
|
+
initialProps?: Record<string, unknown>;
|
|
126
|
+
webRuntime?: "portable" | "host";
|
|
127
|
+
},
|
|
128
|
+
): MountedRokuApplication {
|
|
129
|
+
return mountApplication(context, {
|
|
130
|
+
webRuntime: options.webRuntime,
|
|
131
|
+
createContent() {
|
|
132
|
+
options.load();
|
|
133
|
+
return { element: registeredApplication(options.appKey, options.initialProps) };
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { createElement, useEffect, useState, useRef } from "react";
|
|
2
|
+
import { useNativeHost } from "../react-native/nativeHostContext";
|
|
3
|
+
import { RokuHostError } from "../scene/sceneGraph.types";
|
|
4
|
+
import type { TextRasterLease } from "./textRaster.types";
|
|
5
|
+
export function BitmapLayer({
|
|
6
|
+
identity,
|
|
7
|
+
width,
|
|
8
|
+
height,
|
|
9
|
+
pixels,
|
|
10
|
+
}: {
|
|
11
|
+
identity: string;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
pixels: () => Uint8Array;
|
|
15
|
+
}) {
|
|
16
|
+
const host = useNativeHost();
|
|
17
|
+
const render = useRef(pixels);
|
|
18
|
+
render.current = pixels;
|
|
19
|
+
identity = `${width}x${height}:${identity}`;
|
|
20
|
+
const [state, setState] = useState<
|
|
21
|
+
{ identity: string; uri: string } | { identity: string; error: unknown }
|
|
22
|
+
>();
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
let active = true,
|
|
25
|
+
lease: TextRasterLease | undefined;
|
|
26
|
+
const port = host.raster?.acquirePixels;
|
|
27
|
+
if (!port) {
|
|
28
|
+
setState({
|
|
29
|
+
identity,
|
|
30
|
+
error: new RokuHostError(
|
|
31
|
+
"C09_RASTER_PORT",
|
|
32
|
+
"Vector graphics require the bounded bitmap resource port",
|
|
33
|
+
),
|
|
34
|
+
});
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
void port
|
|
38
|
+
.call(host.raster, {
|
|
39
|
+
key: identity,
|
|
40
|
+
width,
|
|
41
|
+
height,
|
|
42
|
+
pixels: () => render.current(),
|
|
43
|
+
})
|
|
44
|
+
.then(
|
|
45
|
+
(value) => {
|
|
46
|
+
if (!active) value.release();
|
|
47
|
+
else {
|
|
48
|
+
lease = value;
|
|
49
|
+
setState({ identity, uri: value.image.uri });
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
(error) => {
|
|
53
|
+
if (active) setState({ identity, error });
|
|
54
|
+
},
|
|
55
|
+
);
|
|
56
|
+
return () => {
|
|
57
|
+
active = false;
|
|
58
|
+
lease?.release();
|
|
59
|
+
};
|
|
60
|
+
}, [host, identity, width, height]);
|
|
61
|
+
if (state?.identity === identity && "error" in state) throw state.error;
|
|
62
|
+
return state?.identity === identity && "uri" in state
|
|
63
|
+
? createElement("poster", {
|
|
64
|
+
fields: { uri: state.uri, loadDisplayMode: "scaleToFit" },
|
|
65
|
+
layout: { decoration: "background" },
|
|
66
|
+
})
|
|
67
|
+
: null;
|
|
68
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createElement, useId, useState } from "react";
|
|
2
|
+
import { BitmapLayer } from "./BitmapLayer";
|
|
3
|
+
import { surfaceRadii } from "./surfaces";
|
|
4
|
+
import type { LayoutStyle } from "../layout/flexLayout";
|
|
5
|
+
import type { Point } from "../vector/svgPath";
|
|
6
|
+
import { svgPixels } from "../vector/svgPixels";
|
|
7
|
+
import { rokuColor } from "../react-native/styleSheet";
|
|
8
|
+
import { RokuHostError } from "../scene/sceneGraph.types";
|
|
9
|
+
const edges = ["Top", "Right", "Bottom", "Left"] as const;
|
|
10
|
+
function rounded(
|
|
11
|
+
x: number,
|
|
12
|
+
y: number,
|
|
13
|
+
width: number,
|
|
14
|
+
height: number,
|
|
15
|
+
radii: readonly (readonly [number, number])[],
|
|
16
|
+
): Point[] {
|
|
17
|
+
const centers = [
|
|
18
|
+
[x + width - radii[1][0], y + radii[1][1]],
|
|
19
|
+
[x + width - radii[2][0], y + height - radii[2][1]],
|
|
20
|
+
[x + radii[3][0], y + height - radii[3][1]],
|
|
21
|
+
[x + radii[0][0], y + radii[0][1]],
|
|
22
|
+
];
|
|
23
|
+
const order = [1, 2, 3, 0];
|
|
24
|
+
const points = centers.flatMap(([cx, cy], i) =>
|
|
25
|
+
Array.from({ length: 17 }, (_, n) => {
|
|
26
|
+
const angle = ((-1 + i) * Math.PI) / 2 + (n * Math.PI) / 32,
|
|
27
|
+
[rx, ry] = radii[order[i]];
|
|
28
|
+
return [cx + rx * Math.cos(angle), cy + ry * Math.sin(angle)] as Point;
|
|
29
|
+
}),
|
|
30
|
+
);
|
|
31
|
+
return [...points, points[0]];
|
|
32
|
+
}
|
|
33
|
+
export function roundedBorderPixels(style: LayoutStyle, width: number, height: number) {
|
|
34
|
+
const borders = edges.map((edge) =>
|
|
35
|
+
Number(style[`border${edge}Width`] ?? style.borderWidth ?? 0),
|
|
36
|
+
);
|
|
37
|
+
if (borders.some((value) => !Number.isFinite(value) || value < 0))
|
|
38
|
+
throw new RokuHostError("C03_BORDER", "Border widths must be finite and nonnegative");
|
|
39
|
+
const colors = edges
|
|
40
|
+
.filter((_, index) => borders[index] > 0)
|
|
41
|
+
.map((edge) => String(style[`border${edge}Color`] ?? style.borderColor ?? "black"));
|
|
42
|
+
if (new Set(colors.map(rokuColor)).size > 1)
|
|
43
|
+
throw new RokuHostError(
|
|
44
|
+
"C03_ROUNDED_BORDER",
|
|
45
|
+
"Multicolor asymmetric rounded borders need a paint adapter",
|
|
46
|
+
);
|
|
47
|
+
const radii = surfaceRadii(style, width, height),
|
|
48
|
+
[top, right, bottom, left] = borders;
|
|
49
|
+
const outer = rounded(
|
|
50
|
+
0,
|
|
51
|
+
0,
|
|
52
|
+
width,
|
|
53
|
+
height,
|
|
54
|
+
radii.map((radius) => [radius, radius] as const),
|
|
55
|
+
);
|
|
56
|
+
const inner =
|
|
57
|
+
width > left + right && height > top + bottom
|
|
58
|
+
? rounded(
|
|
59
|
+
left,
|
|
60
|
+
top,
|
|
61
|
+
width - left - right,
|
|
62
|
+
height - top - bottom,
|
|
63
|
+
radii.map(
|
|
64
|
+
(radius, index) =>
|
|
65
|
+
[
|
|
66
|
+
Math.max(0, radius - (index === 0 || index === 3 ? left : right)),
|
|
67
|
+
Math.max(0, radius - (index < 2 ? top : bottom)),
|
|
68
|
+
] as const,
|
|
69
|
+
),
|
|
70
|
+
).reverse()
|
|
71
|
+
: [];
|
|
72
|
+
return svgPixels(Math.ceil(width), Math.ceil(height), [
|
|
73
|
+
{
|
|
74
|
+
paths: [outer, ...(inner.length ? [inner] : [])],
|
|
75
|
+
fill: colors[0] ?? "transparent",
|
|
76
|
+
},
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
79
|
+
export function RoundedBorder({ style }: { style: LayoutStyle }) {
|
|
80
|
+
const id = useId(),
|
|
81
|
+
[size, setSize] = useState<{ width: number; height: number }>();
|
|
82
|
+
const identity = JSON.stringify({
|
|
83
|
+
style: Object.fromEntries(Object.entries(style).filter(([key]) => key.startsWith("border"))),
|
|
84
|
+
size,
|
|
85
|
+
});
|
|
86
|
+
return createElement(
|
|
87
|
+
"group",
|
|
88
|
+
{
|
|
89
|
+
layout: {
|
|
90
|
+
id,
|
|
91
|
+
decoration: "background",
|
|
92
|
+
onLayout(event: unknown) {
|
|
93
|
+
const value = (
|
|
94
|
+
event as {
|
|
95
|
+
nativeEvent: { layout: { width: number; height: number } };
|
|
96
|
+
}
|
|
97
|
+
).nativeEvent.layout;
|
|
98
|
+
if (value.width > 0 && value.height > 0)
|
|
99
|
+
setSize((previous) =>
|
|
100
|
+
previous?.width === value.width && previous.height === value.height
|
|
101
|
+
? previous
|
|
102
|
+
: { width: value.width, height: value.height },
|
|
103
|
+
);
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
size
|
|
108
|
+
? createElement(BitmapLayer, {
|
|
109
|
+
identity,
|
|
110
|
+
width: Math.ceil(size.width),
|
|
111
|
+
height: Math.ceil(size.height),
|
|
112
|
+
pixels: () => roundedBorderPixels(style, size.width, size.height),
|
|
113
|
+
})
|
|
114
|
+
: null,
|
|
115
|
+
);
|
|
116
|
+
}
|