@applicaster/quick-brick-player 13.0.0-rc.121 → 13.0.0-rc.122

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/quick-brick-player",
3
- "version": "13.0.0-rc.121",
3
+ "version": "13.0.0-rc.122",
4
4
  "description": "Quick Brick Player",
5
5
  "main": "./src/index.ts",
6
6
  "types": "index.d.ts",
@@ -37,9 +37,9 @@
37
37
  "dependencies": {
38
38
  "@applicaster/quick-brick-mobile-transport-controls": "13.0.0-rc.120",
39
39
  "@applicaster/quick-brick-tv-transport-controls": "13.0.0-rc.56",
40
- "@applicaster/zapp-react-native-tvos-app": "13.0.0-rc.121",
41
- "@applicaster/zapp-react-native-ui-components": "13.0.0-rc.121",
42
- "@applicaster/zapp-react-native-utils": "13.0.0-rc.121",
40
+ "@applicaster/zapp-react-native-tvos-app": "13.0.0-rc.122",
41
+ "@applicaster/zapp-react-native-ui-components": "13.0.0-rc.122",
42
+ "@applicaster/zapp-react-native-utils": "13.0.0-rc.122",
43
43
  "query-string": "7.1.3",
44
44
  "react-native-web-linear-gradient": "1.1.2",
45
45
  "shaka-player": "4.3.5",
@@ -8,6 +8,9 @@ import {
8
8
  DURATION_TO_MINIMIZE,
9
9
  DURATION_TO_MAXIMIZE,
10
10
  } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation";
11
+ import { PlayerAnimationStateT } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation/ModalAnimationContext";
12
+
13
+ import { useChangePlayerState } from "./hooks";
11
14
 
12
15
  const styles = StyleSheet.create({
13
16
  container: {
@@ -21,9 +24,10 @@ type Props = PropsWithChildren<{
21
24
  entry: ZappEntry;
22
25
  style?: ImageStyle | ImageStyle[];
23
26
  imageWidth: number;
27
+ docked: boolean;
24
28
  }>;
25
29
 
26
- export const AnimatedImage = ({ entry, style, imageWidth }: Props) => {
30
+ export const AnimatedImage = ({ entry, style, imageWidth, docked }: Props) => {
27
31
  const heightAnim = React.useRef(new Animated.Value(imageWidth)).current;
28
32
 
29
33
  const source = React.useMemo(
@@ -31,27 +35,40 @@ export const AnimatedImage = ({ entry, style, imageWidth }: Props) => {
31
35
  [entry]
32
36
  );
33
37
 
34
- const { playerAnimationState, minimisedHeight } = useModalAnimationContext();
38
+ const { minimisedHeight } = useModalAnimationContext();
39
+
40
+ const changePlayerState$ = useChangePlayerState({ docked });
35
41
 
36
42
  React.useEffect(() => {
37
- if (playerAnimationState === PlayerAnimationStateEnum.minimize) {
38
- Animated.timing(heightAnim, {
39
- toValue: minimisedHeight,
40
- duration: DURATION_TO_MINIMIZE,
41
- useNativeDriver: false, // width/height can't use native driver
42
- }).start();
43
+ const subscription = changePlayerState$.subscribe({
44
+ next: (nextPlayerState: PlayerAnimationStateT) => {
45
+ if (nextPlayerState === PlayerAnimationStateEnum.minimize) {
46
+ Animated.timing(heightAnim, {
47
+ toValue: minimisedHeight,
48
+ duration: DURATION_TO_MINIMIZE,
49
+ useNativeDriver: false, // width/height can't use native driver
50
+ }).start();
51
+ }
52
+
53
+ if (nextPlayerState === PlayerAnimationStateEnum.maximize) {
54
+ Animated.timing(heightAnim, {
55
+ toValue: imageWidth,
56
+ duration: DURATION_TO_MAXIMIZE,
57
+ useNativeDriver: false, // width/height can't use native driver
58
+ }).start();
59
+ }
43
60
 
44
- return;
45
- }
61
+ if (nextPlayerState === PlayerAnimationStateEnum.appear_as_docked) {
62
+ // minimize image immediatly
63
+ heightAnim.setValue(minimisedHeight);
64
+ }
65
+ },
66
+ });
46
67
 
47
- if (playerAnimationState === PlayerAnimationStateEnum.maximize) {
48
- Animated.timing(heightAnim, {
49
- toValue: imageWidth,
50
- duration: DURATION_TO_MAXIMIZE,
51
- useNativeDriver: false, // width/height can't use native driver
52
- }).start();
53
- }
54
- }, [playerAnimationState, imageWidth]);
68
+ return () => {
69
+ subscription.unsubscribe();
70
+ };
71
+ }, [changePlayerState$, minimisedHeight, imageWidth]);
55
72
 
56
73
  if (!source) return null;
57
74
 
@@ -0,0 +1 @@
1
+ export { useChangePlayerState } from "./useChangePlayerState";
@@ -0,0 +1,79 @@
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 emitMaximazed = (): 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
+ emitMaximazed,
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.emitMaximazed();
65
+
66
+ return;
67
+ }
68
+
69
+ if (
70
+ docked &&
71
+ isNil(previousPlayerAnimationState) &&
72
+ isNil(playerAnimationState)
73
+ ) {
74
+ changePlayerStateRef.current.emitAppearInDocked();
75
+ }
76
+ }, [previousPlayerAnimationState, playerAnimationState, docked]);
77
+
78
+ return changePlayerStateRef.current.changePlayerState$;
79
+ };
@@ -5,6 +5,7 @@ import {
5
5
  ComponentAnimationType,
6
6
  useModalAnimationContext,
7
7
  } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation";
8
+ import { noop } from "@applicaster/zapp-react-native-utils/functionUtils";
8
9
 
9
10
  import { AnimatedImage } from "./AnimatedImage";
10
11
  import { FlexImage } from "./FlexImage";
@@ -29,7 +30,7 @@ type Props = {
29
30
  docked: boolean;
30
31
  imageWidth?: Option<number>;
31
32
  verticalOffset: number;
32
- onLayoutImage: (event: LayoutChangeEvent) => void;
33
+ onLayoutImage?: (event: LayoutChangeEvent) => void;
33
34
  };
34
35
 
35
36
  export const PlayerImage = (props: Props) => {
@@ -40,7 +41,7 @@ export const PlayerImage = (props: Props) => {
40
41
  verticalOffset,
41
42
  imageWidth,
42
43
  configuration,
43
- onLayoutImage,
44
+ onLayoutImage = noop,
44
45
  } = props;
45
46
 
46
47
  const {
@@ -99,6 +100,7 @@ export const PlayerImage = (props: Props) => {
99
100
  entry={entry}
100
101
  style={[styles.backgroundImageContainer, { borderRadius }]}
101
102
  imageWidth={imageWidth}
103
+ docked={docked}
102
104
  />
103
105
  )}
104
106
  </View>