@applicaster/zapp-react-native-ui-components 14.0.12-rc.0 → 14.0.13-rc.0

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.
@@ -1,17 +1,13 @@
1
1
  import * as React from "react";
2
2
  import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
3
- import {
4
- useDimensions,
5
- useIsTablet as isTablet,
6
- useNavigation,
7
- } from "@applicaster/zapp-react-native-utils/reactHooks";
3
+ import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
8
4
 
9
5
  import { BufferAnimation } from "../PlayerContainer/BufferAnimation";
10
6
  import { PlayerContainer } from "../PlayerContainer";
11
7
  import { useModalSize } from "../VideoModal/hooks";
12
8
  import { ViewStyle } from "react-native";
13
- import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
14
9
  import { findCastPlugin, getPlayer } from "./utils";
10
+ import { useWaitForValidOrientation } from "../Screen/hooks";
15
11
 
16
12
  type Props = {
17
13
  item: ZappEntry;
@@ -26,13 +22,6 @@ type PlayableComponent = {
26
22
  Component: React.ComponentType<any>;
27
23
  };
28
24
 
29
- const dimensionsContext: "window" | "screen" = platformSelect({
30
- android_tv: "window",
31
- amazon: "window",
32
- // eslint-disable-next-line react-hooks/rules-of-hooks
33
- default: isTablet() ? "window" : "screen", // on tablet, window represents correct values, on phone it's not as the screen could be rotated
34
- });
35
-
36
25
  export function HandlePlayable({
37
26
  item,
38
27
  isModal,
@@ -94,27 +83,23 @@ export function HandlePlayable({
94
83
  });
95
84
  }, [casting]);
96
85
 
97
- const { width: screenWidth, height: screenHeight } =
98
- useDimensions(dimensionsContext);
99
-
100
86
  const modalSize = useModalSize();
101
87
 
102
- const style = React.useMemo(
103
- () =>
104
- ({
105
- width: isModal
106
- ? modalSize.width
107
- : mode === "PIP"
108
- ? "100%"
109
- : screenWidth,
110
- height: isModal
111
- ? modalSize.height
112
- : mode === "PIP"
113
- ? "100%"
114
- : screenHeight,
115
- }) as ViewStyle,
116
- [screenWidth, screenHeight, modalSize, isModal, mode]
117
- );
88
+ const isOrientationReady = useWaitForValidOrientation();
89
+
90
+ const style = React.useMemo(() => {
91
+ const isFullScreenReady =
92
+ mode === "PIP" || (mode === "FULLSCREEN" && isOrientationReady);
93
+
94
+ const getDimensionValue = (value: string | number) => {
95
+ return isModal ? value : isFullScreenReady ? "100%" : 0; // do not show player, until full screen mode is ready
96
+ };
97
+
98
+ return {
99
+ width: getDimensionValue(modalSize.width),
100
+ height: getDimensionValue(modalSize.height),
101
+ } as ViewStyle;
102
+ }, [modalSize, isModal, mode, isOrientationReady]);
118
103
 
119
104
  const Component = playable?.Component;
120
105
 
@@ -5,6 +5,14 @@ import {
5
5
 
6
6
  import { CHROMECAST_PLUGIN_ID, YOUTUBE_PLUGIN_ID } from "./const";
7
7
  import { omit } from "@applicaster/zapp-react-native-utils/utils";
8
+ import { getXray } from "@applicaster/zapp-react-native-utils/logger";
9
+
10
+ const { Logger } = getXray();
11
+
12
+ const logger = new Logger(
13
+ "QuickBrick",
14
+ "packages/zapp-react-native-ui-components/Components/HandlePlayable"
15
+ );
8
16
 
9
17
  const getPlayerModuleProperties = (PlayerModule: ZappPlugin) => {
10
18
  if (PlayerModule?.Component && typeof PlayerModule.Component === "object") {
@@ -52,10 +60,25 @@ export const getPlayer = (
52
60
  if (type) {
53
61
  PlayerModule = findPluginByIdentifier(type, plugins)?.module;
54
62
 
63
+ if (!PlayerModule) {
64
+ logger.error({
65
+ message:
66
+ "PlayerModule is undefined – type mapping may be wrong or type not set for player",
67
+ data: {
68
+ type,
69
+ screen_id,
70
+ item_type_value: item?.type?.value,
71
+ },
72
+ });
73
+
74
+ return [null, {}];
75
+ }
76
+
55
77
  return getPlayerWithModuleProperties(PlayerModule);
56
78
  }
57
79
  }
58
80
 
81
+ // TODO: Probably should be removed, Youtube plugin is deprecated
59
82
  if (item?.content?.type === "youtube-id") {
60
83
  PlayerModule = findYoutubePlugin(plugins)?.module;
61
84
 
@@ -70,5 +93,13 @@ export const getPlayer = (
70
93
  )
71
94
  );
72
95
 
96
+ if (!PlayerModule) {
97
+ logger.error({
98
+ message: "PlayerModule is undefined – playable plugin not found",
99
+ });
100
+
101
+ return [null, {}];
102
+ }
103
+
73
104
  return getPlayerWithModuleProperties(PlayerModule);
74
105
  };
@@ -661,36 +661,38 @@ const PlayerContainerComponent = (props: Props) => {
661
661
  <PlayerFocusableWrapperView
662
662
  nextFocusDown={context.bottomFocusableId}
663
663
  >
664
- <Player
665
- source={{
666
- uri,
667
- entry: item,
668
- }}
669
- focused={isInlineTV ? true : undefined}
670
- autoplay={true}
671
- controls={false}
672
- disableCastAction={disableCastAction}
673
- docked={navigator.isVideoModalDocked()}
674
- entry={item}
675
- fullscreen={mode === VideoModalMode.FULLSCREEN}
676
- inline={inline}
677
- isModal={isModal}
678
- isTabletPortrait={appData.isTabletPortrait}
679
- muted={false}
680
- playableItem={item}
681
- playerEvent={playerEvent}
682
- playerId={state.playerId}
683
- pluginConfiguration={pluginConfiguration}
684
- ref={playerRef}
685
- toggleFullscreen={toggleFullscreen}
686
- style={videoStyle}
687
- playNextData={playNextData}
688
- setNextVideoPreloadThresholdPercentage={
689
- setNextVideoPreloadThresholdPercentage
690
- }
691
- >
692
- {renderApplePlayer(applePlayerProps)}
693
- </Player>
664
+ {Player ? (
665
+ <Player
666
+ source={{
667
+ uri,
668
+ entry: item,
669
+ }}
670
+ focused={isInlineTV ? true : undefined}
671
+ autoplay={true}
672
+ controls={false}
673
+ disableCastAction={disableCastAction}
674
+ docked={navigator.isVideoModalDocked()}
675
+ entry={item}
676
+ fullscreen={mode === VideoModalMode.FULLSCREEN}
677
+ inline={inline}
678
+ isModal={isModal}
679
+ isTabletPortrait={appData.isTabletPortrait}
680
+ muted={false}
681
+ playableItem={item}
682
+ playerEvent={playerEvent}
683
+ playerId={state.playerId}
684
+ pluginConfiguration={pluginConfiguration}
685
+ ref={playerRef}
686
+ toggleFullscreen={toggleFullscreen}
687
+ style={videoStyle}
688
+ playNextData={playNextData}
689
+ setNextVideoPreloadThresholdPercentage={
690
+ setNextVideoPreloadThresholdPercentage
691
+ }
692
+ >
693
+ {renderApplePlayer(applePlayerProps)}
694
+ </Player>
695
+ ) : null}
694
696
  </PlayerFocusableWrapperView>
695
697
 
696
698
  {state.error ? <ErrorDisplay error={state.error} /> : null}
@@ -14,6 +14,7 @@ const mockIsOrientationCompatible = jest.fn(() => true);
14
14
 
15
15
  jest.mock("react-native-safe-area-context", () => ({
16
16
  useSafeAreaInsets: () => ({ top: 44 }),
17
+ useSafeAreaFrame: () => ({ x: 0, y: 0, width: 375, height: 812 }),
17
18
  }));
18
19
 
19
20
  jest.mock("../../RouteManager", () => ({
@@ -5,15 +5,85 @@ import {
5
5
  } from "@applicaster/zapp-react-native-utils/appUtils/orientationHelper";
6
6
  import {
7
7
  useCurrentScreenData,
8
- useDimensions,
9
8
  useRoute,
10
9
  useIsTablet,
10
+ useIsScreenActive,
11
11
  } from "@applicaster/zapp-react-native-utils/reactHooks";
12
12
  import { useMemo, useEffect, useState } from "react";
13
+ import { useSafeAreaFrame } from "react-native-safe-area-context";
14
+
15
+ type MemoizedSafeAreaFrameWithActiveStateOptions = {
16
+ updateForInactiveScreens?: boolean;
17
+ isActive: boolean;
18
+ };
19
+
20
+ /**
21
+ * Base hook that wraps useSafeAreaFrame with memoization and inactive screen filtering.
22
+ * Requires isActive to be passed explicitly - use useMemoizedSafeAreaFrame for automatic detection.
23
+ *
24
+ * @param options.updateForInactiveScreens - If false, frame won't update when screen is inactive (default: true)
25
+ * @param options.isActive - Whether the screen is currently active
26
+ * @returns The memoized safe area frame { x, y, width, height }
27
+ */
28
+ export const useMemoizedSafeAreaFrameWithActiveState = (
29
+ options: MemoizedSafeAreaFrameWithActiveStateOptions
30
+ ) => {
31
+ const { updateForInactiveScreens = true, isActive } = options;
32
+ const frame = useSafeAreaFrame();
33
+
34
+ const [memoFrame, setMemoFrame] = useState(frame);
35
+
36
+ useEffect(() => {
37
+ const shouldUpdate = isActive || updateForInactiveScreens;
38
+
39
+ const dimensionsChanged =
40
+ frame.width !== memoFrame.width || frame.height !== memoFrame.height;
41
+
42
+ if (shouldUpdate && dimensionsChanged) {
43
+ setMemoFrame(frame);
44
+ }
45
+ }, [
46
+ frame.width,
47
+ frame.height,
48
+ isActive,
49
+ updateForInactiveScreens,
50
+ frame,
51
+ memoFrame.width,
52
+ memoFrame.height,
53
+ ]);
54
+
55
+ return memoFrame;
56
+ };
57
+
58
+ type MemoizedSafeAreaFrameOptions = {
59
+ updateForInactiveScreens?: boolean;
60
+ };
61
+
62
+ /**
63
+ * Hook that wraps useSafeAreaFrame with memoization and inactive screen filtering.
64
+ * Uses useIsScreenActive() internally to determine active state - use useMemoizedSafeAreaFrameWithActiveState
65
+ * if you need to pass isActive explicitly.
66
+ *
67
+ * @param options.updateForInactiveScreens - If false, frame won't update when screen is inactive (default: true)
68
+ * @returns The memoized safe area frame { x, y, width, height }
69
+ */
70
+ export const useMemoizedSafeAreaFrame = (
71
+ options: MemoizedSafeAreaFrameOptions = {}
72
+ ) => {
73
+ const { updateForInactiveScreens = true } = options;
74
+ const isActive = useIsScreenActive();
75
+
76
+ return useMemoizedSafeAreaFrameWithActiveState({
77
+ updateForInactiveScreens,
78
+ isActive,
79
+ });
80
+ };
13
81
 
14
82
  export const useWaitForValidOrientation = () => {
15
- const { width: screenWidth, height } = useDimensions("screen", {
16
- fullDimensions: true,
83
+ // Use memoized safe area frame to synchronize with Scene's dimension source
84
+ // This prevents race conditions where the orientation check passes before
85
+ // Scene's memoFrame has updated to the new dimensions
86
+ const { width: screenWidth, height } = useMemoizedSafeAreaFrame({
17
87
  updateForInactiveScreens: false,
18
88
  });
19
89
 
@@ -93,7 +93,13 @@ export function Screen(_props: Props) {
93
93
  const isActive = useIsScreenActive();
94
94
 
95
95
  const ref = React.useRef(null);
96
- const isReady = useWaitForValidOrientation();
96
+ const isOrientationReady = useWaitForValidOrientation();
97
+
98
+ // Playable screens handle their own orientation via the native player plugin,
99
+ // so we skip the orientation wait gate to avoid a deadlock where the screen
100
+ // waits for landscape but blocks rendering that would trigger the rotation.
101
+ const isPlayableRoute = pathname?.includes("/playable");
102
+ const isReady = isOrientationReady || isPlayableRoute;
97
103
 
98
104
  React.useEffect(() => {
99
105
  if (ref.current && isActive && isReady) {
@@ -1,9 +1,9 @@
1
- import React, { useEffect } from "react";
1
+ import React from "react";
2
2
  import { equals } from "ramda";
3
3
  import { Animated, ViewProps, ViewStyle } from "react-native";
4
- import { useSafeAreaFrame } from "react-native-safe-area-context";
5
4
 
6
5
  import { useScreenOrientationHandler } from "@applicaster/zapp-react-native-ui-components/Components/Screen/orientationHandler";
6
+ import { useMemoizedSafeAreaFrameWithActiveState } from "@applicaster/zapp-react-native-ui-components/Components/Screen/hooks";
7
7
 
8
8
  import { PathnameContext } from "../../Contexts/PathnameContext";
9
9
  import { ScreenDataContext } from "../../Contexts/ScreenDataContext";
@@ -94,19 +94,13 @@ function SceneComponent({
94
94
  isActive,
95
95
  });
96
96
 
97
- const frame = useSafeAreaFrame();
98
-
99
- const [memoFrame, setMemoFrame] = React.useState(frame);
100
-
101
- useEffect(() => {
102
- if (isActive) {
103
- setMemoFrame((oldFrame) =>
104
- oldFrame.width === frame.width && oldFrame.height === frame.height
105
- ? oldFrame
106
- : frame
107
- );
108
- }
109
- }, [isActive, frame.width, frame.height]);
97
+ // Use shared memoized frame hook - synchronized with useWaitForValidOrientation
98
+ // to prevent race conditions during orientation changes
99
+ // Pass isActive from props since Scene knows its active state from Transitioner
100
+ const memoFrame = useMemoizedSafeAreaFrameWithActiveState({
101
+ updateForInactiveScreens: false,
102
+ isActive,
103
+ });
110
104
 
111
105
  const isAnimating = animating && overlayStyle;
112
106
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-ui-components",
3
- "version": "14.0.12-rc.0",
3
+ "version": "14.0.13-rc.0",
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.12-rc.0",
32
- "@applicaster/zapp-react-native-bridge": "14.0.12-rc.0",
33
- "@applicaster/zapp-react-native-redux": "14.0.12-rc.0",
34
- "@applicaster/zapp-react-native-utils": "14.0.12-rc.0",
31
+ "@applicaster/applicaster-types": "14.0.13-rc.0",
32
+ "@applicaster/zapp-react-native-bridge": "14.0.13-rc.0",
33
+ "@applicaster/zapp-react-native-redux": "14.0.13-rc.0",
34
+ "@applicaster/zapp-react-native-utils": "14.0.13-rc.0",
35
35
  "fast-json-stable-stringify": "^2.1.0",
36
36
  "promise": "^8.3.0",
37
37
  "url": "^0.11.0",