@applicaster/zapp-react-native-ui-components 12.0.0-rc.7 → 12.0.0-rc.71

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