@applicaster/zapp-react-native-ui-components 12.0.0-rc.10 → 12.0.0-rc.100

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 (150) hide show
  1. package/Components/AudioPlayer/AudioPlayer.tsx +9 -1
  2. package/Components/AudioPlayer/__tests__/__snapshots__/audioPlayer.test.js.snap +5 -0
  3. package/Components/AudioPlayer/helpers.tsx +1 -0
  4. package/Components/BaseFocusable/index.tsx +3 -3
  5. package/Components/Cell/Cell.tsx +32 -11
  6. package/Components/Cell/CellWithFocusable.tsx +40 -19
  7. package/Components/Cell/TvOSCellComponent.tsx +5 -9
  8. package/Components/ErrorScreen/index.tsx +1 -1
  9. package/Components/Focusable/Focusable.tsx +6 -1
  10. package/Components/FocusableCell/index.tsx +7 -7
  11. package/Components/FocusableGroup/index.tsx +11 -2
  12. package/Components/FocusableList/FocusableChild.ts +24 -14
  13. package/Components/FocusableList/FocusableItem.tsx +1 -1
  14. package/Components/FocusableList/FocusableListItemWrapper.tsx +76 -0
  15. package/Components/FocusableList/hooks/useCellState.android.ts +3 -1
  16. package/Components/FocusableList/index.tsx +26 -25
  17. package/Components/GeneralContentScreen/GeneralContentScreen.tsx +11 -8
  18. package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +13 -6
  19. package/Components/GeneralContentScreen/utils/useCurationAPI.ts +1 -1
  20. package/Components/HandlePlayable/HandlePlayable.tsx +4 -1
  21. package/Components/HookRenderer/index.tsx +1 -6
  22. package/Components/Image/Image.android.tsx +3 -26
  23. package/Components/Image/Image.tsx +18 -2
  24. package/Components/Image/utils/index.ts +39 -0
  25. package/Components/Layout/TV/ScreenContainer.tsx +79 -5
  26. package/Components/Layout/TV/ScreenLayoutContextProvider.tsx +2 -2
  27. package/Components/Layout/TV/__tests__/ScreenContainer.test.tsx +38 -28
  28. package/Components/Layout/TV/__tests__/__snapshots__/ScreenContainer.test.tsx.snap +25 -13
  29. package/Components/Layout/TV/__tests__/__snapshots__/index.test.tsx.snap +10 -50
  30. package/Components/Layout/TV/__tests__/index.test.tsx +20 -108
  31. package/Components/Layout/TV/index.tsx +15 -84
  32. package/Components/Layout/TV/index.web.tsx +33 -0
  33. package/Components/Layout/index.tsx +15 -11
  34. package/Components/MasterCell/DefaultComponents/ActionButton.tsx +4 -1
  35. package/Components/MasterCell/DefaultComponents/BorderContainerView/index.tsx +88 -113
  36. package/Components/MasterCell/DefaultComponents/CellBadge/index.tsx +21 -8
  37. package/Components/MasterCell/DefaultComponents/DynamicBadge.tsx +4 -2
  38. package/Components/MasterCell/DefaultComponents/FocusableView/index.tsx +4 -1
  39. package/Components/MasterCell/DefaultComponents/Image/Image.android.tsx +9 -26
  40. package/Components/MasterCell/DefaultComponents/Image/Image.ios.tsx +5 -3
  41. package/Components/MasterCell/DefaultComponents/Image/hooks/useImageSize.ts +65 -0
  42. package/Components/MasterCell/DefaultComponents/ImageContainer/index.tsx +5 -1
  43. package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +37 -2
  44. package/Components/MasterCell/DefaultComponents/SecondaryImage/Image.tsx +3 -2
  45. package/Components/MasterCell/DefaultComponents/Text/index.tsx +14 -2
  46. package/Components/MasterCell/DefaultComponents/Toggle.tsx +5 -1
  47. package/Components/MasterCell/DefaultComponents/__tests__/image.test.js +1 -1
  48. package/Components/MasterCell/DefaultComponents/__tests__/text.test.tsx +24 -9
  49. package/Components/MasterCell/DefaultComponents/tv/ButtonContainerView/index.android.tsx +4 -1
  50. package/Components/MasterCell/DefaultComponents/tv/ButtonContainerView/index.tsx +10 -2
  51. package/Components/MasterCell/SharedUI/CollapsibleTextContainer/index.ts +6 -10
  52. package/Components/MasterCell/dataAdapter.ts +21 -7
  53. package/Components/MasterCell/hooks/useAsyncRendering/index.ts +1 -1
  54. package/Components/MasterCell/index.tsx +3 -1
  55. package/Components/MasterCell/utils/__tests__/insertBetween.test.js +9 -0
  56. package/Components/MasterCell/utils/index.ts +33 -35
  57. package/Components/MeasurmentsPortal/BasicMeasurementsPortal.tsx +11 -7
  58. package/Components/MeasurmentsPortal/MeasurementsPortal.tsx +10 -1
  59. package/Components/ModalComponent/BottomSheetModalContent.tsx +121 -0
  60. package/Components/ModalComponent/Button/Item.tsx +82 -0
  61. package/Components/ModalComponent/Button/ItemIcon.tsx +60 -0
  62. package/Components/ModalComponent/Button/ItemLabel.tsx +101 -0
  63. package/Components/ModalComponent/Button/assets.ts +4 -0
  64. package/Components/ModalComponent/Button/index.tsx +111 -0
  65. package/Components/ModalComponent/Header/CloseButton.tsx +59 -0
  66. package/Components/ModalComponent/Header/Title.tsx +70 -0
  67. package/Components/ModalComponent/Header/assets.ts +4 -0
  68. package/Components/ModalComponent/Header/index.tsx +71 -0
  69. package/Components/ModalComponent/Header/utils.ts +79 -0
  70. package/Components/ModalComponent/index.tsx +38 -0
  71. package/Components/ModalComponent/utils.ts +126 -0
  72. package/Components/Navigator/StackNavigator.tsx +57 -0
  73. package/Components/Navigator/index.ts +1 -0
  74. package/Components/PlayerContainer/PlayerContainer.tsx +66 -31
  75. package/Components/PlayerContainer/ProgramInfo/index.tsx +3 -1
  76. package/Components/PlayerImageBackground/index.tsx +34 -8
  77. package/Components/River/ComponentsMap/ComponentsMap.tsx +97 -2
  78. package/Components/River/RefreshControl.tsx +55 -1
  79. package/Components/River/River.tsx +8 -5
  80. package/Components/River/TV/River.tsx +2 -25
  81. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +1 -1
  82. package/Components/River/__tests__/componentsMap.test.js +7 -0
  83. package/Components/River/useScreenConfiguration.ts +2 -2
  84. package/Components/RouteManager/__tests__/__snapshots__/routeManager.test.js.snap +1 -0
  85. package/Components/RouteManager/__tests__/routeManager.test.js +9 -2
  86. package/Components/RouteManager/index.tsx +4 -2
  87. package/Components/Screen/TV/hooks/index.ts +3 -0
  88. package/Components/Screen/TV/hooks/useInitialFocus.ts +70 -0
  89. package/Components/Screen/TV/hooks/useRestoreFocus.ts +22 -0
  90. package/Components/Screen/TV/index.web.tsx +165 -0
  91. package/Components/Screen/__tests__/Screen.test.tsx +91 -74
  92. package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +24 -6
  93. package/Components/Screen/__tests__/navigationHandler.test.ts +1 -178
  94. package/Components/Screen/index.tsx +110 -54
  95. package/Components/Screen/navigationHandler.ts +5 -82
  96. package/Components/ScreenResolver/index.tsx +10 -13
  97. package/Components/Tabs/TV/styles.ts +1 -1
  98. package/Components/TrackedView/index.tsx +6 -3
  99. package/Components/Transitioner/Scene.tsx +32 -26
  100. package/Components/Transitioner/Transitioner.tsx +21 -28
  101. package/Components/Transitioner/__tests__/__snapshots__/Scene.test.js.snap +12 -4
  102. package/Components/Transitioner/__tests__/__snapshots__/transitioner.test.js.snap +1 -0
  103. package/Components/VideoLive/LiveImageManager.ts +70 -14
  104. package/Components/VideoLive/PlayerLiveImageComponent.tsx +132 -95
  105. package/Components/VideoLive/__tests__/PlayerLiveImageComponent.test.tsx +45 -3
  106. package/Components/VideoLive/__tests__/__snapshots__/PlayerLiveImageComponent.test.tsx.snap +21 -29
  107. package/Components/VideoModal/ModalAnimation/AnimatedPlayerModalWrapper.tsx +66 -0
  108. package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.tsx +355 -0
  109. package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.tsx +161 -0
  110. package/Components/VideoModal/ModalAnimation/AnimationComponent.tsx +456 -0
  111. package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +182 -0
  112. package/Components/VideoModal/ModalAnimation/index.ts +15 -0
  113. package/Components/VideoModal/ModalAnimation/utils.ts +302 -0
  114. package/Components/VideoModal/PlayerDetails.tsx +6 -3
  115. package/Components/VideoModal/PlayerWrapper.tsx +81 -49
  116. package/Components/VideoModal/VideoModal.tsx +23 -40
  117. package/Components/VideoModal/__tests__/PlayerDetails.test.tsx +0 -2
  118. package/Components/VideoModal/__tests__/PlayerWrapper.test.tsx +12 -1
  119. package/Components/VideoModal/__tests__/__snapshots__/PlayerWrapper.test.tsx.snap +266 -166
  120. package/Components/VideoModal/hooks/useModalSize.ts +10 -12
  121. package/Components/VideoModal/utils.ts +8 -5
  122. package/Components/Viewport/ViewportAware/__tests__/viewportAware.test.js +26 -21
  123. package/Components/Viewport/ViewportTracker/ViewportTracker.tsx +31 -40
  124. package/Components/Viewport/ViewportTracker/__tests__/viewportTracker.test.js +4 -5
  125. package/Components/Viewport/ViewportTracker/index.tsx +1 -0
  126. package/Components/Viewport/utils.js +1 -1
  127. package/Components/ZappUIComponent/index.tsx +22 -12
  128. package/Components/index.js +2 -0
  129. package/Contexts/FocusableGroupContext/FocusableGroupContext.ts +3 -0
  130. package/Contexts/FocusableGroupContext/FocusableGroupContextProvider.tsx +16 -0
  131. package/Contexts/FocusableGroupContext/__tests__/FocusableGroupContextProvider.test.tsx +22 -0
  132. package/Contexts/FocusableGroupContext/__tests__/withFocusableContext.test.tsx +26 -0
  133. package/Contexts/FocusableGroupContext/index.ts +7 -0
  134. package/Contexts/FocusableGroupContext/withFocusableContext.tsx +17 -0
  135. package/Contexts/MenuToggleContext/{index.js → index.ts} +16 -0
  136. package/Contexts/ScreenContext/__tests__/__snapshots__/index.test.tsx.snap +3 -0
  137. package/Contexts/ScreenContext/__tests__/index.test.tsx +27 -0
  138. package/Contexts/ScreenContext/index.tsx +95 -29
  139. package/Contexts/ScreenDataContext/index.tsx +20 -0
  140. package/Contexts/ZappPipesContext/ZappPipesEntryContext.ts +1 -1
  141. package/Decorators/ComponentsMapWrapper/withComponentsMapProvider.tsx +7 -2
  142. package/Decorators/RiverResolver/index.tsx +0 -4
  143. package/Decorators/index.tsx +0 -4
  144. package/events/index.ts +1 -0
  145. package/package.json +5 -6
  146. package/Components/Layout/TV/TransitionOverlay.tsx +0 -64
  147. package/Components/VideoModal/hooks/usePosition.ts +0 -50
  148. /package/Components/FocusableGroup/{index.android.js → index.android.ts} +0 -0
  149. /package/Components/FocusableGroup/{index.ios.js → index.ios.ts} +0 -0
  150. /package/Contexts/{index.js → index.ts} +0 -0
