@applicaster/zapp-react-native-ui-components 16.0.0-rc.7 → 16.0.0-rc.9

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.
@@ -129,6 +129,11 @@ export const ScreenContainer = React.memo(function ScreenContainer({
129
129
  []
130
130
  );
131
131
 
132
+ // We need to render menu first and then proceed with screen content,
133
+ // otherwise screen will stay black until everything is loaded and screen
134
+ // rendering put huge load the CPU pushing rendering even further.
135
+ // With this approach, menu will be rendered immediately and screen content
136
+ // will be rendered after paint, which makes it more responsive and prevents black screen.
132
137
  const [navBarReady, setNavBarReady] = React.useState(false);
133
138
 
134
139
  const navBarContainer = (
@@ -8,7 +8,7 @@ export function ButtonContainerView({
8
8
  children,
9
9
  }: ContainerProps) {
10
10
  return (
11
- <View style={style}>
11
+ <View style={style} pointerEvents="box-none">
12
12
  <View style={contentStyle}>{children}</View>
13
13
  </View>
14
14
  );
@@ -0,0 +1,60 @@
1
+ import { renderHook, act } from "@testing-library/react-native";
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
+
14
+ act(() => {
15
+ callbacks.forEach((cb) => cb(0));
16
+ });
17
+ };
18
+
19
+ beforeEach(() => {
20
+ frameCallbacks = [];
21
+ originalRaf = global.requestAnimationFrame;
22
+ originalCancelRaf = global.cancelAnimationFrame;
23
+
24
+ global.requestAnimationFrame = jest.fn((cb: FrameRequestCallback) => {
25
+ frameCallbacks.push(cb);
26
+
27
+ return frameCallbacks.length;
28
+ }) as unknown as typeof requestAnimationFrame;
29
+
30
+ global.cancelAnimationFrame = jest.fn();
31
+ });
32
+
33
+ afterEach(() => {
34
+ global.requestAnimationFrame = originalRaf;
35
+ global.cancelAnimationFrame = originalCancelRaf;
36
+ });
37
+
38
+ it("returns false on the initial render", () => {
39
+ const { result } = renderHook(() => useAfterPaint());
40
+
41
+ expect(result.current).toBe(false);
42
+ });
43
+
44
+ it("stays false after only one animation frame (before paint completes)", () => {
45
+ const { result } = renderHook(() => useAfterPaint());
46
+
47
+ flushFrame();
48
+
49
+ expect(result.current).toBe(false);
50
+ });
51
+
52
+ it("returns true after two animation frames (a real post-paint boundary)", () => {
53
+ const { result } = renderHook(() => useAfterPaint());
54
+
55
+ flushFrame();
56
+ flushFrame();
57
+
58
+ expect(result.current).toBe(true);
59
+ });
60
+ });
@@ -1 +1,3 @@
1
1
  export { useInitialFocus } from "./useInitialFocus";
2
+
3
+ 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
+ };
@@ -21,7 +21,7 @@ import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/he
21
21
 
22
22
  import { NavBarContainer } from "../../Layout/TV/NavBarContainer";
23
23
  import { ScreenResolver } from "../../ScreenResolver";
24
- import { useInitialFocus } from "./hooks";
24
+ import { useInitialFocus, useAfterPaint } from "./hooks";
25
25
  import { isPlayerPlugin } from "@applicaster/zapp-react-native-utils/pluginUtils";
26
26
  import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils";
27
27
  import { FreezeWithCallback } from "../../FreezeWithCallback";
