@applicaster/quick-brick-player 15.0.0-rc.4 → 15.0.0-rc.41

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/package.json +6 -6
  2. package/src/Player/AudioLayer/AudioPlayerWrapper.tsx +20 -8
  3. package/src/Player/AudioLayer/Layout/DockedControls/index.tsx +71 -63
  4. package/src/Player/AudioLayer/Layout/MobileLayout.tsx +1 -6
  5. package/src/Player/AudioLayer/Layout/PlayerImage/index.tsx +27 -25
  6. package/src/Player/AudioLayer/Layout/PlayerImage/styles.ts +6 -1
  7. package/src/Player/AudioLayer/Layout/TabletLandscapeLayout.tsx +5 -8
  8. package/src/Player/AudioLayer/Layout/TabletPortraitLayout.tsx +1 -6
  9. package/src/Player/AudioLayer/utils.ts +1 -27
  10. package/src/Player/PlayerModal/PlayerModal.tsx +16 -15
  11. package/src/Player/PlayerModal/VideoPlayerModal.tsx +138 -120
  12. package/src/Player/PlayerModal/consts/index.ts +2 -19
  13. package/src/Player/PlayerModal/hooks/index.ts +117 -141
  14. package/src/Player/PlayerModal/styles.ts +5 -0
  15. package/src/Player/PlayerModal/utils/index.ts +111 -0
  16. package/src/Player/PlayerView/types.ts +1 -2
  17. package/src/Player/hooks/progressStates/__tests__/utils.test.ts +23 -0
  18. package/src/Player/hooks/progressStates/useLiveProgressState.tsx +78 -0
  19. package/src/Player/hooks/progressStates/useProgressState.tsx +30 -0
  20. package/src/Player/hooks/progressStates/useVodProgressState.tsx +115 -0
  21. package/src/Player/hooks/progressStates/utils.ts +33 -0
  22. package/src/Player/index.tsx +559 -357
  23. package/src/utils/dimensions.ts +29 -0
  24. package/src/utils/index.ts +12 -0
  25. package/src/utils/logger.ts +6 -0
  26. package/src/utils/playerHelpers.ts +11 -0
  27. package/src/utils/playerStyles.ts +50 -0
  28. package/src/Player/AudioLayer/Layout/PlayerImage/AnimatedImage.tsx +0 -82
  29. package/src/Player/AudioLayer/Layout/PlayerImage/hooks/index.ts +0 -1
  30. package/src/Player/AudioLayer/Layout/PlayerImage/hooks/useChangePlayerState.ts +0 -99
