@applicaster/zapp-react-native-ui-components 16.0.0-rc.99 → 17.0.0-alpha.1102403272
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/AudioPlayer/index.web.tsx +10 -0
- package/Components/Cell/PlatformCellComponent.ts +9 -0
- package/Components/Cell/PlatformCellComponent.web.ts +3 -0
- package/Components/Cell/index.js +2 -9
- package/Components/CellRendererResolver/index.ts +22 -3
- package/Components/ComponentResolver/ComponentResolver.ts +6 -2
- package/Components/ComponentResolver/__tests__/componentResolver.test.js +13 -5
- package/Components/ContentScreen/index.js +2 -2
- package/Components/Focusable/index.web.tsx +3 -0
- package/Components/FocusableList/hooks/useCheckItemIdsForUnique.ts +2 -7
- package/Components/GeneralContentScreen/GeneralContentScreen.tsx +1 -1
- package/Components/GeneralContentScreen/hookAdapter/logger.ts +1 -1
- package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +158 -1
- package/Components/GeneralContentScreen/utils/index.ts +2 -2
- package/Components/GeneralContentScreen/utils/logger.ts +3 -4
- package/Components/GeneralContentScreen/utils/useCurationAPI.ts +32 -10
- package/Components/HandlePlayable/utils.ts +2 -7
- package/Components/HookRenderer/HookRenderer.tsx +2 -2
- package/Components/MasterCell/DefaultComponents/ActionButton.tsx +42 -4
- package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.android.tv.tsx +7 -4
- package/Components/MasterCell/DefaultComponents/ButtonContainerView/types.ts +1 -0
- package/Components/MasterCell/DefaultComponents/FocusableView/index.android.tsx +10 -4
- package/Components/MasterCell/DefaultComponents/Image/hoc/utils/__tests__/withDimensions.test.ts +1 -1
- package/Components/MasterCell/DefaultComponents/Image/hoc/utils/index.ts +2 -4
- package/Components/MasterCell/DefaultComponents/Image/hooks/checkTooBigImageSize.ts +2 -7
- package/Components/MasterCell/DefaultComponents/Image/index.web.ts +7 -0
- package/Components/MasterCell/DefaultComponents/LiveImage/__tests__/prepareEntry.test.ts +30 -0
- package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +34 -7
- package/Components/MasterCell/DefaultComponents/PressableView.tsx +3 -0
- package/Components/MasterCell/DefaultComponents/Text/hooks/useText.ts +2 -7
- package/Components/MasterCell/DefaultComponents/__tests__/ActionButton.missingPlugin.test.tsx +66 -0
- package/Components/MasterCell/DefaultComponents/__tests__/ActionButton.test.tsx +288 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ActionButton.tsx +2 -1
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +4 -2
- package/Components/MasterCell/SharedUI/CollapsibleTextContainer/__tests__/factory.test.ts +2 -2
- package/Components/MasterCell/SharedUI/CollapsibleTextContainer/index.ts +2 -1
- package/Components/MasterCell/__tests__/masterCell.test.js +116 -0
- package/Components/MasterCell/index.tsx +45 -6
- package/Components/MasterCell/logger.ts +2 -2
- package/Components/MasterCell/utils/__tests__/getFocusableElementId.test.ts +38 -0
- package/Components/MasterCell/utils/__tests__/useIsCellSelected.test.ts +91 -0
- package/Components/MasterCell/utils/__tests__/withoutFocusedState.test.js +20 -0
- package/Components/MasterCell/utils/behaviorProvider.ts +57 -38
- package/Components/MasterCell/utils/index.ts +60 -19
- package/Components/ModalComponent/ActionsBottomSheet/openActionsBottomSheet.ts +1 -1
- package/Components/ModalComponent/AudioPlayer/Components/Button.tsx +7 -3
- package/Components/ModalComponent/AudioPlayer/Components/Item.tsx +22 -1
- package/Components/ModalComponent/AudioPlayer/Components/__tests__/Item.test.tsx +52 -1
- package/Components/ModalComponent/AudioPlayer/utils/__tests__/mergeStyles.test.ts +77 -0
- package/Components/ModalComponent/AudioPlayer/utils/mergeStyles.ts +58 -16
- package/Components/ModalComponent/BottomSheetDragArea.web.tsx +15 -0
- package/Components/ModalComponent/BottomSheetModalContent.tsx +51 -82
- package/Components/ModalComponent/Button/index.tsx +3 -1
- package/Components/ModalComponent/SortableList.tsx +2 -3
- package/Components/ModalComponent/__tests__/BottomSheetDragArea.test.tsx +30 -0
- package/Components/ModalComponent/__tests__/BottomSheetModalContent.test.tsx +237 -17
- package/Components/ModalComponent/__tests__/showTextInput.test.ts +25 -0
- package/Components/ModalComponent/presets/__tests__/getCell.test.ts +29 -2
- package/Components/ModalComponent/presets/index.ts +2 -3
- package/Components/ModalComponent/showTextInput.ts +2 -0
- package/Components/OfflineHandler/__tests__/index.test.tsx +136 -0
- package/Components/OfflineHandler/index.tsx +45 -6
- package/Components/PlayerContainer/PlayerContainer.tsx +30 -6
- package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +51 -0
- package/Components/PlayerContainer/logger.ts +9 -5
- package/Components/River/ComponentsMap/ComponentsMap.tsx +4 -1
- package/Components/River/ComponentsMap/index.web.tsx +3 -0
- package/Components/River/RiverItem.tsx +4 -0
- package/Components/River/TV/River.tsx +7 -1
- package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +2 -0
- package/Components/ScreenFeedLoader/ScreenFeedLoader.tsx +2 -2
- package/Components/ScreenResolver/index.tsx +6 -4
- package/Components/Tabs/TV/index.web.tsx +5 -0
- package/Components/TopCutoffOverlay/__tests__/TopCutoffOverlay.test.tsx +56 -10
- package/Components/TopCutoffOverlay/index.tsx +41 -10
- package/Components/Transitioner/AnimationManager.js +1 -1
- package/Components/Transitioner/Scene.tsx +4 -3
- package/Components/Transitioner/Transitioner.tsx +71 -33
- package/Components/Transitioner/__tests__/transitioner.test.js +372 -3
- package/Components/VideoLive/LiveImageManager.ts +126 -12
- package/Components/VideoLive/MuteUnmuteController.ts +135 -0
- package/Components/VideoLive/PlayerLiveImageComponent.tsx +15 -19
- package/Components/VideoLive/__tests__/LiveImageManager.test.ts +30 -0
- package/Components/VideoLive/__tests__/LiveImageMuteState.test.ts +311 -0
- package/Components/VideoLive/__tests__/MuteUnmuteController.test.ts +135 -0
- package/Components/VideoLive/__tests__/PlayerLiveImageComponent.test.tsx +63 -1
- package/Components/VideoLive/loggerHelper.ts +2 -2
- package/Components/VideoModal/PlayerDetails.tsx +27 -2
- package/Components/VideoModal/PlayerWrapper.tsx +9 -2
- package/Components/VideoModal/__tests__/PlayerDetails.test.tsx +84 -0
- package/Components/VideoModal/__tests__/PlayerWrapper.test.tsx +1 -0
- package/Components/VideoModal/__tests__/playerWrapperStyle.test.ts +263 -0
- package/Components/VideoModal/__tests__/playerWrapperUtils.test.ts +125 -0
- package/Components/VideoModal/hooks/useModalSize.ts +2 -7
- package/Components/VideoModal/playerWrapperStyle.ts +62 -23
- package/Components/VideoModal/playerWrapperUtils.ts +141 -1
- package/Components/__tests__/webVariants.test.js +73 -0
- package/Components/default-cell-renderer/containerStyles/index.web.ts +6 -0
- package/Components/default-cell-renderer/viewTrees/index.web.ts +10 -0
- package/Contexts/ZappPipesContext/ZappPipesContextFactory.tsx +3 -5
- package/Decorators/RiverResolver/__tests__/riverResolver.missingRiver.test.tsx +52 -0
- package/Decorators/RiverResolver/index.tsx +25 -0
- package/Decorators/ZappPipesDataConnector/__tests__/UrlFeedResolver.test.tsx +4 -3
- package/Decorators/ZappPipesDataConnector/__tests__/screenToolbox.test.ts +347 -0
- package/Decorators/ZappPipesDataConnector/__tests__/screenToolboxUnavailable.test.ts +53 -0
- package/Decorators/ZappPipesDataConnector/index.tsx +19 -4
- package/Decorators/ZappPipesDataConnector/resolvers/UrlFeedResolver.tsx +2 -21
- package/Decorators/ZappPipesDataConnector/screenToolbox.ts +384 -0
- package/Decorators/ZappPipesDataConnector/utils/mongoFilter.ts +1 -1
- package/Decorators/ZappPipesDataConnector/utils/useFilter.tsx +1 -1
- package/Helpers/logger.js +2 -2
- package/package.json +5 -5
|
@@ -273,7 +273,10 @@ const PlayerContainerComponent = (props: Props) => {
|
|
|
273
273
|
const playEntry = (entry: ZappEntry) => navigator.replaceTop(entry, { mode });
|
|
274
274
|
|
|
275
275
|
const onPlayNextPerformNextVideoPlay = React.useCallback(() => {
|
|
276
|
-
|
|
276
|
+
// The overlay's entry, or the player's when the overlay is not showing yet (X-Ray player.next)
|
|
277
|
+
const nextEntry = playNextOverlayState?.entry ?? player?.getPlayNextEntry();
|
|
278
|
+
|
|
279
|
+
if (!nextEntry) {
|
|
277
280
|
log_warning(
|
|
278
281
|
"onPlayNextPerformNextVideoPlay: playNextOverlayState.entry is not defined"
|
|
279
282
|
);
|
|
@@ -282,16 +285,30 @@ const PlayerContainerComponent = (props: Props) => {
|
|
|
282
285
|
}
|
|
283
286
|
|
|
284
287
|
log_debug(
|
|
285
|
-
`onPlayNextPerformNextVideoPlay: delay completed, replaceTop to item: ${
|
|
288
|
+
`onPlayNextPerformNextVideoPlay: delay completed, replaceTop to item: ${nextEntry.title}, id: ${nextEntry.id}, outgoing item id: ${item?.id}`
|
|
286
289
|
);
|
|
287
290
|
|
|
288
|
-
|
|
291
|
+
(
|
|
292
|
+
playNextOverlayState?.hidePlayNext ??
|
|
293
|
+
player?.getOverlayObservable()?.hidePlayNext
|
|
294
|
+
)?.();
|
|
289
295
|
|
|
290
296
|
playerEvent(PLAYER_EVENTS.PlayNextTriggered, { id: item?.id });
|
|
291
297
|
|
|
292
298
|
setIsLoadingNextVideo(true);
|
|
293
|
-
playEntry(
|
|
294
|
-
}, [playNextOverlayState, item?.id]);
|
|
299
|
+
playEntry(nextEntry);
|
|
300
|
+
}, [playNextOverlayState, item?.id, player]);
|
|
301
|
+
|
|
302
|
+
// Lets the X-Ray player.next tool run the same Play Next path as the overlay.
|
|
303
|
+
useEffect(() => {
|
|
304
|
+
if (!player) return;
|
|
305
|
+
|
|
306
|
+
player.playNextHandler = onPlayNextPerformNextVideoPlay;
|
|
307
|
+
|
|
308
|
+
return () => {
|
|
309
|
+
player.playNextHandler = null;
|
|
310
|
+
};
|
|
311
|
+
}, [player, onPlayNextPerformNextVideoPlay]);
|
|
295
312
|
|
|
296
313
|
const playNextData: Nullable<PlayNextData> = React.useMemo(() => {
|
|
297
314
|
if (!playNextOverlayState) {
|
|
@@ -404,10 +421,17 @@ const PlayerContainerComponent = (props: Props) => {
|
|
|
404
421
|
const { eventType } = event;
|
|
405
422
|
|
|
406
423
|
if (!isLanguageOverlayVisible && eventType === "menu") {
|
|
424
|
+
// First Back dismisses Play Next, the next one closes the player
|
|
425
|
+
if (playNextOverlayState) {
|
|
426
|
+
playNextOverlayState.handleUserCancelPlayNext();
|
|
427
|
+
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
|
|
407
431
|
close();
|
|
408
432
|
}
|
|
409
433
|
},
|
|
410
|
-
[close]
|
|
434
|
+
[close, playNextOverlayState]
|
|
411
435
|
);
|
|
412
436
|
|
|
413
437
|
// Effects
|
|
@@ -127,6 +127,8 @@ jest.mock(
|
|
|
127
127
|
seekTo: jest.fn(),
|
|
128
128
|
getPluginConfiguration: jest.fn(() => ({})),
|
|
129
129
|
getOverlayObservable: jest.fn(() => ({ getPlayNextEntry: () => null })),
|
|
130
|
+
getPlayNextEntry: jest.fn(() => null),
|
|
131
|
+
playNextHandler: null,
|
|
130
132
|
};
|
|
131
133
|
|
|
132
134
|
return {
|
|
@@ -335,3 +337,52 @@ describe("PlayerContainer hardware back handling", () => {
|
|
|
335
337
|
expect(mockNavigator.closeVideoModal).not.toHaveBeenCalled();
|
|
336
338
|
});
|
|
337
339
|
});
|
|
340
|
+
|
|
341
|
+
describe("PlayerContainer Play Next action for X-Ray player.next", () => {
|
|
342
|
+
beforeEach(() => {
|
|
343
|
+
jest.clearAllMocks();
|
|
344
|
+
mockIsTV.mockReturnValue(false);
|
|
345
|
+
mockPlayer.getPluginConfiguration.mockReturnValue({});
|
|
346
|
+
mockPlayerManager.getPluginConfiguration.mockReturnValue({});
|
|
347
|
+
mockPlayerManager.on.mockReturnThis();
|
|
348
|
+
mockPlayerManager.removeHandler.mockReturnThis();
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it("sets its Play Next action on the player and clears it on unmount", () => {
|
|
352
|
+
const { unmount } = renderPlayerContainer();
|
|
353
|
+
|
|
354
|
+
expect(mockPlayer.playNextHandler).toEqual(expect.any(Function));
|
|
355
|
+
|
|
356
|
+
unmount();
|
|
357
|
+
|
|
358
|
+
expect(mockPlayer.playNextHandler).toBeNull();
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it("plays the player's next entry once, with analytics and the overlay hidden, when the overlay is not showing", () => {
|
|
362
|
+
const next = { id: "entry-2", title: "Next" };
|
|
363
|
+
const hidePlayNext = jest.fn();
|
|
364
|
+
mockPlayer.getPlayNextEntry.mockReturnValue(next);
|
|
365
|
+
|
|
366
|
+
mockPlayer.getOverlayObservable.mockReturnValue({
|
|
367
|
+
getPlayNextEntry: () => next,
|
|
368
|
+
hidePlayNext,
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
renderPlayerContainer();
|
|
372
|
+
|
|
373
|
+
mockPlayer.playNextHandler();
|
|
374
|
+
|
|
375
|
+
expect(hidePlayNext).toHaveBeenCalledTimes(1);
|
|
376
|
+
|
|
377
|
+
expect(mockPlayerManager.invokeHandler).toHaveBeenCalledWith(
|
|
378
|
+
"play_next_triggered",
|
|
379
|
+
{ id: "entry-1" }
|
|
380
|
+
);
|
|
381
|
+
|
|
382
|
+
expect(mockNavigator.replaceTop).toHaveBeenCalledTimes(1);
|
|
383
|
+
|
|
384
|
+
expect(mockNavigator.replaceTop).toHaveBeenCalledWith(next, {
|
|
385
|
+
mode: VideoModalMode.MAXIMIZED,
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
});
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
createLogger,
|
|
3
|
+
subsystemLogger,
|
|
4
|
+
} from "@applicaster/zapp-react-native-utils/logger";
|
|
3
5
|
|
|
4
6
|
export const { log_verbose, log_error, log_debug, log_info, log_warning } =
|
|
5
|
-
createLogger({ category: "
|
|
7
|
+
createLogger({ category: "PlayerContainer", subsystem: "player/container" });
|
|
6
8
|
|
|
7
|
-
export const playerContainerLogger =
|
|
8
|
-
|
|
9
|
+
export const playerContainerLogger = subsystemLogger(
|
|
10
|
+
"player/container",
|
|
11
|
+
"PlayerContainer"
|
|
12
|
+
);
|
|
@@ -118,7 +118,10 @@ function ComponentsMapComponent(props: Props) {
|
|
|
118
118
|
};
|
|
119
119
|
|
|
120
120
|
return (
|
|
121
|
-
<ScreenLoadingMeasurementsListItemWrapper
|
|
121
|
+
<ScreenLoadingMeasurementsListItemWrapper
|
|
122
|
+
index={index}
|
|
123
|
+
testID={`component-${item.id}`}
|
|
124
|
+
>
|
|
122
125
|
<RiverItem {...riverItemProps} />
|
|
123
126
|
</ScreenLoadingMeasurementsListItemWrapper>
|
|
124
127
|
);
|
|
@@ -124,6 +124,10 @@ function RiverItemComponent(props: RiverItemType) {
|
|
|
124
124
|
if (isComponentMissing) {
|
|
125
125
|
riverLogger.warning({
|
|
126
126
|
message: `Component ${item.component_type} is null - skipping rendering`,
|
|
127
|
+
data: {
|
|
128
|
+
diagnostic: { code: "component-plugin-missing" },
|
|
129
|
+
component: item,
|
|
130
|
+
},
|
|
127
131
|
});
|
|
128
132
|
|
|
129
133
|
onLoadFinished(index);
|
|
@@ -97,7 +97,13 @@ export const River = (props: Props) => {
|
|
|
97
97
|
if (!river) {
|
|
98
98
|
utilsLogger.error({
|
|
99
99
|
message: `River ${screenData.id} not found!`,
|
|
100
|
-
data: {
|
|
100
|
+
data: {
|
|
101
|
+
diagnostic: { code: "type-mapping" },
|
|
102
|
+
screen_id: screenData?.id,
|
|
103
|
+
// Without a river the screen data is the entry that was pushed.
|
|
104
|
+
entry: screenData,
|
|
105
|
+
feedData,
|
|
106
|
+
},
|
|
101
107
|
});
|
|
102
108
|
|
|
103
109
|
return <Text>`River ${screenData?.id} not found!`</Text>;
|
|
@@ -213,6 +213,7 @@ exports[`componentsMap renders renders components map correctly 1`] = `
|
|
|
213
213
|
<View
|
|
214
214
|
onLayout={[Function]}
|
|
215
215
|
style={{}}
|
|
216
|
+
testID="component-A1"
|
|
216
217
|
>
|
|
217
218
|
<View />
|
|
218
219
|
</View>
|
|
@@ -225,6 +226,7 @@ exports[`componentsMap renders renders components map correctly 1`] = `
|
|
|
225
226
|
<View
|
|
226
227
|
onLayout={[Function]}
|
|
227
228
|
style={{}}
|
|
229
|
+
testID="component-A2"
|
|
228
230
|
/>
|
|
229
231
|
</View>
|
|
230
232
|
<View
|
|
@@ -3,9 +3,9 @@ import { PreloaderWrapper } from "../PreloaderWrapper";
|
|
|
3
3
|
import { useScreenContextV2 } from "@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext";
|
|
4
4
|
import { useFeedLoader } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { subsystemLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
7
7
|
|
|
8
|
-
const logger =
|
|
8
|
+
const logger = subsystemLogger("ui/screens", "ScreenFeedLoader");
|
|
9
9
|
|
|
10
10
|
/** Loads and provides `feedData` and store to */
|
|
11
11
|
export const ScreenFeedLoader: React.FC<{
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
|
|
3
|
-
import { componentsLogger } from "../../Helpers/logger";
|
|
4
|
-
|
|
5
3
|
import { useScreenAnalytics } from "@applicaster/zapp-react-native-utils/analyticsUtils/helpers/hooks";
|
|
6
4
|
|
|
7
5
|
import { ScreenResultCallback } from "@applicaster/zapp-react-native-utils/zappFrameworkUtils/HookCallback/callbackNavigationAction";
|
|
8
6
|
import { useScreenComponentResolver } from "./hooks/useScreenComponentResolver";
|
|
9
7
|
import { withDefaultScreenContext } from "./withDefaultScreenContext";
|
|
8
|
+
import { subsystemLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
10
9
|
|
|
11
10
|
export enum PresentationType {
|
|
12
11
|
Standalone = "Standalone",
|
|
13
12
|
Hook = "Hook",
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
const logger =
|
|
15
|
+
const logger = subsystemLogger("ui/screens", "ScreenResolver");
|
|
17
16
|
|
|
18
17
|
type Props = {
|
|
19
18
|
screenType: string;
|
|
@@ -44,7 +43,10 @@ export function ScreenResolverComponent(props: Props) {
|
|
|
44
43
|
|
|
45
44
|
logger.warning({
|
|
46
45
|
message: "Could not resolve screen plugin",
|
|
47
|
-
data:
|
|
46
|
+
data: {
|
|
47
|
+
diagnostic: { code: "screen-plugin-missing" },
|
|
48
|
+
...props,
|
|
49
|
+
},
|
|
48
50
|
});
|
|
49
51
|
|
|
50
52
|
return null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { Text } from "react-native";
|
|
2
|
+
import { StyleSheet, Text } from "react-native";
|
|
3
3
|
import { render } from "@testing-library/react-native";
|
|
4
4
|
|
|
5
5
|
jest.mock(
|
|
@@ -29,15 +29,8 @@ import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
|
|
|
29
29
|
const findOverlayStyle = (node: any): Record<string, any> | null => {
|
|
30
30
|
if (!node) return null;
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
? node.props.style
|
|
35
|
-
: node.props?.style
|
|
36
|
-
? [node.props.style]
|
|
37
|
-
: [];
|
|
38
|
-
|
|
39
|
-
const styleObj = styles.find((s: any) => s?.position === "absolute");
|
|
40
|
-
if (styleObj) return styleObj;
|
|
32
|
+
const style = StyleSheet.flatten(node.props?.style);
|
|
33
|
+
if (style?.position === "absolute") return style;
|
|
41
34
|
|
|
42
35
|
const children = node.children || [];
|
|
43
36
|
|
|
@@ -138,6 +131,59 @@ describe("TopCutoffOverlay", () => {
|
|
|
138
131
|
expect(findOverlayStyle(tree.toJSON())?.backgroundColor).toBe("#ff0000");
|
|
139
132
|
});
|
|
140
133
|
|
|
134
|
+
it("falls back to themeBackgroundColor when screenBackgroundColor is transparent", () => {
|
|
135
|
+
mockUseScreenConfig.mockReturnValue({ backgroundColor: "transparent" });
|
|
136
|
+
|
|
137
|
+
const tree = render(
|
|
138
|
+
<TopCutoffOverlay>
|
|
139
|
+
<Text>Child content</Text>
|
|
140
|
+
</TopCutoffOverlay>
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
expect(findOverlayStyle(tree.toJSON())?.backgroundColor).toBe("#222222");
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("falls back to themeBackgroundColor when screenBackgroundColor is transparent rgba", () => {
|
|
147
|
+
mockUseScreenConfig.mockReturnValue({
|
|
148
|
+
backgroundColor: "rgba(0,0,0,0)",
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const tree = render(
|
|
152
|
+
<TopCutoffOverlay>
|
|
153
|
+
<Text>Child content</Text>
|
|
154
|
+
</TopCutoffOverlay>
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
expect(findOverlayStyle(tree.toJSON())?.backgroundColor).toBe("#222222");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("falls back to themeBackgroundColor when screenBackgroundColor is invalid", () => {
|
|
161
|
+
mockUseScreenConfig.mockReturnValue({ backgroundColor: "not-a-color" });
|
|
162
|
+
|
|
163
|
+
const tree = render(
|
|
164
|
+
<TopCutoffOverlay>
|
|
165
|
+
<Text>Child content</Text>
|
|
166
|
+
</TopCutoffOverlay>
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
expect(findOverlayStyle(tree.toJSON())?.backgroundColor).toBe("#222222");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("falls back to transparent when both screen and theme background colors are invalid", () => {
|
|
173
|
+
mockUseScreenConfig.mockReturnValue({ backgroundColor: "not-a-color" });
|
|
174
|
+
mockUseTheme.mockReturnValue({ app_background_color: "also-not-a-color" });
|
|
175
|
+
|
|
176
|
+
const tree = render(
|
|
177
|
+
<TopCutoffOverlay>
|
|
178
|
+
<Text>Child content</Text>
|
|
179
|
+
</TopCutoffOverlay>
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
expect(findOverlayStyle(tree.toJSON())?.backgroundColor).toBe(
|
|
183
|
+
"transparent"
|
|
184
|
+
);
|
|
185
|
+
});
|
|
186
|
+
|
|
141
187
|
it("falls back to themeBackgroundColor when screenBackgroundColor is not available", () => {
|
|
142
188
|
mockUseScreenConfig.mockReturnValue({ backgroundColor: undefined });
|
|
143
189
|
|
|
@@ -3,8 +3,32 @@ import { View, StyleSheet } from "react-native";
|
|
|
3
3
|
import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
|
|
4
4
|
import { useScreenConfiguration } from "@applicaster/zapp-react-native-ui-components/Components/River/useScreenConfiguration";
|
|
5
5
|
|
|
6
|
+
import {
|
|
7
|
+
isValidColor,
|
|
8
|
+
isTransparentColor,
|
|
9
|
+
} from "@applicaster/zapp-react-native-utils/colorUtils";
|
|
10
|
+
|
|
6
11
|
import { useMarginTop } from "./hooks";
|
|
7
12
|
|
|
13
|
+
function getTopCutoffBackgroundColor(
|
|
14
|
+
screenBackgroundColor: string,
|
|
15
|
+
themeBackgroundColor: string
|
|
16
|
+
) {
|
|
17
|
+
if (isTransparentColor(screenBackgroundColor)) {
|
|
18
|
+
return isValidColor(themeBackgroundColor)
|
|
19
|
+
? themeBackgroundColor
|
|
20
|
+
: "transparent";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (isValidColor(screenBackgroundColor)) {
|
|
24
|
+
return screenBackgroundColor;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return isValidColor(themeBackgroundColor)
|
|
28
|
+
? themeBackgroundColor
|
|
29
|
+
: "transparent";
|
|
30
|
+
}
|
|
31
|
+
|
|
8
32
|
interface IProps {
|
|
9
33
|
targetScreenId?: string;
|
|
10
34
|
children: React.ReactElement | null;
|
|
@@ -15,6 +39,12 @@ const styles = StyleSheet.create({
|
|
|
15
39
|
container: {
|
|
16
40
|
flex: 1,
|
|
17
41
|
},
|
|
42
|
+
cutoffBlock: {
|
|
43
|
+
position: "absolute",
|
|
44
|
+
top: 0,
|
|
45
|
+
left: 0,
|
|
46
|
+
right: 0,
|
|
47
|
+
},
|
|
18
48
|
});
|
|
19
49
|
|
|
20
50
|
export const TopCutoffOverlay: React.FC<IProps> = ({
|
|
@@ -39,16 +69,17 @@ export const TopCutoffOverlay: React.FC<IProps> = ({
|
|
|
39
69
|
{children}
|
|
40
70
|
|
|
41
71
|
<View
|
|
42
|
-
style={
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
72
|
+
style={[
|
|
73
|
+
styles.cutoffBlock,
|
|
74
|
+
{
|
|
75
|
+
height: cutoffHeight,
|
|
76
|
+
|
|
77
|
+
backgroundColor: getTopCutoffBackgroundColor(
|
|
78
|
+
screenBackgroundColor,
|
|
79
|
+
themeBackgroundColor
|
|
80
|
+
),
|
|
81
|
+
},
|
|
82
|
+
]}
|
|
52
83
|
/>
|
|
53
84
|
</View>
|
|
54
85
|
);
|
|
@@ -66,7 +66,7 @@ export class AnimationManager {
|
|
|
66
66
|
*
|
|
67
67
|
* @param {object} to contains style to animate and scenes index
|
|
68
68
|
* @param {string} action push|back
|
|
69
|
-
* @param {number} stepsBack number of steps back
|
|
69
|
+
* @param {number} [stepsBack] number of steps back, used by the back action only
|
|
70
70
|
*/
|
|
71
71
|
stateForAction({ to, scenes }, action, stepsBack) {
|
|
72
72
|
let rootIndex = to.index;
|
|
@@ -17,13 +17,14 @@ const fullWidthDimensions = {
|
|
|
17
17
|
type Props = {
|
|
18
18
|
children: any;
|
|
19
19
|
style: any;
|
|
20
|
-
pointerEvents
|
|
21
|
-
overlayStyle
|
|
22
|
-
animating
|
|
20
|
+
pointerEvents?: ViewProps["pointerEvents"];
|
|
21
|
+
overlayStyle?: ViewStyle;
|
|
22
|
+
animating?: boolean;
|
|
23
23
|
contentStyle: ViewStyle;
|
|
24
24
|
pathname: string;
|
|
25
25
|
isActive: boolean;
|
|
26
26
|
screenData: NavigationScreenData;
|
|
27
|
+
screenUniqueId?: string;
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
export function CurrentScreenContextProvider({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { View } from "react-native";
|
|
3
|
-
import { append, compose, identity, tail,
|
|
3
|
+
import { append, compose, identity, tail, update } from "ramda";
|
|
4
4
|
|
|
5
5
|
import { AnimationManager } from "./AnimationManager";
|
|
6
6
|
import { Scene } from "./Scene";
|
|
@@ -18,11 +18,23 @@ export const NAV_ACTION_REPLACE = "REPLACE";
|
|
|
18
18
|
|
|
19
19
|
export const NAV_ACTION_BACK = "POP";
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
const RIVER_SEGMENT_REGEX = /river\//g;
|
|
22
|
+
|
|
23
|
+
// Number of "river/" segments in the route, i.e. its depth in the navigation stack
|
|
24
|
+
function countRiverSegments(route?: string): number {
|
|
25
|
+
return (route?.match(RIVER_SEGMENT_REGEX) || []).length;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// The screen element rendered for the current route
|
|
29
|
+
type SceneChild = React.ReactElement<{
|
|
30
|
+
pathname: string;
|
|
31
|
+
screenData: NavigationScreenData;
|
|
32
|
+
}>;
|
|
33
|
+
|
|
34
|
+
type TransitionerScene = {
|
|
35
|
+
children: SceneChild;
|
|
36
|
+
key: string;
|
|
37
|
+
screenUniqueId: string;
|
|
26
38
|
};
|
|
27
39
|
|
|
28
40
|
/**
|
|
@@ -31,7 +43,7 @@ type SceneProps = {
|
|
|
31
43
|
* @param {Object} children
|
|
32
44
|
* @returns { children: Object, key: string }
|
|
33
45
|
*/
|
|
34
|
-
function prepareScene(children) {
|
|
46
|
+
function prepareScene(children: SceneChild): TransitionerScene {
|
|
35
47
|
return {
|
|
36
48
|
children,
|
|
37
49
|
key: children.props.pathname,
|
|
@@ -45,7 +57,10 @@ function prepareScene(children) {
|
|
|
45
57
|
* @param {any} props Component's props
|
|
46
58
|
* @param {any} state Component's state
|
|
47
59
|
*/
|
|
48
|
-
function scenesForBackTransition(
|
|
60
|
+
function scenesForBackTransition(
|
|
61
|
+
props: Pick<Props, "children">,
|
|
62
|
+
{ scenes }: Pick<State, "scenes">
|
|
63
|
+
): TransitionerScene[] {
|
|
49
64
|
return scenes.length > 1
|
|
50
65
|
? identity(scenes)
|
|
51
66
|
: [prepareScene(props.children), scenes[0]];
|
|
@@ -53,7 +68,8 @@ function scenesForBackTransition(props: SceneProps, { scenes }) {
|
|
|
53
68
|
|
|
54
69
|
type Props = {
|
|
55
70
|
transitionConfig: any;
|
|
56
|
-
|
|
71
|
+
isRTL?: boolean;
|
|
72
|
+
children: SceneChild;
|
|
57
73
|
navigator: {
|
|
58
74
|
previousAction: string;
|
|
59
75
|
currentRoute: string;
|
|
@@ -78,13 +94,12 @@ type Props = {
|
|
|
78
94
|
};
|
|
79
95
|
|
|
80
96
|
type State = {
|
|
81
|
-
animatedValue: any;
|
|
82
97
|
animating: boolean;
|
|
83
98
|
duration: number;
|
|
84
99
|
easing: any;
|
|
85
100
|
from: any;
|
|
86
101
|
to: any;
|
|
87
|
-
scenes:
|
|
102
|
+
scenes: TransitionerScene[];
|
|
88
103
|
};
|
|
89
104
|
|
|
90
105
|
const styles = {
|
|
@@ -92,11 +107,18 @@ const styles = {
|
|
|
92
107
|
} as const;
|
|
93
108
|
|
|
94
109
|
export class TransitionerComponent extends React.PureComponent<Props, State> {
|
|
110
|
+
private animationManager: AnimationManager;
|
|
111
|
+
|
|
112
|
+
private transitionId: number;
|
|
113
|
+
|
|
95
114
|
constructor(props: Props) {
|
|
96
115
|
super(props);
|
|
97
116
|
|
|
98
117
|
this.animationManager = new AnimationManager(props);
|
|
99
118
|
|
|
119
|
+
// Bumped by every animated transition; end callbacks of older ones are ignored
|
|
120
|
+
this.transitionId = 0;
|
|
121
|
+
|
|
100
122
|
this.state = {
|
|
101
123
|
scenes: [prepareScene(props.children)], // starting with index: 0
|
|
102
124
|
...this.animationManager.initialState(),
|
|
@@ -113,29 +135,36 @@ export class TransitionerComponent extends React.PureComponent<Props, State> {
|
|
|
113
135
|
* and trigger push animation with callbacks.
|
|
114
136
|
*/
|
|
115
137
|
pushTransitionStart() {
|
|
138
|
+
const transitionId = ++this.transitionId;
|
|
139
|
+
|
|
116
140
|
this.setState(
|
|
117
141
|
{
|
|
118
|
-
|
|
142
|
+
// Append right after the visible scene: stateForAction(PUSH) animates to.index + 1
|
|
143
|
+
scenes: [
|
|
144
|
+
...this.state.scenes.slice(0, this.state.to.index + 1),
|
|
145
|
+
prepareScene(this.props.children),
|
|
146
|
+
],
|
|
119
147
|
...this.animationManager.stateForAction(this.state, NAV_ACTION_PUSH),
|
|
120
148
|
},
|
|
121
149
|
() => {
|
|
122
|
-
this.animationManager.animate(this.state,
|
|
150
|
+
this.animationManager.animate(this.state, () =>
|
|
151
|
+
this.pushTransitionEnd(transitionId)
|
|
152
|
+
);
|
|
123
153
|
}
|
|
124
154
|
);
|
|
125
155
|
}
|
|
126
156
|
|
|
127
157
|
/**
|
|
128
158
|
* Trigger back animation.
|
|
129
|
-
* The
|
|
159
|
+
* The scenes after the target one are removed in the "backTransitionEnd" callback,
|
|
130
160
|
* only after the animation is complete.
|
|
131
161
|
*/
|
|
132
|
-
backTransitionStart() {
|
|
133
|
-
const
|
|
162
|
+
backTransitionStart(previousRoute: string) {
|
|
163
|
+
const transitionId = ++this.transitionId;
|
|
134
164
|
const currentRoute = this.props.navigator?.currentRoute;
|
|
135
165
|
|
|
136
166
|
const diffLengthRoutes =
|
|
137
|
-
(previousRoute
|
|
138
|
-
(currentRoute?.match(/river\//g) || []).length;
|
|
167
|
+
countRiverSegments(previousRoute) - countRiverSegments(currentRoute);
|
|
139
168
|
|
|
140
169
|
const stepsBack =
|
|
141
170
|
diffLengthRoutes && diffLengthRoutes > 0 ? diffLengthRoutes : 1;
|
|
@@ -151,30 +180,32 @@ export class TransitionerComponent extends React.PureComponent<Props, State> {
|
|
|
151
180
|
},
|
|
152
181
|
() => {
|
|
153
182
|
this.animationManager.animate(this.state, () =>
|
|
154
|
-
this.backTransitionEnd(
|
|
183
|
+
this.backTransitionEnd(transitionId)
|
|
155
184
|
);
|
|
156
185
|
}
|
|
157
186
|
);
|
|
158
187
|
}
|
|
159
188
|
|
|
160
|
-
shouldSkipAnimationForRoute(route) {
|
|
189
|
+
shouldSkipAnimationForRoute(route: string) {
|
|
161
190
|
// We are skipping animations for some routes, likes hooks & the player mainly
|
|
162
191
|
|
|
163
192
|
return route.includes("/playable") || route.includes("/hook");
|
|
164
193
|
}
|
|
165
194
|
|
|
166
|
-
shouldResetStateForRoute(route) {
|
|
195
|
+
shouldResetStateForRoute(route: string) {
|
|
167
196
|
// We are resetting the transitioner state for root routes
|
|
168
197
|
|
|
169
|
-
return (route
|
|
198
|
+
return countRiverSegments(route) === 1;
|
|
170
199
|
}
|
|
171
200
|
|
|
172
|
-
transitionWithoutAnimation(resetState) {
|
|
173
|
-
|
|
201
|
+
transitionWithoutAnimation(resetState?: boolean) {
|
|
202
|
+
// Scenes after the visible one are only leaving (back animation in flight),
|
|
203
|
+
// so the new scene replaces the one being backed to
|
|
204
|
+
const scenes = this.state.scenes.slice(0, this.state.to.index + 1);
|
|
174
205
|
const newScene = prepareScene(this.props.children);
|
|
175
206
|
const isLastSceneHook = scenes[scenes.length - 1].key.startsWith("/hook");
|
|
176
207
|
|
|
177
|
-
let newState
|
|
208
|
+
let newState: Pick<State, "scenes"> | Pick<State, "scenes" | "to">;
|
|
178
209
|
|
|
179
210
|
if (resetState) {
|
|
180
211
|
newState = {
|
|
@@ -242,7 +273,7 @@ export class TransitionerComponent extends React.PureComponent<Props, State> {
|
|
|
242
273
|
break;
|
|
243
274
|
|
|
244
275
|
case NAV_ACTION_BACK: {
|
|
245
|
-
this.backTransitionStart();
|
|
276
|
+
this.backTransitionStart(previousRoute);
|
|
246
277
|
break;
|
|
247
278
|
}
|
|
248
279
|
|
|
@@ -264,20 +295,27 @@ export class TransitionerComponent extends React.PureComponent<Props, State> {
|
|
|
264
295
|
}
|
|
265
296
|
}
|
|
266
297
|
|
|
267
|
-
// Sets state.animating to false
|
|
268
|
-
|
|
298
|
+
// Sets state.animating to false,
|
|
299
|
+
// unless a newer transition has started since this one
|
|
300
|
+
pushTransitionEnd(transitionId: number) {
|
|
301
|
+
if (transitionId !== this.transitionId) return;
|
|
302
|
+
|
|
269
303
|
this.setState({
|
|
270
304
|
animating: false,
|
|
271
305
|
});
|
|
272
306
|
}
|
|
273
307
|
|
|
274
308
|
// Sets state.animating to false
|
|
275
|
-
// and
|
|
276
|
-
|
|
277
|
-
|
|
309
|
+
// and drops every scene after the target one. Reads the latest state,
|
|
310
|
+
// so it's correct however many backs were merged into this animation.
|
|
311
|
+
// Ignored if a newer transition has started since this one
|
|
312
|
+
backTransitionEnd(transitionId: number) {
|
|
313
|
+
if (transitionId !== this.transitionId) return;
|
|
314
|
+
|
|
315
|
+
this.setState(({ scenes, to }) => ({
|
|
278
316
|
animating: false,
|
|
279
|
-
scenes:
|
|
280
|
-
});
|
|
317
|
+
scenes: scenes.slice(0, to.index + 1),
|
|
318
|
+
}));
|
|
281
319
|
}
|
|
282
320
|
|
|
283
321
|
// On initial state, both "to" and "from" point to a single scene
|