@applicaster/zapp-react-native-ui-components 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.
- package/Components/AnimatedInOut/index.tsx +69 -26
- package/Components/Cell/Cell.tsx +8 -3
- package/Components/Cell/FocusableWrapper.tsx +44 -0
- package/Components/Cell/TvOSCellComponent.tsx +92 -17
- package/Components/HandlePlayable/HandlePlayable.tsx +14 -65
- package/Components/HandlePlayable/const.ts +3 -0
- package/Components/HandlePlayable/utils.ts +74 -0
- package/Components/MasterCell/DefaultComponents/BorderContainerView/__tests__/index.test.tsx +16 -1
- package/Components/MasterCell/DefaultComponents/BorderContainerView/index.tsx +36 -2
- package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +10 -6
- package/Components/MasterCell/DefaultComponents/Text/index.tsx +8 -8
- package/Components/MasterCell/index.tsx +2 -0
- package/Components/PlayerContainer/PlayerContainer.tsx +1 -16
- package/Components/PlayerImageBackground/index.tsx +3 -22
- package/Components/Screen/TV/hooks/useInitialFocus.ts +14 -4
- package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +2 -0
- package/Components/Screen/index.tsx +22 -5
- package/Components/ScreenRevealManager/ScreenRevealManager.ts +40 -8
- package/Components/ScreenRevealManager/__tests__/ScreenRevealManager.test.ts +86 -69
- package/Components/ScreenRevealManager/utils/index.ts +23 -0
- package/Components/ScreenRevealManager/withScreenRevealManager.tsx +54 -24
- package/Components/Tabs/TV/Tabs.tsx +20 -3
- package/Components/Transitioner/Scene.tsx +15 -2
- package/Components/VideoLive/__tests__/__snapshots__/PlayerLiveImageComponent.test.tsx.snap +1 -0
- package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +114 -171
- package/Components/VideoModal/ModalAnimation/index.ts +2 -13
- package/Components/VideoModal/ModalAnimation/utils.ts +1 -327
- package/Components/VideoModal/PlayerWrapper.tsx +14 -88
- package/Components/VideoModal/VideoModal.tsx +1 -5
- package/Components/VideoModal/__tests__/PlayerWrapper.test.tsx +1 -0
- package/Components/VideoModal/hooks/useModalSize.ts +10 -5
- package/Components/VideoModal/playerWrapperStyle.ts +70 -0
- package/Components/VideoModal/playerWrapperUtils.ts +91 -0
- package/Components/VideoModal/utils.ts +7 -0
- package/index.d.ts +7 -0
- package/package.json +5 -5
- package/Components/VideoModal/ModalAnimation/AnimatedPlayerModalWrapper.tsx +0 -60
- package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.tsx +0 -417
- package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.web.tsx +0 -294
- package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.tsx +0 -176
- package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.web.tsx +0 -93
- package/Components/VideoModal/ModalAnimation/AnimationComponent.tsx +0 -500
- package/Components/VideoModal/ModalAnimation/__tests__/getMoveUpValue.test.ts +0 -108
|
@@ -9,6 +9,7 @@ import { useTrackCurrentAutoScrollingElement } from "@applicaster/zapp-react-nat
|
|
|
9
9
|
import { useUIComponentContext } from "@applicaster/zapp-react-native-ui-components/Contexts/UIComponentContext";
|
|
10
10
|
import { getPropComponentType } from "@applicaster/zapp-react-native-utils/cellUtils";
|
|
11
11
|
import { findPluginByIdentifier } from "@applicaster/zapp-react-native-utils/pluginUtils";
|
|
12
|
+
import { useAccessibilityState } from "@applicaster/zapp-react-native-utils/appUtils/accessibilityManager/hooks";
|
|
12
13
|
|
|
13
14
|
type LiveImageProps = {
|
|
14
15
|
item: ZappEntry;
|
|
@@ -108,8 +109,7 @@ const prepareEntry = (entry) => {
|
|
|
108
109
|
};
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
const previewPlayback =
|
|
112
|
-
entry.extensions?.["brightcove"]?.["preview_playback"];
|
|
112
|
+
const previewPlayback = entry.extensions?.brightcove?.preview_playback;
|
|
113
113
|
|
|
114
114
|
if (previewPlayback) {
|
|
115
115
|
return {
|
|
@@ -117,14 +117,14 @@ const prepareEntry = (entry) => {
|
|
|
117
117
|
extensions: {
|
|
118
118
|
...entry.extensions,
|
|
119
119
|
brightcove: {
|
|
120
|
-
...entry?.extensions?.
|
|
120
|
+
...entry?.extensions?.brightcove,
|
|
121
121
|
video_id: previewPlayback,
|
|
122
122
|
},
|
|
123
123
|
},
|
|
124
124
|
};
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
if (entry.extensions?.
|
|
127
|
+
if (entry.extensions?.brightcove?.video_id) {
|
|
128
128
|
return entry;
|
|
129
129
|
}
|
|
130
130
|
|
|
@@ -174,7 +174,7 @@ const getPlayerConfig = (player_screen_id, actionIdentifier) => {
|
|
|
174
174
|
// TODO: Add more dict if needed from the screen component, styles, data etc
|
|
175
175
|
return {
|
|
176
176
|
playerPluginId: playerScreen?.type ?? DEFAULT_PLAYER_IDENTIFIER,
|
|
177
|
-
screenConfig: playerScreen?.
|
|
177
|
+
screenConfig: playerScreen?.general,
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
180
|
|
|
@@ -206,6 +206,9 @@ const LiveImageComponent = (props: LiveImageProps) => {
|
|
|
206
206
|
state,
|
|
207
207
|
} = props;
|
|
208
208
|
|
|
209
|
+
const accessibilityState = useAccessibilityState({});
|
|
210
|
+
const isScreenReaderEnabled = accessibilityState.screenReaderEnabled;
|
|
211
|
+
|
|
209
212
|
const component = useUIComponentContext();
|
|
210
213
|
|
|
211
214
|
// Fix for blinking on state change
|
|
@@ -239,7 +242,8 @@ const LiveImageComponent = (props: LiveImageProps) => {
|
|
|
239
242
|
getFocusedState(state, componentType, isCurrentlyFocused) &&
|
|
240
243
|
playableEntry &&
|
|
241
244
|
cellUUID &&
|
|
242
|
-
isSupportedTVForLiveImage()
|
|
245
|
+
isSupportedTVForLiveImage() &&
|
|
246
|
+
!isScreenReaderEnabled;
|
|
243
247
|
|
|
244
248
|
return (
|
|
245
249
|
<>
|
|
@@ -52,14 +52,14 @@ const _Text = ({
|
|
|
52
52
|
: textTransform(transformText, _label);
|
|
53
53
|
|
|
54
54
|
React.useLayoutEffect(() => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
if (cellFocused) {
|
|
56
|
+
switch (otherProps.state) {
|
|
57
|
+
case "focused":
|
|
58
|
+
accessibilityManager.addHeading(textLabel);
|
|
59
|
+
break;
|
|
60
|
+
case "focused_selected":
|
|
61
|
+
accessibilityManager.addHeading(`${textLabel}, Selected`);
|
|
62
|
+
break;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
}, [cellFocused, otherProps.state, textLabel]);
|
|
@@ -56,11 +56,6 @@ import { toNumber } from "@applicaster/zapp-react-native-utils/numberUtils";
|
|
|
56
56
|
import { usePlayNextOverlay } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayNextOverlay";
|
|
57
57
|
import { PlayNextState } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/OverlayObserver/OverlaysObserver";
|
|
58
58
|
|
|
59
|
-
import {
|
|
60
|
-
PlayerAnimationStateEnum,
|
|
61
|
-
useModalAnimationContext,
|
|
62
|
-
} from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation";
|
|
63
|
-
|
|
64
59
|
import {
|
|
65
60
|
PlayerNativeCommandTypes,
|
|
66
61
|
PlayerNativeSendCommand,
|
|
@@ -248,9 +243,6 @@ const PlayerContainerComponent = (props: Props) => {
|
|
|
248
243
|
const screenData = useTargetScreenData(item);
|
|
249
244
|
const { setVisible: showNavBar } = useSetNavbarState();
|
|
250
245
|
|
|
251
|
-
const { isActiveGesture, startComponentsAnimation, setPlayerAnimationState } =
|
|
252
|
-
useModalAnimationContext();
|
|
253
|
-
|
|
254
246
|
const playerEvent = (event, ...args) => {
|
|
255
247
|
playerManager.invokeHandler(event, ...args);
|
|
256
248
|
};
|
|
@@ -482,8 +474,6 @@ const PlayerContainerComponent = (props: Props) => {
|
|
|
482
474
|
if (isModal && mode === VideoModalMode.MAXIMIZED) {
|
|
483
475
|
if (disableMiniPlayer) {
|
|
484
476
|
navigator.closeVideoModal();
|
|
485
|
-
} else {
|
|
486
|
-
setPlayerAnimationState(PlayerAnimationStateEnum.minimize);
|
|
487
477
|
}
|
|
488
478
|
}
|
|
489
479
|
|
|
@@ -680,11 +670,7 @@ const PlayerContainerComponent = (props: Props) => {
|
|
|
680
670
|
autoplay={true}
|
|
681
671
|
controls={false}
|
|
682
672
|
disableCastAction={disableCastAction}
|
|
683
|
-
docked={
|
|
684
|
-
navigator.isVideoModalDocked() &&
|
|
685
|
-
!startComponentsAnimation &&
|
|
686
|
-
!isActiveGesture
|
|
687
|
-
}
|
|
673
|
+
docked={navigator.isVideoModalDocked()}
|
|
688
674
|
entry={item}
|
|
689
675
|
fullscreen={mode === VideoModalMode.FULLSCREEN}
|
|
690
676
|
inline={inline}
|
|
@@ -702,7 +688,6 @@ const PlayerContainerComponent = (props: Props) => {
|
|
|
702
688
|
setNextVideoPreloadThresholdPercentage={
|
|
703
689
|
setNextVideoPreloadThresholdPercentage
|
|
704
690
|
}
|
|
705
|
-
startComponentsAnimation={startComponentsAnimation}
|
|
706
691
|
>
|
|
707
692
|
{renderApplePlayer(applePlayerProps)}
|
|
708
693
|
</Player>
|
|
@@ -2,12 +2,6 @@ import React, { PropsWithChildren } from "react";
|
|
|
2
2
|
import { ImageBackground, View } from "react-native";
|
|
3
3
|
|
|
4
4
|
import { imageSrcFromMediaItem } from "@applicaster/zapp-react-native-utils/configurationUtils";
|
|
5
|
-
import {
|
|
6
|
-
AnimationComponent,
|
|
7
|
-
ComponentAnimationType,
|
|
8
|
-
useModalAnimationContext,
|
|
9
|
-
PlayerAnimationStateEnum,
|
|
10
|
-
} from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation";
|
|
11
5
|
|
|
12
6
|
type Props = PropsWithChildren<{
|
|
13
7
|
entry: ZappEntry;
|
|
@@ -25,30 +19,17 @@ const PlayerImageBackgroundComponent = ({
|
|
|
25
19
|
style,
|
|
26
20
|
imageStyle,
|
|
27
21
|
imageKey,
|
|
28
|
-
defaultImageDimensions,
|
|
29
22
|
}: Props) => {
|
|
30
23
|
const source = React.useMemo(
|
|
31
24
|
() => ({ uri: imageSrcFromMediaItem(entry, [imageKey]) }),
|
|
32
25
|
[imageKey, entry]
|
|
33
26
|
);
|
|
34
27
|
|
|
35
|
-
const { playerAnimationState } = useModalAnimationContext();
|
|
36
|
-
|
|
37
28
|
if (!source) return <>{children}</>;
|
|
38
29
|
|
|
39
30
|
return (
|
|
40
|
-
<View
|
|
41
|
-
style={
|
|
42
|
-
playerAnimationState === PlayerAnimationStateEnum.maximize
|
|
43
|
-
? defaultImageDimensions
|
|
44
|
-
: style
|
|
45
|
-
}
|
|
46
|
-
>
|
|
47
|
-
<AnimationComponent
|
|
48
|
-
style={style}
|
|
49
|
-
animationType={ComponentAnimationType.player}
|
|
50
|
-
additionalData={defaultImageDimensions}
|
|
51
|
-
>
|
|
31
|
+
<View style={style}>
|
|
32
|
+
<View style={style}>
|
|
52
33
|
<ImageBackground
|
|
53
34
|
resizeMode="cover"
|
|
54
35
|
style={imageSize}
|
|
@@ -57,7 +38,7 @@ const PlayerImageBackgroundComponent = ({
|
|
|
57
38
|
>
|
|
58
39
|
{children}
|
|
59
40
|
</ImageBackground>
|
|
60
|
-
</
|
|
41
|
+
</View>
|
|
61
42
|
</View>
|
|
62
43
|
);
|
|
63
44
|
};
|
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
setFocusOnMenu,
|
|
11
11
|
} from "@applicaster/zapp-react-native-utils/appUtils/focusManagerAux";
|
|
12
12
|
|
|
13
|
+
import { waitUntilScreenRevealManagerIsReady } from "@applicaster/zapp-react-native-ui-components/Components/ScreenRevealManager/utils";
|
|
14
|
+
|
|
13
15
|
type Return =
|
|
14
16
|
| {
|
|
15
17
|
onContent: true;
|
|
@@ -57,14 +59,22 @@ export const useInitialFocus = (): void => {
|
|
|
57
59
|
React.useEffect(() => {
|
|
58
60
|
const initialFocus = getInitialFocus(focusOnContent, isNavBarVisible);
|
|
59
61
|
|
|
60
|
-
if (initialFocus.
|
|
61
|
-
|
|
62
|
+
if (initialFocus.onMenu) {
|
|
63
|
+
setFocusOnMenu(currentRoute);
|
|
62
64
|
|
|
63
65
|
return;
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
if (initialFocus.
|
|
67
|
-
|
|
68
|
+
if (initialFocus.onContent) {
|
|
69
|
+
const subscription = waitUntilScreenRevealManagerIsReady().subscribe(
|
|
70
|
+
() => {
|
|
71
|
+
setFocusOnContent(currentRoute);
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
return () => {
|
|
76
|
+
subscription.unsubscribe();
|
|
77
|
+
};
|
|
68
78
|
}
|
|
69
79
|
}, []);
|
|
70
80
|
};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
exports[`<Screen Component /> when the navbar should be hidden renders correctly 1`] = `
|
|
4
4
|
<View
|
|
5
|
+
importantForAccessibility="yes"
|
|
5
6
|
style={
|
|
6
7
|
{
|
|
7
8
|
"backgroundColor": "blue",
|
|
@@ -34,6 +35,7 @@ exports[`<Screen Component /> when the navbar should be hidden renders correctly
|
|
|
34
35
|
|
|
35
36
|
exports[`<Screen Component /> when the navbar should show renders correctly 1`] = `
|
|
36
37
|
<View
|
|
38
|
+
importantForAccessibility="yes"
|
|
37
39
|
style={
|
|
38
40
|
{
|
|
39
41
|
"backgroundColor": "blue",
|
|
@@ -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
|
-
|
|
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
|
|
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}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { makeListOf } from "@applicaster/zapp-react-native-utils/arrayUtils";
|
|
2
2
|
import { isFirstComponentGallery } from "@applicaster/zapp-react-native-utils/componentsUtils";
|
|
3
|
-
import {
|
|
3
|
+
import { race, Subject, Subscription } from "rxjs";
|
|
4
|
+
import { first } from "rxjs/operators";
|
|
5
|
+
|
|
6
|
+
import { withTimeout$ } from "@applicaster/zapp-react-native-utils/idleUtils";
|
|
7
|
+
|
|
8
|
+
const MAX_TIMEOUT_TO_WAIT_COMPONENTS_TO_LOAD = 2000; // 2 seconds
|
|
4
9
|
|
|
5
10
|
const INITIAL_NUMBER_TO_LOAD = 3;
|
|
6
11
|
|
|
@@ -34,7 +39,8 @@ const getNumberOfComponentsWaitToLoadBeforePresent = (
|
|
|
34
39
|
export class ScreenRevealManager {
|
|
35
40
|
public numberOfComponentsWaitToLoadBeforePresent: number;
|
|
36
41
|
private renderingState: Array<ComponentLoadingState>;
|
|
37
|
-
private
|
|
42
|
+
private subject$ = new Subject<void>();
|
|
43
|
+
private subscription: Subscription;
|
|
38
44
|
|
|
39
45
|
constructor(componentsToRender: ZappUIComponent[], callback: Callback) {
|
|
40
46
|
this.numberOfComponentsWaitToLoadBeforePresent =
|
|
@@ -45,32 +51,58 @@ export class ScreenRevealManager {
|
|
|
45
51
|
this.numberOfComponentsWaitToLoadBeforePresent
|
|
46
52
|
);
|
|
47
53
|
|
|
48
|
-
this.
|
|
54
|
+
this.subscription = race(
|
|
55
|
+
withTimeout$(MAX_TIMEOUT_TO_WAIT_COMPONENTS_TO_LOAD),
|
|
56
|
+
this.subject$
|
|
57
|
+
)
|
|
58
|
+
.pipe(first())
|
|
59
|
+
.subscribe(callback);
|
|
49
60
|
}
|
|
50
61
|
|
|
51
62
|
onLoadFinished = (index: number): void => {
|
|
63
|
+
const currentState = this.renderingState[index];
|
|
64
|
+
|
|
65
|
+
if (
|
|
66
|
+
COMPONENT_LOADING_STATE.LOADED_WITH_SUCCESS === currentState ||
|
|
67
|
+
COMPONENT_LOADING_STATE.LOADED_WITH_FAILURE === currentState
|
|
68
|
+
) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
52
72
|
this.renderingState[index] = COMPONENT_LOADING_STATE.LOADED_WITH_SUCCESS;
|
|
53
73
|
|
|
54
74
|
if (
|
|
55
75
|
getNumberOfLoaded(this.renderingState) >=
|
|
56
76
|
this.numberOfComponentsWaitToLoadBeforePresent
|
|
57
77
|
) {
|
|
58
|
-
this.
|
|
78
|
+
this.subject$.next();
|
|
79
|
+
this.subject$.complete();
|
|
59
80
|
}
|
|
60
81
|
};
|
|
61
82
|
|
|
62
83
|
onLoadFailed = (index: number): void => {
|
|
84
|
+
const currentState = this.renderingState[index];
|
|
85
|
+
|
|
86
|
+
if (
|
|
87
|
+
COMPONENT_LOADING_STATE.LOADED_WITH_SUCCESS === currentState ||
|
|
88
|
+
COMPONENT_LOADING_STATE.LOADED_WITH_FAILURE === currentState
|
|
89
|
+
) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
63
93
|
this.renderingState[index] = COMPONENT_LOADING_STATE.LOADED_WITH_FAILURE;
|
|
64
94
|
|
|
65
95
|
if (
|
|
66
96
|
getNumberOfLoaded(this.renderingState) >=
|
|
67
97
|
this.numberOfComponentsWaitToLoadBeforePresent
|
|
68
98
|
) {
|
|
69
|
-
this.
|
|
99
|
+
this.subject$.next();
|
|
100
|
+
this.subject$.complete();
|
|
70
101
|
}
|
|
71
102
|
};
|
|
72
103
|
|
|
73
|
-
|
|
74
|
-
this.
|
|
75
|
-
|
|
104
|
+
dispose(): void {
|
|
105
|
+
this.subscription?.unsubscribe();
|
|
106
|
+
this.subject$.complete();
|
|
107
|
+
}
|
|
76
108
|
}
|
|
@@ -2,106 +2,123 @@ import {
|
|
|
2
2
|
ScreenRevealManager,
|
|
3
3
|
COMPONENT_LOADING_STATE,
|
|
4
4
|
} from "../ScreenRevealManager";
|
|
5
|
+
import { Subject } from "rxjs";
|
|
6
|
+
|
|
7
|
+
jest.mock("@applicaster/zapp-react-native-utils/arrayUtils", () => ({
|
|
8
|
+
makeListOf: jest.fn((value: any, length: number) =>
|
|
9
|
+
Array(length).fill(value)
|
|
10
|
+
),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
jest.mock("@applicaster/zapp-react-native-utils/componentsUtils", () => ({
|
|
14
|
+
isFirstComponentGallery: jest.fn(),
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
jest.mock("@applicaster/zapp-react-native-utils/idleUtils", () => ({
|
|
18
|
+
withTimeout$: jest.fn(),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
import { makeListOf } from "@applicaster/zapp-react-native-utils/arrayUtils";
|
|
22
|
+
import { isFirstComponentGallery } from "@applicaster/zapp-react-native-utils/componentsUtils";
|
|
23
|
+
import { withTimeout$ } from "@applicaster/zapp-react-native-utils/idleUtils";
|
|
5
24
|
|
|
6
25
|
describe("ScreenRevealManager", () => {
|
|
7
|
-
|
|
26
|
+
let mockCallback: jest.Mock;
|
|
27
|
+
let timeout$: Subject<void>;
|
|
8
28
|
|
|
9
29
|
beforeEach(() => {
|
|
10
|
-
jest.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
it("should initialize with the correct number of components to wait for", () => {
|
|
14
|
-
const componentsToRender: ZappUIComponent[] = [
|
|
15
|
-
{ component_type: "component1" },
|
|
16
|
-
{ component_type: "component2" },
|
|
17
|
-
{ component_type: "component3" },
|
|
18
|
-
];
|
|
30
|
+
jest.useFakeTimers();
|
|
31
|
+
mockCallback = jest.fn();
|
|
32
|
+
timeout$ = new Subject();
|
|
19
33
|
|
|
20
|
-
|
|
34
|
+
(withTimeout$ as jest.Mock).mockReturnValue(timeout$);
|
|
35
|
+
(isFirstComponentGallery as jest.Mock).mockReturnValue(false);
|
|
21
36
|
|
|
22
|
-
|
|
37
|
+
(makeListOf as jest.Mock).mockImplementation((value, length) =>
|
|
38
|
+
Array(length).fill(value)
|
|
39
|
+
);
|
|
40
|
+
});
|
|
23
41
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
]);
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
jest.clearAllTimers();
|
|
44
|
+
jest.useRealTimers();
|
|
45
|
+
jest.resetAllMocks();
|
|
29
46
|
});
|
|
30
47
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
{ component_type: "component3" },
|
|
36
|
-
];
|
|
48
|
+
// ────────────────────────────────────────────────
|
|
49
|
+
it("should initialize with correct number of components and UNKNOWN state", () => {
|
|
50
|
+
const components = new Array(5).fill({});
|
|
51
|
+
const mgr = new ScreenRevealManager(components, mockCallback);
|
|
37
52
|
|
|
38
|
-
|
|
53
|
+
expect(mgr.numberOfComponentsWaitToLoadBeforePresent).toBe(3);
|
|
54
|
+
expect(makeListOf).toHaveBeenCalledWith(COMPONENT_LOADING_STATE.UNKNOWN, 3);
|
|
55
|
+
});
|
|
39
56
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
57
|
+
// ────────────────────────────────────────────────
|
|
58
|
+
it("should set numberOfComponentsWaitToLoadBeforePresent to 1 if first component is gallery", () => {
|
|
59
|
+
(isFirstComponentGallery as jest.Mock).mockReturnValue(true);
|
|
43
60
|
|
|
44
|
-
|
|
61
|
+
const components = new Array(5).fill({});
|
|
62
|
+
const mgr = new ScreenRevealManager(components, mockCallback);
|
|
63
|
+
|
|
64
|
+
expect(mgr.numberOfComponentsWaitToLoadBeforePresent).toBe(1);
|
|
45
65
|
});
|
|
46
66
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
{ component_type: "component3" },
|
|
52
|
-
];
|
|
67
|
+
// ────────────────────────────────────────────────
|
|
68
|
+
it("should trigger callback after all components load successfully", () => {
|
|
69
|
+
const components = new Array(3).fill({});
|
|
70
|
+
const mgr = new ScreenRevealManager(components, mockCallback);
|
|
53
71
|
|
|
54
|
-
|
|
72
|
+
mgr.onLoadFinished(0);
|
|
73
|
+
expect(mockCallback).not.toHaveBeenCalled();
|
|
55
74
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
manager.onLoadFailed(2);
|
|
75
|
+
mgr.onLoadFinished(1);
|
|
76
|
+
expect(mockCallback).not.toHaveBeenCalled();
|
|
59
77
|
|
|
78
|
+
mgr.onLoadFinished(2);
|
|
60
79
|
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
61
80
|
});
|
|
62
81
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
{ component_type: "component3" },
|
|
68
|
-
];
|
|
69
|
-
|
|
70
|
-
const manager = new ScreenRevealManager(componentsToRender, mockCallback);
|
|
82
|
+
// ────────────────────────────────────────────────
|
|
83
|
+
it("should trigger callback after some components fail to load but all finished", () => {
|
|
84
|
+
const components = new Array(3).fill({});
|
|
85
|
+
const mgr = new ScreenRevealManager(components, mockCallback);
|
|
71
86
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
87
|
+
mgr.onLoadFinished(0);
|
|
88
|
+
mgr.onLoadFailed(1);
|
|
89
|
+
mgr.onLoadFailed(2);
|
|
75
90
|
|
|
76
91
|
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
77
92
|
});
|
|
78
93
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
{ component_type: "component3" },
|
|
84
|
-
];
|
|
85
|
-
|
|
86
|
-
const manager = new ScreenRevealManager(componentsToRender, mockCallback);
|
|
94
|
+
// ────────────────────────────────────────────────
|
|
95
|
+
it("should not trigger callback twice when same component finishes twice", () => {
|
|
96
|
+
const components = new Array(3).fill({});
|
|
97
|
+
const mgr = new ScreenRevealManager(components, mockCallback);
|
|
87
98
|
|
|
88
|
-
|
|
89
|
-
|
|
99
|
+
mgr.onLoadFinished(0);
|
|
100
|
+
mgr.onLoadFinished(0); // duplicate
|
|
101
|
+
mgr.onLoadFinished(1);
|
|
102
|
+
mgr.onLoadFinished(2);
|
|
90
103
|
|
|
91
|
-
expect(mockCallback).
|
|
104
|
+
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
92
105
|
});
|
|
93
106
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
{ component_type: "component3" },
|
|
99
|
-
];
|
|
107
|
+
// ────────────────────────────────────────────────
|
|
108
|
+
it("should trigger callback when timeout$ emits before all loaded", () => {
|
|
109
|
+
const components = new Array(3).fill({});
|
|
110
|
+
new ScreenRevealManager(components, mockCallback);
|
|
100
111
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
manager.onLoadFinished(0);
|
|
112
|
+
timeout$.next(); // simulate timeout event from withTimeout$
|
|
104
113
|
|
|
105
114
|
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
106
115
|
});
|
|
116
|
+
|
|
117
|
+
// ────────────────────────────────────────────────
|
|
118
|
+
it("should not call callback if nothing loads and no timeout emitted", () => {
|
|
119
|
+
const components = new Array(3).fill({});
|
|
120
|
+
new ScreenRevealManager(components, mockCallback);
|
|
121
|
+
|
|
122
|
+
expect(mockCallback).not.toHaveBeenCalled();
|
|
123
|
+
});
|
|
107
124
|
});
|
|
@@ -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
|
+
};
|