@@ -0,0 +1,29 @@
1
+ import { Dimensions } from "react-native";
2
+
3
+ export const getWindowDimensions = () => {
4
+ const { width, height } = Dimensions.get("window");
5
+
6
+ return { width, height };
7
+ };
8
+
9
+ export const getMaxWindowDimension = () => {
10
+ const { width, height } = getWindowDimensions();
11
+
12
+ return Math.max(width, height);
13
+ };
14
+
15
+ export const getMinWindowDimension = () => {
16
+ const { width, height } = getWindowDimensions();
17
+
18
+ return Math.min(width, height);
19
+ };
20
+
21
+ /**
22
+ * Calculates the screen aspect ratio (long edge / short edge)
23
+ */
24
+ export const getScreenAspectRatio = () => {
25
+ const longEdge = getMaxWindowDimension();
26
+ const shortEdge = getMinWindowDimension();
27
+
28
+ return longEdge / shortEdge;
29
+ };
@@ -0,0 +1,12 @@
1
+ export * as const from "./const";
2
+
3
+ export * from "./dimensions";
4
+
5
+ export * from "./playerHelpers";
6
+
7
+ export * from "./playerStyles";
8
+
9
+ /**
10
+ * Logger instance for the player
11
+ */
12
+ export { logger } from "./logger";
@@ -0,0 +1,6 @@
1
+ import { Categories, createLogger, Subsystem } from "../logger";
2
+
3
+ export const logger = createLogger({
4
+ category: Categories.PLAYER,
5
+ subsystem: Subsystem,
6
+ });
@@ -0,0 +1,11 @@
1
+ import { logger } from "./logger";
2
+
3
+ export const createUnhandledEventHandler = (eventName: string) => {
4
+ return function dispatchUnhandledEvent({ nativeEvent = null }) {
5
+ logger.warning({
6
+ message:
7
+ "You have invoked an event that is being deprecated or unhandled",
8
+ data: { eventName, nativeEvent },
9
+ });
10
+ };
11
+ };
@@ -0,0 +1,50 @@
1
+ import { ViewStyle } from "react-native";
2
+ import {
3
+ isApplePlatform,
4
+ isTV,
5
+ isAndroidPlatform,
6
+ } from "@applicaster/zapp-react-native-utils/reactUtils";
7
+
8
+ export const PLAYER_CONTAINER_STYLES = {
9
+ playerContainerBlack: { backgroundColor: "#000000" },
10
+ playerContainerTransparent: { backgroundColor: "transparent" },
11
+ audio: {
12
+ overflow: "hidden" as const,
13
+ position: "absolute" as const,
14
+ zIndex: 1,
15
+ },
16
+ } as const;
17
+
18
+ export const getPlayerContainerStyles = (
19
+ isAudioItem: boolean,
20
+ styles: typeof PLAYER_CONTAINER_STYLES
21
+ ) => {
22
+ return isApplePlatform()
23
+ ? styles.playerContainerBlack
24
+ : isTV() && isAudioItem
25
+ ? styles.playerContainerTransparent
26
+ : styles.playerContainerBlack;
27
+ };
28
+
29
+ export const getBackgroundImageStyle = (
30
+ dimensions: any,
31
+ isAudioItem: boolean,
32
+ styles: typeof PLAYER_CONTAINER_STYLES
33
+ ): ViewStyle => ({
34
+ ...(isAudioItem ? styles.audio : { position: "absolute" }),
35
+ ...dimensions,
36
+ });
37
+
38
+ export const getPlayerViewStyle = (
39
+ dimensions: ViewStyle,
40
+ isAudioItem: boolean,
41
+ styles: typeof PLAYER_CONTAINER_STYLES
42
+ ): ViewStyle => {
43
+ const generalStyles = isAudioItem ? styles.audio : {};
44
+
45
+ if (isAndroidPlatform() && isAudioItem) {
46
+ return generalStyles;
47
+ }
48
+
49
+ return { ...generalStyles, ...dimensions };
50
+ };
@@ -1,82 +0,0 @@
1
- import React, { PropsWithChildren } from "react";
2
- import { Image, Animated, StyleSheet, ImageStyle } from "react-native";
3
-
4
- import {
5
- useModalAnimationContext,
6
- PlayerAnimationStateEnum,
7
- DURATION_TO_MINIMIZE,
8
- DURATION_TO_MAXIMIZE,
9
- } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation";
10
- import { PlayerAnimationStateT } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation/ModalAnimationContext";
11
- import { useBackgroundImage } from "@applicaster/zapp-react-native-utils/audioPlayerUtils";
12
-
13
- import { useChangePlayerState } from "./hooks";
14
-
15
- const styles = StyleSheet.create({
16
- container: {
17
- // we have to specify flex:0 and dimensions to make animation work
18
- flex: 0,
19
- aspectRatio: 1,
20
- },
21
- });
22
-
23
- type Props = PropsWithChildren<{
24
- entry: ZappEntry;
25
- style?: ImageStyle | ImageStyle[];
26
- imageWidth: number;
27
- docked: boolean;
28
- }>;
29
-
30
- export const AnimatedImage = ({ entry, style, imageWidth, docked }: Props) => {
31
- const heightAnim = React.useRef(new Animated.Value(imageWidth)).current;
32
-
33
- const backgroundImageSource = useBackgroundImage(entry);
34
-
35
- const { minimisedHeight } = useModalAnimationContext();
36
-
37
- const changePlayerState$ = useChangePlayerState({ docked });
38
-
39
- React.useEffect(() => {
40
- const subscription = changePlayerState$.subscribe({
41
- next: (nextPlayerState: PlayerAnimationStateT) => {
42
- if (nextPlayerState === PlayerAnimationStateEnum.minimize) {
43
- Animated.timing(heightAnim, {
44
- toValue: minimisedHeight,
45
- duration: DURATION_TO_MINIMIZE,
46
- useNativeDriver: false, // width/height can't use native driver
47
- }).start();
48
- }
49
-
50
- if (nextPlayerState === PlayerAnimationStateEnum.maximize) {
51
- Animated.timing(heightAnim, {
52
- toValue: imageWidth,
53
- duration: DURATION_TO_MAXIMIZE,
54
- useNativeDriver: false, // width/height can't use native driver
55
- }).start();
56
- }
57
-
58
- if (nextPlayerState === PlayerAnimationStateEnum.appear_as_docked) {
59
- // minimize image immediatly
60
- heightAnim.setValue(minimisedHeight);
61
- }
62
- },
63
- });
64
-
65
- return () => {
66
- subscription.unsubscribe();
67
- };
68
- }, [changePlayerState$, minimisedHeight, imageWidth]);
69
-
70
- return (
71
- <Animated.View
72
- style={[
73
- styles.container,
74
- {
75
- width: heightAnim,
76
- },
77
- ]}
78
- >
79
- <Image resizeMode="cover" style={style} source={backgroundImageSource} />
80
- </Animated.View>
81
- );
82
- };
@@ -1 +0,0 @@
1
- export { useChangePlayerState } from "./useChangePlayerState";
@@ -1,99 +0,0 @@
1
- import * as React from "react";
2
- import { Subject, Observable } from "rxjs";
3
-
4
- import { distinctUntilChanged } from "rxjs/operators";
5
- import { isNil } from "@applicaster/zapp-react-native-utils/utils";
6
- import { useRefWithInitialValue } from "@applicaster/zapp-react-native-utils/reactHooks/state/useRefWithInitialValue";
7
- import { usePrevious } from "@applicaster/zapp-react-native-utils/reactHooks/utils";
8
- import {
9
- useModalAnimationContext,
10
- PlayerAnimationStateEnum,
11
- } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation";
12
- import { PlayerAnimationStateT } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation/ModalAnimationContext";
13
-
14
- const builder = () => {
15
- const changePlayerState$ = new Subject<PlayerAnimationStateT>();
16
-
17
- const emitMaximized = (): void => {
18
- changePlayerState$.next(PlayerAnimationStateEnum.maximize);
19
- };
20
-
21
- const emitMinimized = (): void => {
22
- changePlayerState$.next(PlayerAnimationStateEnum.minimize);
23
- };
24
-
25
- const emitAppearInDocked = (): void => {
26
- // if audio_player was presented in docked mode
27
- changePlayerState$.next(PlayerAnimationStateEnum.appear_as_docked);
28
- };
29
-
30
- return {
31
- emitMaximized,
32
- emitMinimized,
33
- emitAppearInDocked,
34
- changePlayerState$: changePlayerState$.pipe(distinctUntilChanged()),
35
- };
36
- };
37
-
38
- export const useChangePlayerState = ({
39
- docked,
40
- }): Observable<PlayerAnimationStateT> => {
41
- const changePlayerStateRef =
42
- useRefWithInitialValue<ReturnType<typeof builder>>(builder);
43
-
44
- const { playerAnimationState } = useModalAnimationContext();
45
-
46
- const previousPlayerAnimationState = usePrevious(playerAnimationState);
47
-
48
- React.useEffect(() => {
49
- if (
50
- !docked &&
51
- isNil(previousPlayerAnimationState) &&
52
- playerAnimationState === PlayerAnimationStateEnum.minimize
53
- ) {
54
- changePlayerStateRef.current.emitMinimized();
55
-
56
- return;
57
- }
58
-
59
- if (
60
- !docked &&
61
- isNil(previousPlayerAnimationState) &&
62
- playerAnimationState === PlayerAnimationStateEnum.maximize
63
- ) {
64
- changePlayerStateRef.current.emitMaximized();
65
-
66
- return;
67
- }
68
-
69
- if (
70
- !docked &&
71
- previousPlayerAnimationState === PlayerAnimationStateEnum.drag_scroll &&
72
- playerAnimationState === PlayerAnimationStateEnum.maximize
73
- ) {
74
- changePlayerStateRef.current.emitMaximized();
75
-
76
- return;
77
- }
78
-
79
- if (
80
- !docked &&
81
- previousPlayerAnimationState === PlayerAnimationStateEnum.drag_scroll &&
82
- playerAnimationState === PlayerAnimationStateEnum.minimize
83
- ) {
84
- changePlayerStateRef.current.emitMinimized();
85
-
86
- return;
87
- }
88
-
89
- if (
90
- docked &&
91
- isNil(previousPlayerAnimationState) &&
92
- isNil(playerAnimationState)
93
- ) {
94
- changePlayerStateRef.current.emitAppearInDocked();
95
- }
96
- }, [previousPlayerAnimationState, playerAnimationState, docked]);
97
-
98
- return changePlayerStateRef.current.changePlayerState$;
99
- };