@applicaster/zapp-react-native-ui-components 14.0.29-rc.0 → 14.0.30-alpha.6838902303

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.
@@ -0,0 +1,42 @@
1
+ import React from "react";
2
+ import { View, ViewStyle } from "react-native";
3
+
4
+ import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
5
+ import {
6
+ selectRemoteConfigurations,
7
+ useAppSelector,
8
+ } from "@applicaster/zapp-react-native-redux";
9
+
10
+ import { getBackgroundImageUrl } from "../Layout/utils";
11
+
12
+ const baseBackgroundStyles = (imageUrl, backgroundColor) =>
13
+ ({
14
+ position: "absolute",
15
+ left: 0,
16
+ top: 0,
17
+ right: 0,
18
+ bottom: 0,
19
+ zIndex: -1,
20
+ backgroundSize: "cover",
21
+ background: imageUrl
22
+ ? `url(${imageUrl}) no-repeat top center ${backgroundColor}`
23
+ : backgroundColor,
24
+ }) as ViewStyle;
25
+
26
+ export const BackgroundImage = ({ children }: React.PropsWithChildren) => {
27
+ const theme = useTheme();
28
+
29
+ const remoteConfigurations = useAppSelector(selectRemoteConfigurations);
30
+
31
+ const backgroundColor = theme.app_background_color;
32
+ const backgroundImageUrl = getBackgroundImageUrl(remoteConfigurations);
33
+
34
+ return (
35
+ <View
36
+ id="background"
37
+ style={baseBackgroundStyles(backgroundImageUrl, backgroundColor)}
38
+ >
39
+ {children}
40
+ </View>
41
+ );
42
+ };
@@ -0,0 +1,28 @@
1
+ import * as React from "react";
2
+ import {
3
+ View,
4
+ StyleSheet,
5
+ ImageURISource,
6
+ ImageBackground,
7
+ } from "react-native";
8
+
9
+ import { ASSETS } from "@applicaster/zapp-react-native-ui-components/Helpers";
10
+
11
+ const imageSource: ImageURISource = {
12
+ uri: ASSETS.APP_BACKGROUND_IMAGE,
13
+ };
14
+
15
+ const styles = StyleSheet.create({
16
+ container: { flex: 1 },
17
+ backgroundImage: { width: "100%", height: "100%" },
18
+ });
19
+
20
+ export function BackgroundImage({ children }: React.PropsWithChildren) {
21
+ return (
22
+ <View style={styles.container}>
23
+ <ImageBackground style={styles.backgroundImage} source={imageSource}>
24
+ {children}
25
+ </ImageBackground>
26
+ </View>
27
+ );
28
+ }
@@ -0,0 +1,24 @@
1
+ import * as React from "react";
2
+ import { View, StyleSheet, ImageURISource } from "react-native";
3
+
4
+ import { QBImage as Image } from "@applicaster/zapp-react-native-ui-components/Components/Image";
5
+ import { ASSETS } from "@applicaster/zapp-react-native-ui-components/Helpers";
6
+
7
+ const imageSource: ImageURISource = {
8
+ uri: ASSETS.APP_BACKGROUND_IMAGE,
9
+ };
10
+
11
+ const styles = StyleSheet.create({
12
+ container: { flex: 1 },
13
+ backgroundImage: { width: "100%", height: "100%" },
14
+ });
15
+
16
+ export function BackgroundImage({ children }: React.PropsWithChildren) {
17
+ return (
18
+ <View style={styles.container}>
19
+ <Image style={styles.backgroundImage} source={imageSource}>
20
+ {children}
21
+ </Image>
22
+ </View>
23
+ );
24
+ }
@@ -0,0 +1 @@
1
+ export { BackgroundImage } from "./BackgroundImage";
@@ -107,6 +107,12 @@ export const GeneralContentScreen = ({
107
107
 
108
108
  const isReady = useRiverActionProviderReady();
109
109
 
110
+ React.useEffect(() => {
111
+ if (isReady) {
112
+ (globalThis as any).performance?.mark?.(`qb:content-ready:${screenId}`);
113
+ }
114
+ }, [isReady, screenId]);
115
+
110
116
  const contextValue = React.useMemo(
111
117
  () => whenMatchingType(Function, cellTapAction) || onCellTapAction,
112
118
  [typeof cellTapAction === "function" ? cellTapAction : onCellTapAction]
@@ -2,7 +2,6 @@
2
2
 
3
3
  exports[`Layout TV renders 1`] = `
4
4
  <View
5
- backgroundColor="#000000"
6
5
  testID="background-component"
7
6
  >
8
7
  <View
@@ -9,7 +9,6 @@ import { ScreenLayoutContextProvider } from "./ScreenLayoutContextProvider";
9
9
  import { PathnameContext } from "../../../Contexts/PathnameContext";
10
10
  import { ScreenDataContext } from "../../../Contexts/ScreenDataContext";
11
11
  import { ScreenContextProvider } from "../../../Contexts/ScreenContext";
12
- import { LayoutBackground } from "./LayoutBackground";
13
12
 
14
13
  type Components = {
15
14
  NavBar: React.ComponentType<any>;
@@ -40,7 +39,7 @@ const Layout = ({ Components, ComponentsExtraProps, children }: Props) => {
40
39
  return (
41
40
  <LayoutContainer>
42
41
  <ScreenLayoutContextProvider>
43
- <LayoutBackground Background={Components.Background}>
42
+ <Components.Background>
44
43
  <ScreenDataContext.Provider value={navigator.data}>
45
44
  <PathnameContext.Provider value={navigator.currentRoute}>
46
45
  <ScreenContextProvider pathname={navigator.currentRoute}>
@@ -53,7 +52,7 @@ const Layout = ({ Components, ComponentsExtraProps, children }: Props) => {
53
52
  </ScreenContextProvider>
54
53
  </PathnameContext.Provider>
55
54
  </ScreenDataContext.Provider>
56
- </LayoutBackground>
55
+ </Components.Background>
57
56
  </ScreenLayoutContextProvider>
58
57
  </LayoutContainer>
59
58
  );
@@ -5,7 +5,6 @@ import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
5
5
 
6
6
  import { ScreenLayoutContextProvider } from "./ScreenLayoutContextProvider";
7
7
  import { StackNavigator } from "../../Navigator";
8
- import { LayoutBackground } from "./LayoutBackground";
9
8
 
10
9
  type Components = {
11
10
  NavBar: React.ComponentType<any>;
@@ -26,9 +25,9 @@ const Layout = ({ Components }: Props) => {
26
25
 
27
26
  return (
28
27
  <ScreenLayoutContextProvider>
29
- <LayoutBackground Background={Components.Background}>
28
+ <Components.Background>
30
29
  <StackNavigator Components={Components} />
31
- </LayoutBackground>
30
+ </Components.Background>
32
31
  </ScreenLayoutContextProvider>
33
32
  );
34
33
  };
@@ -0,0 +1,56 @@
1
+ import { renderHook, act } from "@testing-library/react-hooks";
2
+
3
+ import { useAfterPaint } from "../useAfterPaint";
4
+
5
+ describe("useAfterPaint", () => {
6
+ let frameCallbacks: FrameRequestCallback[];
7
+ let originalRaf: typeof requestAnimationFrame;
8
+ let originalCancelRaf: typeof cancelAnimationFrame;
9
+
10
+ const flushFrame = () => {
11
+ const callbacks = frameCallbacks;
12
+ frameCallbacks = [];
13
+ act(() => {
14
+ callbacks.forEach((cb) => cb(0));
15
+ });
16
+ };
17
+
18
+ beforeEach(() => {
19
+ frameCallbacks = [];
20
+ originalRaf = global.requestAnimationFrame;
21
+ originalCancelRaf = global.cancelAnimationFrame;
22
+ global.requestAnimationFrame = jest.fn((cb: FrameRequestCallback) => {
23
+ frameCallbacks.push(cb);
24
+ return frameCallbacks.length;
25
+ }) as unknown as typeof requestAnimationFrame;
26
+ global.cancelAnimationFrame = jest.fn();
27
+ });
28
+
29
+ afterEach(() => {
30
+ global.requestAnimationFrame = originalRaf;
31
+ global.cancelAnimationFrame = originalCancelRaf;
32
+ });
33
+
34
+ it("returns false on the initial render", () => {
35
+ const { result } = renderHook(() => useAfterPaint());
36
+
37
+ expect(result.current).toBe(false);
38
+ });
39
+
40
+ it("stays false after only one animation frame (before paint completes)", () => {
41
+ const { result } = renderHook(() => useAfterPaint());
42
+
43
+ flushFrame();
44
+
45
+ expect(result.current).toBe(false);
46
+ });
47
+
48
+ it("returns true after two animation frames (a real post-paint boundary)", () => {
49
+ const { result } = renderHook(() => useAfterPaint());
50
+
51
+ flushFrame();
52
+ flushFrame();
53
+
54
+ expect(result.current).toBe(true);
55
+ });
56
+ });
@@ -1 +1,2 @@
1
1
  export { useInitialFocus } from "./useInitialFocus";
2
+ export { useAfterPaint } from "./useAfterPaint";
@@ -0,0 +1,23 @@
1
+ import * as React from "react";
2
+
3
+ export const useAfterPaint = (): boolean => {
4
+ const [painted, setPainted] = React.useState(false);
5
+
6
+ React.useEffect(() => {
7
+ let secondFrame: number | undefined;
8
+
9
+ const firstFrame = requestAnimationFrame(() => {
10
+ secondFrame = requestAnimationFrame(() => setPainted(true));
11
+ });
12
+
13
+ return () => {
14
+ cancelAnimationFrame(firstFrame);
15
+
16
+ if (secondFrame !== undefined) {
17
+ cancelAnimationFrame(secondFrame);
18
+ }
19
+ };
20
+ }, []);
21
+
22
+ return painted;
23
+ };
@@ -20,7 +20,7 @@ import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/he
20
20
 
21
21
  import { NavBarContainer } from "../../Layout/TV/NavBarContainer";
22
22
  import { ScreenResolver } from "../../ScreenResolver";
23
- import { useInitialFocus } from "./hooks";
23
+ import { useInitialFocus, useAfterPaint } from "./hooks";
24
24
  import { isPlayerPlugin } from "@applicaster/zapp-react-native-utils/pluginUtils";
25
25
  import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils";
26
26
  import { FreezeWithCallback } from "../../FreezeWithCallback";
@@ -155,6 +155,14 @@ export const Screen = ({ route, Components }: Props) => {
155
155
 
156
156
  const isScreenActive = useIsScreenActive();
157
157
 
158
+ const isContentReady = useAfterPaint();
159
+
160
+ React.useEffect(() => {
161
+ if (isContentReady) {
162
+ (globalThis as any).performance?.mark?.(`qb:navbar-painted:${route}`);
163
+ }
164
+ }, [isContentReady, route]);
165
+
158
166
  return (
159
167
  <FreezeWithCallback freeze={!isScreenActive} onRelease={onRelease}>
160
168
  <View style={[styles.container, { backgroundColor }]}>
@@ -165,12 +173,14 @@ export const Screen = ({ route, Components }: Props) => {
165
173
  navigationProps={navigationProps}
166
174
  />
167
175
  </NavBarContainer>
168
- <ScreenResolver
169
- screenType={screenType}
170
- screenId={screenId}
171
- screenData={screenData}
172
- groupId={route}
173
- />
176
+ {isContentReady ? (
177
+ <ScreenResolver
178
+ screenType={screenType}
179
+ screenId={screenId}
180
+ screenData={screenData}
181
+ groupId={route}
182
+ />
183
+ ) : null}
174
184
  </View>
175
185
  </FreezeWithCallback>
176
186
  );
@@ -0,0 +1,34 @@
1
+ import * as React from "react";
2
+ import { Animated, StyleSheet } from "react-native";
3
+
4
+ import { BackgroundImage } from "@applicaster/zapp-react-native-ui-components/Components/BackgroundImage";
5
+
6
+ const styles = StyleSheet.create({
7
+ container: {
8
+ ...StyleSheet.absoluteFillObject,
9
+ position: "absolute",
10
+ },
11
+ });
12
+
13
+ export const Overlay = ({
14
+ opacity,
15
+ backgroundColor,
16
+ }: {
17
+ opacity: Animated.Value;
18
+ backgroundColor: string;
19
+ }) => {
20
+ return (
21
+ <Animated.View
22
+ style={[
23
+ styles.container,
24
+ {
25
+ opacity,
26
+ backgroundColor,
27
+ },
28
+ ]}
29
+ testID="animated-component"
30
+ >
31
+ <BackgroundImage />
32
+ </Animated.View>
33
+ );
34
+ };
@@ -0,0 +1,88 @@
1
+ import React from "react";
2
+ import { Animated } from "react-native";
3
+ import { render } from "@testing-library/react-native";
4
+
5
+ jest.mock(
6
+ "@applicaster/zapp-react-native-ui-components/Components/BackgroundImage",
7
+ () => {
8
+ const { Text } = require("react-native");
9
+
10
+ return {
11
+ BackgroundImage: () => (
12
+ <Text testID="background-image">BackgroundImage</Text>
13
+ ),
14
+ };
15
+ }
16
+ );
17
+
18
+ import { Overlay } from "../Overlay";
19
+
20
+ const flattenStyle = (style: unknown): Record<string, unknown> => {
21
+ if (!style) {
22
+ return {};
23
+ }
24
+
25
+ if (Array.isArray(style)) {
26
+ return style.reduce<Record<string, unknown>>(
27
+ (acc, item) => ({ ...acc, ...flattenStyle(item) }),
28
+ {}
29
+ );
30
+ }
31
+
32
+ if (typeof style === "object") {
33
+ return style as Record<string, unknown>;
34
+ }
35
+
36
+ return {};
37
+ };
38
+
39
+ describe("Overlay", () => {
40
+ it("renders the animated overlay container", () => {
41
+ const opacity = new Animated.Value(1);
42
+
43
+ const { getByTestId } = render(
44
+ <Overlay opacity={opacity} backgroundColor="#000000" />
45
+ );
46
+
47
+ expect(getByTestId("animated-component")).toBeTruthy();
48
+ });
49
+
50
+ it("applies opacity and backgroundColor to the overlay", () => {
51
+ const opacity = new Animated.Value(0.5);
52
+
53
+ const { getByTestId } = render(
54
+ <Overlay opacity={opacity} backgroundColor="#ff0000" />
55
+ );
56
+
57
+ const style = flattenStyle(getByTestId("animated-component").props.style);
58
+
59
+ expect(style.backgroundColor).toBe("#ff0000");
60
+ expect(style.opacity).toBe(0.5);
61
+ });
62
+
63
+ it("positions the overlay with absolute fill layout", () => {
64
+ const opacity = new Animated.Value(1);
65
+
66
+ const { getByTestId } = render(
67
+ <Overlay opacity={opacity} backgroundColor="#000000" />
68
+ );
69
+
70
+ const style = flattenStyle(getByTestId("animated-component").props.style);
71
+
72
+ expect(style.position).toBe("absolute");
73
+ expect(style.top).toBe(0);
74
+ expect(style.left).toBe(0);
75
+ expect(style.right).toBe(0);
76
+ expect(style.bottom).toBe(0);
77
+ });
78
+
79
+ it("renders BackgroundImage inside the overlay", () => {
80
+ const opacity = new Animated.Value(1);
81
+
82
+ const { getByTestId } = render(
83
+ <Overlay opacity={opacity} backgroundColor="#000000" />
84
+ );
85
+
86
+ expect(getByTestId("background-image")).toBeTruthy();
87
+ });
88
+ });
@@ -1,8 +1,10 @@
1
1
  import * as React from "react";
2
- import { Animated, StyleSheet } from "react-native";
2
+ import { Animated } from "react-native";
3
+
3
4
  import { isFirstComponentScreenPicker } from "@applicaster/zapp-react-native-utils/componentsUtils";
4
5
  import { useRefWithInitialValue } from "@applicaster/zapp-react-native-utils/reactHooks/state/useRefWithInitialValue";
5
6
  import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
7
+ import { Overlay } from "./Overlay";
6
8
 
7
9
  import { ScreenRevealManager } from "./ScreenRevealManager";
8
10
  import {
@@ -10,13 +12,6 @@ import {
10
12
  emitScreenRevealManagerIsNotReadyToShow,
11
13
  } from "./utils";
12
14
 
13
- const styles = StyleSheet.create({
14
- container: {
15
- ...StyleSheet.absoluteFillObject,
16
- position: "absolute",
17
- },
18
- });
19
-
20
15
  export const TIMEOUT = 300; // 300 ms
21
16
 
22
17
  const HIDDEN = 0; // opacity = 0
@@ -93,17 +88,11 @@ export const withScreenRevealManager = (Component) => {
93
88
  onLoadFailedFromScreenRevealManager={managerRef.current.onLoadFailed}
94
89
  />
95
90
  {isShowOverlay ? (
96
- <Animated.View
97
- style={[
98
- styles.container,
99
- {
100
- opacity: opacityRef.current,
101
- // TODO: we should support background image as well, but for now we will use background color from theme
102
- backgroundColor:
103
- props.backgroundColor ?? theme.app_background_color,
104
- },
105
- ]}
106
- testID="animated-component"
91
+ <Overlay
92
+ opacity={opacityRef.current}
93
+ backgroundColor={
94
+ props.backgroundColor ?? theme.app_background_color
95
+ }
107
96
  />
108
97
  ) : null}
109
98
  </>
package/Helpers/index.js CHANGED
@@ -1,5 +1,11 @@
1
+ import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
2
+
1
3
  export const ASSETS = {
2
- APP_BACKGROUND_IMAGE: "app_background_image",
4
+ APP_BACKGROUND_IMAGE: platformSelect({
5
+ tvos: "app_background_image",
6
+ android_tv: "tv_app_background",
7
+ amazon: "tv_app_background",
8
+ }),
3
9
  };
4
10
 
5
11
  export const ANALYTICS_CORE_EVENTS = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-ui-components",
3
- "version": "14.0.29-rc.0",
3
+ "version": "14.0.30-alpha.6838902303",
4
4
  "description": "Applicaster Zapp React Native ui components for the Quick Brick App",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,10 +28,10 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "14.0.29-rc.0",
32
- "@applicaster/zapp-react-native-bridge": "14.0.29-rc.0",
33
- "@applicaster/zapp-react-native-redux": "14.0.29-rc.0",
34
- "@applicaster/zapp-react-native-utils": "14.0.29-rc.0",
31
+ "@applicaster/applicaster-types": "14.0.30-alpha.6838902303",
32
+ "@applicaster/zapp-react-native-bridge": "14.0.30-alpha.6838902303",
33
+ "@applicaster/zapp-react-native-redux": "14.0.30-alpha.6838902303",
34
+ "@applicaster/zapp-react-native-utils": "14.0.30-alpha.6838902303",
35
35
  "fast-json-stable-stringify": "^2.1.0",
36
36
  "promise": "^8.3.0",
37
37
  "url": "^0.11.0",
@@ -1,28 +0,0 @@
1
- import React from "react";
2
- import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
3
- import { getBackgroundImageUrl } from "../utils";
4
- import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
5
-
6
- export const LayoutBackground = ({
7
- Background,
8
- children,
9
- }: {
10
- Background: React.ComponentType<any>;
11
- children: React.ReactNode;
12
- }) => {
13
- const theme = useTheme();
14
-
15
- const { remoteConfigurations } = usePickFromState(["remoteConfigurations"]);
16
-
17
- const backgroundColor = theme.app_background_color;
18
- const backgroundImageUrl = getBackgroundImageUrl(remoteConfigurations);
19
-
20
- return (
21
- <Background
22
- backgroundColor={backgroundColor}
23
- backgroundImageUrl={backgroundImageUrl}
24
- >
25
- {children}
26
- </Background>
27
- );
28
- };