@applicaster/zapp-react-native-ui-components 15.0.0-alpha.5412418016 → 15.0.0-alpha.5587607173

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.
Files changed (30) hide show
  1. package/Components/AnimatedInOut/index.tsx +69 -26
  2. package/Components/Cell/TvOSCellComponent.tsx +12 -3
  3. package/Components/HandlePlayable/HandlePlayable.tsx +14 -65
  4. package/Components/HandlePlayable/const.ts +3 -0
  5. package/Components/HandlePlayable/utils.ts +74 -0
  6. package/Components/PlayerContainer/PlayerContainer.tsx +1 -16
  7. package/Components/PlayerImageBackground/index.tsx +3 -22
  8. package/Components/ScreenRevealManager/ScreenRevealManager.ts +40 -8
  9. package/Components/ScreenRevealManager/__tests__/ScreenRevealManager.test.ts +86 -69
  10. package/Components/ScreenRevealManager/withScreenRevealManager.tsx +44 -26
  11. package/Components/TopMarginApplicator/TopMarginApplicator.tsx +0 -6
  12. package/Components/VideoLive/__tests__/__snapshots__/PlayerLiveImageComponent.test.tsx.snap +1 -0
  13. package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +114 -171
  14. package/Components/VideoModal/ModalAnimation/index.ts +2 -13
  15. package/Components/VideoModal/ModalAnimation/utils.ts +1 -327
  16. package/Components/VideoModal/PlayerWrapper.tsx +14 -88
  17. package/Components/VideoModal/VideoModal.tsx +1 -5
  18. package/Components/VideoModal/__tests__/PlayerWrapper.test.tsx +1 -0
  19. package/Components/VideoModal/hooks/useModalSize.ts +10 -5
  20. package/Components/VideoModal/playerWrapperStyle.ts +70 -0
  21. package/Components/VideoModal/playerWrapperUtils.ts +91 -0
  22. package/Components/VideoModal/utils.ts +7 -0
  23. package/package.json +5 -5
  24. package/Components/VideoModal/ModalAnimation/AnimatedPlayerModalWrapper.tsx +0 -60
  25. package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.tsx +0 -417
  26. package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.web.tsx +0 -294
  27. package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.tsx +0 -176
  28. package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.web.tsx +0 -93
  29. package/Components/VideoModal/ModalAnimation/AnimationComponent.tsx +0 -500
  30. package/Components/VideoModal/ModalAnimation/__tests__/getMoveUpValue.test.ts +0 -108
@@ -2,106 +2,123 @@ import {
2
2
  ScreenRevealManager,
3
3
  COMPONENT_LOADING_STATE,
4
4
  } from "../ScreenRevealManager";
5
+ import { Subject } from "rxjs";
6
+
7
+ jest.mock("@applicaster/zapp-react-native-utils/arrayUtils", () => ({
8
+ makeListOf: jest.fn((value: any, length: number) =>
9
+ Array(length).fill(value)
10
+ ),
11
+ }));
12
+
13
+ jest.mock("@applicaster/zapp-react-native-utils/componentsUtils", () => ({
14
+ isFirstComponentGallery: jest.fn(),
15
+ }));
16
+
17
+ jest.mock("@applicaster/zapp-react-native-utils/idleUtils", () => ({
18
+ withTimeout$: jest.fn(),
19
+ }));
20
+
21
+ import { makeListOf } from "@applicaster/zapp-react-native-utils/arrayUtils";
22
+ import { isFirstComponentGallery } from "@applicaster/zapp-react-native-utils/componentsUtils";
23
+ import { withTimeout$ } from "@applicaster/zapp-react-native-utils/idleUtils";
5
24
 
