@applicaster/zapp-react-native-ui-components 16.0.0-alpha.8047301539 → 16.0.0-alpha.8154281859
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/CellRendererResolver/index.ts +1 -1
- package/Components/GeneralContentScreen/GeneralContentScreenHookAdapter.tsx +9 -5
- package/Components/GeneralContentScreen/__tests__/GeneralContentScreenHookAdapter.test.tsx +4 -1
- package/Components/GeneralContentScreen/__tests__/HookContentFocusGroup.web.test.tsx +91 -0
- package/Components/GeneralContentScreen/hookAdapter/networkService.ts +1 -2
- package/Components/GeneralContentScreen/hookAdapter/runInBackground.ts +2 -7
- package/Components/GeneralContentScreen/hookAdapter/validationHelper.ts +5 -5
- package/Components/GeneralContentScreen/hookFocus/index.tsx +13 -0
- package/Components/GeneralContentScreen/hookFocus/index.web.tsx +69 -0
- package/Components/Layout/FullWidthRow.tsx +38 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/placement.test.ts +47 -21
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/placement.ts +34 -6
- package/Components/MasterCell/DefaultComponents/ImageContainer/index.tsx +5 -3
- package/Components/MasterCell/DefaultComponents/PressableView.tsx +29 -9
- package/Components/MasterCell/DefaultComponents/Text/hooks/useText.ts +4 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ActionButton.tsx +154 -100
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/AssetComponent.tsx +15 -4
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Button.ts +56 -22
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Spacer.ts +6 -4
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabelsContainer.ts +3 -1
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +32 -21
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/index.test.ts +15 -4
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/index.ts +23 -16
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/__tests__/insertButtons.test.ts +8 -3
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/index.ts +2 -2
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/__tests__/insertButtonsBetweenLabels.test.ts +45 -13
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/index.ts +2 -2
- package/Components/MasterCell/contexts/PressedStateContext.ts +3 -0
- package/Components/MasterCell/dataAdapter.ts +15 -5
- package/Components/MasterCell/hooks/index.ts +2 -0
- package/Components/MasterCell/hooks/usePressedState.ts +4 -0
- package/Components/MasterCell/index.tsx +30 -5
- package/Components/MasterCell/utils/__tests__/resolveColor.test.js +169 -132
- package/Components/MasterCell/utils/__tests__/resolveColorForProp.test.js +92 -0
- package/Components/MasterCell/utils/index.ts +85 -46
- package/Components/ModalComponent/AudioPlayer/Components/Action.tsx +332 -0
- package/Components/ModalComponent/AudioPlayer/Components/Button.tsx +402 -0
- package/Components/ModalComponent/AudioPlayer/Components/Header.tsx +811 -0
- package/Components/ModalComponent/AudioPlayer/Components/Input.tsx +671 -0
- package/Components/ModalComponent/AudioPlayer/Components/Item.tsx +878 -0
- package/Components/ModalComponent/AudioPlayer/Components/index.ts +9 -0
- package/Components/ModalComponent/BottomSheetModalContent.tsx +34 -18
- package/Components/OfflineHandler/__tests__/__snapshots__/index.test.tsx.snap +4 -85
- package/Components/OfflineHandler/__tests__/index.test.tsx +78 -18
- package/Components/OfflineHandler/hooks.ts +123 -0
- package/Components/OfflineHandler/index.tsx +51 -73
- package/Components/OfflineHandler/utils/index.ts +1 -13
- package/Components/PlayerContainer/PlayerContainer.tsx +9 -3
- package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +284 -0
- package/Components/PreloaderWrapper/index.tsx +1 -1
- package/Components/River/ComponentsMap/ComponentsMap.tsx +2 -2
- package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +3 -15
- package/Components/Screen/index.tsx +8 -4
- package/Components/ScreenFeedLoader/ScreenFeedLoader.tsx +5 -3
- package/Components/ScreenResolverFeedProvider/ScreenResolverFeedProvider.tsx +1 -1
- package/Components/TopCutoffOverlay/index.tsx +2 -2
- package/Components/Transitioner/Transitioner.tsx +28 -17
- package/Components/ZappFrameworkComponents/BarView/BarView.tsx +12 -5
- package/Components/ZappFrameworkComponents/BarView/__tests__/BarView.test.tsx +2 -2
- package/Contexts/CachedDimensionsContext/__tests__/index.test.ts +154 -0
- package/Contexts/CachedDimensionsContext/index.ts +17 -2
- package/Helpers/ComponentCellSelectionHelper/index.js +0 -6
- package/Helpers/index.js +0 -39
- package/package.json +5 -5
- package/Components/OfflineHandler/NotificationView/NotificationView.lg.tsx +0 -112
- package/Components/OfflineHandler/NotificationView/NotificationView.samsung.tsx +0 -107
- package/Components/OfflineHandler/NotificationView/NotificationView.tsx +0 -153
- package/Components/OfflineHandler/NotificationView/__tests__/index.test.tsx +0 -66
- package/Components/OfflineHandler/NotificationView/utils.ts +0 -34
- package/Components/Screen/utils.ts +0 -16
- package/Helpers/Analytics/index.js +0 -95
- /package/Components/BackgroundImage/{BackgroundImage.tv.android.tsx → BackgroundImage.android.tv.tsx} +0 -0
- /package/Components/BackgroundImage/{BackgroundImage.tv.ios.tsx → BackgroundImage.ios.tv.tsx} +0 -0
- /package/Components/MasterCell/DefaultComponents/ButtonContainerView/{index.tv.android.tsx → index.android.tv.tsx} +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { GeneralContentScreen } from "./GeneralContentScreen";
|
|
3
|
+
import { HookContentFocusGroup } from "./hookFocus";
|
|
3
4
|
import { runInBackground } from "./hookAdapter/runInBackground";
|
|
4
5
|
import { log_error } from "./hookAdapter/logger";
|
|
5
6
|
|
|
@@ -19,11 +20,14 @@ function GeneralContentScreenHookComponent(props: HookComponentProps) {
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
return (
|
|
22
|
-
<
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
<HookContentFocusGroup>
|
|
24
|
+
<GeneralContentScreen
|
|
25
|
+
screenId={hookPlugin.screen_id}
|
|
26
|
+
isScreenWrappedInContainer={false}
|
|
27
|
+
focused={focused}
|
|
28
|
+
parentFocus={parentFocus}
|
|
29
|
+
/>
|
|
30
|
+
</HookContentFocusGroup>
|
|
27
31
|
);
|
|
28
32
|
}
|
|
29
33
|
|
|
@@ -41,7 +41,10 @@ describe("GeneralContentScreenHookAdapter", () => {
|
|
|
41
41
|
expect(getByTestId("general-content-screen")).toBeDefined();
|
|
42
42
|
|
|
43
43
|
expect(mockScreenSpy).toHaveBeenCalledWith(
|
|
44
|
-
expect.objectContaining({
|
|
44
|
+
expect.objectContaining({
|
|
45
|
+
screenId: "screen-1",
|
|
46
|
+
isScreenWrappedInContainer: false,
|
|
47
|
+
})
|
|
45
48
|
);
|
|
46
49
|
});
|
|
47
50
|
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@testing-library/react-native";
|
|
3
|
+
import { View } from "react-native";
|
|
4
|
+
|
|
5
|
+
import { HookContentFocusGroup } from "../hookFocus/index.web";
|
|
6
|
+
|
|
7
|
+
const mockFocusableGroupSpy = jest.fn();
|
|
8
|
+
const mockUseInitialFocusSpy = jest.fn();
|
|
9
|
+
|
|
10
|
+
const mockModalState = { isRunningInBackground: false };
|
|
11
|
+
|
|
12
|
+
jest.mock("../../FocusableGroup", () => ({
|
|
13
|
+
FocusableGroup: (props) => {
|
|
14
|
+
const React = require("react");
|
|
15
|
+
const { View } = require("react-native");
|
|
16
|
+
|
|
17
|
+
mockFocusableGroupSpy(props);
|
|
18
|
+
|
|
19
|
+
return <View testID="focusable-group">{props.children}</View>;
|
|
20
|
+
},
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation", () => ({
|
|
24
|
+
useContentId: () => "quick-brick-content___route",
|
|
25
|
+
useNavbarId: () => "quick-brick-navbar___route",
|
|
26
|
+
usePathname: () => "hooks-modal/profile-select",
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
jest.mock("../../Screen/TV/hooks", () => ({
|
|
30
|
+
useInitialFocus: () => mockUseInitialFocusSpy(),
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
jest.mock("../../../Contexts/ZappHookModalContext", () => ({
|
|
34
|
+
useZappHookModalStore: (selector) => selector(mockModalState),
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
describe("HookContentFocusGroup (web)", () => {
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
jest.clearAllMocks();
|
|
40
|
+
mockModalState.isRunningInBackground = false;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("wraps content in a preferred-focus content group and triggers initial focus when presented full screen", () => {
|
|
44
|
+
const { getByTestId } = render(
|
|
45
|
+
<HookContentFocusGroup>
|
|
46
|
+
<View testID="child" />
|
|
47
|
+
</HookContentFocusGroup>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(getByTestId("focusable-group")).toBeDefined();
|
|
51
|
+
expect(getByTestId("child")).toBeDefined();
|
|
52
|
+
expect(mockUseInitialFocusSpy).toHaveBeenCalledTimes(1);
|
|
53
|
+
|
|
54
|
+
expect(mockFocusableGroupSpy).toHaveBeenCalledWith(
|
|
55
|
+
expect.objectContaining({
|
|
56
|
+
id: "quick-brick-content___route",
|
|
57
|
+
groupId: "hooks-modal/profile-select",
|
|
58
|
+
nextFocusUp: "quick-brick-navbar___route",
|
|
59
|
+
preferredFocus: true,
|
|
60
|
+
shouldUsePreferredFocus: true,
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("injects the content group id into the wrapped child so its cells register under it", () => {
|
|
66
|
+
render(
|
|
67
|
+
<HookContentFocusGroup>
|
|
68
|
+
<View testID="child" />
|
|
69
|
+
</HookContentFocusGroup>
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const child = mockFocusableGroupSpy.mock.calls[0][0].children;
|
|
73
|
+
|
|
74
|
+
expect(child.props.groupId).toBe("quick-brick-content___route");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("renders the child without focus handling when running in background (not full screen)", () => {
|
|
78
|
+
mockModalState.isRunningInBackground = true;
|
|
79
|
+
|
|
80
|
+
const { getByTestId, queryByTestId } = render(
|
|
81
|
+
<HookContentFocusGroup>
|
|
82
|
+
<View testID="child" />
|
|
83
|
+
</HookContentFocusGroup>
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
expect(getByTestId("child")).toBeDefined();
|
|
87
|
+
expect(queryByTestId("focusable-group")).toBeNull();
|
|
88
|
+
expect(mockUseInitialFocusSpy).not.toHaveBeenCalled();
|
|
89
|
+
expect(mockFocusableGroupSpy).not.toHaveBeenCalled();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -43,8 +43,7 @@ export const requestToSkipHook = async (
|
|
|
43
43
|
{ response: logData }
|
|
44
44
|
);
|
|
45
45
|
|
|
46
|
-
//
|
|
47
|
-
// response body means "skip the hook", an empty/null body means "run it".
|
|
46
|
+
// Non-empty body = skip the hook (same contract as hook-screen-wrapper)
|
|
48
47
|
return Boolean(responseHelper.responseData);
|
|
49
48
|
} catch (error) {
|
|
50
49
|
log_error(`requestToSkipHook: Error: ${error.message}`, { error });
|
|
@@ -3,13 +3,8 @@ import { requestToSkipHook } from "./networkService";
|
|
|
3
3
|
import { log_debug, log_error } from "./logger";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Headless pre-hook for the General Content Screen.
|
|
7
|
-
*
|
|
8
|
-
* `configuration` is the Hook object passed by the HooksManager, which has the
|
|
9
|
-
* hook river merged into it. The skip-hook fields are defined under the `rules`
|
|
10
|
-
* section of the General Content Screen manifest, so they are read from
|
|
11
|
-
* `configuration.rules` (unlike the standalone hook-screen-wrapper plugin, which
|
|
12
|
-
* defines them under `general`).
|
|
6
|
+
* Headless pre-hook for the General Content Screen. `configuration` is the
|
|
7
|
+
* Hook object with the screen merged in; skip-hook fields live under `rules`.
|
|
13
8
|
*/
|
|
14
9
|
export const runInBackground = async (
|
|
15
10
|
item,
|
|
@@ -6,11 +6,11 @@ import { log_error, log_info } from "./logger";
|
|
|
6
6
|
type ParseKey = { key: string; namespace?: string };
|
|
7
7
|
|
|
8
8
|
export function parseKeyEntries(input: string): ParseKey[] {
|
|
9
|
-
return input
|
|
10
|
-
.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
return input.split(",").flatMap((item) => {
|
|
10
|
+
const trimmed = item.trim();
|
|
11
|
+
|
|
12
|
+
return trimmed ? getNamespaceAndKey(trimmed) : [];
|
|
13
|
+
});
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export const getKeyToSkipHook = async (key: string, namespace?: string) => {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
type Props = {
|
|
4
|
+
children: React.ReactElement;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* On native platforms the river `ComponentsMap` registers its own initial focus,
|
|
9
|
+
* so a hook-presented general content screen needs no extra focus wrapper here.
|
|
10
|
+
* The web counterpart (`index.web.tsx`) recreates the content focus group that
|
|
11
|
+
* the `River` wrapper would normally provide.
|
|
12
|
+
*/
|
|
13
|
+
export const HookContentFocusGroup = ({ children }: Props) => <>{children}</>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { StyleSheet } from "react-native";
|
|
3
|
+
import { shallow } from "zustand/shallow";
|
|
4
|
+
|
|
5
|
+
import { FocusableGroup } from "../../FocusableGroup";
|
|
6
|
+
import {
|
|
7
|
+
useContentId,
|
|
8
|
+
useNavbarId,
|
|
9
|
+
usePathname,
|
|
10
|
+
} from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
|
|
11
|
+
import { useZappHookModalStore } from "../../../Contexts/ZappHookModalContext";
|
|
12
|
+
|
|
13
|
+
import { useInitialFocus } from "../../Screen/TV/hooks";
|
|
14
|
+
|
|
15
|
+
const styles = StyleSheet.create({
|
|
16
|
+
container: { flex: 1 },
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
type Props = {
|
|
20
|
+
children: React.ReactElement;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A general content screen presented as a full-screen hook is rendered straight
|
|
25
|
+
* through `ComponentsMap`, bypassing the web `River` wrapper. That wrapper is what
|
|
26
|
+
* normally creates the `quick-brick-content` FocusableGroup (with `preferredFocus`)
|
|
27
|
+
* the focus manager relies on and what lets initial focus land on the content.
|
|
28
|
+
*
|
|
29
|
+
* Without it the hook screen renders but nothing is focusable on web TV. This
|
|
30
|
+
* recreates that content group and triggers initial focus, mirroring `River`.
|
|
31
|
+
*/
|
|
32
|
+
const FocusedHookContent = ({ children }: Props) => {
|
|
33
|
+
const contentId = useContentId();
|
|
34
|
+
const navbarId = useNavbarId();
|
|
35
|
+
const pathname = usePathname();
|
|
36
|
+
|
|
37
|
+
useInitialFocus();
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<FocusableGroup
|
|
41
|
+
id={contentId}
|
|
42
|
+
// Nest under the hook-modal route so the focus manager treats this as the
|
|
43
|
+
// active screen's content node; `useInitialFocus` targets the same route.
|
|
44
|
+
groupId={pathname}
|
|
45
|
+
nextFocusUp={navbarId}
|
|
46
|
+
preferredFocus
|
|
47
|
+
shouldUsePreferredFocus
|
|
48
|
+
style={styles.container}
|
|
49
|
+
>
|
|
50
|
+
{React.cloneElement(children, { groupId: contentId })}
|
|
51
|
+
</FocusableGroup>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const HookContentFocusGroup = ({ children }: Props) => {
|
|
56
|
+
const isRunningInBackground = useZappHookModalStore(
|
|
57
|
+
(state) => state.isRunningInBackground,
|
|
58
|
+
shallow
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
// A hook presented full screen (either as a `/hooks/<id>` screen or a
|
|
62
|
+
// full-screen modal) needs the content focus group. Only background runs,
|
|
63
|
+
// which render invisibly, must be left alone so they don't steal focus.
|
|
64
|
+
if (isRunningInBackground) {
|
|
65
|
+
return <>{children}</>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return <FocusedHookContent>{children}</FocusedHookContent>;
|
|
69
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { StyleSheet, View } from "react-native";
|
|
3
|
+
|
|
4
|
+
const styles = StyleSheet.create({
|
|
5
|
+
row: { flexDirection: "row" },
|
|
6
|
+
basis: {
|
|
7
|
+
maxWidth: "100%",
|
|
8
|
+
flexBasis: "100%",
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
type Props = {
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Constrains its child to exactly the available parent width.
|
|
18
|
+
*
|
|
19
|
+
* UI components such as Hero and List render their items inside a parent
|
|
20
|
+
* `ScrollView` (e.g. when wrapped by tabs). A child placed directly in a
|
|
21
|
+
* scroll container can size itself to its own content rather than to the
|
|
22
|
+
* viewport, which causes items to be measured at a stale width and resize
|
|
23
|
+
* unexpectedly after layout changes such as device rotation.
|
|
24
|
+
*
|
|
25
|
+
* Wrapping the content in a `flexDirection: "row"` parent with a
|
|
26
|
+
* `flexBasis: "100%"` / `maxWidth: "100%"` child forces the child to
|
|
27
|
+
* re-derive its width from the parent on every layout pass instead of
|
|
28
|
+
* caching a measured pixel width, keeping it full-width and stable.
|
|
29
|
+
*
|
|
30
|
+
* @param children - The content to render at full parent width.
|
|
31
|
+
*/
|
|
32
|
+
export function FullWidthRow({ children }: Props) {
|
|
33
|
+
return (
|
|
34
|
+
<View style={styles.row}>
|
|
35
|
+
<View style={styles.basis}>{children}</View>
|
|
36
|
+
</View>
|
|
37
|
+
);
|
|
38
|
+
}
|
package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/placement.test.ts
CHANGED
|
@@ -6,28 +6,54 @@ import {
|
|
|
6
6
|
describe("ActionButtonsCore placement", () => {
|
|
7
7
|
const buttons = { type: "View", name: "buttons" };
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
{ name: "
|
|
11
|
-
{ name: "
|
|
12
|
-
{ name: "
|
|
9
|
+
const slots = [
|
|
10
|
+
{ name: "text_label_1", element: { type: "View", id: "label_1" } },
|
|
11
|
+
{ name: "text_label_2", element: { type: "View", id: "label_2" } },
|
|
12
|
+
{ name: "text_label_3", element: { type: "View", id: "label_3" } },
|
|
13
13
|
];
|
|
14
14
|
|
|
15
|
-
const
|
|
16
|
-
{ name: "below_label_1" },
|
|
17
|
-
{ name: "below_label_2" },
|
|
18
|
-
{ name: "below_label_3" },
|
|
19
|
-
];
|
|
15
|
+
const labels = slots.map((slot) => slot.element);
|
|
20
16
|
|
|
21
17
|
it("inserts buttons after the matching label", () => {
|
|
22
18
|
expect(
|
|
23
|
-
insertBetweenLabels({ position: "
|
|
24
|
-
).toEqual([
|
|
19
|
+
insertBetweenLabels({ position: "below_text_label_2" }, buttons, slots)
|
|
20
|
+
).toEqual([labels[0], labels[1], buttons, labels[2]]);
|
|
25
21
|
});
|
|
26
22
|
|
|
27
23
|
it("inserts buttons before the matching label", () => {
|
|
28
24
|
expect(
|
|
29
|
-
insertBetweenLabels({ position: "
|
|
30
|
-
).toEqual([
|
|
25
|
+
insertBetweenLabels({ position: "above_text_label_2" }, buttons, slots)
|
|
26
|
+
).toEqual([labels[0], buttons, labels[1], labels[2]]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("inserts buttons after the matching label on a plain name match", () => {
|
|
30
|
+
expect(
|
|
31
|
+
insertBetweenLabels({ position: "text_label_2" }, buttons, slots)
|
|
32
|
+
).toEqual([labels[0], labels[1], buttons, labels[2]]);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("keeps the slot when its label is empty (null element)", () => {
|
|
36
|
+
const slotsWithEmpty = [
|
|
37
|
+
{ name: "text_label_1", element: { id: "label_1" } },
|
|
38
|
+
{ name: "text_label_2", element: null },
|
|
39
|
+
{ name: "text_label_3", element: { id: "label_3" } },
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
expect(
|
|
43
|
+
insertBetweenLabels(
|
|
44
|
+
{ position: "above_text_label_2" },
|
|
45
|
+
buttons,
|
|
46
|
+
slotsWithEmpty
|
|
47
|
+
)
|
|
48
|
+
).toEqual([{ id: "label_1" }, buttons, { id: "label_3" }]);
|
|
49
|
+
|
|
50
|
+
expect(
|
|
51
|
+
insertBetweenLabels(
|
|
52
|
+
{ position: "below_text_label_2" },
|
|
53
|
+
buttons,
|
|
54
|
+
slotsWithEmpty
|
|
55
|
+
)
|
|
56
|
+
).toEqual([{ id: "label_1" }, buttons, { id: "label_3" }]);
|
|
31
57
|
});
|
|
32
58
|
|
|
33
59
|
it("prepends buttons only when on_top is allowed", () => {
|
|
@@ -35,17 +61,17 @@ describe("ActionButtonsCore placement", () => {
|
|
|
35
61
|
insertBetweenLabels(
|
|
36
62
|
{ position: "on_top", allowOnTop: true },
|
|
37
63
|
buttons,
|
|
38
|
-
|
|
64
|
+
slots
|
|
39
65
|
)
|
|
40
|
-
).toEqual([buttons, ...
|
|
66
|
+
).toEqual([buttons, ...labels]);
|
|
41
67
|
|
|
42
68
|
expect(
|
|
43
69
|
insertBetweenLabels(
|
|
44
70
|
{ position: "on_top", allowOnTop: false },
|
|
45
71
|
buttons,
|
|
46
|
-
|
|
72
|
+
slots
|
|
47
73
|
)
|
|
48
|
-
).toEqual(
|
|
74
|
+
).toEqual(labels);
|
|
49
75
|
});
|
|
50
76
|
|
|
51
77
|
it("appends buttons when appendWhenMissing is enabled", () => {
|
|
@@ -53,9 +79,9 @@ describe("ActionButtonsCore placement", () => {
|
|
|
53
79
|
insertBetweenLabels(
|
|
54
80
|
{ position: "unknown", appendWhenMissing: true },
|
|
55
81
|
buttons,
|
|
56
|
-
|
|
82
|
+
slots
|
|
57
83
|
)
|
|
58
|
-
).toEqual([...
|
|
84
|
+
).toEqual([...labels, buttons]);
|
|
59
85
|
});
|
|
60
86
|
|
|
61
87
|
it("returns labels unchanged when appendWhenMissing is disabled", () => {
|
|
@@ -63,9 +89,9 @@ describe("ActionButtonsCore placement", () => {
|
|
|
63
89
|
insertBetweenLabels(
|
|
64
90
|
{ position: "unknown", appendWhenMissing: false },
|
|
65
91
|
buttons,
|
|
66
|
-
|
|
92
|
+
slots
|
|
67
93
|
)
|
|
68
|
-
).toEqual(
|
|
94
|
+
).toEqual(labels);
|
|
69
95
|
});
|
|
70
96
|
|
|
71
97
|
const labelContainers = [
|
|
@@ -17,6 +17,11 @@ type InsertOptions = {
|
|
|
17
17
|
appendWhenMissing?: boolean;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
+
type Slot = {
|
|
21
|
+
name: string;
|
|
22
|
+
element?: unknown;
|
|
23
|
+
};
|
|
24
|
+
|
|
20
25
|
const hasLabelName = (value: unknown): value is Label =>
|
|
21
26
|
!!value &&
|
|
22
27
|
typeof value === "object" &&
|
|
@@ -100,8 +105,14 @@ const containsNestedLabel = (
|
|
|
100
105
|
export const insertBetweenLabels = (
|
|
101
106
|
{ position, allowOnTop = false, appendWhenMissing = false }: InsertOptions,
|
|
102
107
|
buttons: unknown,
|
|
103
|
-
|
|
108
|
+
slots: Slot[] = []
|
|
104
109
|
) => {
|
|
110
|
+
// Slots are defined by the canonical label list, so an empty (null) label
|
|
111
|
+
// still keeps its position — buttons placed above/below it survive.
|
|
112
|
+
const labels = slots
|
|
113
|
+
.map((slot) => slot.element)
|
|
114
|
+
.filter((element) => element != null);
|
|
115
|
+
|
|
105
116
|
if (buttons == null) {
|
|
106
117
|
return labels;
|
|
107
118
|
}
|
|
@@ -110,14 +121,31 @@ export const insertBetweenLabels = (
|
|
|
110
121
|
return [buttons, ...labels];
|
|
111
122
|
}
|
|
112
123
|
|
|
113
|
-
|
|
114
|
-
const
|
|
124
|
+
let inserted = false;
|
|
125
|
+
const result: unknown[] = [];
|
|
126
|
+
|
|
127
|
+
for (const { name, element } of slots) {
|
|
128
|
+
if (position === `above_${name}`) {
|
|
129
|
+
result.push(buttons);
|
|
130
|
+
inserted = true;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (element != null) {
|
|
134
|
+
result.push(element);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Insert after on `below_*` or a plain label-name match.
|
|
138
|
+
if (position === `below_${name}` || position === name) {
|
|
139
|
+
result.push(buttons);
|
|
140
|
+
inserted = true;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
115
143
|
|
|
116
|
-
if (!inserted
|
|
117
|
-
return [...labels, buttons];
|
|
144
|
+
if (!inserted) {
|
|
145
|
+
return appendWhenMissing ? [...labels, buttons] : labels;
|
|
118
146
|
}
|
|
119
147
|
|
|
120
|
-
return
|
|
148
|
+
return result;
|
|
121
149
|
};
|
|
122
150
|
|
|
123
151
|
export const insertBetweenLabelContainers = (
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { PropsWithChildren } from "react";
|
|
2
2
|
import { isVideoPreviewEnabled } from "@applicaster/zapp-react-native-ui-components/Components/MasterCell/utils";
|
|
3
3
|
import { LiveImage } from "../LiveImage";
|
|
4
4
|
import PureImage from "../Image";
|
|
5
5
|
import { useIsScreenActive } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
6
6
|
|
|
7
|
-
type Props = {
|
|
7
|
+
type Props = PropsWithChildren<{
|
|
8
8
|
enable_video_preview: boolean;
|
|
9
9
|
player_screen_id: string;
|
|
10
|
-
|
|
10
|
+
uri?: string;
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}>;
|
|
11
13
|
|
|
12
14
|
export const ImageContainer = (props: Props) => {
|
|
13
15
|
const isActive = useIsScreenActive();
|
|
@@ -1,34 +1,54 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import {
|
|
1
|
+
import React, { useCallback } from "react";
|
|
2
|
+
import { Pressable, ViewStyle } from "react-native";
|
|
3
|
+
import { PressedStateContext } from "../contexts/PressedStateContext";
|
|
3
4
|
|
|
4
5
|
type Props = {
|
|
5
6
|
children?: React.ReactNode;
|
|
6
|
-
style?:
|
|
7
|
+
style?: ViewStyle | ViewStyle[];
|
|
8
|
+
pressedStyle?: ViewStyle | ViewStyle[];
|
|
7
9
|
testID?: string;
|
|
8
10
|
accessibilityLabel?: string;
|
|
9
11
|
accessibilityHint?: string;
|
|
10
12
|
onPress?: () => void;
|
|
13
|
+
testOnly_pressed?: boolean;
|
|
11
14
|
};
|
|
12
15
|
|
|
13
16
|
export function PressableView({
|
|
14
17
|
children,
|
|
15
|
-
style
|
|
18
|
+
style,
|
|
16
19
|
testID,
|
|
17
20
|
accessibilityLabel,
|
|
18
21
|
accessibilityHint,
|
|
22
|
+
pressedStyle,
|
|
19
23
|
onPress,
|
|
24
|
+
testOnly_pressed = false,
|
|
20
25
|
}: Props) {
|
|
21
26
|
return (
|
|
22
|
-
<
|
|
23
|
-
|
|
27
|
+
<Pressable
|
|
28
|
+
testOnly_pressed={testOnly_pressed}
|
|
24
29
|
onPress={onPress}
|
|
25
30
|
testID={testID}
|
|
26
31
|
accessibilityLabel={accessibilityLabel}
|
|
27
32
|
accessibilityHint={accessibilityHint}
|
|
28
33
|
accessible={!!(testID || accessibilityLabel)}
|
|
29
|
-
style={
|
|
34
|
+
style={useCallback(
|
|
35
|
+
({ pressed }) => [
|
|
36
|
+
style,
|
|
37
|
+
pressed && {
|
|
38
|
+
opacity: 1,
|
|
39
|
+
},
|
|
40
|
+
pressed && pressedStyle,
|
|
41
|
+
],
|
|
42
|
+
[style, pressedStyle]
|
|
43
|
+
)}
|
|
30
44
|
>
|
|
31
|
-
{
|
|
32
|
-
|
|
45
|
+
{({ pressed }) => {
|
|
46
|
+
return (
|
|
47
|
+
<PressedStateContext.Provider value={pressed}>
|
|
48
|
+
{children}
|
|
49
|
+
</PressedStateContext.Provider>
|
|
50
|
+
);
|
|
51
|
+
}}
|
|
52
|
+
</Pressable>
|
|
33
53
|
);
|
|
34
54
|
}
|
|
@@ -83,6 +83,10 @@ export const useTextLabel = ({ label, entry }): string => {
|
|
|
83
83
|
return prepareHebrewText(label, isRTL);
|
|
84
84
|
};
|
|
85
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Uses `otherProps.state` ("focused" | "default") to select between `focusedStyles` and `normalStyles`.
|
|
88
|
+
* For mobile action buttons, map `usePressedState()` (boolean) to this state value (e.g. pressed ? "focused" : "default").
|
|
89
|
+
*/
|
|
86
90
|
export const withFocusedStyles = ({ style, otherProps }) => {
|
|
87
91
|
const state = R.path(["state"], otherProps);
|
|
88
92
|
|