@applicaster/zapp-react-native-ui-components 12.0.0-alpha.4802689107 → 12.0.0-alpha.4945500007
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.
- package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +13 -6
- package/Components/GeneralContentScreen/utils/useCurationAPI.ts +1 -1
- package/Components/MasterCell/DefaultComponents/Image/Image.ios.tsx +5 -3
- package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +14 -1
- package/Components/MasterCell/DefaultComponents/__tests__/image.test.js +1 -1
- package/Components/MasterCell/utils/index.ts +16 -5
- package/Components/PlayerContainer/PlayerContainer.tsx +14 -2
- package/Components/PlayerImageBackground/index.tsx +34 -8
- package/Components/River/ComponentsMap/ComponentsMap.tsx +86 -22
- package/Components/River/__tests__/componentsMap.test.js +6 -0
- package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +4 -0
- package/Components/Screen/index.tsx +36 -25
- package/Components/VideoLive/__tests__/PlayerLiveImageComponent.test.tsx +20 -5
- package/Components/VideoLive/__tests__/__snapshots__/PlayerLiveImageComponent.test.tsx.snap +0 -5
- package/Components/VideoModal/ModalAnimation/AnimatedPlayerModalWrapper.tsx +78 -0
- package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.tsx +342 -0
- package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.tsx +151 -0
- package/Components/VideoModal/ModalAnimation/AnimationComponent.tsx +438 -0
- package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +143 -0
- package/Components/VideoModal/ModalAnimation/index.ts +15 -0
- package/Components/VideoModal/ModalAnimation/utils.ts +299 -0
- package/Components/VideoModal/PlayerWrapper.tsx +64 -41
- package/Components/VideoModal/VideoModal.tsx +8 -25
- package/Components/VideoModal/__tests__/PlayerWrapper.test.tsx +6 -1
- package/Components/VideoModal/__tests__/__snapshots__/PlayerWrapper.test.tsx.snap +151 -119
- package/Components/VideoModal/utils.ts +3 -3
- package/Components/Viewport/ViewportTracker/ViewportTracker.tsx +31 -40
- package/Components/Viewport/ViewportTracker/index.tsx +1 -0
- package/Components/Viewport/utils.js +1 -1
- package/Contexts/MenuToggleContext/{index.js → index.ts} +16 -0
- package/Contexts/ScreenContext/__tests__/__snapshots__/index.test.tsx.snap +3 -0
- package/Contexts/ScreenContext/__tests__/index.test.tsx +27 -0
- package/Contexts/ScreenContext/index.tsx +94 -25
- package/package.json +5 -5
- package/Components/VideoModal/hooks/usePosition.ts +0 -50
- /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,143 @@
|
|
|
1
|
+
import React, { useContext } from "react";
|
|
2
|
+
import { Animated } from "react-native";
|
|
3
|
+
|
|
4
|
+
import { useSafeAreaFrame } from "react-native-safe-area-context";
|
|
5
|
+
import { useGetBottomTabBarHeight } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
6
|
+
|
|
7
|
+
import { useConfiguration } from "../utils";
|
|
8
|
+
|
|
9
|
+
export enum PlayerAnimationStateEnum {
|
|
10
|
+
minimize = "minimize",
|
|
11
|
+
maximaze = "maximaze",
|
|
12
|
+
drag_player = "drag_player",
|
|
13
|
+
drag_scroll = "drag_scroll",
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type PlayerAnimationStateT = number | PlayerAnimationStateEnum | null;
|
|
17
|
+
|
|
18
|
+
export type ModalAnimationContextT = {
|
|
19
|
+
isActiveGesture: boolean;
|
|
20
|
+
playerAnimationState: PlayerAnimationStateT;
|
|
21
|
+
setPlayerAnimationState: (value: PlayerAnimationStateT) => void;
|
|
22
|
+
startComponentsAnimation: boolean;
|
|
23
|
+
setStartComponentsAnimation: (value: boolean) => void;
|
|
24
|
+
resetPlayerAnimationState: () => void;
|
|
25
|
+
minimisedHeight: number;
|
|
26
|
+
animatedValues: {
|
|
27
|
+
lastScrollY: Animated.Value;
|
|
28
|
+
dragScrollY: Animated.Value;
|
|
29
|
+
dragVideoPlayerY: Animated.Value;
|
|
30
|
+
translateYOffset: Animated.Value;
|
|
31
|
+
};
|
|
32
|
+
lastScrollYValue: React.MutableRefObject<number>;
|
|
33
|
+
scrollPosition: React.MutableRefObject<number>;
|
|
34
|
+
modalSnapPoints: number[];
|
|
35
|
+
lastSnap: number;
|
|
36
|
+
setLastSnap: (value: number) => void;
|
|
37
|
+
tabletLandscapePlayerTopPosition: number;
|
|
38
|
+
setTabletLandscapePlayerTopPosition: (value: number) => void;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const ReactContext = React.createContext<ModalAnimationContextT>({
|
|
42
|
+
isActiveGesture: false,
|
|
43
|
+
playerAnimationState: null,
|
|
44
|
+
setPlayerAnimationState: () => null,
|
|
45
|
+
startComponentsAnimation: false,
|
|
46
|
+
setStartComponentsAnimation: () => null,
|
|
47
|
+
resetPlayerAnimationState: () => null,
|
|
48
|
+
minimisedHeight: 60,
|
|
49
|
+
animatedValues: {
|
|
50
|
+
lastScrollY: new Animated.Value(0),
|
|
51
|
+
dragScrollY: new Animated.Value(0),
|
|
52
|
+
dragVideoPlayerY: new Animated.Value(0),
|
|
53
|
+
translateYOffset: new Animated.Value(0),
|
|
54
|
+
},
|
|
55
|
+
lastScrollYValue: null,
|
|
56
|
+
scrollPosition: null,
|
|
57
|
+
modalSnapPoints: [0, 0],
|
|
58
|
+
lastSnap: 0,
|
|
59
|
+
setLastSnap: () => null,
|
|
60
|
+
tabletLandscapePlayerTopPosition: 0,
|
|
61
|
+
setTabletLandscapePlayerTopPosition: () => null,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export function useModalAnimationContext() {
|
|
65
|
+
return useContext<ModalAnimationContextT>(ReactContext);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const Provider = ({ children }: { children: React.ReactNode }) => {
|
|
69
|
+
const [playerAnimationState, setPlayerAnimationState] =
|
|
70
|
+
React.useState<PlayerAnimationStateT>(null);
|
|
71
|
+
|
|
72
|
+
const [
|
|
73
|
+
tabletLandscapePlayerTopPosition,
|
|
74
|
+
setTabletLandscapePlayerTopPosition,
|
|
75
|
+
] = React.useState<number>(0);
|
|
76
|
+
|
|
77
|
+
const [startComponentsAnimation, setStartComponentsAnimation] =
|
|
78
|
+
React.useState<boolean>(false);
|
|
79
|
+
|
|
80
|
+
const { minimised_height: minimisedHeight } = useConfiguration();
|
|
81
|
+
|
|
82
|
+
const resetPlayerAnimationState = React.useCallback(() => {
|
|
83
|
+
setPlayerAnimationState(null);
|
|
84
|
+
setStartComponentsAnimation(false);
|
|
85
|
+
}, []);
|
|
86
|
+
|
|
87
|
+
// Animated values
|
|
88
|
+
const lastScrollY = React.useRef(new Animated.Value(0)).current;
|
|
89
|
+
const dragScrollY = React.useRef(new Animated.Value(0)).current;
|
|
90
|
+
const translateYOffset = React.useRef(new Animated.Value(0)).current;
|
|
91
|
+
const dragVideoPlayerY = React.useRef(new Animated.Value(0)).current;
|
|
92
|
+
|
|
93
|
+
const { height } = useSafeAreaFrame();
|
|
94
|
+
const bottomTabBarHeight = useGetBottomTabBarHeight();
|
|
95
|
+
const minValue = height - minimisedHeight - bottomTabBarHeight;
|
|
96
|
+
const modalSnapPoints = React.useMemo(() => [0, minValue], [minValue]);
|
|
97
|
+
// Last snap state which will helps us to make smooth responder to scrollview animation
|
|
98
|
+
const [lastSnap, setLastSnap] = React.useState<number>(modalSnapPoints[0]);
|
|
99
|
+
// Extracted animated values which we will use for calculations
|
|
100
|
+
const lastScrollYValue = React.useRef<number>(0);
|
|
101
|
+
const scrollPosition = React.useRef<number>(0);
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<ReactContext.Provider
|
|
105
|
+
value={{
|
|
106
|
+
startComponentsAnimation,
|
|
107
|
+
setStartComponentsAnimation,
|
|
108
|
+
isActiveGesture: playerAnimationState !== null,
|
|
109
|
+
playerAnimationState,
|
|
110
|
+
setPlayerAnimationState,
|
|
111
|
+
resetPlayerAnimationState,
|
|
112
|
+
minimisedHeight,
|
|
113
|
+
animatedValues: {
|
|
114
|
+
lastScrollY,
|
|
115
|
+
dragScrollY,
|
|
116
|
+
dragVideoPlayerY,
|
|
117
|
+
translateYOffset,
|
|
118
|
+
},
|
|
119
|
+
lastScrollYValue,
|
|
120
|
+
scrollPosition,
|
|
121
|
+
modalSnapPoints,
|
|
122
|
+
lastSnap,
|
|
123
|
+
setLastSnap,
|
|
124
|
+
tabletLandscapePlayerTopPosition,
|
|
125
|
+
setTabletLandscapePlayerTopPosition,
|
|
126
|
+
}}
|
|
127
|
+
>
|
|
128
|
+
{children}
|
|
129
|
+
</ReactContext.Provider>
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export const withModalAnimationProvider = (Component) => {
|
|
134
|
+
const WithProvider = (props) => {
|
|
135
|
+
return (
|
|
136
|
+
<Provider>
|
|
137
|
+
<Component {...props} />
|
|
138
|
+
</Provider>
|
|
139
|
+
);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
return WithProvider;
|
|
143
|
+
};
|
|
@@ -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";
|