@applicaster/zapp-react-native-ui-components 15.0.0-rc.13 → 15.0.0-rc.131
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/BaseFocusable/index.ios.ts +12 -2
- package/Components/Cell/Cell.tsx +14 -3
- package/Components/Cell/CellWithFocusable.tsx +9 -0
- package/Components/Cell/FocusableWrapper.tsx +3 -0
- package/Components/Cell/TvOSCellComponent.tsx +30 -6
- package/Components/Focusable/Focusable.tsx +4 -2
- package/Components/Focusable/FocusableTvOS.tsx +18 -1
- package/Components/Focusable/__tests__/__snapshots__/FocusableTvOS.test.tsx.snap +1 -0
- package/Components/FocusableGroup/FocusableTvOS.tsx +32 -1
- package/Components/GeneralContentScreen/GeneralContentScreen.tsx +39 -28
- package/Components/GeneralContentScreen/__tests__/GeneralContentScreen.test.tsx +104 -0
- package/Components/GeneralContentScreen/utils/__tests__/getScreenDataSource.test.ts +19 -0
- package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +1 -1
- package/Components/GeneralContentScreen/utils/getScreenDataSource.ts +9 -0
- package/Components/GeneralContentScreen/utils/useCurationAPI.ts +22 -6
- package/Components/HandlePlayable/HandlePlayable.tsx +33 -94
- package/Components/HandlePlayable/const.ts +3 -0
- package/Components/HandlePlayable/utils.ts +105 -0
- package/Components/HookRenderer/HookRenderer.tsx +40 -10
- package/Components/HookRenderer/__tests__/HookRenderer.test.tsx +60 -0
- package/Components/Layout/TV/LayoutBackground.tsx +5 -2
- package/Components/Layout/TV/NavBarContainer.tsx +1 -10
- package/Components/Layout/TV/ScreenContainer.tsx +2 -6
- package/Components/Layout/TV/__tests__/__snapshots__/NavBarContainer.test.tsx.snap +7 -12
- package/Components/Layout/TV/__tests__/__snapshots__/ScreenContainer.test.tsx.snap +7 -12
- package/Components/Layout/TV/index.tsx +3 -4
- package/Components/Layout/TV/index.web.tsx +3 -4
- package/Components/LinkHandler/LinkHandler.tsx +2 -2
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/model.test.ts +80 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/placement.test.ts +187 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/selectors.test.ts +45 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/style.test.ts +49 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/model.ts +47 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/placement.ts +170 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/selectors.ts +26 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/style.ts +29 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/types.ts +37 -0
- package/Components/MasterCell/DefaultComponents/BorderContainerView/__tests__/index.test.tsx +16 -1
- package/Components/MasterCell/DefaultComponents/BorderContainerView/index.tsx +30 -2
- package/Components/MasterCell/DefaultComponents/Button.tsx +0 -15
- package/Components/MasterCell/DefaultComponents/Image/Image.android.tsx +5 -1
- package/Components/MasterCell/DefaultComponents/Image/Image.ios.tsx +11 -3
- package/Components/MasterCell/DefaultComponents/Image/Image.web.tsx +9 -1
- package/Components/MasterCell/DefaultComponents/Image/hooks/useImage.ts +15 -14
- package/Components/MasterCell/DefaultComponents/LiveImage/__tests__/prepareEntry.test.ts +352 -0
- package/Components/MasterCell/DefaultComponents/LiveImage/executePreloadHooks.ts +136 -0
- package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +43 -22
- package/Components/MasterCell/DefaultComponents/PressableView.tsx +196 -0
- package/Components/MasterCell/DefaultComponents/SecondaryImage/Image.tsx +40 -39
- package/Components/MasterCell/DefaultComponents/SecondaryImage/__tests__/Image.test.tsx +95 -0
- package/Components/MasterCell/DefaultComponents/SecondaryImage/__tests__/__snapshots__/Image.test.tsx.snap +86 -0
- package/Components/MasterCell/DefaultComponents/SecondaryImage/__tests__/index.test.ts +141 -0
- package/Components/MasterCell/DefaultComponents/SecondaryImage/hooks/__tests__/useGetImageDimensions.test.ts +7 -6
- package/Components/MasterCell/DefaultComponents/SecondaryImage/index.ts +1 -1
- package/Components/MasterCell/DefaultComponents/Text/index.tsx +10 -14
- package/Components/MasterCell/DefaultComponents/index.ts +2 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Asset.ts +46 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Button.ts +126 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ButtonContainerView.ts +23 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Spacer.ts +16 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabel.ts +67 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabelsContainer.ts +32 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +191 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/builders.test.ts +140 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/index.test.ts +222 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/helpers.ts +105 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/index.ts +104 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/__tests__/insertButtons.test.ts +118 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/index.ts +73 -0
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/__tests__/index.test.ts +86 -0
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/index.ts +35 -48
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/__tests__/getPluginIdentifier.test.ts +115 -29
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/index.ts +39 -144
- package/Components/MasterCell/elementMapper.tsx +1 -0
- package/Components/MasterCell/hoc/__tests__/withAsyncRender.test.tsx +219 -0
- package/Components/MasterCell/hoc/withAsyncRender.tsx +9 -7
- package/Components/MasterCell/index.tsx +2 -0
- package/Components/MasterCell/utils/__tests__/resolveColor.test.js +82 -3
- package/Components/MasterCell/utils/index.ts +61 -31
- package/Components/MeasurmentsPortal/MeasurementsPortal.tsx +102 -87
- package/Components/MeasurmentsPortal/__tests__/MeasurementsPortal.test.tsx +355 -0
- package/Components/OfflineHandler/NotificationView/NotificationView.lg.tsx +17 -9
- package/Components/OfflineHandler/NotificationView/NotificationView.samsung.tsx +16 -8
- package/Components/OfflineHandler/NotificationView/NotificationView.tsx +2 -2
- package/Components/OfflineHandler/NotificationView/__tests__/index.test.tsx +17 -18
- package/Components/OfflineHandler/NotificationView/utils.ts +34 -0
- package/Components/OfflineHandler/__tests__/index.test.tsx +27 -18
- package/Components/PlayerContainer/PlayerContainer.tsx +43 -64
- package/Components/PlayerImageBackground/index.tsx +3 -22
- package/Components/PreloaderWrapper/__tests__/index.test.tsx +26 -0
- package/Components/PreloaderWrapper/index.tsx +15 -0
- package/Components/River/ComponentsMap/ComponentsMap.tsx +16 -0
- package/Components/River/ComponentsMap/hooks/__tests__/useLoadingState.test.ts +1 -1
- package/Components/River/RefreshControl.tsx +36 -13
- package/Components/River/RiverItem.tsx +26 -20
- package/Components/River/TV/River.tsx +31 -14
- package/Components/River/TV/index.tsx +8 -4
- package/Components/River/TV/utils/__tests__/toStringOrEmpty.test.ts +30 -0
- package/Components/River/TV/utils/index.ts +4 -0
- package/Components/River/TV/withFocusableGroupForContent.tsx +71 -0
- package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +2 -0
- package/Components/River/__tests__/componentsMap.test.js +38 -0
- package/Components/Screen/TV/index.web.tsx +4 -2
- package/Components/Screen/__tests__/Screen.test.tsx +66 -42
- package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +68 -44
- package/Components/Screen/hooks.ts +75 -6
- package/Components/Screen/index.tsx +9 -4
- package/Components/Screen/navigationHandler.ts +49 -24
- package/Components/Screen/orientationHandler.ts +10 -13
- package/Components/ScreenFeedLoader/ScreenFeedLoader.tsx +46 -0
- package/Components/ScreenFeedLoader/__tests__/ScreenFeedLoader.test.tsx +94 -0
- package/Components/ScreenFeedLoader/index.ts +1 -0
- package/Components/ScreenResolver/__tests__/screenResolver.test.js +24 -0
- package/Components/ScreenResolver/hooks/index.ts +3 -0
- package/Components/ScreenResolver/hooks/useGetComponent.ts +15 -0
- package/Components/ScreenResolver/hooks/useScreenComponentResolver.tsx +90 -0
- package/Components/ScreenResolver/index.tsx +15 -111
- package/Components/ScreenResolver/utils/__tests__/getScreenTypeProps.test.ts +45 -0
- package/Components/ScreenResolver/utils/getScreenTypeProps.ts +43 -0
- package/Components/ScreenResolver/utils/index.ts +1 -0
- package/Components/ScreenResolver/withDefaultScreenContext.tsx +16 -0
- package/Components/ScreenResolverFeedProvider/ScreenResolverFeedProvider.tsx +25 -0
- package/Components/ScreenResolverFeedProvider/__tests__/ScreenResolverFeedProvider.test.tsx +44 -0
- package/Components/ScreenResolverFeedProvider/index.ts +1 -0
- package/Components/ScreenRevealManager/ScreenRevealManager.ts +40 -8
- package/Components/ScreenRevealManager/__tests__/ScreenRevealManager.test.ts +86 -69
- package/Components/ScreenRevealManager/withScreenRevealManager.tsx +44 -26
- package/Components/Tabs/TV/Tabs.tsx +20 -3
- package/Components/Tabs/TabContent.tsx +7 -4
- package/Components/Transitioner/Scene.tsx +10 -3
- package/Components/Transitioner/index.js +3 -3
- package/Components/VideoLive/LiveImageManager.ts +199 -54
- package/Components/VideoLive/PlayerLiveImageComponent.tsx +31 -33
- package/Components/VideoLive/__tests__/PlayerLiveImageComponent.test.tsx +2 -17
- package/Components/VideoLive/__tests__/__snapshots__/PlayerLiveImageComponent.test.tsx.snap +1 -0
- package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +118 -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/__tests__/useDelayedPlayerDetails.test.ts +15 -7
- 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 +19 -9
- package/Components/Viewport/ViewportAware/__tests__/viewportAware.test.js +0 -2
- package/Components/Viewport/ViewportAware/index.tsx +16 -7
- package/Components/Viewport/ViewportEvents/__tests__/viewportEvents.test.js +1 -1
- package/Components/ZappUIComponent/index.tsx +12 -6
- package/Components/default-cell-renderer/viewTrees/mobile/index.ts +0 -3
- package/Components/index.js +1 -1
- package/Contexts/ScreenContext/__tests__/index.test.tsx +57 -0
- package/Contexts/ScreenContext/index.tsx +71 -19
- package/Contexts/ScreenTrackedViewPositionsContext/__tests__/index.test.tsx +1 -1
- package/Contexts/ZappHookModalContext/index.tsx +37 -61
- package/Contexts/ZappPipesContext/ZappPipesContextFactory.tsx +18 -7
- package/Contexts/index.ts +0 -2
- package/Decorators/Analytics/index.tsx +6 -5
- package/Decorators/ConfigurationWrapper/__tests__/__snapshots__/withConfigurationProvider.test.tsx.snap +1 -0
- package/Decorators/ConfigurationWrapper/const.ts +1 -0
- package/Decorators/ZappPipesDataConnector/ResolverSelector.tsx +25 -7
- package/Decorators/ZappPipesDataConnector/__tests__/ResolverSelector.test.tsx +212 -5
- package/Decorators/ZappPipesDataConnector/__tests__/UrlFeedResolver.test.tsx +39 -21
- package/Decorators/ZappPipesDataConnector/__tests__/zappPipesDataConnector.test.js +1 -1
- package/Decorators/ZappPipesDataConnector/index.tsx +2 -2
- package/Decorators/ZappPipesDataConnector/resolvers/StaticFeedResolver.tsx +1 -1
- package/Decorators/ZappPipesDataConnector/resolvers/UrlFeedResolver.tsx +18 -7
- package/Helpers/DataSourceHelper/__tests__/itemLimitForData.test.ts +80 -0
- package/Helpers/DataSourceHelper/index.ts +19 -0
- package/events/index.ts +3 -0
- package/events/scrollEndReached.ts +15 -0
- package/index.d.ts +7 -0
- package/package.json +6 -5
- package/Components/MasterCell/DefaultComponents/Text/utils/__tests__/withAdjustedLineHeight.test.ts +0 -46
- package/Components/MasterCell/DefaultComponents/Text/utils/index.ts +0 -21
- package/Components/PlayerContainer/ErrorDisplay/ErrorDisplay.tsx +0 -57
- package/Components/PlayerContainer/ErrorDisplay/index.ts +0 -9
- package/Components/River/TV/withTVEventHandler.tsx +0 -27
- 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
- package/Helpers/DataSourceHelper/index.js +0 -19
- /package/Components/HookRenderer/{index.tsx → index.ts} +0 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Dimensions, DimensionValue, Platform, ViewStyle } from "react-native";
|
|
2
|
+
import { Edge } from "react-native-safe-area-context";
|
|
3
|
+
|
|
4
|
+
export type DimensionsT = {
|
|
5
|
+
width: number | string;
|
|
6
|
+
height: number | string | undefined;
|
|
7
|
+
aspectRatio?: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type Configuration = {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
tablet_landscape_sidebar_width?: string;
|
|
13
|
+
tablet_landscape_player_container_background_color?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// This is safe, remembering screen dimensions once as they do not change during runtime
|
|
17
|
+
// TODO: consider sharing screen orientation as a shared function for the app
|
|
18
|
+
const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get("screen");
|
|
19
|
+
|
|
20
|
+
export const getWindowDimensions = () => {
|
|
21
|
+
const { width, height } = Dimensions.get("window");
|
|
22
|
+
|
|
23
|
+
return { width, height };
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const getMaxWindowDimension = () => {
|
|
27
|
+
const { width, height } = getWindowDimensions();
|
|
28
|
+
|
|
29
|
+
return Math.max(width, height);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const getMinWindowDimension = () => {
|
|
33
|
+
const { width, height } = getWindowDimensions();
|
|
34
|
+
|
|
35
|
+
return Math.min(width, height);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const getScreenAspectRatio = () => {
|
|
39
|
+
const longEdge = Math.max(SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
40
|
+
const shortEdge = Math.min(SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
41
|
+
|
|
42
|
+
return longEdge / shortEdge;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const getEdges = (
|
|
46
|
+
isTablet: boolean,
|
|
47
|
+
isInlineModal: boolean
|
|
48
|
+
): readonly Edge[] => {
|
|
49
|
+
if (isTablet) {
|
|
50
|
+
return ["top"];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!isInlineModal && Platform.OS === "android") {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return ["top"];
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const getBaseDimensions = (
|
|
61
|
+
isInlineModal: boolean,
|
|
62
|
+
isTabletLandscape: boolean,
|
|
63
|
+
tabletWidth: DimensionValue
|
|
64
|
+
): ViewStyle => ({
|
|
65
|
+
width: isInlineModal && isTabletLandscape ? tabletWidth : "100%",
|
|
66
|
+
height: undefined,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export const calculateAspectRatio = (
|
|
70
|
+
isInlineModal: boolean,
|
|
71
|
+
pip?: boolean
|
|
72
|
+
): number => {
|
|
73
|
+
return !isInlineModal && !pip ? getScreenAspectRatio() : 16 / 9;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const getPlayerDimensions = (
|
|
77
|
+
baseDimensions: ViewStyle,
|
|
78
|
+
aspectRatio: number
|
|
79
|
+
): ViewStyle => ({
|
|
80
|
+
...(baseDimensions as any),
|
|
81
|
+
width: baseDimensions.width,
|
|
82
|
+
aspectRatio,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export const getContainerDimensions = (
|
|
86
|
+
baseDimensions: ViewStyle,
|
|
87
|
+
aspectRatio?: string | number
|
|
88
|
+
): ViewStyle => ({
|
|
89
|
+
...baseDimensions,
|
|
90
|
+
aspectRatio,
|
|
91
|
+
});
|
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
import { mergeRight } from "ramda";
|
|
2
2
|
import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
useAppSelector,
|
|
5
|
+
useContentTypes,
|
|
6
|
+
} from "@applicaster/zapp-react-native-redux/hooks";
|
|
4
7
|
import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation";
|
|
5
8
|
import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks/device/useIsTablet";
|
|
6
9
|
import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils";
|
|
10
|
+
import { create } from "zustand";
|
|
11
|
+
import { useRivers } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
12
|
+
import { selectPluginConfigurationsByPluginId } from "@applicaster/zapp-react-native-redux";
|
|
7
13
|
|
|
8
14
|
export const useConfiguration = () => {
|
|
9
15
|
const {
|
|
10
16
|
videoModalState: { item },
|
|
11
17
|
} = useNavigation();
|
|
12
18
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
"contentTypes",
|
|
16
|
-
"pluginConfigurations",
|
|
17
|
-
]);
|
|
19
|
+
const rivers = useRivers();
|
|
20
|
+
const contentTypes = useContentTypes();
|
|
18
21
|
|
|
19
22
|
const targetScreenId = contentTypes?.[item?.type?.value]?.screen_id;
|
|
20
23
|
const targetScreenConfiguration = rivers?.[targetScreenId];
|
|
21
24
|
|
|
22
|
-
const
|
|
23
|
-
|
|
25
|
+
const { configuration_json } = useAppSelector((state) =>
|
|
26
|
+
selectPluginConfigurationsByPluginId(state, targetScreenConfiguration?.type)
|
|
27
|
+
);
|
|
24
28
|
|
|
25
29
|
const playerPluginConfig = playerManager.getPluginConfiguration();
|
|
26
30
|
|
|
27
31
|
const config = mergeRight(playerPluginConfig, {
|
|
28
|
-
...
|
|
32
|
+
...configuration_json,
|
|
29
33
|
...targetScreenConfiguration?.general,
|
|
30
34
|
...targetScreenConfiguration?.styles,
|
|
31
35
|
});
|
|
@@ -52,6 +56,12 @@ export const useConfiguration = () => {
|
|
|
52
56
|
};
|
|
53
57
|
};
|
|
54
58
|
|
|
59
|
+
export const useAnimationStateStore = create<{
|
|
60
|
+
isAnimationInProgress: boolean;
|
|
61
|
+
}>(() => ({
|
|
62
|
+
isAnimationInProgress: false,
|
|
63
|
+
}));
|
|
64
|
+
|
|
55
65
|
const fullSize = {
|
|
56
66
|
width: "100%",
|
|
57
67
|
height: "100%",
|
|
@@ -32,7 +32,7 @@ function getTestDimensions(testDimensions) {
|
|
|
32
32
|
return (process.env.NODE_ENV === "test" && testDimensions) || null;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
function ViewportAwareComponent(props: Props,
|
|
35
|
+
function ViewportAwareComponent(props: Props, forwardedRef) {
|
|
36
36
|
const viewportEvents = useViewportEventsContext();
|
|
37
37
|
|
|
38
38
|
const {
|
|
@@ -47,13 +47,22 @@ function ViewportAwareComponent(props: Props, ref) {
|
|
|
47
47
|
getTestDimensions(testDimensions) || initialDimensions
|
|
48
48
|
);
|
|
49
49
|
|
|
50
|
+
const localRef = React.useRef(null);
|
|
51
|
+
|
|
50
52
|
const [viewportChangeEvent, setViewportChangeEvent] = React.useState(null);
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
const assignRef = React.useCallback(
|
|
55
|
+
(_ref) => {
|
|
56
|
+
localRef.current = _ref;
|
|
57
|
+
|
|
58
|
+
if (typeof forwardedRef === "function") {
|
|
59
|
+
forwardedRef(_ref);
|
|
60
|
+
} else if (forwardedRef) {
|
|
61
|
+
forwardedRef.current = _ref;
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
[forwardedRef]
|
|
65
|
+
);
|
|
57
66
|
|
|
58
67
|
const checkInViewport = (viewportChangeEvent, layoutEvent) => {
|
|
59
68
|
const inVerticalViewport = Utils.isInViewport(
|
|
@@ -94,7 +103,7 @@ function ViewportAwareComponent(props: Props, ref) {
|
|
|
94
103
|
const onViewportChange = (viewportChangeEvent) => {
|
|
95
104
|
setViewportChangeEvent(viewportChangeEvent);
|
|
96
105
|
|
|
97
|
-
const nodeHandle = findNodeHandle(
|
|
106
|
+
const nodeHandle = findNodeHandle(localRef.current);
|
|
98
107
|
|
|
99
108
|
if (!nodeHandle) {
|
|
100
109
|
return;
|
|
@@ -144,12 +144,23 @@ New signature: {Component, ErrorComponent, LoadingComponent, options}`
|
|
|
144
144
|
[props, parent]
|
|
145
145
|
);
|
|
146
146
|
|
|
147
|
+
const hasError = !!zappPipesData?.error;
|
|
148
|
+
|
|
147
149
|
React.useEffect(() => {
|
|
148
150
|
if (!skipOnLoadFinished && !isLoading) {
|
|
149
151
|
onLoadFinished();
|
|
150
152
|
}
|
|
151
153
|
}, [isLoading]);
|
|
152
154
|
|
|
155
|
+
React.useEffect(() => {
|
|
156
|
+
if (hasError) {
|
|
157
|
+
onLoadFailed?.({
|
|
158
|
+
error: zappPipesData.error,
|
|
159
|
+
index: componentIndex,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}, [hasError, componentIndex, onLoadFailed, zappPipesData?.error]);
|
|
163
|
+
|
|
153
164
|
if (isDataSourceEmpty(props) && allowsEmptyDataSource) {
|
|
154
165
|
return RenderComponent(Component, componentProps);
|
|
155
166
|
}
|
|
@@ -158,12 +169,7 @@ New signature: {Component, ErrorComponent, LoadingComponent, options}`
|
|
|
158
169
|
return RenderComponent(LoadingComponent || Placeholder, componentProps);
|
|
159
170
|
}
|
|
160
171
|
|
|
161
|
-
if (
|
|
162
|
-
onLoadFailed?.({
|
|
163
|
-
error: zappPipesData.error,
|
|
164
|
-
index: componentIndex,
|
|
165
|
-
});
|
|
166
|
-
|
|
172
|
+
if (hasError) {
|
|
167
173
|
return RenderComponent(ErrorComponent, componentProps);
|
|
168
174
|
}
|
|
169
175
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DefaultCell } from "./DefaultCell";
|
|
2
2
|
import { GridCell } from "./GridCell";
|
|
3
3
|
import { HeroCell } from "./HeroCell";
|
|
4
|
-
// import { ScreenSelectorLabel } from "./ScreenSelectorLabel";
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Return a view tree ready to be injected with styles etc. Mapping is done
|
|
@@ -15,8 +14,6 @@ export function viewTreeResolver({ component_type }) {
|
|
|
15
14
|
switch (component_type) {
|
|
16
15
|
case "hero":
|
|
17
16
|
return HeroCell;
|
|
18
|
-
// case "screen_picker":
|
|
19
|
-
// return ScreenSelectorLabel;
|
|
20
17
|
case "grid":
|
|
21
18
|
return GridCell;
|
|
22
19
|
case "horizontal_list":
|
package/Components/index.js
CHANGED
|
@@ -10,7 +10,7 @@ export { ContentScreen } from "./ContentScreen";
|
|
|
10
10
|
|
|
11
11
|
export { TextInputTv } from "./TextInputTv";
|
|
12
12
|
|
|
13
|
-
export { HookRenderer } from "./HookRenderer";
|
|
13
|
+
export { HookRenderer } from "./HookRenderer/HookRenderer";
|
|
14
14
|
|
|
15
15
|
export { Touchable } from "./Touchable";
|
|
16
16
|
|
|
@@ -2,6 +2,32 @@ import { render } from "@testing-library/react-native";
|
|
|
2
2
|
import { ScreenContext, ScreenContextProvider, withScreenContext } from "../";
|
|
3
3
|
import React from "react";
|
|
4
4
|
|
|
5
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks", () => ({
|
|
6
|
+
useCurrentScreenData: jest.fn(() => ({})),
|
|
7
|
+
useNavigation: jest.fn(() => ({
|
|
8
|
+
data: {},
|
|
9
|
+
modalData: null,
|
|
10
|
+
videoModalState: {},
|
|
11
|
+
canGoBack: jest.fn(() => false),
|
|
12
|
+
})),
|
|
13
|
+
useRoute: jest.fn(() => ({ screenData: null })),
|
|
14
|
+
isNavBarVisible: jest.fn(() => true),
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
jest.mock(
|
|
18
|
+
"@applicaster/zapp-react-native-ui-components/Contexts/ModalNavigationContext",
|
|
19
|
+
() => ({
|
|
20
|
+
useModalNavigationContext: jest.fn(() => false),
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
jest.mock(
|
|
25
|
+
"@applicaster/zapp-react-native-ui-components/Contexts/NestedNavigationContext",
|
|
26
|
+
() => ({
|
|
27
|
+
useNestedNavigationContext: jest.fn(() => false),
|
|
28
|
+
})
|
|
29
|
+
);
|
|
30
|
+
|
|
5
31
|
describe("ScreenContext", () => {
|
|
6
32
|
describe("ScreneContext context", () => {
|
|
7
33
|
it("should return the context", () => {
|
|
@@ -13,6 +39,37 @@ describe("ScreenContext", () => {
|
|
|
13
39
|
it("should return the provider", () => {
|
|
14
40
|
expect(ScreenContextProvider).toBeDefined();
|
|
15
41
|
});
|
|
42
|
+
|
|
43
|
+
it("recreates _feedStore when pathname changes", () => {
|
|
44
|
+
const contexts = [];
|
|
45
|
+
|
|
46
|
+
const CaptureContext = () => {
|
|
47
|
+
const context = React.useContext(ScreenContext);
|
|
48
|
+
contexts.push(context);
|
|
49
|
+
|
|
50
|
+
return null;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const { rerender } = render(
|
|
54
|
+
<ScreenContextProvider pathname="/screen-a">
|
|
55
|
+
<CaptureContext />
|
|
56
|
+
</ScreenContextProvider>
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const first = contexts[contexts.length - 1];
|
|
60
|
+
first._feedStore.setState({ screenFeed: "screen-a" });
|
|
61
|
+
|
|
62
|
+
rerender(
|
|
63
|
+
<ScreenContextProvider pathname="/screen-b">
|
|
64
|
+
<CaptureContext />
|
|
65
|
+
</ScreenContextProvider>
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const second = contexts[contexts.length - 1];
|
|
69
|
+
|
|
70
|
+
expect(second._feedStore).not.toBe(first._feedStore);
|
|
71
|
+
expect(second._feedStore.getState()).toEqual({});
|
|
72
|
+
});
|
|
16
73
|
});
|
|
17
74
|
|
|
18
75
|
describe("withScreenContext", () => {
|
|
@@ -16,6 +16,7 @@ import { useNestedNavigationContext } from "@applicaster/zapp-react-native-ui-co
|
|
|
16
16
|
import { create } from "zustand";
|
|
17
17
|
import { subscribeWithSelector } from "zustand/middleware";
|
|
18
18
|
import { useShallow } from "zustand/react/shallow";
|
|
19
|
+
|
|
19
20
|
import { Animated } from "react-native";
|
|
20
21
|
|
|
21
22
|
interface NavBarStoreState {
|
|
@@ -29,6 +30,8 @@ interface NavBarStoreState {
|
|
|
29
30
|
scrollState: number;
|
|
30
31
|
contentPosition: string;
|
|
31
32
|
scrollYAnimated: Animated.Value;
|
|
33
|
+
hideOnScrollAnimated: Animated.Value;
|
|
34
|
+
hideOnScroll: boolean;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
interface NavBarState {
|
|
@@ -62,35 +65,62 @@ const createStateStore = () =>
|
|
|
62
65
|
);
|
|
63
66
|
|
|
64
67
|
const createStore = () =>
|
|
65
|
-
create
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
68
|
+
create(
|
|
69
|
+
subscribeWithSelector<NavBarStoreState>((set) => ({
|
|
70
|
+
title: "",
|
|
71
|
+
summary: "",
|
|
72
|
+
visible: true,
|
|
73
|
+
height: 0,
|
|
74
|
+
scrollState: 0,
|
|
75
|
+
contentPosition: "",
|
|
76
|
+
scrollYAnimated: new Animated.Value(0),
|
|
77
|
+
hideOnScrollAnimated: new Animated.Value(0),
|
|
78
|
+
hideOnScroll: false,
|
|
79
|
+
setTitle(title) {
|
|
80
|
+
set({ title });
|
|
81
|
+
},
|
|
82
|
+
setSummary(summary) {
|
|
83
|
+
set({ summary });
|
|
84
|
+
},
|
|
85
|
+
setVisible(visible) {
|
|
86
|
+
set({ visible });
|
|
87
|
+
},
|
|
88
|
+
}))
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const createScreenComponentsStore = () =>
|
|
92
|
+
create(subscribeWithSelector<Record<string, unknown>>((_) => ({})));
|
|
93
|
+
|
|
94
|
+
const createFeedStore = () =>
|
|
95
|
+
create(subscribeWithSelector<Record<string, unknown>>((_) => ({})));
|
|
83
96
|
|
|
84
97
|
type ScreenContextType = {
|
|
85
98
|
_navBarStore: ReturnType<typeof createStore>;
|
|
86
99
|
_stateStore: ReturnType<typeof createStateStore>;
|
|
100
|
+
_feedStore: ReturnType<typeof createFeedStore>;
|
|
87
101
|
navBar: NavBarState;
|
|
88
102
|
legacyFormatScreenData: LegacyNavigationScreenData | null;
|
|
103
|
+
/**
|
|
104
|
+
* Zustand store for component-level state within a screen.
|
|
105
|
+
*
|
|
106
|
+
* **Purpose:** Persists state across component mount/unmount cycles (e.g., during virtualization)
|
|
107
|
+
* and enables state sharing between components using the same key within the same screen.
|
|
108
|
+
*
|
|
109
|
+
* **Lifecycle:** Tied to the screen/route — recreated on each route change.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* // Used by useComponentScreenState hook:
|
|
113
|
+
* const store = useScreenContextV2()._componentStateStore;
|
|
114
|
+
* store.setState({ 'my-key': value });
|
|
115
|
+
* const value = store.getState()['my-key'];
|
|
116
|
+
*/
|
|
117
|
+
_componentStateStore: ReturnType<typeof createScreenComponentsStore>;
|
|
89
118
|
};
|
|
90
119
|
|
|
91
120
|
export const ScreenContext = createContext<ScreenContextType>({
|
|
92
121
|
_stateStore: createStateStore(),
|
|
93
122
|
_navBarStore: createStore(),
|
|
123
|
+
_feedStore: createFeedStore(),
|
|
94
124
|
navBar: {
|
|
95
125
|
visible: true,
|
|
96
126
|
title: "",
|
|
@@ -100,6 +130,7 @@ export const ScreenContext = createContext<ScreenContextType>({
|
|
|
100
130
|
setSummary: (_subtitle) => void 0,
|
|
101
131
|
},
|
|
102
132
|
legacyFormatScreenData: {} as LegacyNavigationScreenData,
|
|
133
|
+
_componentStateStore: createScreenComponentsStore(),
|
|
103
134
|
});
|
|
104
135
|
|
|
105
136
|
export function ScreenContextProvider({
|
|
@@ -131,6 +162,10 @@ export function ScreenContextProvider({
|
|
|
131
162
|
null
|
|
132
163
|
);
|
|
133
164
|
|
|
165
|
+
const screenFeedStoreRef = useRef<null | ReturnType<typeof createFeedStore>>(
|
|
166
|
+
null
|
|
167
|
+
);
|
|
168
|
+
|
|
134
169
|
const getScreenState = useCallback(() => {
|
|
135
170
|
if (screenStateRef.current !== null) {
|
|
136
171
|
return screenStateRef.current;
|
|
@@ -153,6 +188,21 @@ export function ScreenContextProvider({
|
|
|
153
188
|
return navBarState;
|
|
154
189
|
}, []);
|
|
155
190
|
|
|
191
|
+
// Assign feed store to ref to persist it across re-renders, but recreate on pathname change
|
|
192
|
+
const screenFeedStore = useMemo(() => createFeedStore(), [pathname]);
|
|
193
|
+
|
|
194
|
+
if (screenFeedStoreRef.current !== screenFeedStore) {
|
|
195
|
+
screenFeedStoreRef.current = screenFeedStore;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Component state store - recreated when pathname changes (route change).
|
|
199
|
+
// Unlike _navBarStore and _stateStore (cached via refs), this store
|
|
200
|
+
// resets only when pathname changes to provide a clean state for the new route.
|
|
201
|
+
const componentStateStore = useMemo(
|
|
202
|
+
() => createScreenComponentsStore(),
|
|
203
|
+
[pathname]
|
|
204
|
+
);
|
|
205
|
+
|
|
156
206
|
const screenNavBarState = getScreenNavBarState()(
|
|
157
207
|
useShallow((state) => ({
|
|
158
208
|
visible: state.visible,
|
|
@@ -203,10 +253,12 @@ export function ScreenContextProvider({
|
|
|
203
253
|
() => ({
|
|
204
254
|
_navBarStore: getScreenNavBarState(),
|
|
205
255
|
_stateStore: getScreenState(),
|
|
256
|
+
_feedStore: screenFeedStoreRef.current,
|
|
206
257
|
navBar: navBarState,
|
|
207
258
|
legacyFormatScreenData: routeScreenData,
|
|
259
|
+
_componentStateStore: componentStateStore,
|
|
208
260
|
}),
|
|
209
|
-
[navBarState, screenData, routeScreenData]
|
|
261
|
+
[navBarState, screenData, routeScreenData, componentStateStore]
|
|
210
262
|
)}
|
|
211
263
|
>
|
|
212
264
|
{children}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { create } from "zustand";
|
|
2
2
|
|
|
3
3
|
type HookModalState = {
|
|
4
4
|
path: string;
|
|
@@ -10,11 +10,12 @@ export type HookModalContextT = {
|
|
|
10
10
|
setIsHooksExecutionInProgress: (hookExecutionState?: boolean) => void;
|
|
11
11
|
isRunningInBackground: boolean;
|
|
12
12
|
isPresentationFullScreen: boolean;
|
|
13
|
-
setIsRunningInBackground: (
|
|
14
|
-
setIsPresentingFullScreen: (
|
|
13
|
+
setIsRunningInBackground: () => void;
|
|
14
|
+
setIsPresentingFullScreen: () => void;
|
|
15
15
|
state: HookModalState;
|
|
16
16
|
setState: (state: HookModalState) => void;
|
|
17
17
|
resetState: () => void;
|
|
18
|
+
hookPresentationMode: HookPresentationMode;
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
const initialState = {
|
|
@@ -24,68 +25,43 @@ const initialState = {
|
|
|
24
25
|
|
|
25
26
|
type HookPresentationMode = "background" | "fullScreen";
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
isRunningInBackground: null,
|
|
31
|
-
setIsRunningInBackground: () => {},
|
|
32
|
-
setIsPresentingFullScreen: () => {},
|
|
33
|
-
isPresentationFullScreen: null,
|
|
28
|
+
// Use useZappHookModalStore() in React components (hooks)
|
|
29
|
+
// Use zappHookModalStore.getState() in non-React functions (utility functions, etc.)
|
|
30
|
+
export const useZappHookModalStore = create<HookModalContextT>()((set) => ({
|
|
34
31
|
state: initialState,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const Provider = ({ children }: { children: React.ReactNode }) => {
|
|
40
|
-
const [state, setState] = React.useState<HookModalState>(initialState);
|
|
41
|
-
|
|
42
|
-
const [hookPresentationMode, setHookPresentationMode] =
|
|
43
|
-
React.useState<HookPresentationMode>(null);
|
|
44
|
-
|
|
45
|
-
const resetState = useCallback(() => {
|
|
46
|
-
setState(initialState);
|
|
47
|
-
}, [setState]);
|
|
48
|
-
|
|
49
|
-
const [isHooksExecutionInProgress, setIsHooksExecutionInProgress] =
|
|
50
|
-
React.useState(false);
|
|
32
|
+
isHooksExecutionInProgress: false,
|
|
33
|
+
hookPresentationMode: null as HookPresentationMode,
|
|
34
|
+
isRunningInBackground: false,
|
|
35
|
+
isPresentationFullScreen: false,
|
|
51
36
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
37
|
+
setState: (newState: HookModalState) => {
|
|
38
|
+
set({ state: newState });
|
|
39
|
+
},
|
|
55
40
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
41
|
+
setIsHooksExecutionInProgress: (hookExecutionState?: boolean) => {
|
|
42
|
+
set({ isHooksExecutionInProgress: hookExecutionState ?? false });
|
|
43
|
+
},
|
|
59
44
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
isHooksExecutionInProgress,
|
|
68
|
-
setIsHooksExecutionInProgress,
|
|
69
|
-
state,
|
|
70
|
-
setState,
|
|
71
|
-
resetState,
|
|
72
|
-
}}
|
|
73
|
-
>
|
|
74
|
-
{children}
|
|
75
|
-
</ReactContext.Provider>
|
|
76
|
-
);
|
|
77
|
-
};
|
|
45
|
+
setIsRunningInBackground: () => {
|
|
46
|
+
set({
|
|
47
|
+
hookPresentationMode: "background",
|
|
48
|
+
isRunningInBackground: true,
|
|
49
|
+
isPresentationFullScreen: false,
|
|
50
|
+
});
|
|
51
|
+
},
|
|
78
52
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
};
|
|
53
|
+
setIsPresentingFullScreen: () => {
|
|
54
|
+
set({
|
|
55
|
+
hookPresentationMode: "fullScreen",
|
|
56
|
+
isRunningInBackground: false,
|
|
57
|
+
isPresentationFullScreen: true,
|
|
58
|
+
});
|
|
59
|
+
},
|
|
87
60
|
|
|
88
|
-
|
|
89
|
-
};
|
|
61
|
+
resetState: () => {
|
|
62
|
+
set({ state: initialState });
|
|
63
|
+
},
|
|
64
|
+
}));
|
|
90
65
|
|
|
91
|
-
|
|
66
|
+
// Export an alias for clearer non-React usage (utility functions, etc.)
|
|
67
|
+
export const zappHookModalStore = useZappHookModalStore;
|