@applicaster/zapp-react-native-ui-components 15.0.0-rc.3 → 15.0.0-rc.30

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 (35) hide show
  1. package/Components/AnimatedInOut/index.tsx +69 -26
  2. package/Components/Cell/FocusableWrapper.tsx +44 -0
  3. package/Components/Cell/TvOSCellComponent.tsx +80 -14
  4. package/Components/GeneralContentScreen/utils/useCurationAPI.ts +9 -11
  5. package/Components/HandlePlayable/HandlePlayable.tsx +14 -65
  6. package/Components/HandlePlayable/const.ts +3 -0
  7. package/Components/HandlePlayable/utils.ts +74 -0
  8. package/Components/PlayerContainer/PlayerContainer.tsx +1 -16
  9. package/Components/PlayerImageBackground/index.tsx +3 -22
  10. package/Components/Screen/TV/hooks/useInitialFocus.ts +14 -4
  11. package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +2 -0
  12. package/Components/Screen/index.tsx +22 -5
  13. package/Components/ScreenResolver/index.tsx +8 -2
  14. package/Components/ScreenRevealManager/utils/index.ts +23 -0
  15. package/Components/ScreenRevealManager/withScreenRevealManager.tsx +54 -24
  16. package/Components/VideoLive/__tests__/__snapshots__/PlayerLiveImageComponent.test.tsx.snap +1 -0
  17. package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +3 -153
  18. package/Components/VideoModal/ModalAnimation/index.ts +2 -13
  19. package/Components/VideoModal/ModalAnimation/utils.ts +1 -327
  20. package/Components/VideoModal/PlayerWrapper.tsx +14 -88
  21. package/Components/VideoModal/__tests__/PlayerWrapper.test.tsx +1 -0
  22. package/Components/VideoModal/hooks/useModalSize.ts +10 -5
  23. package/Components/VideoModal/playerWrapperStyle.ts +70 -0
  24. package/Components/VideoModal/playerWrapperUtils.ts +91 -0
  25. package/Components/ZappFrameworkComponents/BarView/BarView.tsx +4 -6
  26. package/Components/ZappFrameworkComponents/BarView/__tests__/BarView.test.tsx +2 -2
  27. package/Decorators/RiverFeedLoader/utils/getDatasourceUrl.ts +6 -10
  28. package/package.json +5 -5
  29. package/Components/VideoModal/ModalAnimation/AnimatedPlayerModalWrapper.tsx +0 -60
  30. package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.tsx +0 -417
  31. package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.web.tsx +0 -294
  32. package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.tsx +0 -176
  33. package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.web.tsx +0 -93
  34. package/Components/VideoModal/ModalAnimation/AnimationComponent.tsx +0 -500
  35. package/Components/VideoModal/ModalAnimation/__tests__/getMoveUpValue.test.ts +0 -108
@@ -1,6 +1,6 @@
1
1
  /// <reference types="@applicaster/applicaster-types" />
2
2
  import React from "react";
3
- import { View } from "react-native";
3
+ import { AccessibilityInfo, findNodeHandle, View } from "react-native";
4
4
  import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
5
5
 
6
6
  import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
@@ -12,6 +12,7 @@ import {
12
12
  } from "@applicaster/zapp-react-native-utils/navigationUtils";
