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,76 @@
|
|
|
1
|
+
import { createContext, createElement, forwardRef, useContext, type ReactNode } from "react";
|
|
2
|
+
import { useNativeHost } from "./nativeHostContext";
|
|
3
|
+
import { View } from "./primitives";
|
|
4
|
+
import { flattenStyle, type NativeStyle } from "./styleSheet";
|
|
5
|
+
import type { NativeViewHandle } from "./nativeViewHandle";
|
|
6
|
+
import { RokuHostError } from "../scene/sceneGraph.types";
|
|
7
|
+
|
|
8
|
+
interface Insets {
|
|
9
|
+
readonly top: number;
|
|
10
|
+
readonly right: number;
|
|
11
|
+
readonly bottom: number;
|
|
12
|
+
readonly left: number;
|
|
13
|
+
}
|
|
14
|
+
interface Frame {
|
|
15
|
+
readonly x: number;
|
|
16
|
+
readonly y: number;
|
|
17
|
+
readonly width: number;
|
|
18
|
+
readonly height: number;
|
|
19
|
+
}
|
|
20
|
+
const ZERO = Object.freeze({ top: 0, right: 0, bottom: 0, left: 0 });
|
|
21
|
+
export const SafeAreaInsetsContext = createContext<Insets | null>(null);
|
|
22
|
+
export const SafeAreaFrameContext = createContext<Frame | null>(null);
|
|
23
|
+
export const initialWindowMetrics = null;
|
|
24
|
+
|
|
25
|
+
export function SafeAreaProvider({
|
|
26
|
+
children,
|
|
27
|
+
initialMetrics,
|
|
28
|
+
}: {
|
|
29
|
+
readonly children?: ReactNode;
|
|
30
|
+
readonly initialMetrics?: { insets: Insets; frame: Frame } | null;
|
|
31
|
+
}) {
|
|
32
|
+
const host = useNativeHost();
|
|
33
|
+
const insets = initialMetrics?.insets ?? ZERO,
|
|
34
|
+
frame = initialMetrics?.frame ?? { x: 0, y: 0, ...host.viewport };
|
|
35
|
+
for (const value of Object.values(insets))
|
|
36
|
+
if (!Number.isFinite(value) || value < 0)
|
|
37
|
+
throw new RokuHostError("C03_SAFE_AREA", "Insets must be finite and nonnegative");
|
|
38
|
+
return createElement(
|
|
39
|
+
SafeAreaInsetsContext.Provider,
|
|
40
|
+
{ value: insets },
|
|
41
|
+
createElement(SafeAreaFrameContext.Provider, { value: frame }, children),
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
export function useSafeAreaInsets(): Insets {
|
|
45
|
+
return useContext(SafeAreaInsetsContext) ?? ZERO;
|
|
46
|
+
}
|
|
47
|
+
export function useSafeAreaFrame(): Frame {
|
|
48
|
+
const host = useNativeHost();
|
|
49
|
+
return useContext(SafeAreaFrameContext) ?? { x: 0, y: 0, ...host.viewport };
|
|
50
|
+
}
|
|
51
|
+
export const SafeAreaView = forwardRef<
|
|
52
|
+
NativeViewHandle,
|
|
53
|
+
{
|
|
54
|
+
readonly children?: ReactNode;
|
|
55
|
+
readonly style?: NativeStyle;
|
|
56
|
+
readonly edges?: readonly (keyof Insets)[];
|
|
57
|
+
}
|
|
58
|
+
>((props, ref) => {
|
|
59
|
+
const insets = useSafeAreaInsets(),
|
|
60
|
+
style = flattenStyle(props.style) ?? {},
|
|
61
|
+
padding: Record<string, number> = {};
|
|
62
|
+
for (const edge of props.edges ?? ["top", "right", "bottom", "left"]) {
|
|
63
|
+
if (!insets[edge]) continue;
|
|
64
|
+
const name = `padding${edge[0].toUpperCase()}${edge.slice(1)}`;
|
|
65
|
+
const current =
|
|
66
|
+
style[name] ??
|
|
67
|
+
style[edge === "top" || edge === "bottom" ? "paddingVertical" : "paddingHorizontal"] ??
|
|
68
|
+
style.padding ??
|
|
69
|
+
0;
|
|
70
|
+
if (typeof current !== "number")
|
|
71
|
+
throw new RokuHostError("C03_SAFE_AREA", "Nonzero insets require numeric padding");
|
|
72
|
+
padding[name] = current + insets[edge];
|
|
73
|
+
}
|
|
74
|
+
return createElement(View, { ref, style: [style, padding] }, props.children);
|
|
75
|
+
});
|
|
76
|
+
SafeAreaView.displayName = "RokuSafeAreaView";
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createElement,
|
|
3
|
+
forwardRef,
|
|
4
|
+
useImperativeHandle,
|
|
5
|
+
useLayoutEffect,
|
|
6
|
+
useMemo,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
useSyncExternalStore,
|
|
10
|
+
type ReactNode,
|
|
11
|
+
} from "react";
|
|
12
|
+
import { makeMutable } from "../animation/sharedValue";
|
|
13
|
+
import { ScrollViewLayer, View, type NativeElementProps } from "./primitives";
|
|
14
|
+
import { useNativeHost } from "./nativeHostContext";
|
|
15
|
+
import { findNodeHandle, type NativeViewHandle } from "./nativeViewHandle";
|
|
16
|
+
import { RokuHostError } from "../scene/sceneGraph.types";
|
|
17
|
+
import { flattenStyle, type NativeStyle } from "./styleSheet";
|
|
18
|
+
export interface ScrollEvent {
|
|
19
|
+
readonly nativeEvent: {
|
|
20
|
+
readonly contentOffset: { x: number; y: number };
|
|
21
|
+
readonly contentSize: { width: number; height: number };
|
|
22
|
+
readonly layoutMeasurement: { width: number; height: number };
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export interface ScrollViewProps extends NativeElementProps {
|
|
26
|
+
readonly children?: ReactNode;
|
|
27
|
+
readonly horizontal?: boolean;
|
|
28
|
+
readonly contentContainerStyle?: NativeStyle;
|
|
29
|
+
readonly onContentSizeChange?: (width: number, height: number) => void;
|
|
30
|
+
readonly onScroll?: (event: ScrollEvent) => void;
|
|
31
|
+
readonly scrollEventThrottle?: number;
|
|
32
|
+
readonly showsVerticalScrollIndicator?: boolean;
|
|
33
|
+
readonly showsHorizontalScrollIndicator?: boolean;
|
|
34
|
+
readonly scrollEnabled?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface ScrollViewHandle extends NativeViewHandle {
|
|
37
|
+
scrollTo(
|
|
38
|
+
options?: { x?: number; y?: number; animated?: boolean } | number,
|
|
39
|
+
y?: number,
|
|
40
|
+
animated?: boolean,
|
|
41
|
+
): void;
|
|
42
|
+
scrollToEnd(options?: { animated?: boolean }): void;
|
|
43
|
+
getScrollResponder(): ScrollViewHandle;
|
|
44
|
+
getScrollableNode(): number | null;
|
|
45
|
+
flashScrollIndicators(): void;
|
|
46
|
+
}
|
|
47
|
+
const geometry = (event: unknown) =>
|
|
48
|
+
(
|
|
49
|
+
event as {
|
|
50
|
+
nativeEvent: {
|
|
51
|
+
layout: { x: number; y: number; width: number; height: number };
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
).nativeEvent.layout;
|
|
55
|
+
export const ScrollView = forwardRef<ScrollViewHandle, ScrollViewProps>((props, forwardedRef) => {
|
|
56
|
+
const host = useNativeHost(),
|
|
57
|
+
outer = useRef<NativeViewHandle>(null),
|
|
58
|
+
latest = useRef(props);
|
|
59
|
+
latest.current = props;
|
|
60
|
+
const x = useMemo(() => makeMutable(0), []),
|
|
61
|
+
y = useMemo(() => makeMutable(0), []);
|
|
62
|
+
const offsetX = useSyncExternalStore(x.subscribe, x.get),
|
|
63
|
+
offsetY = useSyncExternalStore(y.subscribe, y.get);
|
|
64
|
+
const viewport = useRef<{ width: number; height: number } | null>(null),
|
|
65
|
+
content = useRef<{ width: number; height: number } | null>(null);
|
|
66
|
+
const pending = useRef<{
|
|
67
|
+
x?: number;
|
|
68
|
+
y?: number;
|
|
69
|
+
animated?: boolean;
|
|
70
|
+
} | null>(null);
|
|
71
|
+
const generation = useRef(0),
|
|
72
|
+
live = useRef(true),
|
|
73
|
+
[indicator, setIndicator] = useState(false),
|
|
74
|
+
indicatorTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
75
|
+
const flash = () => {
|
|
76
|
+
const frame = viewport.current,
|
|
77
|
+
extent = content.current;
|
|
78
|
+
if (
|
|
79
|
+
!frame ||
|
|
80
|
+
!extent ||
|
|
81
|
+
!(
|
|
82
|
+
(extent.height > frame.height && latest.current.showsVerticalScrollIndicator !== false) ||
|
|
83
|
+
(extent.width > frame.width && latest.current.showsHorizontalScrollIndicator !== false)
|
|
84
|
+
)
|
|
85
|
+
)
|
|
86
|
+
return;
|
|
87
|
+
setIndicator(true);
|
|
88
|
+
clearTimeout(indicatorTimer.current);
|
|
89
|
+
indicatorTimer.current = setTimeout(() => {
|
|
90
|
+
if (live.current) host.runSync(() => setIndicator(false));
|
|
91
|
+
}, 800);
|
|
92
|
+
};
|
|
93
|
+
const apply = (options: { x?: number; y?: number; animated?: boolean }) => {
|
|
94
|
+
for (const value of [options.x, options.y])
|
|
95
|
+
if (value != null && (!Number.isFinite(value) || value < 0))
|
|
96
|
+
throw new RokuHostError(
|
|
97
|
+
"C05_SCROLL_OFFSET",
|
|
98
|
+
"Scroll offsets must be finite and nonnegative",
|
|
99
|
+
);
|
|
100
|
+
pending.current = options;
|
|
101
|
+
if (!viewport.current || !content.current) return;
|
|
102
|
+
const nextX = Math.min(
|
|
103
|
+
options.x ?? x.get(),
|
|
104
|
+
Math.max(0, content.current.width - viewport.current.width),
|
|
105
|
+
),
|
|
106
|
+
nextY = Math.min(
|
|
107
|
+
options.y ?? y.get(),
|
|
108
|
+
Math.max(0, content.current.height - viewport.current.height),
|
|
109
|
+
);
|
|
110
|
+
pending.current = null;
|
|
111
|
+
host.runSync(() => {
|
|
112
|
+
if (options.animated) {
|
|
113
|
+
x.value = {
|
|
114
|
+
kind: "timing",
|
|
115
|
+
to: nextX,
|
|
116
|
+
duration: 220,
|
|
117
|
+
easing: (value) => 1 - (1 - value) ** 3,
|
|
118
|
+
};
|
|
119
|
+
y.value = {
|
|
120
|
+
kind: "timing",
|
|
121
|
+
to: nextY,
|
|
122
|
+
duration: 220,
|
|
123
|
+
easing: (value) => 1 - (1 - value) ** 3,
|
|
124
|
+
};
|
|
125
|
+
} else {
|
|
126
|
+
x.value = nextX;
|
|
127
|
+
y.value = nextY;
|
|
128
|
+
}
|
|
129
|
+
flash();
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
useImperativeHandle(forwardedRef, () => {
|
|
133
|
+
if (!outer.current)
|
|
134
|
+
throw new RokuHostError("C05_SCROLL_ATTACHMENT", "The scroll owner has not attached");
|
|
135
|
+
const handle = Object.assign(outer.current, {
|
|
136
|
+
scrollTo(
|
|
137
|
+
options: { x?: number; y?: number; animated?: boolean } | number = {},
|
|
138
|
+
legacyY?: number,
|
|
139
|
+
animated?: boolean,
|
|
140
|
+
) {
|
|
141
|
+
apply(typeof options === "number" ? { x: options, y: legacyY, animated } : options);
|
|
142
|
+
},
|
|
143
|
+
scrollToEnd(options: { animated?: boolean } = {}) {
|
|
144
|
+
apply({
|
|
145
|
+
[latest.current.horizontal ? "x" : "y"]: Number.MAX_SAFE_INTEGER,
|
|
146
|
+
animated: options.animated,
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
getScrollResponder(): ScrollViewHandle {
|
|
150
|
+
return handle;
|
|
151
|
+
},
|
|
152
|
+
getScrollableNode() {
|
|
153
|
+
return findNodeHandle(outer.current);
|
|
154
|
+
},
|
|
155
|
+
flashScrollIndicators() {
|
|
156
|
+
host.runSync(flash);
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
return handle;
|
|
160
|
+
}, [host]);
|
|
161
|
+
useLayoutEffect(() => {
|
|
162
|
+
const token = ++generation.current;
|
|
163
|
+
void host.whenCommitted().then(
|
|
164
|
+
() => {
|
|
165
|
+
if (!live.current || token !== generation.current || !content.current || !viewport.current)
|
|
166
|
+
return;
|
|
167
|
+
latest.current.onScroll?.({
|
|
168
|
+
nativeEvent: {
|
|
169
|
+
contentOffset: { x: offsetX, y: offsetY },
|
|
170
|
+
contentSize: content.current,
|
|
171
|
+
layoutMeasurement: viewport.current,
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
() => undefined,
|
|
176
|
+
);
|
|
177
|
+
}, [host, offsetX, offsetY]);
|
|
178
|
+
useLayoutEffect(() => {
|
|
179
|
+
live.current = true;
|
|
180
|
+
return () => {
|
|
181
|
+
live.current = false;
|
|
182
|
+
generation.current++;
|
|
183
|
+
x.cancel();
|
|
184
|
+
y.cancel();
|
|
185
|
+
clearTimeout(indicatorTimer.current);
|
|
186
|
+
};
|
|
187
|
+
}, [x, y]);
|
|
188
|
+
const sizeChanged = () => apply(pending.current ?? { x: x.get(), y: y.get(), animated: false });
|
|
189
|
+
const extent = content.current,
|
|
190
|
+
frame = viewport.current;
|
|
191
|
+
const vertical =
|
|
192
|
+
frame && extent && extent.height > frame.height && props.showsVerticalScrollIndicator !== false;
|
|
193
|
+
const horizontal =
|
|
194
|
+
frame && extent && extent.width > frame.width && props.showsHorizontalScrollIndicator !== false;
|
|
195
|
+
const viewportStyle = flattenStyle(props.style);
|
|
196
|
+
const contentStyle = flattenStyle(props.contentContainerStyle);
|
|
197
|
+
// Keep Yoga's edge precedence for authored logical insets and reversed flow.
|
|
198
|
+
const translateContent =
|
|
199
|
+
(viewportStyle?.flexDirection == null ||
|
|
200
|
+
viewportStyle.flexDirection === "column" ||
|
|
201
|
+
viewportStyle.flexDirection === "row") &&
|
|
202
|
+
(viewportStyle?.flexWrap == null || viewportStyle.flexWrap === "nowrap") &&
|
|
203
|
+
viewportStyle?.alignItems !== "baseline" &&
|
|
204
|
+
contentStyle?.start == null &&
|
|
205
|
+
contentStyle?.insetInlineStart == null;
|
|
206
|
+
const indicatorY = vertical ? ((frame.height - 8) * offsetY) / extent.height : 0;
|
|
207
|
+
const indicatorX = horizontal ? ((frame.width - 8) * offsetX) / extent.width : 0;
|
|
208
|
+
return createElement(
|
|
209
|
+
View,
|
|
210
|
+
{
|
|
211
|
+
...props,
|
|
212
|
+
ref: outer,
|
|
213
|
+
nativeID: props.nativeID,
|
|
214
|
+
testID: props.testID,
|
|
215
|
+
focusable: props.focusable,
|
|
216
|
+
onFocus: props.onFocus,
|
|
217
|
+
onFocusCapture: props.onFocusCapture,
|
|
218
|
+
onBlur: props.onBlur,
|
|
219
|
+
onBlurCapture: props.onBlurCapture,
|
|
220
|
+
style: [{ flexGrow: 1, flexShrink: 1, overflow: "hidden" }, viewportStyle],
|
|
221
|
+
onLayout(event) {
|
|
222
|
+
const value = geometry(event);
|
|
223
|
+
const previous = viewport.current;
|
|
224
|
+
viewport.current = { width: value.width, height: value.height };
|
|
225
|
+
props.onLayout?.(event);
|
|
226
|
+
if (!previous || previous.width !== value.width || previous.height !== value.height)
|
|
227
|
+
sizeChanged();
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
createElement(
|
|
231
|
+
ScrollViewLayer,
|
|
232
|
+
{
|
|
233
|
+
scrollTranslation: translateContent ? [-offsetX, -offsetY] : undefined,
|
|
234
|
+
style: [
|
|
235
|
+
{
|
|
236
|
+
flexShrink: 0,
|
|
237
|
+
alignSelf: props.horizontal ? "flex-start" : "stretch",
|
|
238
|
+
flexDirection: props.horizontal ? "row" : "column",
|
|
239
|
+
},
|
|
240
|
+
contentStyle,
|
|
241
|
+
{
|
|
242
|
+
position: "relative",
|
|
243
|
+
left: translateContent ? 0 : -offsetX,
|
|
244
|
+
top: translateContent ? 0 : -offsetY,
|
|
245
|
+
},
|
|
246
|
+
],
|
|
247
|
+
onLayout(event) {
|
|
248
|
+
const value = geometry(event),
|
|
249
|
+
previous = content.current;
|
|
250
|
+
content.current = { width: value.width, height: value.height };
|
|
251
|
+
if (!previous || previous.width !== value.width || previous.height !== value.height) {
|
|
252
|
+
props.onContentSizeChange?.(value.width, value.height);
|
|
253
|
+
sizeChanged();
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
props.children,
|
|
258
|
+
),
|
|
259
|
+
vertical
|
|
260
|
+
? createElement(ScrollViewLayer, {
|
|
261
|
+
scrollTranslation: [0, indicatorY],
|
|
262
|
+
style: {
|
|
263
|
+
position: "absolute",
|
|
264
|
+
right: 2,
|
|
265
|
+
top: 4,
|
|
266
|
+
width: 3,
|
|
267
|
+
height: Math.max(12, ((frame.height - 8) * frame.height) / extent.height),
|
|
268
|
+
backgroundColor: "#ffffff88",
|
|
269
|
+
opacity: indicator ? 1 : 0,
|
|
270
|
+
},
|
|
271
|
+
})
|
|
272
|
+
: null,
|
|
273
|
+
horizontal
|
|
274
|
+
? createElement(ScrollViewLayer, {
|
|
275
|
+
scrollTranslation: [indicatorX, 0],
|
|
276
|
+
style: {
|
|
277
|
+
position: "absolute",
|
|
278
|
+
bottom: 2,
|
|
279
|
+
left: 4,
|
|
280
|
+
height: 3,
|
|
281
|
+
width: Math.max(12, ((frame.width - 8) * frame.width) / extent.width),
|
|
282
|
+
backgroundColor: "#ffffff88",
|
|
283
|
+
opacity: indicator ? 1 : 0,
|
|
284
|
+
},
|
|
285
|
+
})
|
|
286
|
+
: null,
|
|
287
|
+
);
|
|
288
|
+
});
|
|
289
|
+
ScrollView.displayName = "RokuScrollView";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
let resolveComponent: ((component: unknown) => unknown) | undefined;
|
|
2
|
+
/** Installed by the pinned style engine after its environment is mounted. */
|
|
3
|
+
export function installStyleInterop(resolve: (component: unknown) => unknown): void {
|
|
4
|
+
resolveComponent = resolve;
|
|
5
|
+
}
|
|
6
|
+
export function styleComponent<T>(component: T): T {
|
|
7
|
+
return (resolveComponent?.(component) as T) ?? component;
|
|
8
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/// <reference path="../types/normalize-colors.d.ts" />
|
|
2
|
+
/// <reference path="../types/normalize-colors.d.ts" />
|
|
3
|
+
import type { LayoutStyle } from "../layout/flexLayout";
|
|
4
|
+
import { RokuHostError } from "../scene/sceneGraph.types";
|
|
5
|
+
import normalizeColor from "@react-native/normalize-colors";
|
|
6
|
+
|
|
7
|
+
export type NativeStyle = LayoutStyle | readonly NativeStyle[] | null | undefined | false | "" | 0;
|
|
8
|
+
export function flattenStyle(style: NativeStyle): LayoutStyle | undefined {
|
|
9
|
+
if (!style) return undefined;
|
|
10
|
+
if (Array.isArray(style)) return Object.assign({}, ...style.map((item) => flattenStyle(item)));
|
|
11
|
+
if (typeof style !== "object")
|
|
12
|
+
throw new RokuHostError(
|
|
13
|
+
"C05_STYLE",
|
|
14
|
+
"Registered numeric styles require a style registry adapter",
|
|
15
|
+
);
|
|
16
|
+
return style as LayoutStyle;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const StyleSheet = {
|
|
20
|
+
create<T extends Record<string, LayoutStyle>>(styles: T): T {
|
|
21
|
+
return styles;
|
|
22
|
+
},
|
|
23
|
+
flatten: flattenStyle,
|
|
24
|
+
compose(first: NativeStyle, second: NativeStyle): NativeStyle {
|
|
25
|
+
return [first, second];
|
|
26
|
+
},
|
|
27
|
+
absoluteFill: Object.freeze({
|
|
28
|
+
position: "absolute",
|
|
29
|
+
top: 0,
|
|
30
|
+
right: 0,
|
|
31
|
+
bottom: 0,
|
|
32
|
+
left: 0,
|
|
33
|
+
}),
|
|
34
|
+
absoluteFillObject: Object.freeze({
|
|
35
|
+
position: "absolute",
|
|
36
|
+
top: 0,
|
|
37
|
+
right: 0,
|
|
38
|
+
bottom: 0,
|
|
39
|
+
left: 0,
|
|
40
|
+
}),
|
|
41
|
+
hairlineWidth: 1,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export function rokuColor(value: unknown): string {
|
|
45
|
+
if (typeof value === "string" && /^0x[\da-f]{8}$/i.test(value)) return value;
|
|
46
|
+
const normalized =
|
|
47
|
+
typeof value === "string" || typeof value === "number" ? normalizeColor(value) : null;
|
|
48
|
+
if (normalized == null)
|
|
49
|
+
throw new RokuHostError(
|
|
50
|
+
"C05_COLOR",
|
|
51
|
+
`Color ${String(value)} requires an implemented color adapter`,
|
|
52
|
+
);
|
|
53
|
+
return `0x${(normalized >>> 0).toString(16).padStart(8, "0").toUpperCase()}`;
|
|
54
|
+
}
|