@@ -157,6 +157,13 @@ export const Screen = ({ route, Components }: Props) => {
157
157
 
158
158
  const isScreenActive = useIsScreenActive();
159
159
 
160
+ // We need to render menu first and then proceed with screen content,
161
+ // otherwise screen will stay black until everything is loaded and screen
162
+ // rendering put huge load the CPU pushing rendering even further.
163
+ // With this approach, menu will be rendered immediately and screen content
164
+ // will be rendered after paint, which makes it more responsive and prevents black screen.
165
+ const isContentReady = useAfterPaint();
166
+
160
167
  return (
161
168
  <FreezeWithCallback freeze={!isScreenActive} onRelease={onRelease}>
162
169
  <View style={[styles.container, { backgroundColor }]}>
@@ -167,12 +174,14 @@ export const Screen = ({ route, Components }: Props) => {
167
174
  navigationProps={navigationProps}
168
175
  />
169
176
  </NavBarContainer>
170
- <ScreenResolver
171
- screenType={screenType}
172
- screenId={screenId}
173
- screenData={screenData}
174
- groupId={route}
175
- />
177
+ {isContentReady ? (
178
+ <ScreenResolver
179
+ screenType={screenType}
180
+ screenId={screenId}
181
+ screenData={screenData}
182
+ groupId={route}
183
+ />
184
+ ) : null}
176
185
  </View>
177
186
  </FreezeWithCallback>
178
187
  );
@@ -624,48 +624,7 @@ export class LiveImage implements QuickBrickPlayer.SharedPlayerCallBacks {
624
624
  return this._preparePromise;
625
625
  }
626
626
 
627
- this._preparePromise = (async (): Promise<boolean> => {
628
- // 1. Run hooks if configured
629
- let entry = this.factoryConfig.entry;
630
-
631
- if (this.preloadHooks?.length) {
632
- const result = await executePreloadHooks({
633
- preloadHooks: this.preloadHooks,
634
- entry,
635
- });
636
-
637
- if (result) {
638
- this.processedEntry = result;
639
- entry = result;
640
- } else {
641
- return false;
642
- }
643
- }
644
-
645
- // 2. Create the player with the correct entry
646
- const factoryItem = playerFactory({
647
- player: this.factoryConfig.player,
648
- playerId: this.factoryConfig.playerId,
649
- autoplay: false,
650
- entry,
651
- muted: this.initiallyMuted,
652
- playerPluginId: this.factoryConfig.playerPluginId,
653
- screenConfig: this.factoryConfig.screenConfig,
654
- playerRole: PlayerRole.Cell,
655
- });
656
-
657
- if (!factoryItem) {
658
- throw new Error("Player factory returned null");
659
- }
660
-
661
- this.player = factoryItem.controller;
662
- this.component = factoryItem.Component;
663
-
664
- // 3. Register callbacks — player now exists
665
- this.player.addListener({ id: "live-image", listener: this });
666
-
667
- return true;
668
- })()
627
+ this._preparePromise = this.createPreparedPlayer()
669
628
  .then((result) => {
670
629
  this._preparePromise = null;
671
630
 
@@ -685,6 +644,45 @@ export class LiveImage implements QuickBrickPlayer.SharedPlayerCallBacks {
685
644
  return this._preparePromise;
686
645
  }
687
646
 
647
+ private async createPreparedPlayer(): Promise<boolean> {
648
+ let entry = this.factoryConfig.entry;
649
+
650
+ if (this.preloadHooks?.length) {
651
+ const result = await executePreloadHooks({
652
+ preloadHooks: this.preloadHooks,
653
+ entry,
654
+ });
655
+
656
+ if (!result) return false;
657
+
658
+ this.processedEntry = result;
659
+ entry = result;
660
+ }
661
+
662
+ const factoryItem = await playerFactory({
663
+ player: this.factoryConfig.player,
664
+ playerId: this.factoryConfig.playerId,
665
+ autoplay: false,
666
+ entry,
667
+ muted: this.initiallyMuted,
668
+ playerPluginId: this.factoryConfig.playerPluginId,
669
+ screenConfig: this.factoryConfig.screenConfig,
670
+ playerRole: PlayerRole.Cell,
671
+ });
672
+
673
+ if (!factoryItem) {
674
+ throw new Error(
675
+ `Player factory returned null (playerId: ${this.factoryConfig.playerId}, playerPluginId: ${this.factoryConfig.playerPluginId})`
676
+ );
677
+ }
678
+
679
+ this.player = factoryItem.controller;
680
+ this.component = factoryItem.Component;
681
+ this.player.addListener({ id: "live-image", listener: this });
682
+
683
+ return true;
684
+ }
685
+
688
686
  public getPlayer = (): Player | null => {
689
687
  return this.player;
690
688
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-ui-components",
3
- "version": "16.0.0-rc.7",
3
+ "version": "16.0.0-rc.9",
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": "16.0.0-rc.7",
32
- "@applicaster/zapp-react-native-bridge": "16.0.0-rc.7",
33
- "@applicaster/zapp-react-native-redux": "16.0.0-rc.7",
34
- "@applicaster/zapp-react-native-utils": "16.0.0-rc.7",
31
+ "@applicaster/applicaster-types": "16.0.0-rc.9",
32
+ "@applicaster/zapp-react-native-bridge": "16.0.0-rc.9",
33
+ "@applicaster/zapp-react-native-redux": "16.0.0-rc.9",
34
+ "@applicaster/zapp-react-native-utils": "16.0.0-rc.9",
35
35
  "fast-json-stable-stringify": "^2.1.0",
36
36
  "promise": "^8.3.0",
37
37
  "url": "^0.11.0",