13
13
  import {
14
14
  useCurrentScreenData,
15
+ useIsScreenActive,
15
16
  useNavbarState,
16
17
  useNavigation,
17
18
  useRoute,
@@ -57,8 +58,8 @@ export function Screen(_props: Props) {
57
58
  const hasMenu = shouldNavBarDisplayMenu(currentRiver, plugins);
58
59
 
59
60
  const navBarProps = React.useMemo<MobileNavBarPluginProps | null>(
60
- getNavBarProps(currentRiver, pathname, title),
61
- [currentRiver, pathname]
61
+ () => getNavBarProps(currentRiver, pathname, title),
62
+ [currentRiver, pathname, title]
62
63
  );
63
64
 
64
65
  const NavBar = React.useMemo(
@@ -89,13 +90,29 @@ export function Screen(_props: Props) {
89
90
  [theme.app_background_color, backgroundColor]
90
91
  );
91
92
 
92
- // Set ready state when screen is rotated to desired orientation
93
+ const isActive = useIsScreenActive();
94
+
95
+ const ref = React.useRef(null);
93
96
  const isReady = useWaitForValidOrientation();
94
97
 
98
+ React.useEffect(() => {
99
+ if (ref.current && isActive && isReady) {
100
+ const nodeHandle = findNodeHandle(ref.current);
101
+
102
+ if (nodeHandle != null) {
103
+ AccessibilityInfo.setAccessibilityFocus(nodeHandle);
104
+ }
105
+ }
106
+ }, [isActive, isReady]);
107
+
95
108
  // We prevent rendering of the screen until UI is actually rotated to screen desired orientation.
96
109
  // This saves unnecessary re-renders and user will not see distorted aspect screen.
97
110
  return (
98
- <View style={style}>
111
+ <View
112
+ ref={ref}
113
+ style={style}
114
+ importantForAccessibility={!isActive ? "no-hide-descendants" : "yes"}
115
+ >
99
116
  {isReady ? (
100
117
  <>
101
118
  {navBarProps ? <NavBar {...navBarProps} hasMenu={hasMenu} /> : null}
@@ -16,6 +16,7 @@ import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
16
16
  import { useScreenAnalytics } from "@applicaster/zapp-react-native-utils/analyticsUtils/helpers/hooks";
17
17
 
18
18
  import { useCallbackActions } from "@applicaster/zapp-react-native-utils/zappFrameworkUtils/HookCallback/useCallbackActions";
19
+ import { ScreenResultCallback } from "@applicaster/zapp-react-native-utils/zappFrameworkUtils/HookCallback/callbackNavigationAction";
19
20
 
20
21
  const logger = componentsLogger.addSubsystem("ScreenResolver");
21
22
 
@@ -26,6 +27,7 @@ type Props = {
26
27
  feedId?: string;
27
28
  feedTitle?: string;
28
29
  focused?: boolean;
30
+ resultCallback?: ScreenResultCallback;
29
31
  parentFocus?: {
30
32
  nextFocusDown?: React.Ref<any>;
31
33
  nextFocusRight?: React.Ref<any>;
@@ -61,13 +63,17 @@ export function ScreenResolverComponent(props: Props) {
61
63
 
62
64
  React.useEffect(() => {
63
65
  setScreenContext(rivers[screenId]);
64
- }, [screenId]);
66
+ }, [rivers, screenId, setScreenContext]);
65
67
 
66
- const callbackAction = useCallbackActions(
68
+ const parentCallback = props.resultCallback;
69
+
70
+ const screenAction = useCallbackActions(
67
71
  hookPlugin || screenData,
68
72
  screenData.callback
69
73
  );
70
74
 
75
+ const callbackAction = parentCallback || screenAction;
76
+
71
77
  const ScreenPlugin =
72
78
  findPluginByType(screenType, plugins, { skipWarning: true }) ||
73
79
  findPluginByIdentifier(screenType, plugins) ||
@@ -0,0 +1,23 @@
1
+ import { ReplaySubject } from "rxjs";
2
+ import { pairwise, filter, first } from "rxjs/operators";
3
+
4
+ // we are interested in last 2 events, because we wait transition from <false> to <true>
5
+ const screenRevealManagerSubject$ = new ReplaySubject<boolean>(2);
6
+
7
+ export const emitScreenRevealManagerIsReadyToShow = () => {
8
+ screenRevealManagerSubject$.next(true);
9
+ };
10
+
11
+ export const emitScreenRevealManagerIsNotReadyToShow = () => {
12
+ screenRevealManagerSubject$.next(false);
13
+ };
14
+
15
+ export const waitUntilScreenRevealManagerIsReady = () => {
16
+ return screenRevealManagerSubject$.pipe(
17
+ pairwise(), // emit consecutive pairs: [prev, curr]
18
+ filter(
19
+ ([previousIsReady, currentIsReady]) => !previousIsReady && currentIsReady
20
+ ), // detect transition from not_ready to ready
21
+ first()
22
+ );
23
+ };
@@ -1,21 +1,23 @@
1
1
  import * as React from "react";
2
- import { Animated } from "react-native";
2
+ import { Animated, StyleSheet } from "react-native";
3
3
  import { isFirstComponentScreenPicker } from "@applicaster/zapp-react-native-utils/componentsUtils";
4
- import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
5
4
  import { useRefWithInitialValue } from "@applicaster/zapp-react-native-utils/reactHooks/state/useRefWithInitialValue";
5
+ import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
6
6
 
7
7
  import { ScreenRevealManager } from "./ScreenRevealManager";
8
+ import {
9
+ emitScreenRevealManagerIsReadyToShow,
10
+ emitScreenRevealManagerIsNotReadyToShow,
11
+ } from "./utils";
8
12
 
9
- const flex = platformSelect({
10
- tvos: 1,
11
- android_tv: 1,
12
- web: undefined,
13
- samsung_tv: undefined,
14
- lg_tv: undefined,
15
- default: undefined,
13
+ const styles = StyleSheet.create({
14
+ container: {
15
+ ...StyleSheet.absoluteFillObject,
16
+ position: "absolute",
17
+ },
16
18
  });
17
19
 
18
- export const TIMEOUT = 500; // 500 ms
20
+ export const TIMEOUT = 300; // 300 ms
19
21
 
20
22
  const HIDDEN = 0; // opacity = 0
21
23
 
@@ -29,29 +31,48 @@ export const withScreenRevealManager = (Component) => {
29
31
  return function WithScreenRevealManager(props: Props) {
30
32
  const { componentsToRender } = props;
31
33
 
32
- const [isReadyToShow, setIsReadyToShow] = React.useState(false);
34
+ const [isContentReadyToBeShown, setIsContentReadyToBeShown] =
35
+ React.useState(false);
33
36
 
34
- const handleSetIsReadyToShow = React.useCallback(() => {
35
- setIsReadyToShow(true);
37
+ const [isShowOverlay, setIsShowOverlay] = React.useState(true);
38
+
39
+ const theme = useTheme<BaseThemePropertiesTV>();
40
+
41
+ const handleSetIsContentReadyToBeShown = React.useCallback(() => {
42
+ setIsContentReadyToBeShown(true);
36
43
  }, []);
37
44
 
38
45
  const managerRef = useRefWithInitialValue<ScreenRevealManager>(
39
- () => new ScreenRevealManager(componentsToRender, handleSetIsReadyToShow)
46
+ () =>
47
+ new ScreenRevealManager(
48
+ componentsToRender,
49
+ handleSetIsContentReadyToBeShown
50
+ )
40
51
  );
41
52
 
42
53
  const opacityRef = useRefWithInitialValue<Animated.Value>(
43
- () => new Animated.Value(HIDDEN)
54
+ () => new Animated.Value(SHOWN)
44
55
  );
45
56
 
46
57
  React.useEffect(() => {
47
- if (isReadyToShow) {
58
+ if (!isContentReadyToBeShown) {
59
+ emitScreenRevealManagerIsNotReadyToShow();
60
+ } else {
61
+ emitScreenRevealManagerIsReadyToShow();
62
+ }
63
+ }, [isContentReadyToBeShown]);
64
+
65
+ React.useEffect(() => {
66
+ if (isContentReadyToBeShown) {
48
67
  Animated.timing(opacityRef.current, {
49
- toValue: SHOWN,
68
+ toValue: HIDDEN,
50
69
  duration: TIMEOUT,
51
70
  useNativeDriver: true,
52
- }).start();
71
+ }).start(() => {
72
+ setIsShowOverlay(false);
73
+ });
53
74
  }
54
- }, [isReadyToShow]);
75
+ }, [isContentReadyToBeShown]);
55
76
 
56
77
  if (isFirstComponentScreenPicker(componentsToRender)) {
57
78
  // for screen-picker with have additional internal ComponentsMap, no need to add this wrapper
@@ -59,10 +80,7 @@ export const withScreenRevealManager = (Component) => {
59
80
  }
60
81
 
61
82
  return (
62
- <Animated.View
63
- style={{ opacity: opacityRef.current, flex }}
64
- testID="animated-component"
65
- >
83
+ <>
66
84
  <Component
67
85
  {...props}
68
86
  initialNumberToLoad={
@@ -73,7 +91,19 @@ export const withScreenRevealManager = (Component) => {
73
91
  }
74
92
  onLoadFailedFromScreenRevealManager={managerRef.current.onLoadFailed}
75
93
  />
76
- </Animated.View>
94
+ {isShowOverlay ? (
95
+ <Animated.View
96
+ style={[
97
+ styles.container,
98
+ {
99
+ opacity: opacityRef.current,
100
+ backgroundColor: theme.app_background_color,
101
+ },
102
+ ]}
103
+ testID="animated-component"
104
+ />
105
+ ) : null}
106
+ </>
77
107
  );
78
108
  };
79
109
  };
@@ -9,6 +9,7 @@ exports[`PlayerLiveImageComponent should render correctly with default props 1`]
9
9
  <View>
10
10
  <View
11
11
  collapsable={false}
12
+ renderToHardwareTextureAndroid={false}
12
13
  style={
13
14
  {
14
15
  "opacity": 1,
@@ -1,78 +1,19 @@
1
1
  import React, { useEffect, useMemo } from "react";
2
2
  import { Animated, Dimensions } from "react-native";
3
3
 
4
- import {
5
- useSafeAreaInsets,
6
- useSafeAreaFrame,
7
- } from "react-native-safe-area-context";
8
- import { useGetBottomTabBarHeight } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useGetBottomTabBarHeight";
9
4
  import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation";
10
- import { isLive } from "@applicaster/zapp-react-native-utils/playerUtils";
11
5
 
12
- import { PROGRESS_BAR_HEIGHT } from "./utils";
13
6
  import { useConfiguration } from "../utils";
14
7
  import { useIsTabletLandscape } from "@applicaster/zapp-react-native-utils/reactHooks/device/useMemoizedIsTablet";
15
8
 
16
- export enum PlayerAnimationStateEnum {
17
- minimize = "minimize",
18
- maximize = "maximize",
19
- drag_player = "drag_player",
20
- drag_scroll = "drag_scroll",
21
- appear_as_docked = "appear_as_docked",
22
- }
23
-
24
- export type PlayerAnimationStateT = number | PlayerAnimationStateEnum | null;
25
-
26
9
  export type ModalAnimationContextT = {
27
10
  yTranslate: React.MutableRefObject<Animated.Value | null>;
28
- isActiveGesture: boolean;
29
- playerAnimationState: PlayerAnimationStateT;
30
- setPlayerAnimationState: (value: PlayerAnimationStateT) => void;
31
- startComponentsAnimation: boolean;
32
- setStartComponentsAnimation: (value: boolean) => void;
33
- resetPlayerAnimationState: () => void;
34
11
  minimisedHeight: number;
35
- animatedValues: {
36
- lastScrollY: Animated.Value;
37
- dragScrollY: Animated.Value;
38
- dragVideoPlayerY: Animated.Value;
39
- translateYOffset: Animated.Value;
40
- };
41
- lastScrollYValue: React.MutableRefObject<number>;
42
- scrollPosition: React.MutableRefObject<number>;
43
- modalSnapPoints: number[];
44
- lastSnap: number;
45
- setLastSnap: (value: number) => void;
46
- tabletLandscapePlayerTopPosition: number;
47
- setTabletLandscapePlayerTopPosition: (value: number) => void;
48
- startComponentsAnimationDistance: number;
49
- progressBarHeight: number;
50
12
  };
51
13
 
52
14
  export const ReactContext = React.createContext<ModalAnimationContextT>({
53
15
  yTranslate: React.createRef<Animated.Value | null>(),
54
- isActiveGesture: false,
55
- playerAnimationState: null,
56
- setPlayerAnimationState: () => null,
57
- startComponentsAnimation: false,
58
- setStartComponentsAnimation: () => null,
59
- resetPlayerAnimationState: () => null,
60
16
  minimisedHeight: 60,
61
- animatedValues: {
62
- lastScrollY: new Animated.Value(0),
63
- dragScrollY: new Animated.Value(0),
64
- dragVideoPlayerY: new Animated.Value(0),
65
- translateYOffset: new Animated.Value(0),
66
- },
67
- lastScrollYValue: null,
68
- scrollPosition: null,
69
- modalSnapPoints: [0, 0],
70
- lastSnap: 0,
71
- setLastSnap: () => null,
72
- tabletLandscapePlayerTopPosition: 0,
73
- setTabletLandscapePlayerTopPosition: () => null,
74
- startComponentsAnimationDistance: 0,
75
- progressBarHeight: 0,
76
17
  });
77
18
 
78
19
  const Provider = ({ children }: { children: React.ReactNode }) => {
@@ -80,49 +21,18 @@ const Provider = ({ children }: { children: React.ReactNode }) => {
80
21
  new Animated.Value(Dimensions.get("window").height)
81
22
  );
82
23
 
83
- const [playerAnimationState, setPlayerAnimationState] =
84
- React.useState<PlayerAnimationStateT>(null);
85
-
86
- const [
87
- tabletLandscapePlayerTopPosition,
88
- setTabletLandscapePlayerTopPosition,
89
- ] = React.useState<number>(0);
90
-
91
- const [startComponentsAnimation, setStartComponentsAnimation] =
92
- React.useState<boolean>(false);
93
-
94
24
  const {
95
- videoModalState: { mode, visible, item },
25
+ videoModalState: { visible },
96
26
  } = useNavigation();
97
27
 
98
- const isLiveItem = isLive(item);
99
28
  const { minimised_height: minimisedHeight } = useConfiguration();
100
29
 
101
- const resetPlayerAnimationState = React.useCallback(() => {
102
- setPlayerAnimationState(null);
103
- setStartComponentsAnimation(false);
104
- }, []);
105
-
106
- // Animated values
107
- const lastScrollY = React.useRef(new Animated.Value(0)).current;
108
- const dragScrollY = React.useRef(new Animated.Value(0)).current;
109
- const translateYOffset = React.useRef(new Animated.Value(0)).current;
110
- const dragVideoPlayerY = React.useRef(new Animated.Value(0)).current;
111
-
112
- const { height: safeAreaFrameHeight } = useSafeAreaFrame();
113
- const [height, setHeight] = React.useState<number>(safeAreaFrameHeight);
114
- const progressBarHeight = isLiveItem ? 0 : PROGRESS_BAR_HEIGHT;
115
- const { bottom: bottomSafeArea } = useSafeAreaInsets();
116
- const bottomTabBarHeight = useGetBottomTabBarHeight();
117
- const startComponentsAnimationDistance = Math.round((height * 60) / 100);
118
30
  const isTabletLandscape = useIsTabletLandscape();
119
31
  const windowDimensions = Dimensions.get("window");
120
32
 
121
33
  useEffect(() => {
122
34
  // Reset player animation state when video modal is closed
123
35
  if (!visible) {
124
- resetPlayerAnimationState();
125
-
126
36
  if (!isTabletLandscape) {
127
37
  // restore to portrait ( in portrait mode height is bigger)
128
38
  if (windowDimensions.height > windowDimensions.width) {
@@ -134,79 +44,19 @@ const Provider = ({ children }: { children: React.ReactNode }) => {
134
44
  }
135
45
  }, [
136
46
  visible,
137
- resetPlayerAnimationState,
138
47
  windowDimensions.height,
139
48
  isTabletLandscape,
49
+ windowDimensions.width,
140
50
  ]);
141
51
 
142
- React.useEffect(() => {
143
- if (visible && mode === "MAXIMIZED" && height !== safeAreaFrameHeight) {
144
- setHeight(safeAreaFrameHeight);
145
- }
146
- }, [height, safeAreaFrameHeight, mode, visible]);
147
-
148
- /*
149
- If bottomTabBarHeight is equal 0 it means an app does not use bottomTabBar.
150
- Because of this we need to minus bottom SafeArea offset.
151
- */
152
-
153
- const minValue =
154
- height -
155
- (minimisedHeight + bottomTabBarHeight + progressBarHeight + bottomSafeArea);
156
-
157
- const modalSnapPoints = React.useMemo(() => [0, minValue], [minValue]);
158
- // Last snap state which will helps us to make smooth responder to scrollview animation
159
- const [lastSnap, setLastSnap] = React.useState<number>(modalSnapPoints[0]);
160
- // Extracted animated values which we will use for calculations
161
- const lastScrollYValue = React.useRef<number>(0);
162
- const scrollPosition = React.useRef<number>(0);
163
-
164
52
  return (
165
53
  <ReactContext.Provider
166
54
  value={useMemo(
167
55
  () => ({
168
56
  yTranslate,
169
- startComponentsAnimation,
170
- setStartComponentsAnimation,
171
- isActiveGesture: playerAnimationState !== null,
172
- playerAnimationState,
173
- setPlayerAnimationState,
174
- resetPlayerAnimationState,
175
57
  minimisedHeight,
176
- animatedValues: {
177
- lastScrollY,
178
- dragScrollY,
179
- dragVideoPlayerY,
180
- translateYOffset,
181
- },
182
- lastScrollYValue,
183
- scrollPosition,
184
- modalSnapPoints,
185
- lastSnap,
186
- setLastSnap,
187
- tabletLandscapePlayerTopPosition,
188
- setTabletLandscapePlayerTopPosition,
189
- startComponentsAnimationDistance,
190
- progressBarHeight,
191
58
  }),
192
- // eslint-disable-next-line react-hooks/exhaustive-deps
193
- [
194
- startComponentsAnimation,
195
- playerAnimationState,
196
- minimisedHeight,
197
- lastScrollY,
198
- dragScrollY,
199
- dragVideoPlayerY,
200
- translateYOffset,
201
- lastSnap,
202
- modalSnapPoints,
203
- lastScrollYValue,
204
- scrollPosition,
205
- tabletLandscapePlayerTopPosition,
206
- startComponentsAnimationDistance,
207
- progressBarHeight,
208
- isLiveItem,
209
- ]
59
+ [minimisedHeight]
210
60
  )}
211
61
  >
212
62
  {children}
@@ -1,18 +1,7 @@
1
- export { AnimatedPlayerModalWrapper } from "./AnimatedPlayerModalWrapper";
2
-
3
- export { AnimatedScrollModal } from "./AnimatedScrollModal";
4
-
5
- export { AnimatedVideoPlayerComponent } from "./AnimatedVideoPlayerComponent";
6
-
7
- export {
8
- withModalAnimationProvider,
9
- PlayerAnimationStateEnum,
10
- } from "./ModalAnimationContext";
1
+ export { withModalAnimationProvider } from "./ModalAnimationContext";
11
2
 
12
3
  export { useModalAnimationContext } from "./useModalAnimationContext";
13
4
 
14
- export { AnimationComponent } from "./AnimationComponent";
15
-
16
- export { ComponentAnimationType, defaultAspectRatioWidth } from "./utils";
5
+ export { defaultAspectRatioWidth } from "./utils";
17
6
 
18
7
  export { DURATION_TO_MINIMIZE, DURATION_TO_MAXIMIZE } from "./const";