@@ -0,0 +1,161 @@
1
+ import React from "react";
2
+ import { Animated, StyleSheet } from "react-native";
3
+
4
+ import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
5
+ import { PanGestureHandler, State } from "react-native-gesture-handler";
6
+
7
+ import { PlayerContainerContext } from "@applicaster/zapp-react-native-ui-components/Components/PlayerContainer/PlayerContainerContext";
8
+ import {
9
+ useModalAnimationContext,
10
+ PlayerAnimationStateEnum,
11
+ } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation";
12
+ import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
13
+
14
+ const generalStyles = StyleSheet.create({
15
+ container: {
16
+ flex: 1,
17
+ width: "100%",
18
+ position: "absolute",
19
+ zIndex: 201,
20
+ },
21
+ });
22
+
23
+ type Props = {
24
+ children: React.ReactNode;
25
+ };
26
+
27
+ export const AnimatedVideoPlayer = ({ children }: Props) => {
28
+ const {
29
+ playerAnimationState,
30
+ setPlayerAnimationState,
31
+ animatedValues: { translateYOffset, dragVideoPlayerY, lastScrollY },
32
+ lastScrollYValue,
33
+ modalSnapPoints,
34
+ lastSnap,
35
+ setLastSnap,
36
+ resetPlayerAnimationState,
37
+ setStartComponentsAnimation,
38
+ } = useModalAnimationContext();
39
+
40
+ const { videoModalState } = useNavigation();
41
+ const { isLanguageOverlayVisible } = React.useContext(PlayerContainerContext);
42
+
43
+ const isMaximazedModal = videoModalState.mode === "MAXIMIZED";
44
+ const isMinimizedModal = videoModalState.mode === "MINIMIZED";
45
+
46
+ const isEnablePanGesture =
47
+ !isLanguageOverlayVisible && (isMaximazedModal || isMinimizedModal);
48
+
49
+ const onGestureEvent = Animated.event(
50
+ [{ nativeEvent: { translationY: dragVideoPlayerY } }],
51
+ { useNativeDriver: true }
52
+ );
53
+
54
+ const onHandlerStateChange = React.useCallback(
55
+ ({ nativeEvent }) => {
56
+ if (nativeEvent.oldState === State.ACTIVE) {
57
+ // eslint-disable-next-line prefer-const
58
+ const { velocityY, translationY } = nativeEvent;
59
+ const preparedTranslationY = Math.abs(translationY);
60
+ const dragToss = 0.05;
61
+
62
+ if (videoModalState.mode === "MAXIMIZED") {
63
+ if (translationY > 0) {
64
+ const endOffsetY =
65
+ lastSnap + preparedTranslationY + dragToss * velocityY + 200;
66
+
67
+ let destSnapPoint = modalSnapPoints[0];
68
+
69
+ for (const snapPoint of modalSnapPoints) {
70
+ const distFromSnap = Math.abs(snapPoint - endOffsetY);
71
+
72
+ if (distFromSnap < Math.abs(destSnapPoint - endOffsetY)) {
73
+ destSnapPoint = snapPoint;
74
+ }
75
+ }
76
+
77
+ setLastSnap(destSnapPoint);
78
+
79
+ if (destSnapPoint === modalSnapPoints[0]) {
80
+ setPlayerAnimationState(PlayerAnimationStateEnum.maximaze);
81
+ } else {
82
+ lastScrollY.setValue(0);
83
+ lastScrollYValue.current = 0;
84
+ setPlayerAnimationState(PlayerAnimationStateEnum.minimize);
85
+ }
86
+ }
87
+ } else if (videoModalState.mode === "MINIMIZED") {
88
+ if (translationY < 0) {
89
+ // from mini to full
90
+ setLastSnap(modalSnapPoints[0]);
91
+
92
+ translateYOffset.setValue(
93
+ modalSnapPoints[1] - preparedTranslationY
94
+ );
95
+
96
+ setPlayerAnimationState(PlayerAnimationStateEnum.maximaze);
97
+ } else {
98
+ resetPlayerAnimationState();
99
+ }
100
+ }
101
+ }
102
+ },
103
+ [lastSnap, modalSnapPoints, videoModalState.mode]
104
+ );
105
+
106
+ React.useEffect(() => {
107
+ const dragVideoPlayerYListenerId = dragVideoPlayerY.addListener(
108
+ ({ value }) => {
109
+ if (
110
+ (isMinimizedModal && value >= 0) ||
111
+ (isMaximazedModal && value <= 0)
112
+ ) {
113
+ if (playerAnimationState === PlayerAnimationStateEnum.drag_player) {
114
+ translateYOffset.setValue(
115
+ modalSnapPoints[isMinimizedModal ? 1 : 0]
116
+ );
117
+ }
118
+ } else {
119
+ const preparedValue = Math.round(Math.abs(value));
120
+
121
+ if (
122
+ preparedValue > 0 &&
123
+ playerAnimationState !== PlayerAnimationStateEnum.drag_scroll
124
+ ) {
125
+ if (playerAnimationState !== PlayerAnimationStateEnum.drag_player) {
126
+ isMinimizedModal && setStartComponentsAnimation(true);
127
+ setPlayerAnimationState(PlayerAnimationStateEnum.drag_player);
128
+ }
129
+
130
+ translateYOffset.setValue(
131
+ isMaximazedModal
132
+ ? preparedValue
133
+ : modalSnapPoints[1] - preparedValue
134
+ );
135
+ }
136
+ }
137
+ }
138
+ );
139
+
140
+ return () => {
141
+ dragVideoPlayerY.removeListener(dragVideoPlayerYListenerId);
142
+ };
143
+ }, [playerAnimationState, isMinimizedModal, isMaximazedModal]);
144
+
145
+ return (
146
+ <PanGestureHandler
147
+ enabled={isEnablePanGesture}
148
+ shouldCancelWhenOutside={isMaximazedModal}
149
+ onGestureEvent={onGestureEvent}
150
+ onHandlerStateChange={onHandlerStateChange}
151
+ >
152
+ <Animated.View style={generalStyles.container}>{children}</Animated.View>
153
+ </PanGestureHandler>
154
+ );
155
+ };
156
+
157
+ export const AnimatedVideoPlayerComponent = ({ children }: Props) => {
158
+ const Component = !isTV() ? AnimatedVideoPlayer : React.Fragment;
159
+
160
+ return <Component>{children}</Component>;
161
+ };
@@ -0,0 +1,456 @@
1
+ import React, { useRef, useState } from "react";
2
+ import { Animated, View } from "react-native";
3
+
4
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
5
+
6
+ import {
7
+ useModalAnimationContext,
8
+ PlayerAnimationStateEnum,
9
+ } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation";
10
+
11
+ import {
12
+ useGetBottomTabBarHeight,
13
+ useNavigation,
14
+ useDimensions,
15
+ } from "@applicaster/zapp-react-native-utils/reactHooks";
16
+ import { useIsRTL } from "@applicaster/zapp-react-native-utils/localizationUtils";
17
+ import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
18
+ import { useAppState } from "@applicaster/zapp-react-native-utils/reactHooks/app";
19
+
20
+ import {
21
+ gestureListenerHelper,
22
+ getAnimationStyle,
23
+ defaultAspectRatioWidth,
24
+ getAnimationDefaultValue,
25
+ ComponentAnimationType,
26
+ AUDIO_PLAYER_HORIZONTAL_PADDING,
27
+ } from "./utils";
28
+
29
+ type Props = {
30
+ animationType: string;
31
+ children: React.ReactNode;
32
+ style?: Record<string, any>;
33
+ additionalData?: { [key: string]: any };
34
+ };
35
+
36
+ export const AnimationView = ({
37
+ animationType,
38
+ style,
39
+ children,
40
+ additionalData = {},
41
+ }: Props) => {
42
+ const {
43
+ startComponentsAnimation,
44
+ setStartComponentsAnimation,
45
+ playerAnimationState,
46
+ minimisedHeight,
47
+ animatedValues: { dragScrollY, dragVideoPlayerY },
48
+ lastScrollYValue,
49
+ scrollPosition,
50
+ tabletLandscapePlayerTopPosition,
51
+ setTabletLandscapePlayerTopPosition,
52
+ modalSnapPoints,
53
+ startComponentsAnimationDistance,
54
+ progressBarHeight,
55
+ } = useModalAnimationContext();
56
+
57
+ const isRTL = useIsRTL();
58
+ const isAppActive = useAppState(true);
59
+
60
+ const {
61
+ width: screenWidth,
62
+ deviceInfo: { isTablet, isTabletLandscape },
63
+ } = useDimensions("window", { deviceInfo: true });
64
+
65
+ const { videoModalState } = useNavigation();
66
+ const insets = useSafeAreaInsets();
67
+ const bottomTabBarHeight = useGetBottomTabBarHeight() + (insets.bottom || 0);
68
+ const minimisedWidth = defaultAspectRatioWidth(minimisedHeight);
69
+ const animationComponentRef = useRef(null);
70
+
71
+ // retrieving top position of the player for tablet landscape mode
72
+ const measureView = React.useCallback(() => {
73
+ if (isTabletLandscape && tabletLandscapePlayerTopPosition === 0) {
74
+ animationComponentRef.current.measure(
75
+ (x, y, width, height, pageX, pageY) => {
76
+ setTabletLandscapePlayerTopPosition(pageY - 20);
77
+ }
78
+ );
79
+ }
80
+ }, [tabletLandscapePlayerTopPosition]);
81
+
82
+ const [defaultValue, setDefaultValue] = useState<any>(
83
+ getAnimationDefaultValue(animationType, bottomTabBarHeight)
84
+ );
85
+
86
+ const isAudioItem = React.useMemo(
87
+ () =>
88
+ videoModalState.item?.content?.type?.includes?.("audio") ||
89
+ videoModalState.item?.type?.value === "audio",
90
+ [videoModalState.item]
91
+ );
92
+
93
+ const inlineAudioPlayer = additionalData.inlineAudioPlayer;
94
+
95
+ const moveUpValue = additionalData.saveArea
96
+ ? -insets.top + (isAudioItem ? 0 : progressBarHeight)
97
+ : isTablet
98
+ ? isTabletLandscape && (!isAudioItem || (isAudioItem && inlineAudioPlayer))
99
+ ? -tabletLandscapePlayerTopPosition + progressBarHeight
100
+ : -130
101
+ : -50 + progressBarHeight;
102
+
103
+ const moveComponentHorizontalValue = additionalData.moveValue
104
+ ? isRTL
105
+ ? additionalData.moveValue
106
+ : -additionalData.moveValue
107
+ : 0;
108
+
109
+ const animationValueType: string =
110
+ animationType === ComponentAnimationType.player ? "ValueXY" : "Value";
111
+
112
+ const getAnimationValue = React.useCallback(
113
+ (animationType, state) => {
114
+ const defaultConfig = {
115
+ toValue: 0,
116
+ duration: state === PlayerAnimationStateEnum.minimize ? 150 : 100,
117
+ useNativeDriver: true,
118
+ };
119
+
120
+ switch (animationType) {
121
+ case ComponentAnimationType.bottomBar: {
122
+ if (state === PlayerAnimationStateEnum.minimize) {
123
+ return defaultConfig;
124
+ }
125
+
126
+ defaultConfig.toValue = defaultValue;
127
+
128
+ return defaultConfig;
129
+ }
130
+
131
+ case ComponentAnimationType.player: {
132
+ if (state === PlayerAnimationStateEnum.minimize) {
133
+ const minWidth =
134
+ isAudioItem && !inlineAudioPlayer
135
+ ? minimisedHeight
136
+ : minimisedWidth;
137
+
138
+ return {
139
+ ...defaultConfig,
140
+ toValue: { x: minWidth, y: minimisedHeight },
141
+ useNativeDriver: false,
142
+ };
143
+ }
144
+
145
+ return {
146
+ ...defaultConfig,
147
+ toValue: defaultValue,
148
+ useNativeDriver: false,
149
+ };
150
+ }
151
+
152
+ case ComponentAnimationType.componentFade: {
153
+ if (state === PlayerAnimationStateEnum.minimize) {
154
+ defaultConfig.toValue = 0;
155
+
156
+ return defaultConfig;
157
+ }
158
+
159
+ defaultConfig.toValue = defaultValue;
160
+
161
+ return defaultConfig;
162
+ }
163
+
164
+ case ComponentAnimationType.componentAppears: {
165
+ if (state === PlayerAnimationStateEnum.minimize) {
166
+ defaultConfig.toValue = 1;
167
+
168
+ return defaultConfig;
169
+ }
170
+
171
+ defaultConfig.toValue = defaultValue;
172
+
173
+ return defaultConfig;
174
+ }
175
+
176
+ case ComponentAnimationType.moveUpComponent: {
177
+ if (state === PlayerAnimationStateEnum.minimize) {
178
+ defaultConfig.toValue = moveUpValue;
179
+
180
+ return defaultConfig;
181
+ }
182
+
183
+ defaultConfig.toValue = defaultValue;
184
+
185
+ return defaultConfig;
186
+ }
187
+
188
+ case ComponentAnimationType.moveComponentHorizontal: {
189
+ if (state === PlayerAnimationStateEnum.minimize) {
190
+ defaultConfig.toValue = moveComponentHorizontalValue;
191
+
192
+ return defaultConfig;
193
+ }
194
+
195
+ defaultConfig.toValue = defaultValue;
196
+
197
+ return defaultConfig;
198
+ }
199
+
200
+ case ComponentAnimationType.audioPlayerPaddingHorizontal: {
201
+ if (state === PlayerAnimationStateEnum.minimize) {
202
+ defaultConfig.toValue = isRTL
203
+ ? AUDIO_PLAYER_HORIZONTAL_PADDING
204
+ : -AUDIO_PLAYER_HORIZONTAL_PADDING;
205
+
206
+ return defaultConfig;
207
+ }
208
+
209
+ defaultConfig.toValue = 0;
210
+
211
+ return defaultConfig;
212
+ }
213
+
214
+ default:
215
+ return defaultConfig;
216
+ }
217
+ },
218
+ [
219
+ defaultValue,
220
+ minimisedWidth,
221
+ minimisedHeight,
222
+ isAudioItem,
223
+ moveUpValue,
224
+ moveComponentHorizontalValue,
225
+ ]
226
+ );
227
+
228
+ const getInitialValue = React.useCallback(() => {
229
+ const mode =
230
+ videoModalState.mode === "PIP"
231
+ ? videoModalState.previousMode
232
+ : videoModalState.mode;
233
+
234
+ switch (mode) {
235
+ case "MINIMIZED":
236
+ return getAnimationValue(
237
+ animationType,
238
+ PlayerAnimationStateEnum.minimize
239
+ ).toValue;
240
+
241
+ case "MAXIMIZED":
242
+ default:
243
+ return getAnimationValue(
244
+ animationType,
245
+ PlayerAnimationStateEnum.maximaze
246
+ ).toValue;
247
+ }
248
+ }, [defaultValue, videoModalState]);
249
+
250
+ const animatedValue = useRef(
251
+ new Animated[animationValueType](getInitialValue())
252
+ ).current;
253
+
254
+ const calculationData = React.useMemo(
255
+ () => ({
256
+ isAudioItem,
257
+ bottomTabBarHeight,
258
+ minimisedHeight,
259
+ minimisedWidth,
260
+ defaultValue,
261
+ moveUpValue,
262
+ moveComponentHorizontalValue,
263
+ isTablet,
264
+ isTabletLandscape,
265
+ isRTL,
266
+ fromMiniPlayer: videoModalState.mode === "MINIMIZED",
267
+ inlineAudioPlayer,
268
+ }),
269
+ [
270
+ bottomTabBarHeight,
271
+ minimisedHeight,
272
+ minimisedWidth,
273
+ defaultValue,
274
+ moveUpValue,
275
+ moveComponentHorizontalValue,
276
+ videoModalState.mode,
277
+ ]
278
+ );
279
+
280
+ React.useEffect(() => {
281
+ if (additionalData.resetAnimationValue) {
282
+ animatedValue.setValue(defaultValue);
283
+ }
284
+ }, [additionalData.resetAnimationValue, defaultValue]);
285
+
286
+ React.useEffect(() => {
287
+ if (animationType === ComponentAnimationType.player) {
288
+ let width, height;
289
+
290
+ if (additionalData.aspectRatio) {
291
+ width = isTabletLandscape ? additionalData.width : screenWidth;
292
+
293
+ height =
294
+ (isTabletLandscape ? additionalData.width : screenWidth) /
295
+ additionalData.aspectRatio;
296
+ } else {
297
+ width =
298
+ typeof additionalData.width === "number" && additionalData.width;
299
+
300
+ height =
301
+ typeof additionalData.height === "number" && additionalData.height;
302
+ }
303
+
304
+ if (defaultValue.x === 0 && width && height) {
305
+ const value = { x: width, y: height };
306
+ setDefaultValue(value);
307
+ animatedValue.setValue(value);
308
+ }
309
+ }
310
+ }, [additionalData, screenWidth]);
311
+
312
+ React.useEffect(() => {
313
+ if (
314
+ playerAnimationState === PlayerAnimationStateEnum.minimize &&
315
+ startComponentsAnimation &&
316
+ videoModalState.mode === "MAXIMIZED"
317
+ ) {
318
+ Animated.timing(
319
+ animatedValue,
320
+ getAnimationValue(animationType, playerAnimationState)
321
+ ).start();
322
+ } else if (playerAnimationState === PlayerAnimationStateEnum.maximaze) {
323
+ animatedValue.setValue(defaultValue);
324
+ }
325
+ }, [
326
+ playerAnimationState,
327
+ startComponentsAnimation,
328
+ videoModalState.mode,
329
+ defaultValue,
330
+ ]);
331
+
332
+ React.useEffect(() => {
333
+ const dragVideoPlayerYListenerId = dragVideoPlayerY.addListener(
334
+ ({ value }) => {
335
+ if (playerAnimationState === PlayerAnimationStateEnum.drag_player) {
336
+ const preparedValue = Math.round(Math.abs(value));
337
+
338
+ gestureListenerHelper({
339
+ listenerValue: value,
340
+ preparedValue,
341
+ animationType,
342
+ animatedValue,
343
+ calculationData,
344
+ modalSnapPoint: modalSnapPoints[1],
345
+ startComponentsAnimationDistance,
346
+ startComponentsAnimation,
347
+ setStartComponentsAnimation,
348
+ getAnimationValue,
349
+ });
350
+ }
351
+ }
352
+ );
353
+
354
+ const dragListenerId = dragScrollY.addListener(({ value }) => {
355
+ if (
356
+ scrollPosition.current === 0 &&
357
+ playerAnimationState === PlayerAnimationStateEnum.drag_scroll
358
+ ) {
359
+ const preparedValue = Math.round(
360
+ Math.abs(value) - lastScrollYValue.current
361
+ );
362
+
363
+ gestureListenerHelper({
364
+ listenerValue: value,
365
+ preparedValue,
366
+ animationType,
367
+ animatedValue,
368
+ calculationData,
369
+ modalSnapPoint: modalSnapPoints[1],
370
+ startComponentsAnimationDistance,
371
+ startComponentsAnimation,
372
+ setStartComponentsAnimation,
373
+ getAnimationValue,
374
+ });
375
+ }
376
+ });
377
+
378
+ return () => {
379
+ dragScrollY.removeListener(dragListenerId);
380
+ dragVideoPlayerY.removeListener(dragVideoPlayerYListenerId);
381
+ };
382
+ }, [playerAnimationState, calculationData, startComponentsAnimation]);
383
+
384
+ const preparedStyles = Array.isArray(style) ? style : [style];
385
+
386
+ return (
387
+ <Animated.View
388
+ onLayout={additionalData.useLayoutMeasure && measureView}
389
+ ref={animationComponentRef}
390
+ style={[
391
+ ...preparedStyles,
392
+ (videoModalState.mode === "MAXIMIZED" ||
393
+ videoModalState.mode === "MINIMIZED" ||
394
+ (videoModalState.mode === "PIP" && isAppActive)) &&
395
+ getAnimationStyle(animationType, animatedValue),
396
+ ]}
397
+ >
398
+ {children}
399
+ </Animated.View>
400
+ );
401
+ };
402
+
403
+ export const AnimationComponent = (props: Props) => {
404
+ const { additionalData = {}, style } = props;
405
+
406
+ const {
407
+ videoModalState: { visible },
408
+ } = useNavigation();
409
+
410
+ const useAnimation =
411
+ visible && !additionalData.disableAnimatedComponent && !isTV();
412
+
413
+ const isReactFragment = !useAnimation && !style;
414
+
415
+ const Component = useAnimation
416
+ ? AnimationView
417
+ : style
418
+ ? View
419
+ : React.Fragment;
420
+
421
+ if (
422
+ additionalData.extraAnimation &&
423
+ typeof additionalData.extraAnimation === "object" &&
424
+ !Array.isArray(additionalData.extraAnimation) &&
425
+ !!Object.keys(additionalData.extraAnimation).length
426
+ ) {
427
+ const animationType = Object.keys(additionalData.extraAnimation)[0];
428
+ const animationProps = additionalData.extraAnimation[animationType] || {};
429
+ delete additionalData.extraAnimation[animationType];
430
+
431
+ return (
432
+ // @ts-ignore
433
+ <Component {...(isReactFragment ? null : props)}>
434
+ <AnimationComponent
435
+ {...animationProps}
436
+ animationType={animationType}
437
+ additionalData={{
438
+ ...animationProps.additionalData,
439
+ extraAnimation:
440
+ !!Object.keys(additionalData.extraAnimation).length &&
441
+ additionalData.extraAnimation,
442
+ }}
443
+ >
444
+ {props.children}
445
+ </AnimationComponent>
446
+ </Component>
447
+ );
448
+ }
449
+
450
+ if (isReactFragment) {
451
+ // @ts-ignore
452
+ return <Component>{props.children}</Component>;
453
+ }
454
+
455
+ return <Component {...props}>{props.children}</Component>;
456
+ };