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,60 @@
|
|
|
1
|
+
import { RokuHostError } from "../scene/sceneGraph.types";
|
|
2
|
+
import type { TextEntrySession } from "../services/DeviceServices";
|
|
3
|
+
|
|
4
|
+
const listeners = new Set<() => void>();
|
|
5
|
+
let attempt = 0,
|
|
6
|
+
generation = 0;
|
|
7
|
+
let current: { generation: number; dismiss(): void } | undefined;
|
|
8
|
+
|
|
9
|
+
/** A blur callback may synchronously focus another editor. The outer request
|
|
10
|
+
* must not overwrite that newer focus transaction. */
|
|
11
|
+
export function prepareKeyboardFocus(): () => boolean {
|
|
12
|
+
const request = ++attempt;
|
|
13
|
+
current?.dismiss();
|
|
14
|
+
return () => attempt === request;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function trackKeyboardSession(
|
|
18
|
+
session: TextEntrySession,
|
|
19
|
+
dismiss: () => void,
|
|
20
|
+
alive: () => boolean,
|
|
21
|
+
): () => void {
|
|
22
|
+
const token = ++generation;
|
|
23
|
+
const owner = { generation: token, dismiss };
|
|
24
|
+
current = owner;
|
|
25
|
+
if (session.closed) {
|
|
26
|
+
// TextInput's result handler is registered first. Even a provider delivering
|
|
27
|
+
// closure before its result cannot let a hide listener discard accepted text.
|
|
28
|
+
void Promise.all([session.result, session.closed]).then(
|
|
29
|
+
([, observed]) => {
|
|
30
|
+
if (observed !== true || generation !== token || !alive()) return;
|
|
31
|
+
for (const listener of [...listeners]) listener();
|
|
32
|
+
},
|
|
33
|
+
() => undefined,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return () => {
|
|
37
|
+
if (current === owner) current = undefined;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Modal keyboard subset: observed dismissal has no invented IME geometry,
|
|
42
|
+
* animation timing or will/show events. */
|
|
43
|
+
export const Keyboard = Object.freeze({
|
|
44
|
+
addListener(name: string, listener: () => void) {
|
|
45
|
+
if (name !== "keyboardDidHide")
|
|
46
|
+
throw new RokuHostError(
|
|
47
|
+
"C07_KEYBOARD_EVENT",
|
|
48
|
+
"Only keyboardDidHide is supported by the modal keyboard host",
|
|
49
|
+
);
|
|
50
|
+
listeners.add(listener);
|
|
51
|
+
return {
|
|
52
|
+
remove: () => {
|
|
53
|
+
listeners.delete(listener);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
dismiss(): void {
|
|
58
|
+
current?.dismiss();
|
|
59
|
+
},
|
|
60
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { createElement, forwardRef, Fragment } from "react";
|
|
2
|
+
import { background, SurfaceClip, useElement, type NativeElementProps } from "./primitives";
|
|
3
|
+
import { useNativeHost } from "./nativeHostContext";
|
|
4
|
+
import type { NativeViewHandle } from "./nativeViewHandle";
|
|
5
|
+
import { hasRoundedCorners, uniformBorder } from "../graphics/surfaces";
|
|
6
|
+
import { rokuColor } from "./styleSheet";
|
|
7
|
+
import { RokuHostError } from "../scene/sceneGraph.types";
|
|
8
|
+
export interface LinearGradientProps extends NativeElementProps {
|
|
9
|
+
readonly colors: readonly unknown[];
|
|
10
|
+
readonly locations?: readonly number[];
|
|
11
|
+
readonly start?: { x: number; y: number };
|
|
12
|
+
readonly end?: { x: number; y: number };
|
|
13
|
+
readonly dither?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export const LinearGradient = forwardRef<NativeViewHandle, LinearGradientProps>((props, ref) => {
|
|
16
|
+
const host = useNativeHost(),
|
|
17
|
+
element = useElement(props, ref);
|
|
18
|
+
if (!host.graphics?.effects)
|
|
19
|
+
throw new RokuHostError("C03_GRADIENT", "Gradients require the OS 16 OpenGL Effect capability");
|
|
20
|
+
if (
|
|
21
|
+
props.colors.length < 2 ||
|
|
22
|
+
props.colors.length > 8 ||
|
|
23
|
+
(props.locations && props.locations.length !== props.colors.length)
|
|
24
|
+
)
|
|
25
|
+
throw new RokuHostError(
|
|
26
|
+
"C03_GRADIENT",
|
|
27
|
+
"Native gradients require 2..8 colors and matching stops",
|
|
28
|
+
);
|
|
29
|
+
if (props.dither === false)
|
|
30
|
+
throw new RokuHostError(
|
|
31
|
+
"C03_GRADIENT_DITHER",
|
|
32
|
+
"The native Effect does not expose a dither switch",
|
|
33
|
+
);
|
|
34
|
+
const border = uniformBorder(element.style),
|
|
35
|
+
rounded = hasRoundedCorners(element.style);
|
|
36
|
+
return createElement(
|
|
37
|
+
"group",
|
|
38
|
+
{ fields: element.fields, layout: element.layout },
|
|
39
|
+
createElement(
|
|
40
|
+
Fragment,
|
|
41
|
+
{ key: "base" },
|
|
42
|
+
element.style.backgroundColor == null
|
|
43
|
+
? null
|
|
44
|
+
: background(
|
|
45
|
+
{
|
|
46
|
+
...element.style,
|
|
47
|
+
borderWidth: 0,
|
|
48
|
+
borderTopWidth: 0,
|
|
49
|
+
borderRightWidth: 0,
|
|
50
|
+
borderBottomWidth: 0,
|
|
51
|
+
borderLeftWidth: 0,
|
|
52
|
+
},
|
|
53
|
+
host.graphics,
|
|
54
|
+
),
|
|
55
|
+
),
|
|
56
|
+
createElement(
|
|
57
|
+
"rectangle",
|
|
58
|
+
{
|
|
59
|
+
// The native Effect composites its stops over the Rectangle color.
|
|
60
|
+
fields: { color: "0x00000000" },
|
|
61
|
+
layout: { decoration: "background" },
|
|
62
|
+
},
|
|
63
|
+
createElement("effect", {
|
|
64
|
+
fields: {
|
|
65
|
+
borderWidth: 0,
|
|
66
|
+
gradientStyle: "linear",
|
|
67
|
+
gradientColors: props.colors.map(rokuColor),
|
|
68
|
+
},
|
|
69
|
+
layout: {
|
|
70
|
+
resource: true,
|
|
71
|
+
radiusStyle: element.style,
|
|
72
|
+
insetBorder: 0,
|
|
73
|
+
gradient: {
|
|
74
|
+
start: props.start ?? { x: 0.5, y: 0 },
|
|
75
|
+
end: props.end ?? { x: 0.5, y: 1 },
|
|
76
|
+
locations:
|
|
77
|
+
props.locations ?? props.colors.map((_, index) => index / (props.colors.length - 1)),
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
),
|
|
82
|
+
border
|
|
83
|
+
? createElement(
|
|
84
|
+
Fragment,
|
|
85
|
+
{ key: "border" },
|
|
86
|
+
...background({ ...element.style, backgroundColor: undefined }, host.graphics),
|
|
87
|
+
)
|
|
88
|
+
: null,
|
|
89
|
+
rounded && element.style.overflow === "hidden"
|
|
90
|
+
? createElement(SurfaceClip, { style: element.style }, props.children)
|
|
91
|
+
: props.children,
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
LinearGradient.displayName = "RokuLinearGradient";
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { createElement, useEffect, useId, useState, useRef, type ReactNode } from "react";
|
|
2
|
+
import { useNativeHost } from "./nativeHostContext";
|
|
3
|
+
import { BackHandler } from "./environment";
|
|
4
|
+
import { Animated, Easing } from "../animation/legacyAnimated";
|
|
5
|
+
import { RokuHostError } from "../scene/sceneGraph.types";
|
|
6
|
+
import type { AccessibilityProps } from "./accessibility";
|
|
7
|
+
let sequence = 0;
|
|
8
|
+
interface ModalProps extends AccessibilityProps {
|
|
9
|
+
readonly children?: ReactNode;
|
|
10
|
+
readonly visible?: boolean;
|
|
11
|
+
readonly transparent?: boolean;
|
|
12
|
+
readonly animationType?: "none" | "fade" | "slide";
|
|
13
|
+
readonly onShow?: () => void;
|
|
14
|
+
readonly onRequestClose?: () => void;
|
|
15
|
+
readonly onDismiss?: () => void;
|
|
16
|
+
}
|
|
17
|
+
/** Roku has one scene viewport. React portals preserve context and escape parent clips. */
|
|
18
|
+
export function Modal({
|
|
19
|
+
children,
|
|
20
|
+
visible = true,
|
|
21
|
+
transparent = false,
|
|
22
|
+
animationType = "none",
|
|
23
|
+
onShow,
|
|
24
|
+
onRequestClose,
|
|
25
|
+
onDismiss,
|
|
26
|
+
...accessibility
|
|
27
|
+
}: ModalProps) {
|
|
28
|
+
const host = useNativeHost(),
|
|
29
|
+
id = useId(),
|
|
30
|
+
[order, setOrder] = useState(() => ++sequence),
|
|
31
|
+
[present, setPresent] = useState(visible),
|
|
32
|
+
[progress] = useState(() => new Animated.Value(animationType === "none" ? 1 : 0));
|
|
33
|
+
const callbacks = useRef({ onShow, onRequestClose, onDismiss });
|
|
34
|
+
const presentation = useRef(0);
|
|
35
|
+
callbacks.current = { onShow, onRequestClose, onDismiss };
|
|
36
|
+
// A newly presented sibling belongs above already presented siblings.
|
|
37
|
+
// Adjust this component's state before reconciling its portal children so
|
|
38
|
+
// nested modals receive their later order. A closing reversal keeps the
|
|
39
|
+
// existing presentation and cannot jump above its retained nested modal.
|
|
40
|
+
if (visible && !present) {
|
|
41
|
+
setPresent(true);
|
|
42
|
+
setOrder(++sequence);
|
|
43
|
+
}
|
|
44
|
+
if (!["none", "fade", "slide"].includes(animationType))
|
|
45
|
+
throw new RokuHostError(
|
|
46
|
+
"C03_MODAL_ANIMATION",
|
|
47
|
+
"The modal animation must be none, fade or slide",
|
|
48
|
+
);
|
|
49
|
+
const mounted = visible || (animationType !== "none" && present);
|
|
50
|
+
const modalID = `roku-modal-${id}`;
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (!mounted) return;
|
|
53
|
+
presentation.current++;
|
|
54
|
+
const subscription = BackHandler.addEventListener("hardwareBackPress", () => {
|
|
55
|
+
// Effect registration order can differ from paint order. The presented
|
|
56
|
+
// portal keeps Back when a dialog inside it isolates accessibility or
|
|
57
|
+
// while the portal finishes its closing animation.
|
|
58
|
+
const placement = host.placement(modalID);
|
|
59
|
+
if (
|
|
60
|
+
!host.active ||
|
|
61
|
+
!placement ||
|
|
62
|
+
placement.visible === false ||
|
|
63
|
+
(placement.modalBlocked && !placement.containsActiveModalScope)
|
|
64
|
+
)
|
|
65
|
+
return false;
|
|
66
|
+
callbacks.current.onRequestClose?.();
|
|
67
|
+
return true;
|
|
68
|
+
});
|
|
69
|
+
return () => {
|
|
70
|
+
subscription.remove();
|
|
71
|
+
const generation = ++presentation.current;
|
|
72
|
+
void host.whenCommitted().then(
|
|
73
|
+
() => {
|
|
74
|
+
if (presentation.current === generation) callbacks.current.onDismiss?.();
|
|
75
|
+
},
|
|
76
|
+
() => {},
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
}, [host, mounted, modalID]);
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
let active = true;
|
|
82
|
+
if (visible) setPresent(true);
|
|
83
|
+
else if (!present) return;
|
|
84
|
+
void host.whenCommitted().then(
|
|
85
|
+
() => {
|
|
86
|
+
if (!active) return;
|
|
87
|
+
const complete = () => {
|
|
88
|
+
if (!active) return;
|
|
89
|
+
if (visible) callbacks.current.onShow?.();
|
|
90
|
+
else setPresent(false);
|
|
91
|
+
};
|
|
92
|
+
if (animationType === "none") {
|
|
93
|
+
progress.setValue(visible ? 1 : 0);
|
|
94
|
+
complete();
|
|
95
|
+
} else {
|
|
96
|
+
Animated.timing(progress, {
|
|
97
|
+
toValue: visible ? 1 : 0,
|
|
98
|
+
duration: 300,
|
|
99
|
+
easing: Easing.linear,
|
|
100
|
+
}).start(({ finished }) => {
|
|
101
|
+
if (finished) complete();
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
() => {},
|
|
106
|
+
);
|
|
107
|
+
return () => {
|
|
108
|
+
active = false;
|
|
109
|
+
progress.stopAnimation();
|
|
110
|
+
};
|
|
111
|
+
}, [host, visible, animationType, progress]);
|
|
112
|
+
return mounted
|
|
113
|
+
? host.portal(
|
|
114
|
+
createElement(
|
|
115
|
+
Animated.View,
|
|
116
|
+
{
|
|
117
|
+
...accessibility,
|
|
118
|
+
nativeID: modalID,
|
|
119
|
+
accessibilityViewIsModal: true,
|
|
120
|
+
"aria-modal": true,
|
|
121
|
+
style: {
|
|
122
|
+
position: "absolute",
|
|
123
|
+
left: 0,
|
|
124
|
+
top: 0,
|
|
125
|
+
width: host.viewport.width,
|
|
126
|
+
height: host.viewport.height,
|
|
127
|
+
zIndex: 100000 + order,
|
|
128
|
+
backgroundColor: transparent ? "transparent" : "white",
|
|
129
|
+
opacity: animationType === "fade" ? progress : 1,
|
|
130
|
+
transform:
|
|
131
|
+
animationType === "slide"
|
|
132
|
+
? [
|
|
133
|
+
{
|
|
134
|
+
translateY: Animated.multiply(
|
|
135
|
+
Animated.subtract(1, progress),
|
|
136
|
+
host.viewport.height,
|
|
137
|
+
),
|
|
138
|
+
},
|
|
139
|
+
]
|
|
140
|
+
: [],
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
children,
|
|
144
|
+
),
|
|
145
|
+
id,
|
|
146
|
+
)
|
|
147
|
+
: null;
|
|
148
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { createContext, useContext, type ReactNode } from "react";
|
|
2
|
+
import type { LayoutRect } from "../layout/flexLayout";
|
|
3
|
+
import type { SceneHandle, SceneTreeElement } from "../renderer/SceneRoot";
|
|
4
|
+
import { RokuHostError } from "../scene/sceneGraph.types";
|
|
5
|
+
import type { NativeFocusRequestOrigin, NativeInput } from "./NativeInput";
|
|
6
|
+
import type { SvgAtlas } from "../vector/svg.types";
|
|
7
|
+
import type { NativeGraphics } from "../graphics/surfaces";
|
|
8
|
+
import type { Affine } from "../layout/affine";
|
|
9
|
+
import type { TextRasterProvider } from "../graphics/textRaster.types";
|
|
10
|
+
import type { TextEntryPort } from "../services/DeviceServices";
|
|
11
|
+
import type { NativeViewHandle } from "./nativeViewHandle";
|
|
12
|
+
import type { NativeFocusBinding } from "./focusEvents";
|
|
13
|
+
import type { AccessibilitySemantics } from "./accessibility";
|
|
14
|
+
|
|
15
|
+
export interface FocusPresentation {
|
|
16
|
+
readonly focusedColor: string | number;
|
|
17
|
+
readonly restingColor: string | number;
|
|
18
|
+
readonly label?: { readonly nativeID: string; readonly text: string };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface NativePlacement {
|
|
22
|
+
readonly parentID?: string;
|
|
23
|
+
readonly view?: NativeViewHandle;
|
|
24
|
+
readonly focusEvents?: NativeFocusBinding;
|
|
25
|
+
readonly nativeTag?: number;
|
|
26
|
+
readonly focusTargets?: Readonly<
|
|
27
|
+
Partial<Record<"up" | "right" | "down" | "left", number | null>>
|
|
28
|
+
>;
|
|
29
|
+
readonly local: LayoutRect;
|
|
30
|
+
readonly world?: Affine;
|
|
31
|
+
readonly global: LayoutRect;
|
|
32
|
+
/** Committed visibility includes hidden/display:none ancestors. */
|
|
33
|
+
readonly visible?: boolean;
|
|
34
|
+
/** Explicit native focus eligibility, independent of touch/accessibility exposure. */
|
|
35
|
+
readonly focusable?: boolean;
|
|
36
|
+
/** Modal isolation fences remote focus/input independently of touch hit testing. */
|
|
37
|
+
readonly modalBlocked?: boolean;
|
|
38
|
+
/** A containing Modal can close the active accessibility scope without taking focus. */
|
|
39
|
+
readonly containsActiveModalScope?: boolean;
|
|
40
|
+
readonly accessibilityHidden?: boolean;
|
|
41
|
+
readonly accessibilityLabel?: string;
|
|
42
|
+
readonly accessibility?: AccessibilitySemantics;
|
|
43
|
+
readonly pointerEvents?: string;
|
|
44
|
+
readonly handle: SceneHandle;
|
|
45
|
+
readonly node?: SceneTreeElement;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface NativeHostContextValue {
|
|
49
|
+
readonly active: boolean;
|
|
50
|
+
readonly viewport: { width: number; height: number };
|
|
51
|
+
readonly input?: NativeInput;
|
|
52
|
+
readonly svgAtlas?: SvgAtlas;
|
|
53
|
+
readonly graphics?: NativeGraphics;
|
|
54
|
+
readonly raster?: TextRasterProvider;
|
|
55
|
+
readonly textEntry?: TextEntryPort;
|
|
56
|
+
portal(element: ReactNode, key: string): ReactNode;
|
|
57
|
+
placement(id: string): NativePlacement | undefined;
|
|
58
|
+
whenCommitted(): Promise<void>;
|
|
59
|
+
runSync(work: () => void): void;
|
|
60
|
+
cancelInput(): void;
|
|
61
|
+
requestFocus(
|
|
62
|
+
id: string,
|
|
63
|
+
view?: NativeViewHandle,
|
|
64
|
+
isCurrent?: () => boolean,
|
|
65
|
+
origin?: NativeFocusRequestOrigin,
|
|
66
|
+
): void;
|
|
67
|
+
dispatchFocus(id: string, focused: boolean): void;
|
|
68
|
+
announceFocus(id: string): void;
|
|
69
|
+
setNativeProps(id: string, props: Readonly<Record<string, unknown>>): void;
|
|
70
|
+
/** Mechanical media commands; field observers remain the source of playback truth. */
|
|
71
|
+
videoCommand(id: string, fields: Readonly<Record<string, string | number | boolean>>): void;
|
|
72
|
+
audioCommand(id: string, fields: Readonly<Record<string, string | number | boolean>>): void;
|
|
73
|
+
}
|
|
74
|
+
export const NativeHostContext = createContext<NativeHostContextValue | null>(null);
|
|
75
|
+
export function useNativeHost(): NativeHostContextValue {
|
|
76
|
+
const host = useContext(NativeHostContext);
|
|
77
|
+
if (!host)
|
|
78
|
+
throw new RokuHostError("C01_HOST", "RN primitives must render inside a Roku native root");
|
|
79
|
+
return host;
|
|
80
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { RokuHostError } from "../scene/sceneGraph.types";
|
|
2
|
+
type Listener = (...values: unknown[]) => void;
|
|
3
|
+
/** JavaScript event delivery; native capabilities still require an explicit installed port. */
|
|
4
|
+
export class EventEmitter {
|
|
5
|
+
private readonly listeners = new Map<string, Set<Listener>>();
|
|
6
|
+
addListener(name: string, listener: Listener) {
|
|
7
|
+
const entries = this.listeners.get(name) ?? new Set();
|
|
8
|
+
entries.add(listener);
|
|
9
|
+
this.listeners.set(name, entries);
|
|
10
|
+
let active = true;
|
|
11
|
+
return {
|
|
12
|
+
remove: () => {
|
|
13
|
+
if (!active) return;
|
|
14
|
+
active = false;
|
|
15
|
+
entries.delete(listener);
|
|
16
|
+
if (!entries.size) this.listeners.delete(name);
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
emit(name: string, ...values: unknown[]): void {
|
|
21
|
+
for (const listener of [...(this.listeners.get(name) ?? [])]) listener(...values);
|
|
22
|
+
}
|
|
23
|
+
removeAllListeners(name?: string): void {
|
|
24
|
+
if (name == null) this.listeners.clear();
|
|
25
|
+
else this.listeners.delete(name);
|
|
26
|
+
}
|
|
27
|
+
listenerCount(name: string): number {
|
|
28
|
+
return this.listeners.get(name)?.size ?? 0;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export const DeviceEventEmitter = new EventEmitter();
|
|
32
|
+
export class NativeEventEmitter {
|
|
33
|
+
constructor(
|
|
34
|
+
private readonly native?: {
|
|
35
|
+
addListener?(name: string): void;
|
|
36
|
+
removeListeners?(count: number): void;
|
|
37
|
+
} | null,
|
|
38
|
+
) {}
|
|
39
|
+
addListener(name: string, listener: Listener) {
|
|
40
|
+
this.native?.addListener?.(name);
|
|
41
|
+
const subscription = DeviceEventEmitter.addListener(name, listener);
|
|
42
|
+
let active = true;
|
|
43
|
+
return {
|
|
44
|
+
remove: () => {
|
|
45
|
+
if (!active) return;
|
|
46
|
+
active = false;
|
|
47
|
+
subscription.remove();
|
|
48
|
+
this.native?.removeListeners?.(1);
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
emit(name: string, ...values: unknown[]): void {
|
|
53
|
+
DeviceEventEmitter.emit(name, ...values);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export const UIManager = Object.freeze({
|
|
57
|
+
// This host has no Fabric view-manager registry. Renderer capabilities are separate ports.
|
|
58
|
+
getViewManagerConfig: (_name: string): null => null,
|
|
59
|
+
dispatchViewManagerCommand(): never {
|
|
60
|
+
throw new RokuHostError(
|
|
61
|
+
"C03_NATIVE_MANAGER",
|
|
62
|
+
"No Fabric view manager is installed in the Roku host",
|
|
63
|
+
);
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
export function requireNativeComponent(name: string): never {
|
|
67
|
+
throw new RokuHostError(
|
|
68
|
+
"C03_NATIVE_COMPONENT",
|
|
69
|
+
`Native component ${name} has no installed Roku view manager`,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
export const TurboModuleRegistry = Object.freeze({
|
|
73
|
+
get: (_name: string): null => null,
|
|
74
|
+
getEnforcing(name: string): never {
|
|
75
|
+
throw new RokuHostError(
|
|
76
|
+
"C03_NATIVE_MODULE",
|
|
77
|
+
`No TurboModule ${name} is installed in the Roku host`,
|
|
78
|
+
);
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
export const Share = Object.freeze({
|
|
82
|
+
share: async (): Promise<never> => {
|
|
83
|
+
throw new RokuHostError("C21_SHARE", "The Roku host has no external share destination");
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
export { Keyboard } from "./keyboard";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TextRasterProvider } from "../graphics/textRaster.types";
|
|
2
|
+
import type { DeviceServices, TextEntryPort } from "../services/DeviceServices";
|
|
3
|
+
import type { SvgAtlas } from "../vector/svg.types";
|
|
4
|
+
import type { NativeGraphics } from "../graphics/surfaces";
|
|
5
|
+
import type { NativeSystemState } from "./NativeSystemState";
|
|
6
|
+
import type { NativeInput } from "./NativeInput";
|
|
7
|
+
import type { TextMetricProvider } from "../layout/textLayout";
|
|
8
|
+
export interface NativeRootOptions {
|
|
9
|
+
readonly strictMode?: boolean;
|
|
10
|
+
readonly textRaster?: TextRasterProvider;
|
|
11
|
+
readonly services?: DeviceServices;
|
|
12
|
+
readonly textEntry?: TextEntryPort;
|
|
13
|
+
readonly svgAtlas?: SvgAtlas;
|
|
14
|
+
readonly graphics?: NativeGraphics;
|
|
15
|
+
readonly system?: NativeSystemState;
|
|
16
|
+
readonly platformVersion?: string | number;
|
|
17
|
+
readonly requestExit?: () => void;
|
|
18
|
+
readonly input?: NativeInput;
|
|
19
|
+
readonly viewport: { width: number; height: number };
|
|
20
|
+
readonly text: TextMetricProvider;
|
|
21
|
+
onError?(error: Error, kind: "uncaught" | "caught" | "recoverable"): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import type { NativeHostContextValue, NativePlacement } from "./nativeHostContext";
|
|
2
|
+
import { RokuHostError } from "../scene/sceneGraph.types";
|
|
3
|
+
import { affineBounds, inverseAffine, multiplyAffine } from "../layout/affine";
|
|
4
|
+
|
|
5
|
+
export interface NativeViewHandle {
|
|
6
|
+
readonly nativeID: string;
|
|
7
|
+
measure(
|
|
8
|
+
callback: (
|
|
9
|
+
x: number,
|
|
10
|
+
y: number,
|
|
11
|
+
width: number,
|
|
12
|
+
height: number,
|
|
13
|
+
pageX: number,
|
|
14
|
+
pageY: number,
|
|
15
|
+
) => void,
|
|
16
|
+
): void;
|
|
17
|
+
measureInWindow(callback: (x: number, y: number, width: number, height: number) => void): void;
|
|
18
|
+
measureLayout(
|
|
19
|
+
relative: NativeViewHandle,
|
|
20
|
+
success: (x: number, y: number, width: number, height: number) => void,
|
|
21
|
+
failure?: () => void,
|
|
22
|
+
): void;
|
|
23
|
+
requestTVFocus(): void;
|
|
24
|
+
/** Submit native focus; only the host's observation acknowledges ownership. */
|
|
25
|
+
focus(): void;
|
|
26
|
+
setNativeProps(props: Readonly<Record<string, unknown>>): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let nextNativeTag = 0;
|
|
30
|
+
type NativeLifetime = {
|
|
31
|
+
tag: number;
|
|
32
|
+
host: NativeHostContextValue;
|
|
33
|
+
active: boolean;
|
|
34
|
+
generation: number;
|
|
35
|
+
};
|
|
36
|
+
const tags = new WeakMap<object, NativeLifetime>();
|
|
37
|
+
const aliases = new WeakMap<object, () => NativeViewHandle | null>();
|
|
38
|
+
const boundTags = new Map<
|
|
39
|
+
number,
|
|
40
|
+
{ handle: NativeViewHandle; lifetime: NativeLifetime; generation: number }
|
|
41
|
+
>();
|
|
42
|
+
|
|
43
|
+
/** Numeric requests use the mounted binding's generation, including before
|
|
44
|
+
* asynchronous native placement. Abandoned render handles never enter this map. */
|
|
45
|
+
export function nativeViewFocusRequest(tag: number, host: NativeHostContextValue) {
|
|
46
|
+
const entry = boundTags.get(tag);
|
|
47
|
+
if (!entry || entry.lifetime.host !== host) return undefined;
|
|
48
|
+
return {
|
|
49
|
+
id: entry.handle.nativeID,
|
|
50
|
+
view: entry.handle,
|
|
51
|
+
isCurrent: () =>
|
|
52
|
+
entry.lifetime.active &&
|
|
53
|
+
host.active &&
|
|
54
|
+
entry.lifetime.generation === entry.generation &&
|
|
55
|
+
boundTags.get(tag) === entry,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Forward composite native refs without opening their editing/scroll APIs.
|
|
60
|
+
* Resolve lazily: a stable TextInput ref can change its underlying native ID. */
|
|
61
|
+
export function aliasNativeViewHandle<T extends NativeViewHandle>(
|
|
62
|
+
handle: T,
|
|
63
|
+
target: () => NativeViewHandle | null,
|
|
64
|
+
): T {
|
|
65
|
+
aliases.set(handle, target);
|
|
66
|
+
return handle;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** A native tag belongs to its mounted root, independently of global service
|
|
70
|
+
* binding order. Accessibility requests also honor the committed reader fence. */
|
|
71
|
+
export function requestNativeAccessibilityFocus(tag: number): void {
|
|
72
|
+
const binding = boundTags.get(tag);
|
|
73
|
+
if (!binding) return;
|
|
74
|
+
const host = binding.lifetime.host;
|
|
75
|
+
const target = nativeViewFocusRequest(tag, host);
|
|
76
|
+
if (!target) return;
|
|
77
|
+
host.requestFocus(target.id, target.view, () => {
|
|
78
|
+
const placement = host.placement(target.id);
|
|
79
|
+
return (
|
|
80
|
+
target.isCurrent() && (placement?.view !== target.view || !placement.accessibilityHidden)
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** React effect replay may rebind the same handle. Retired work keeps the old
|
|
86
|
+
* generation and cannot target another mount with an identical authored ID. */
|
|
87
|
+
export function bindNativeViewHandle(handle: NativeViewHandle): () => void {
|
|
88
|
+
const entry = tags.get(handle);
|
|
89
|
+
if (!entry) throw new RokuHostError("C03_VIEW_HANDLE", "Unknown native view handle");
|
|
90
|
+
const generation = entry.generation;
|
|
91
|
+
entry.active = true;
|
|
92
|
+
boundTags.set(entry.tag, { handle, lifetime: entry, generation });
|
|
93
|
+
return () => {
|
|
94
|
+
if (entry.generation !== generation) return;
|
|
95
|
+
entry.active = false;
|
|
96
|
+
entry.generation++;
|
|
97
|
+
boundTags.delete(entry.tag);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Stable shadow-node identity, available before asynchronous native placement. */
|
|
102
|
+
export function findNodeHandle(instance: unknown): number | null {
|
|
103
|
+
if (typeof instance === "number")
|
|
104
|
+
return Number.isSafeInteger(instance) && instance > 0 ? instance : null;
|
|
105
|
+
let seen: Set<object> | undefined;
|
|
106
|
+
while (instance && typeof instance === "object" && aliases.has(instance)) {
|
|
107
|
+
seen ??= new Set<object>();
|
|
108
|
+
if (seen.has(instance)) return null;
|
|
109
|
+
seen.add(instance);
|
|
110
|
+
instance = aliases.get(instance)!();
|
|
111
|
+
}
|
|
112
|
+
if (!instance || typeof instance !== "object") return null;
|
|
113
|
+
const entry = tags.get(instance);
|
|
114
|
+
return entry?.active && entry.host.active ? entry.tag : null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function createNativeViewHandle(id: string, host: NativeHostContextValue): NativeViewHandle {
|
|
118
|
+
const lifetime = { tag: ++nextNativeTag, host, active: true, generation: 0 };
|
|
119
|
+
const active = (generation = lifetime.generation) =>
|
|
120
|
+
lifetime.active && host.active && generation === lifetime.generation;
|
|
121
|
+
const read = (callback: (placement: NativePlacement) => void, failure?: () => void) => {
|
|
122
|
+
const generation = lifetime.generation;
|
|
123
|
+
if (!active(generation)) return;
|
|
124
|
+
const placement = host.placement(id);
|
|
125
|
+
if (placement?.view === handle) callback(placement);
|
|
126
|
+
else
|
|
127
|
+
void host.whenCommitted().then(
|
|
128
|
+
() => {
|
|
129
|
+
if (!active(generation)) return;
|
|
130
|
+
const next = host.placement(id);
|
|
131
|
+
if (next?.view === handle) callback(next);
|
|
132
|
+
else failure?.();
|
|
133
|
+
},
|
|
134
|
+
() => {
|
|
135
|
+
if (active(generation)) failure?.();
|
|
136
|
+
},
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
const handle: NativeViewHandle = {
|
|
140
|
+
nativeID: id,
|
|
141
|
+
measure(callback) {
|
|
142
|
+
read(({ local, global }) =>
|
|
143
|
+
callback(local.x, local.y, global.width, global.height, global.x, global.y),
|
|
144
|
+
);
|
|
145
|
+
},
|
|
146
|
+
measureInWindow(callback) {
|
|
147
|
+
read(({ global }) => callback(global.x, global.y, global.width, global.height));
|
|
148
|
+
},
|
|
149
|
+
measureLayout(relative, success, failure) {
|
|
150
|
+
if (tags.get(relative)?.host !== host || !tags.get(relative)?.active) {
|
|
151
|
+
failure?.();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
read(({ global, local, world }) => {
|
|
155
|
+
if (!tags.get(relative)?.active) {
|
|
156
|
+
failure?.();
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const other = host.placement(relative.nativeID);
|
|
160
|
+
const inverse = other?.world && inverseAffine(other.world);
|
|
161
|
+
if (world && inverse) {
|
|
162
|
+
const rect = affineBounds(multiplyAffine(inverse, world), local.width, local.height);
|
|
163
|
+
success(rect.x, rect.y, rect.width, rect.height);
|
|
164
|
+
} else if (world && other?.world) failure?.();
|
|
165
|
+
else if (other)
|
|
166
|
+
success(
|
|
167
|
+
global.x - other.global.x,
|
|
168
|
+
global.y - other.global.y,
|
|
169
|
+
global.width,
|
|
170
|
+
global.height,
|
|
171
|
+
);
|
|
172
|
+
else failure?.();
|
|
173
|
+
}, failure);
|
|
174
|
+
},
|
|
175
|
+
requestTVFocus() {
|
|
176
|
+
const generation = lifetime.generation;
|
|
177
|
+
if (active(generation)) host.requestFocus(id, handle, () => active(generation));
|
|
178
|
+
},
|
|
179
|
+
focus() {
|
|
180
|
+
const generation = lifetime.generation;
|
|
181
|
+
if (active(generation)) host.requestFocus(id, handle, () => active(generation));
|
|
182
|
+
},
|
|
183
|
+
setNativeProps(props) {
|
|
184
|
+
if (!active())
|
|
185
|
+
throw new RokuHostError("RETIRED_VIEW", "A retired view cannot receive native props");
|
|
186
|
+
host.setNativeProps(id, props);
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
tags.set(handle, lifetime);
|
|
190
|
+
return handle;
|
|
191
|
+
}
|