6
25
  describe("ScreenRevealManager", () => {
7
- const mockCallback = jest.fn();
26
+ let mockCallback: jest.Mock;
27
+ let timeout$: Subject<void>;
8
28
 
9
29
  beforeEach(() => {
10
- jest.clearAllMocks();
11
- });
12
-
13
- it("should initialize with the correct number of components to wait for", () => {
14
- const componentsToRender: ZappUIComponent[] = [
15
- { component_type: "component1" },
16
- { component_type: "component2" },
17
- { component_type: "component3" },
18
- ];
30
+ jest.useFakeTimers();
31
+ mockCallback = jest.fn();
32
+ timeout$ = new Subject();
19
33
 
20
- const manager = new ScreenRevealManager(componentsToRender, mockCallback);
34
+ (withTimeout$ as jest.Mock).mockReturnValue(timeout$);
35
+ (isFirstComponentGallery as jest.Mock).mockReturnValue(false);
21
36
 
22
- expect(manager.numberOfComponentsWaitToLoadBeforePresent).toBe(3);
37
+ (makeListOf as jest.Mock).mockImplementation((value, length) =>
38
+ Array(length).fill(value)
39
+ );
40
+ });
23
41
 
24
- expect(manager.renderingState).toEqual([
25
- COMPONENT_LOADING_STATE.UNKNOWN,
26
- COMPONENT_LOADING_STATE.UNKNOWN,
27
- COMPONENT_LOADING_STATE.UNKNOWN,
28
- ]);
42
+ afterEach(() => {
43
+ jest.clearAllTimers();
44
+ jest.useRealTimers();
45
+ jest.resetAllMocks();
29
46
  });
30
47
 
31
- it("should call the callback when the required number of components are loaded successfully", () => {
32
- const componentsToRender: ZappUIComponent[] = [
33
- { component_type: "component1" },
34
- { component_type: "component2" },
35
- { component_type: "component3" },
36
- ];
48
+ // ────────────────────────────────────────────────
49
+ it("should initialize with correct number of components and UNKNOWN state", () => {
50
+ const components = new Array(5).fill({});
51
+ const mgr = new ScreenRevealManager(components, mockCallback);
37
52
 
38
- const manager = new ScreenRevealManager(componentsToRender, mockCallback);
53
+ expect(mgr.numberOfComponentsWaitToLoadBeforePresent).toBe(3);
54
+ expect(makeListOf).toHaveBeenCalledWith(COMPONENT_LOADING_STATE.UNKNOWN, 3);
55
+ });
39
56
 
40
- manager.onLoadFinished(0);
41
- manager.onLoadFinished(1);
42
- manager.onLoadFinished(2);
57
+ // ────────────────────────────────────────────────
58
+ it("should set numberOfComponentsWaitToLoadBeforePresent to 1 if first component is gallery", () => {
59
+ (isFirstComponentGallery as jest.Mock).mockReturnValue(true);
43
60
 
44
- expect(mockCallback).toHaveBeenCalledTimes(1);
61
+ const components = new Array(5).fill({});
62
+ const mgr = new ScreenRevealManager(components, mockCallback);
63
+
64
+ expect(mgr.numberOfComponentsWaitToLoadBeforePresent).toBe(1);
45
65
  });
46
66
 
47
- it("should call the callback when the required number of components fail to load", () => {
48
- const componentsToRender: ZappUIComponent[] = [
49
- { component_type: "component1" },
50
- { component_type: "component2" },
51
- { component_type: "component3" },
52
- ];
67
+ // ────────────────────────────────────────────────
68
+ it("should trigger callback after all components load successfully", () => {
69
+ const components = new Array(3).fill({});
70
+ const mgr = new ScreenRevealManager(components, mockCallback);
53
71
 
54
- const manager = new ScreenRevealManager(componentsToRender, mockCallback);
72
+ mgr.onLoadFinished(0);
73
+ expect(mockCallback).not.toHaveBeenCalled();
55
74
 
56
- manager.onLoadFailed(0);
57
- manager.onLoadFailed(1);
58
- manager.onLoadFailed(2);
75
+ mgr.onLoadFinished(1);
76
+ expect(mockCallback).not.toHaveBeenCalled();
59
77
 
78
+ mgr.onLoadFinished(2);
60
79
  expect(mockCallback).toHaveBeenCalledTimes(1);
61
80
  });
62
81
 
63
- it("should call the callback when a mix of successful and failed loads meet the required number", () => {
64
- const componentsToRender: ZappUIComponent[] = [
65
- { component_type: "component1" },
66
- { component_type: "component2" },
67
- { component_type: "component3" },
68
- ];
69
-
70
- const manager = new ScreenRevealManager(componentsToRender, mockCallback);
82
+ // ────────────────────────────────────────────────
83
+ it("should trigger callback after some components fail to load but all finished", () => {
84
+ const components = new Array(3).fill({});
85
+ const mgr = new ScreenRevealManager(components, mockCallback);
71
86
 
72
- manager.onLoadFinished(0);
73
- manager.onLoadFailed(1);
74
- manager.onLoadFinished(2);
87
+ mgr.onLoadFinished(0);
88
+ mgr.onLoadFailed(1);
89
+ mgr.onLoadFailed(2);
75
90
 
76
91
  expect(mockCallback).toHaveBeenCalledTimes(1);
77
92
  });
78
93
 
79
- it("should not call the callback if the required number of components are not loaded", () => {
80
- const componentsToRender: ZappUIComponent[] = [
81
- { component_type: "component1" },
82
- { component_type: "component2" },
83
- { component_type: "component3" },
84
- ];
85
-
86
- const manager = new ScreenRevealManager(componentsToRender, mockCallback);
94
+ // ────────────────────────────────────────────────
95
+ it("should not trigger callback twice when same component finishes twice", () => {
96
+ const components = new Array(3).fill({});
97
+ const mgr = new ScreenRevealManager(components, mockCallback);
87
98
 
88
- manager.onLoadFinished(0);
89
- manager.onLoadFailed(1);
99
+ mgr.onLoadFinished(0);
100
+ mgr.onLoadFinished(0); // duplicate
101
+ mgr.onLoadFinished(1);
102
+ mgr.onLoadFinished(2);
90
103
 
91
- expect(mockCallback).not.toHaveBeenCalled();
104
+ expect(mockCallback).toHaveBeenCalledTimes(1);
92
105
  });
93
106
 
94
- it("should call the callback when the when first component is gallery and it was loaded successfully", () => {
95
- const componentsToRender: ZappUIComponent[] = [
96
- { component_type: "gallery-qb" },
97
- { component_type: "component2" },
98
- { component_type: "component3" },
99
- ];
107
+ // ────────────────────────────────────────────────
108
+ it("should trigger callback when timeout$ emits before all loaded", () => {
109
+ const components = new Array(3).fill({});
110
+ new ScreenRevealManager(components, mockCallback);
100
111
 
101
- const manager = new ScreenRevealManager(componentsToRender, mockCallback);
102
-
103
- manager.onLoadFinished(0);
112
+ timeout$.next(); // simulate timeout event from withTimeout$
104
113
 
105
114
  expect(mockCallback).toHaveBeenCalledTimes(1);
106
115
  });
116
+
117
+ // ────────────────────────────────────────────────
118
+ it("should not call callback if nothing loads and no timeout emitted", () => {
119
+ const components = new Array(3).fill({});
120
+ new ScreenRevealManager(components, mockCallback);
121
+
122
+ expect(mockCallback).not.toHaveBeenCalled();
123
+ });
107
124
  });
@@ -1,8 +1,8 @@
1
1
  import * as React from "react";
2
- import { Animated } from "react-native";
2
+ import { Animated, StyleSheet } from "react-native";
3
3
  import { isFirstComponentScreenPicker } from "@applicaster/zapp-react-native-utils/componentsUtils";
4
- import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
5
4
  import { useRefWithInitialValue } from "@applicaster/zapp-react-native-utils/reactHooks/state/useRefWithInitialValue";
5
+ import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
6
6
 
7
7
  import { ScreenRevealManager } from "./ScreenRevealManager";
8
8
  import {
@@ -10,16 +10,14 @@ import {
10
10
  emitScreenRevealManagerIsNotReadyToShow,
11
11
  } from "./utils";
12
12
 
13
- const flex = platformSelect({
14
- tvos: 1,
15
- android_tv: 1,
16
- web: undefined,
17
- samsung_tv: undefined,
18
- lg_tv: undefined,
19
- default: undefined,
13
+ const styles = StyleSheet.create({
14
+ container: {
15
+ ...StyleSheet.absoluteFillObject,
16
+ position: "absolute",
17
+ },
20
18
  });
21
19
 
22
- export const TIMEOUT = 500; // 500 ms
20
+ export const TIMEOUT = 300; // 300 ms
23
21
 
24
22
  const HIDDEN = 0; // opacity = 0
25
23
 
@@ -33,37 +31,48 @@ export const withScreenRevealManager = (Component) => {
33
31
  return function WithScreenRevealManager(props: Props) {
34
32
  const { componentsToRender } = props;
35
33
 
36
- const [isReadyToShow, setIsReadyToShow] = React.useState(false);
34
+ const [isContentReadyToBeShown, setIsContentReadyToBeShown] =
35
+ React.useState(false);
37
36
 
38
- const handleSetIsReadyToShow = React.useCallback(() => {
39
- setIsReadyToShow(true);
37
+ const [isShowOverlay, setIsShowOverlay] = React.useState(true);
38
+
39
+ const theme = useTheme<BaseThemePropertiesTV>();
40
+
41
+ const handleSetIsContentReadyToBeShown = React.useCallback(() => {
42
+ setIsContentReadyToBeShown(true);
40
43
  }, []);
41
44
 
42
45
  const managerRef = useRefWithInitialValue<ScreenRevealManager>(
43
- () => new ScreenRevealManager(componentsToRender, handleSetIsReadyToShow)
46
+ () =>
47
+ new ScreenRevealManager(
48
+ componentsToRender,
49
+ handleSetIsContentReadyToBeShown
50
+ )
44
51
  );
45
52
 
46
53
  const opacityRef = useRefWithInitialValue<Animated.Value>(
47
- () => new Animated.Value(HIDDEN)
54
+ () => new Animated.Value(SHOWN)
48
55
  );
49
56
 
50
57
  React.useEffect(() => {
51
- if (!isReadyToShow) {
58
+ if (!isContentReadyToBeShown) {
52
59
  emitScreenRevealManagerIsNotReadyToShow();
53
60
  } else {
54
61
  emitScreenRevealManagerIsReadyToShow();
55
62
  }
56
- }, [isReadyToShow]);
63
+ }, [isContentReadyToBeShown]);
57
64
 
58
65
  React.useEffect(() => {
59
- if (isReadyToShow) {
66
+ if (isContentReadyToBeShown) {
60
67
  Animated.timing(opacityRef.current, {
61
- toValue: SHOWN,
68
+ toValue: HIDDEN,
62
69
  duration: TIMEOUT,
63
70
  useNativeDriver: true,
64
- }).start();
71
+ }).start(() => {
72
+ setIsShowOverlay(false);
73
+ });
65
74
  }
66
- }, [isReadyToShow]);
75
+ }, [isContentReadyToBeShown]);
67
76
 
68
77
  if (isFirstComponentScreenPicker(componentsToRender)) {
69
78
  // for screen-picker with have additional internal ComponentsMap, no need to add this wrapper
@@ -71,10 +80,7 @@ export const withScreenRevealManager = (Component) => {
71
80
  }
72
81
 
73
82
  return (
74
- <Animated.View
75
- style={{ opacity: opacityRef.current, flex }}
76
- testID="animated-component"
77
- >
83
+ <>
78
84
  <Component
79
85
  {...props}
80
86
  initialNumberToLoad={
@@ -85,7 +91,19 @@ export const withScreenRevealManager = (Component) => {
85
91
  }
86
92
  onLoadFailedFromScreenRevealManager={managerRef.current.onLoadFailed}
87
93
  />
88
- </Animated.View>
94
+ {isShowOverlay ? (
95
+ <Animated.View
96
+ style={[
97
+ styles.container,
98
+ {
99
+ opacity: opacityRef.current,
100
+ backgroundColor: theme.app_background_color,
101
+ },
102
+ ]}
103
+ testID="animated-component"
104
+ />
105
+ ) : null}
106
+ </>
89
107
  );
90
108
  };
91
109
  };
@@ -78,12 +78,6 @@ export const TopMarginApplicator: React.FC<IProps> = ({
78
78
  // HACK: Remove extraOffset when focusIssue with absolute elements is fixed on tvos
79
79
  const marginTop = useMarginTop(targetScreenId);
80
80
 
81
- // console.log("debug_2", "TopMarginApplicator - render", {
82
- // targetScreenId,
83
- // marginTop,
84
- // extraOffset,
85
- // });
86
-
87
81
  return (
88
82
  <View style={[style, { marginTop: marginTop + extraOffset }]}>
89
83
  {children}
@@ -9,6 +9,7 @@ exports[`PlayerLiveImageComponent should render correctly with default props 1`]
9
9
  <View>
10
10
  <View
11
11
  collapsable={false}
12
+ renderToHardwareTextureAndroid={false}
12
13
  style={
13
14
  {
14
15
  "opacity": 1,
@@ -1,212 +1,155 @@
1
- import React, { useEffect, useMemo } from "react";
1
+ import React, { useMemo } from "react";
2
2
  import { Animated, Dimensions } from "react-native";
3
3
 
4
- import {
5
- useSafeAreaInsets,
6
- useSafeAreaFrame,
7
- } from "react-native-safe-area-context";
8
- import { useGetBottomTabBarHeight } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useGetBottomTabBarHeight";
9
4
  import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation";
10
- import { isLive } from "@applicaster/zapp-react-native-utils/playerUtils";
11
5
 
12
- import { PROGRESS_BAR_HEIGHT } from "./utils";
13
6
  import { useConfiguration } from "../utils";
14
- import { useIsTabletLandscape } from "@applicaster/zapp-react-native-utils/reactHooks/device/useMemoizedIsTablet";
15
-
16
- export enum PlayerAnimationStateEnum {
17
- minimize = "minimize",
18
- maximize = "maximize",
19
- drag_player = "drag_player",
20
- drag_scroll = "drag_scroll",
21
- appear_as_docked = "appear_as_docked",
22
- }
7
+ import { usePlugins } from "@applicaster/zapp-react-native-redux/hooks";
8
+ import { isMenuVisible } from "../../Screen/navigationHandler";
23
9
 
24
- export type PlayerAnimationStateT = number | PlayerAnimationStateEnum | null;
10
+ import {
11
+ useSafeAreaFrame,
12
+ useSafeAreaInsets,
13
+ } from "react-native-safe-area-context";
14
+ import {
15
+ isAndroidPlatform,
16
+ isAndroidVersionAtLeast,
17
+ } from "@applicaster/zapp-react-native-utils/reactUtils";
18
+ import { getTabBarHeight } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/getTabBarHeight";
19
+ import { PROGRESS_BAR_HEIGHT } from "./utils";
20
+ import { useIsTablet as getIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
21
+ import { useAppSelector } from "@applicaster/zapp-react-native-redux";
25
22
 
26
23
  export type ModalAnimationContextT = {
27
- yTranslate: React.MutableRefObject<Animated.Value | null>;
28
- isActiveGesture: boolean;
29
- playerAnimationState: PlayerAnimationStateT;
30
- setPlayerAnimationState: (value: PlayerAnimationStateT) => void;
31
- startComponentsAnimation: boolean;
32
- setStartComponentsAnimation: (value: boolean) => void;
33
- resetPlayerAnimationState: () => void;
24
+ yTranslate: React.MutableRefObject<Animated.AnimatedInterpolation<number>>;
25
+ offsetAnimatedValueRef: React.MutableRefObject<Animated.Value>;
26
+ offset: React.MutableRefObject<number>;
27
+ heightAboveMinimised: number;
28
+ gestureTranslationRef: React.MutableRefObject<Animated.Value>;
34
29
  minimisedHeight: number;
35
- animatedValues: {
36
- lastScrollY: Animated.Value;
37
- dragScrollY: Animated.Value;
38
- dragVideoPlayerY: Animated.Value;
39
- translateYOffset: Animated.Value;
40
- };
41
- lastScrollYValue: React.MutableRefObject<number>;
42
- scrollPosition: React.MutableRefObject<number>;
43
- modalSnapPoints: number[];
44
- lastSnap: number;
45
- setLastSnap: (value: number) => void;
46
- tabletLandscapePlayerTopPosition: number;
47
- setTabletLandscapePlayerTopPosition: (value: number) => void;
48
- startComponentsAnimationDistance: number;
49
- progressBarHeight: number;
50
30
  };
51
31
 
52
32
  export const ReactContext = React.createContext<ModalAnimationContextT>({
53
33
  yTranslate: React.createRef<Animated.Value | null>(),
54
- isActiveGesture: false,
55
- playerAnimationState: null,
56
- setPlayerAnimationState: () => null,
57
- startComponentsAnimation: false,
58
- setStartComponentsAnimation: () => null,
59
- resetPlayerAnimationState: () => null,
34
+ offsetAnimatedValueRef: React.createRef<Animated.Value>(),
35
+ offset: React.createRef<number>(),
36
+ heightAboveMinimised: 0,
37
+ gestureTranslationRef: React.createRef<Animated.Value>(),
60
38
  minimisedHeight: 60,
61
- animatedValues: {
62
- lastScrollY: new Animated.Value(0),
63
- dragScrollY: new Animated.Value(0),
64
- dragVideoPlayerY: new Animated.Value(0),
65
- translateYOffset: new Animated.Value(0),
66
- },
67
- lastScrollYValue: null,
68
- scrollPosition: null,
69
- modalSnapPoints: [0, 0],
70
- lastSnap: 0,
71
- setLastSnap: () => null,
72
- tabletLandscapePlayerTopPosition: 0,
73
- setTabletLandscapePlayerTopPosition: () => null,
74
- startComponentsAnimationDistance: 0,
75
- progressBarHeight: 0,
76
39
  });
77
40
 
41
+ const SAFE_AREA_BREAKING_API_VERSION = 35;
42
+
43
+ export const isOldAndroidDevice =
44
+ isAndroidPlatform() &&
45
+ !isAndroidVersionAtLeast(SAFE_AREA_BREAKING_API_VERSION);
46
+
47
+ const bottomTabBarHeight = getTabBarHeight();
48
+
78
49
  const Provider = ({ children }: { children: React.ReactNode }) => {
50
+ const { height } = Dimensions.get("window");
51
+
79
52
  const yTranslate = React.useRef(
80
- new Animated.Value(Dimensions.get("window").height)
53
+ new Animated.Value(height).interpolate<number>({
54
+ inputRange: [0, height],
55
+ outputRange: [0, height],
56
+ })
81
57
  );
82
58
 
83
- const [playerAnimationState, setPlayerAnimationState] =
84
- React.useState<PlayerAnimationStateT>(null);
85
-
86
- const [
87
- tabletLandscapePlayerTopPosition,
88
- setTabletLandscapePlayerTopPosition,
89
- ] = React.useState<number>(0);
90
-
91
- const [startComponentsAnimation, setStartComponentsAnimation] =
92
- React.useState<boolean>(false);
59
+ const { minimised_height: minimisedHeight } = useConfiguration();
93
60
 
94
61
  const {
95
- videoModalState: { mode, visible, item },
62
+ videoModalState: { visible, mode },
63
+ currentRoute,
64
+ screenData,
96
65
  } = useNavigation();
97
66
 
98
- const isLiveItem = isLive(item);
99
- const { minimised_height: minimisedHeight } = useConfiguration();
67
+ const isTabletPortrait = useAppSelector(
68
+ (state) => state.appData.isTabletPortrait
69
+ );
100
70
 
101
- const resetPlayerAnimationState = React.useCallback(() => {
102
- setPlayerAnimationState(null);
103
- setStartComponentsAnimation(false);
104
- }, []);
105
-
106
- // Animated values
107
- const lastScrollY = React.useRef(new Animated.Value(0)).current;
108
- const dragScrollY = React.useRef(new Animated.Value(0)).current;
109
- const translateYOffset = React.useRef(new Animated.Value(0)).current;
110
- const dragVideoPlayerY = React.useRef(new Animated.Value(0)).current;
111
-
112
- const { height: safeAreaFrameHeight } = useSafeAreaFrame();
113
- const [height, setHeight] = React.useState<number>(safeAreaFrameHeight);
114
- const progressBarHeight = isLiveItem ? 0 : PROGRESS_BAR_HEIGHT;
115
- const { bottom: bottomSafeArea } = useSafeAreaInsets();
116
- const bottomTabBarHeight = useGetBottomTabBarHeight();
117
- const startComponentsAnimationDistance = Math.round((height * 60) / 100);
118
- const isTabletLandscape = useIsTabletLandscape();
119
- const windowDimensions = Dimensions.get("window");
120
-
121
- useEffect(() => {
122
- // Reset player animation state when video modal is closed
123
- if (!visible) {
124
- resetPlayerAnimationState();
125
-
126
- if (!isTabletLandscape) {
127
- // restore to portrait ( in portrait mode height is bigger)
128
- if (windowDimensions.height > windowDimensions.width) {
129
- yTranslate.current?.setValue(windowDimensions.height);
130
- }
131
- } else {
132
- yTranslate.current?.setValue(windowDimensions.height);
133
- }
134
- }
135
- }, [
136
- visible,
137
- resetPlayerAnimationState,
138
- windowDimensions.height,
139
- isTabletLandscape,
140
- ]);
71
+ const plugins = usePlugins();
72
+
73
+ const menuVisible = isMenuVisible(currentRoute, screenData, plugins);
74
+
75
+ const frame = useSafeAreaFrame();
76
+ const insets = useSafeAreaInsets();
77
+
78
+ const [heightAboveMinimised, setHeightAboveMinimised] = React.useState(0);
79
+
80
+ // memoizing heightAboveMinimised value
81
+ const offset = React.useRef(heightAboveMinimised);
82
+
83
+ // Used for memoizing modal y position after start/end of transition
84
+ const offsetAnimatedValueRef = React.useRef(
85
+ new Animated.Value(-offset.current)
86
+ );
87
+
88
+ // Used for gesture handling
89
+ const gestureTranslationRef = React.useRef(new Animated.Value(0));
90
+
91
+ const videoModalStateRef = React.useRef({ visible, mode });
141
92
 
142
93
  React.useEffect(() => {
143
- if (visible && mode === "MAXIMIZED" && height !== safeAreaFrameHeight) {
144
- setHeight(safeAreaFrameHeight);
145
- }
146
- }, [height, safeAreaFrameHeight, mode, visible]);
94
+ videoModalStateRef.current = { visible, mode };
95
+ }, [visible, mode]);
147
96
 
148
- /*
149
- If bottomTabBarHeight is equal 0 it means an app does not use bottomTabBar.
150
- Because of this we need to minus bottom SafeArea offset.
151
- */
97
+ const translateY = useMemo(() => {
98
+ const maxRange = heightAboveMinimised;
152
99
 
153
- const minValue =
154
- height -
155
- (minimisedHeight + bottomTabBarHeight + progressBarHeight + bottomSafeArea);
100
+ const combined: Animated.AnimatedAddition<number> = Animated.add(
101
+ offsetAnimatedValueRef.current,
102
+ gestureTranslationRef.current
103
+ );
156
104
 
157
- const modalSnapPoints = React.useMemo(() => [0, minValue], [minValue]);
158
- // Last snap state which will helps us to make smooth responder to scrollview animation
159
- const [lastSnap, setLastSnap] = React.useState<number>(modalSnapPoints[0]);
160
- // Extracted animated values which we will use for calculations
161
- const lastScrollYValue = React.useRef<number>(0);
162
- const scrollPosition = React.useRef<number>(0);
105
+ return combined.interpolate({
106
+ inputRange: [0, maxRange],
107
+ outputRange: [0, maxRange],
108
+ extrapolate: "clamp",
109
+ });
110
+ }, [visible, heightAboveMinimised]);
111
+
112
+ offset.current = heightAboveMinimised;
113
+ yTranslate.current = translateY;
114
+
115
+ React.useEffect(() => {
116
+ const collapsedHeight =
117
+ minimisedHeight +
118
+ (menuVisible ? bottomTabBarHeight : 0) +
119
+ (isOldAndroidDevice ? 0 : insets.bottom) + // insets.bottom is added to properly display docked modal
120
+ PROGRESS_BAR_HEIGHT;
121
+
122
+ const heightAboveMinimised = frame.height - collapsedHeight;
123
+
124
+ const isLandscape = frame.width > frame.height;
125
+
126
+ const isTablet = getIsTablet();
127
+
128
+ const shouldIgnoreLandscape = isTablet ? isTabletPortrait : true;
129
+
130
+ if (
131
+ heightAboveMinimised !== offset.current &&
132
+ videoModalStateRef.current.mode !== "PIP" &&
133
+ videoModalStateRef.current.mode !== "FULLSCREEN"
134
+ ) {
135
+ if (isLandscape && shouldIgnoreLandscape) return;
136
+ setHeightAboveMinimised(heightAboveMinimised);
137
+ offset.current = heightAboveMinimised;
138
+ }
139
+ }, [frame.height, insets.bottom, menuVisible, minimisedHeight]);
163
140
 
164
141
  return (
165
142
  <ReactContext.Provider
166
143
  value={useMemo(
167
144
  () => ({
168
145
  yTranslate,
169
- startComponentsAnimation,
170
- setStartComponentsAnimation,
171
- isActiveGesture: playerAnimationState !== null,
172
- playerAnimationState,
173
- setPlayerAnimationState,
174
- resetPlayerAnimationState,
146
+ offsetAnimatedValueRef,
147
+ offset,
148
+ heightAboveMinimised,
175
149
  minimisedHeight,
176
- animatedValues: {
177
- lastScrollY,
178
- dragScrollY,
179
- dragVideoPlayerY,
180
- translateYOffset,
181
- },
182
- lastScrollYValue,
183
- scrollPosition,
184
- modalSnapPoints,
185
- lastSnap,
186
- setLastSnap,
187
- tabletLandscapePlayerTopPosition,
188
- setTabletLandscapePlayerTopPosition,
189
- startComponentsAnimationDistance,
190
- progressBarHeight,
150
+ gestureTranslationRef,
191
151
  }),
192
- // eslint-disable-next-line react-hooks/exhaustive-deps
193
- [
194
- startComponentsAnimation,
195
- playerAnimationState,
196
- minimisedHeight,
197
- lastScrollY,
198
- dragScrollY,
199
- dragVideoPlayerY,
200
- translateYOffset,
201
- lastSnap,
202
- modalSnapPoints,
203
- lastScrollYValue,
204
- scrollPosition,
205
- tabletLandscapePlayerTopPosition,
206
- startComponentsAnimationDistance,
207
- progressBarHeight,
208
- isLiveItem,
209
- ]
152
+ [minimisedHeight, heightAboveMinimised]
210
153
  )}
211
154
  >
212
155
  {children}