@applicaster/zapp-react-native-ui-components 16.0.0-alpha.2628821467 → 16.0.0-alpha.2851031376
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/GeneralContentScreen/GeneralContentScreenHookAdapter.tsx +39 -0
- package/Components/GeneralContentScreen/__tests__/GeneralContentScreenHookAdapter.test.tsx +64 -0
- package/Components/GeneralContentScreen/__tests__/HookContentFocusGroup.web.test.tsx +91 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/networkService.test.ts +74 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/runInBackground.test.ts +139 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/validationHelper.test.ts +124 -0
- package/Components/GeneralContentScreen/hookAdapter/logger.ts +6 -0
- package/Components/GeneralContentScreen/hookAdapter/networkService.ts +53 -0
- package/Components/GeneralContentScreen/hookAdapter/runInBackground.ts +48 -0
- package/Components/GeneralContentScreen/hookAdapter/validationHelper.ts +72 -0
- package/Components/GeneralContentScreen/hookFocus/index.tsx +13 -0
- package/Components/GeneralContentScreen/hookFocus/index.web.tsx +69 -0
- package/Components/GeneralContentScreen/index.ts +2 -0
- package/Components/River/ComponentsMap/ComponentsMap.tsx +103 -186
- package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +22 -1
- package/package.json +5 -5
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { GeneralContentScreen } from "./GeneralContentScreen";
|
|
3
|
+
import { HookContentFocusGroup } from "./hookFocus";
|
|
4
|
+
import { runInBackground } from "./hookAdapter/runInBackground";
|
|
5
|
+
import { log_error } from "./hookAdapter/logger";
|
|
6
|
+
|
|
7
|
+
type HookComponentProps = HookPluginProps & {
|
|
8
|
+
configuration?: unknown;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
function GeneralContentScreenHookComponent(props: HookComponentProps) {
|
|
12
|
+
const { hookPlugin, focused, parentFocus } = props;
|
|
13
|
+
|
|
14
|
+
if (!hookPlugin?.screen_id) {
|
|
15
|
+
log_error(
|
|
16
|
+
"GeneralContentScreenHookAdapter: This component should only be used as a hook, but no hookPlugin was provided."
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<HookContentFocusGroup>
|
|
24
|
+
<GeneralContentScreen
|
|
25
|
+
screenId={hookPlugin.screen_id}
|
|
26
|
+
isScreenWrappedInContainer={false}
|
|
27
|
+
focused={focused}
|
|
28
|
+
parentFocus={parentFocus}
|
|
29
|
+
/>
|
|
30
|
+
</HookContentFocusGroup>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const GeneralContentScreenHookAdapter = {
|
|
35
|
+
isFlowBlocker: () => true,
|
|
36
|
+
presentFullScreen: true,
|
|
37
|
+
Component: GeneralContentScreenHookComponent,
|
|
38
|
+
runInBackground,
|
|
39
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@testing-library/react-native";
|
|
3
|
+
import { GeneralContentScreenHookAdapter } from "../GeneralContentScreenHookAdapter";
|
|
4
|
+
import { log_error } from "../hookAdapter/logger";
|
|
5
|
+
|
|
6
|
+
const mockScreenSpy = jest.fn();
|
|
7
|
+
|
|
8
|
+
jest.mock("../GeneralContentScreen", () => ({
|
|
9
|
+
GeneralContentScreen: (props) => {
|
|
10
|
+
const React = require("react");
|
|
11
|
+
const { View } = require("react-native");
|
|
12
|
+
|
|
13
|
+
mockScreenSpy(props);
|
|
14
|
+
|
|
15
|
+
return <View testID="general-content-screen" />;
|
|
16
|
+
},
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
jest.mock("../hookAdapter/runInBackground", () => ({
|
|
20
|
+
runInBackground: jest.fn(),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
jest.mock("../hookAdapter/logger", () => ({
|
|
24
|
+
log_debug: jest.fn(),
|
|
25
|
+
log_error: jest.fn(),
|
|
26
|
+
log_info: jest.fn(),
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
const { Component } = GeneralContentScreenHookAdapter;
|
|
30
|
+
|
|
31
|
+
describe("GeneralContentScreenHookAdapter", () => {
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
jest.clearAllMocks();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("renders GeneralContentScreen with the hook plugin screen id", () => {
|
|
37
|
+
const { getByTestId } = render(
|
|
38
|
+
<Component hookPlugin={{ screen_id: "screen-1" }} focused />
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
expect(getByTestId("general-content-screen")).toBeDefined();
|
|
42
|
+
|
|
43
|
+
expect(mockScreenSpy).toHaveBeenCalledWith(
|
|
44
|
+
expect.objectContaining({
|
|
45
|
+
screenId: "screen-1",
|
|
46
|
+
isScreenWrappedInContainer: false,
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("renders nothing and logs an error when hookPlugin is missing", () => {
|
|
52
|
+
const { toJSON } = render(<Component />);
|
|
53
|
+
|
|
54
|
+
expect(toJSON()).toBeNull();
|
|
55
|
+
expect(mockScreenSpy).not.toHaveBeenCalled();
|
|
56
|
+
expect(log_error).toHaveBeenCalled();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("renders nothing when hookPlugin has no screen_id", () => {
|
|
60
|
+
const { toJSON } = render(<Component hookPlugin={{}} />);
|
|
61
|
+
|
|
62
|
+
expect(toJSON()).toBeNull();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { requestToSkipHook } from "../networkService";
|
|
2
|
+
|
|
3
|
+
const mockCall = jest.fn();
|
|
4
|
+
const mockBuildAxiosRequest = jest.fn();
|
|
5
|
+
let mockHelper: Record<string, any>;
|
|
6
|
+
|
|
7
|
+
jest.mock("@applicaster/zapp-pipes-v2-client", () => ({
|
|
8
|
+
RequestBuilder: jest.fn().mockImplementation(() => ({
|
|
9
|
+
setEntryContext: jest.fn().mockReturnThis(),
|
|
10
|
+
setScreenContext: jest.fn().mockReturnThis(),
|
|
11
|
+
setUrl: jest.fn().mockReturnThis(),
|
|
12
|
+
buildAxiosRequest: (...args) => mockBuildAxiosRequest(...args),
|
|
13
|
+
call: (...args) => mockCall(...args),
|
|
14
|
+
})),
|
|
15
|
+
PipesClientResponseHelper: jest.fn().mockImplementation(() => mockHelper),
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
jest.mock("../logger", () => ({
|
|
19
|
+
log_debug: jest.fn(),
|
|
20
|
+
log_error: jest.fn(),
|
|
21
|
+
log_info: jest.fn(),
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
const dataSource = { source: "https://skip-endpoint", mapping: {} };
|
|
25
|
+
const payload = { id: "entry-1" };
|
|
26
|
+
|
|
27
|
+
describe("requestToSkipHook", () => {
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
jest.clearAllMocks();
|
|
30
|
+
mockBuildAxiosRequest.mockResolvedValue({ url: "https://skip-endpoint" });
|
|
31
|
+
mockCall.mockResolvedValue({});
|
|
32
|
+
|
|
33
|
+
mockHelper = {
|
|
34
|
+
error: null,
|
|
35
|
+
statusCode: 200,
|
|
36
|
+
responseData: null,
|
|
37
|
+
getLogsData: jest.fn(() => ({})),
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("returns true when the endpoint returns a non-empty body", async () => {
|
|
42
|
+
mockHelper.responseData = true;
|
|
43
|
+
|
|
44
|
+
await expect(requestToSkipHook(dataSource, payload)).resolves.toBe(true);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("treats any truthy payload as skip (hook-screen-wrapper contract)", async () => {
|
|
48
|
+
mockHelper.responseData = { entry: [] };
|
|
49
|
+
|
|
50
|
+
await expect(requestToSkipHook(dataSource, payload)).resolves.toBe(true);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("returns false when the endpoint returns an empty body", async () => {
|
|
54
|
+
mockHelper.responseData = null;
|
|
55
|
+
|
|
56
|
+
await expect(requestToSkipHook(dataSource, payload)).resolves.toBe(false);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("throws when the response contains an error", async () => {
|
|
60
|
+
mockHelper.error = new Error("server error");
|
|
61
|
+
|
|
62
|
+
await expect(requestToSkipHook(dataSource, payload)).rejects.toThrow(
|
|
63
|
+
"server error"
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("throws when the request itself fails", async () => {
|
|
68
|
+
mockCall.mockRejectedValue(new Error("network down"));
|
|
69
|
+
|
|
70
|
+
await expect(requestToSkipHook(dataSource, payload)).rejects.toThrow(
|
|
71
|
+
"network down"
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { runInBackground } from "../runInBackground";
|
|
2
|
+
import { shouldSkipHook } from "../validationHelper";
|
|
3
|
+
import { requestToSkipHook } from "../networkService";
|
|
4
|
+
|
|
5
|
+
jest.mock("../validationHelper", () => ({
|
|
6
|
+
shouldSkipHook: jest.fn(),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
jest.mock("../networkService", () => ({
|
|
10
|
+
requestToSkipHook: jest.fn(),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
jest.mock("../logger", () => ({
|
|
14
|
+
log_debug: jest.fn(),
|
|
15
|
+
log_error: jest.fn(),
|
|
16
|
+
log_info: jest.fn(),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
const mockShouldSkipHook = shouldSkipHook as jest.Mock;
|
|
20
|
+
const mockRequestToSkipHook = requestToSkipHook as jest.Mock;
|
|
21
|
+
|
|
22
|
+
const item = { id: "entry-1" };
|
|
23
|
+
const endpoint = { source: "https://skip-endpoint", mapping: {} };
|
|
24
|
+
|
|
25
|
+
describe("runInBackground", () => {
|
|
26
|
+
let callback: jest.Mock;
|
|
27
|
+
let presentUI: jest.Mock;
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
jest.clearAllMocks();
|
|
31
|
+
callback = jest.fn();
|
|
32
|
+
presentUI = jest.fn();
|
|
33
|
+
mockShouldSkipHook.mockResolvedValue(false);
|
|
34
|
+
mockRequestToSkipHook.mockResolvedValue(false);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("presents the UI when no skip rules are configured", async () => {
|
|
38
|
+
await runInBackground(item, callback, {}, presentUI);
|
|
39
|
+
|
|
40
|
+
expect(presentUI).toHaveBeenCalled();
|
|
41
|
+
expect(callback).not.toHaveBeenCalled();
|
|
42
|
+
expect(mockShouldSkipHook).not.toHaveBeenCalled();
|
|
43
|
+
expect(mockRequestToSkipHook).not.toHaveBeenCalled();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("finishes the hook when a storage key is found, without calling the endpoint", async () => {
|
|
47
|
+
mockShouldSkipHook.mockResolvedValue(true);
|
|
48
|
+
|
|
49
|
+
const configuration = {
|
|
50
|
+
rules: {
|
|
51
|
+
skip_hook_storage_key: "ns.key",
|
|
52
|
+
skip_hook_endpoint: endpoint,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
await runInBackground(item, callback, configuration, presentUI);
|
|
57
|
+
|
|
58
|
+
expect(mockShouldSkipHook).toHaveBeenCalledWith("ns.key");
|
|
59
|
+
|
|
60
|
+
expect(callback).toHaveBeenCalledWith({
|
|
61
|
+
success: true,
|
|
62
|
+
error: null,
|
|
63
|
+
payload: item,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
expect(mockRequestToSkipHook).not.toHaveBeenCalled();
|
|
67
|
+
expect(presentUI).not.toHaveBeenCalled();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("falls through to the endpoint check when storage keys are not found", async () => {
|
|
71
|
+
const configuration = {
|
|
72
|
+
rules: {
|
|
73
|
+
skip_hook_storage_key: "ns.key",
|
|
74
|
+
skip_hook_endpoint: endpoint,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
await runInBackground(item, callback, configuration, presentUI);
|
|
79
|
+
|
|
80
|
+
expect(mockRequestToSkipHook).toHaveBeenCalledWith(endpoint, item);
|
|
81
|
+
expect(presentUI).toHaveBeenCalled();
|
|
82
|
+
expect(callback).not.toHaveBeenCalled();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("finishes the hook when the endpoint allows skipping", async () => {
|
|
86
|
+
mockRequestToSkipHook.mockResolvedValue(true);
|
|
87
|
+
|
|
88
|
+
const configuration = {
|
|
89
|
+
rules: { skip_hook_endpoint: endpoint },
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
await runInBackground(item, callback, configuration, presentUI);
|
|
93
|
+
|
|
94
|
+
expect(callback).toHaveBeenCalledWith({
|
|
95
|
+
success: true,
|
|
96
|
+
error: null,
|
|
97
|
+
payload: item,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
expect(presentUI).not.toHaveBeenCalled();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("ignores an endpoint configuration without a source", async () => {
|
|
104
|
+
const configuration = {
|
|
105
|
+
rules: { skip_hook_endpoint: { mapping: {} } },
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
await runInBackground(item, callback, configuration, presentUI);
|
|
109
|
+
|
|
110
|
+
expect(mockRequestToSkipHook).not.toHaveBeenCalled();
|
|
111
|
+
expect(presentUI).toHaveBeenCalled();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("presents the UI when the endpoint check throws", async () => {
|
|
115
|
+
mockRequestToSkipHook.mockRejectedValue(new Error("network down"));
|
|
116
|
+
|
|
117
|
+
const configuration = {
|
|
118
|
+
rules: { skip_hook_endpoint: endpoint },
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
await runInBackground(item, callback, configuration, presentUI);
|
|
122
|
+
|
|
123
|
+
expect(presentUI).toHaveBeenCalled();
|
|
124
|
+
expect(callback).not.toHaveBeenCalled();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("presents the UI when the storage check throws", async () => {
|
|
128
|
+
mockShouldSkipHook.mockRejectedValue(new Error("storage error"));
|
|
129
|
+
|
|
130
|
+
const configuration = {
|
|
131
|
+
rules: { skip_hook_storage_key: "ns.key" },
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
await runInBackground(item, callback, configuration, presentUI);
|
|
135
|
+
|
|
136
|
+
expect(presentUI).toHaveBeenCalled();
|
|
137
|
+
expect(callback).not.toHaveBeenCalled();
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseKeyEntries,
|
|
3
|
+
getKeyToSkipHook,
|
|
4
|
+
shouldSkipHook,
|
|
5
|
+
} from "../validationHelper";
|
|
6
|
+
|
|
7
|
+
const mockSessionGetItem = jest.fn();
|
|
8
|
+
const mockLocalGetItem = jest.fn();
|
|
9
|
+
|
|
10
|
+
jest.mock(
|
|
11
|
+
"@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage",
|
|
12
|
+
() => ({
|
|
13
|
+
sessionStorage: { getItem: (...args) => mockSessionGetItem(...args) },
|
|
14
|
+
})
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
jest.mock(
|
|
18
|
+
"@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage",
|
|
19
|
+
() => ({
|
|
20
|
+
localStorage: { getItem: (...args) => mockLocalGetItem(...args) },
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
jest.mock("../logger", () => ({
|
|
25
|
+
log_debug: jest.fn(),
|
|
26
|
+
log_error: jest.fn(),
|
|
27
|
+
log_info: jest.fn(),
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
describe("parseKeyEntries", () => {
|
|
31
|
+
it("parses a namespaced key as namespace.key", () => {
|
|
32
|
+
expect(parseKeyEntries("myNamespace.myKey")).toEqual([
|
|
33
|
+
{ namespace: "myNamespace", key: "myKey" },
|
|
34
|
+
]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("treats everything before the last dot as the namespace", () => {
|
|
38
|
+
expect(parseKeyEntries("com.applicaster.feature.someKey")).toEqual([
|
|
39
|
+
{ namespace: "com.applicaster.feature", key: "someKey" },
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("falls back to the default namespace when there is no dot", () => {
|
|
44
|
+
expect(parseKeyEntries("plainKey")).toEqual([
|
|
45
|
+
{ namespace: "applicaster.v2", key: "plainKey" },
|
|
46
|
+
]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("splits comma-separated entries, trimming whitespace and empty items", () => {
|
|
50
|
+
expect(parseKeyEntries(" ns1.key1 , , ns2.key2 ,")).toEqual([
|
|
51
|
+
{ namespace: "ns1", key: "key1" },
|
|
52
|
+
{ namespace: "ns2", key: "key2" },
|
|
53
|
+
]);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("getKeyToSkipHook", () => {
|
|
58
|
+
beforeEach(() => {
|
|
59
|
+
jest.clearAllMocks();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("returns the session storage value when present, without hitting local storage", async () => {
|
|
63
|
+
mockSessionGetItem.mockResolvedValue("session-value");
|
|
64
|
+
|
|
65
|
+
const value = await getKeyToSkipHook("myKey", "myNamespace");
|
|
66
|
+
|
|
67
|
+
expect(value).toBe("session-value");
|
|
68
|
+
expect(mockSessionGetItem).toHaveBeenCalledWith("myKey", "myNamespace");
|
|
69
|
+
expect(mockLocalGetItem).not.toHaveBeenCalled();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("falls back to local storage when session storage is empty", async () => {
|
|
73
|
+
mockSessionGetItem.mockResolvedValue(null);
|
|
74
|
+
mockLocalGetItem.mockResolvedValue("local-value");
|
|
75
|
+
|
|
76
|
+
const value = await getKeyToSkipHook("myKey", "myNamespace");
|
|
77
|
+
|
|
78
|
+
expect(value).toBe("local-value");
|
|
79
|
+
expect(mockLocalGetItem).toHaveBeenCalledWith("myKey", "myNamespace");
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe("shouldSkipHook", () => {
|
|
84
|
+
beforeEach(() => {
|
|
85
|
+
jest.clearAllMocks();
|
|
86
|
+
mockSessionGetItem.mockResolvedValue(null);
|
|
87
|
+
mockLocalGetItem.mockResolvedValue(null);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("returns false when no condition is provided", async () => {
|
|
91
|
+
await expect(shouldSkipHook(undefined)).resolves.toBe(false);
|
|
92
|
+
await expect(shouldSkipHook("")).resolves.toBe(false);
|
|
93
|
+
await expect(shouldSkipHook(" ")).resolves.toBe(false);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("returns true when a key is found in storage, querying with parsed namespace and key", async () => {
|
|
97
|
+
mockSessionGetItem.mockResolvedValue("value");
|
|
98
|
+
|
|
99
|
+
await expect(shouldSkipHook("myNamespace.myKey")).resolves.toBe(true);
|
|
100
|
+
expect(mockSessionGetItem).toHaveBeenCalledWith("myKey", "myNamespace");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("returns true when any of the comma-separated keys is found", async () => {
|
|
104
|
+
mockLocalGetItem.mockImplementation((key) =>
|
|
105
|
+
Promise.resolve(key === "key2" ? "value" : null)
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
await expect(shouldSkipHook("ns1.key1, ns2.key2")).resolves.toBe(true);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("returns false when none of the keys are found", async () => {
|
|
112
|
+
await expect(shouldSkipHook("ns1.key1, ns2.key2")).resolves.toBe(false);
|
|
113
|
+
expect(mockSessionGetItem).toHaveBeenCalledTimes(2);
|
|
114
|
+
expect(mockLocalGetItem).toHaveBeenCalledTimes(2);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("continues to the next key when a storage read throws", async () => {
|
|
118
|
+
mockSessionGetItem
|
|
119
|
+
.mockRejectedValueOnce(new Error("storage error"))
|
|
120
|
+
.mockResolvedValueOnce("value");
|
|
121
|
+
|
|
122
|
+
await expect(shouldSkipHook("ns1.key1, ns2.key2")).resolves.toBe(true);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PipesClientResponseHelper,
|
|
3
|
+
RequestBuilder,
|
|
4
|
+
} from "@applicaster/zapp-pipes-v2-client";
|
|
5
|
+
import { log_debug, log_error } from "./logger";
|
|
6
|
+
|
|
7
|
+
export const requestToSkipHook = async (
|
|
8
|
+
dataSource: ZappDataSource,
|
|
9
|
+
payload: ZappEntry
|
|
10
|
+
): Promise<boolean> => {
|
|
11
|
+
try {
|
|
12
|
+
const requestBuilder = new RequestBuilder()
|
|
13
|
+
.setEntryContext(payload)
|
|
14
|
+
// @ts-ignore: empty screen context is acceptable for this request
|
|
15
|
+
.setScreenContext({})
|
|
16
|
+
.setUrl(dataSource.source, dataSource.mapping);
|
|
17
|
+
|
|
18
|
+
const request = await requestBuilder.buildAxiosRequest();
|
|
19
|
+
|
|
20
|
+
log_debug(
|
|
21
|
+
`requestToSkipHook: Request built for source: ${
|
|
22
|
+
request?.url || dataSource.source
|
|
23
|
+
}`,
|
|
24
|
+
{ ...request, source: dataSource.source }
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const responseObject = await requestBuilder.call<boolean>();
|
|
28
|
+
const responseHelper = new PipesClientResponseHelper(responseObject);
|
|
29
|
+
|
|
30
|
+
const error = responseHelper.error;
|
|
31
|
+
const logData = responseHelper.getLogsData();
|
|
32
|
+
|
|
33
|
+
if (error) {
|
|
34
|
+
log_error(`requestToSkipHook: Error: ${error.message}`, {
|
|
35
|
+
response: logData,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
log_debug(
|
|
42
|
+
`requestToSkipHook: Request received successfully. Status: ${responseHelper.statusCode}`,
|
|
43
|
+
{ response: logData }
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
// Non-empty body = skip the hook (same contract as hook-screen-wrapper)
|
|
47
|
+
return Boolean(responseHelper.responseData);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
log_error(`requestToSkipHook: Error: ${error.message}`, { error });
|
|
50
|
+
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { shouldSkipHook } from "./validationHelper";
|
|
2
|
+
import { requestToSkipHook } from "./networkService";
|
|
3
|
+
import { log_debug, log_error } from "./logger";
|
|
4
|
+
|
|
5
|
+
/**
|
|
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`.
|
|
8
|
+
*/
|
|
9
|
+
export const runInBackground = async (
|
|
10
|
+
item,
|
|
11
|
+
callback,
|
|
12
|
+
configuration,
|
|
13
|
+
presentUI
|
|
14
|
+
) => {
|
|
15
|
+
try {
|
|
16
|
+
const skipHookIfKeysExist = configuration?.rules?.skip_hook_storage_key;
|
|
17
|
+
|
|
18
|
+
if (skipHookIfKeysExist) {
|
|
19
|
+
const shouldSkip = await shouldSkipHook(skipHookIfKeysExist);
|
|
20
|
+
|
|
21
|
+
if (shouldSkip) {
|
|
22
|
+
log_debug(
|
|
23
|
+
`runInBackground: Storage key found: ${skipHookIfKeysExist}. Skipping hook.`
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
return callback({ success: true, error: null, payload: item });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const skipHookEndpoint = configuration?.rules?.skip_hook_endpoint;
|
|
31
|
+
|
|
32
|
+
if (skipHookEndpoint?.source) {
|
|
33
|
+
const success = await requestToSkipHook(skipHookEndpoint, item);
|
|
34
|
+
|
|
35
|
+
if (success) {
|
|
36
|
+
log_debug(
|
|
37
|
+
"runInBackground: Network call forced to finish hook. Skipping hook."
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return callback({ success: true, error: null, payload: item });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} catch (error) {
|
|
44
|
+
log_error(`runInBackground: Error: ${error.message}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return presentUI();
|
|
48
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { getNamespaceAndKey } from "@applicaster/zapp-react-native-utils/appUtils/contextKeysManager/utils";
|
|
2
|
+
import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
3
|
+
import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
|
|
4
|
+
import { log_error, log_info } from "./logger";
|
|
5
|
+
|
|
6
|
+
type ParseKey = { key: string; namespace?: string };
|
|
7
|
+
|
|
8
|
+
export function parseKeyEntries(input: string): ParseKey[] {
|
|
9
|
+
return input.split(",").flatMap((item) => {
|
|
10
|
+
const trimmed = item.trim();
|
|
11
|
+
|
|
12
|
+
return trimmed ? getNamespaceAndKey(trimmed) : [];
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const getKeyToSkipHook = async (key: string, namespace?: string) => {
|
|
17
|
+
const value = await sessionStorage.getItem(key, namespace);
|
|
18
|
+
|
|
19
|
+
if (value) {
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return await localStorage.getItem(key, namespace);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const shouldSkipHook = async (
|
|
27
|
+
skipHookIfKeysExist?: string
|
|
28
|
+
): Promise<boolean> => {
|
|
29
|
+
if (!skipHookIfKeysExist?.trim()) {
|
|
30
|
+
log_info("shouldSkipHook: No skipping condition provided");
|
|
31
|
+
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const keyEntries = parseKeyEntries(skipHookIfKeysExist);
|
|
36
|
+
|
|
37
|
+
if (keyEntries.length === 0) {
|
|
38
|
+
log_info("shouldSkipHook: No valid keys provided");
|
|
39
|
+
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
for (const entry of keyEntries) {
|
|
44
|
+
try {
|
|
45
|
+
const value = await getKeyToSkipHook(entry.key, entry.namespace);
|
|
46
|
+
|
|
47
|
+
if (value) {
|
|
48
|
+
log_info(
|
|
49
|
+
`shouldSkipHook: Hook will be skipped due to: ${
|
|
50
|
+
entry.namespace ?? ""
|
|
51
|
+
} ${entry.key}. Finishing hook flow`
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
} catch (error) {
|
|
57
|
+
log_error(
|
|
58
|
+
`shouldSkipHook: Error: ${error.message} checking key: ${
|
|
59
|
+
entry.namespace ?? ""
|
|
60
|
+
} ${entry.key}`,
|
|
61
|
+
{ error }
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
log_info(
|
|
67
|
+
// eslint-disable-next-line max-len
|
|
68
|
+
"shouldSkipHook: No skipping condition met, none of the provided keys found in storage, proceeding with hook"
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return false;
|
|
72
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import * as R from "ramda";
|
|
3
|
-
import { FlatList,
|
|
3
|
+
import { FlatList, StyleSheet, View } from "react-native";
|
|
4
4
|
import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
|
|
5
5
|
import { RiverItem } from "../RiverItem";
|
|
6
6
|
import { RiverFooter } from "../RiverFooter";
|
|
@@ -36,16 +36,18 @@ type Props = {
|
|
|
36
36
|
groupId?: string;
|
|
37
37
|
isScreenWrappedInContainer?: boolean;
|
|
38
38
|
riverComponents: ZappUIComponent[];
|
|
39
|
-
scrollViewExtraProps?:
|
|
39
|
+
scrollViewExtraProps?: {};
|
|
40
40
|
riverId?: string;
|
|
41
|
-
getStaticComponentFeed:
|
|
42
|
-
component: ZappUIComponent;
|
|
43
|
-
index: number;
|
|
44
|
-
}) => ZappFeed | Promise<ZappFeed>;
|
|
41
|
+
getStaticComponentFeed: any;
|
|
45
42
|
stickyHeaderIndices?: number[];
|
|
46
|
-
useScrollView?: boolean;
|
|
47
43
|
};
|
|
48
44
|
|
|
45
|
+
const styles = StyleSheet.create({
|
|
46
|
+
container: {
|
|
47
|
+
flex: 1,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
49
51
|
const getNearestValue = (value, optionA, optionB) =>
|
|
50
52
|
Math.abs(value - optionA) < Math.abs(value - optionB) ? optionA : optionB;
|
|
51
53
|
|
|
@@ -62,14 +64,11 @@ function ComponentsMapComponent(props: Props) {
|
|
|
62
64
|
riverId,
|
|
63
65
|
getStaticComponentFeed,
|
|
64
66
|
stickyHeaderIndices,
|
|
65
|
-
useScrollView,
|
|
66
67
|
} = props;
|
|
67
68
|
|
|
68
69
|
const flatListRef = React.useRef<FlatList | null>(null);
|
|
69
|
-
const scrollViewRef = React.useRef<ScrollView | null>(null);
|
|
70
70
|
const flatListWrapperRef = React.useRef<View | null>(null);
|
|
71
71
|
const hasUserScrolledRef = React.useRef(false);
|
|
72
|
-
const scrollEndReachedRef = React.useRef(false);
|
|
73
72
|
const screenConfig = useScreenConfiguration(riverId);
|
|
74
73
|
const screenData = useScreenData(riverId);
|
|
75
74
|
const pullToRefreshEnabled = screenData?.rules?.pull_to_refresh_enabled;
|
|
@@ -88,7 +87,7 @@ function ComponentsMapComponent(props: Props) {
|
|
|
88
87
|
|
|
89
88
|
const onLoadDone = React.useCallback(() => {
|
|
90
89
|
logTimestamp(riverId?.toString());
|
|
91
|
-
}, [logTimestamp
|
|
90
|
+
}, [logTimestamp]);
|
|
92
91
|
|
|
93
92
|
const { loadingState, onLoadFinished, onLoadFailed, shouldShowLoadingError } =
|
|
94
93
|
useLoadingState(riverComponents.length, onLoadDone);
|
|
@@ -117,17 +116,7 @@ function ComponentsMapComponent(props: Props) {
|
|
|
117
116
|
</ScreenLoadingMeasurementsListItemWrapper>
|
|
118
117
|
);
|
|
119
118
|
},
|
|
120
|
-
[
|
|
121
|
-
feed,
|
|
122
|
-
getStaticComponentFeed,
|
|
123
|
-
groupId,
|
|
124
|
-
isScreenWrappedInContainer,
|
|
125
|
-
loadingState,
|
|
126
|
-
onLoadFailed,
|
|
127
|
-
onLoadFinished,
|
|
128
|
-
riverComponents.length,
|
|
129
|
-
riverId,
|
|
130
|
-
]
|
|
119
|
+
[feed, getStaticComponentFeed, onLoadFailed, onLoadFinished]
|
|
131
120
|
);
|
|
132
121
|
|
|
133
122
|
const screenStyle = React.useMemo(
|
|
@@ -149,13 +138,7 @@ function ComponentsMapComponent(props: Props) {
|
|
|
149
138
|
R.prop("screen_padding_right")(theme)
|
|
150
139
|
),
|
|
151
140
|
}),
|
|
152
|
-
[
|
|
153
|
-
screenConfig.paddingTop,
|
|
154
|
-
screenConfig.paddingBottom,
|
|
155
|
-
screenConfig.paddingLeft,
|
|
156
|
-
screenConfig.paddingRight,
|
|
157
|
-
theme,
|
|
158
|
-
]
|
|
141
|
+
[riverId]
|
|
159
142
|
);
|
|
160
143
|
|
|
161
144
|
const handleOnLayout = React.useCallback(
|
|
@@ -190,50 +173,55 @@ function ComponentsMapComponent(props: Props) {
|
|
|
190
173
|
canMomentum.current = true;
|
|
191
174
|
}, []);
|
|
192
175
|
|
|
193
|
-
/*
|
|
194
|
-
const
|
|
195
|
-
(
|
|
196
|
-
|
|
176
|
+
/* onMomentumScrollEnd: Handling snap to expanded/collapsed state ( for navbar ) */
|
|
177
|
+
const _onMomentumScrollEnd = React.useCallback(({ nativeEvent }) => {
|
|
178
|
+
if (!canMomentum.current) return;
|
|
179
|
+
canMomentum.current = false;
|
|
197
180
|
|
|
198
|
-
|
|
199
|
-
if (scrollState === 0 || scrollState === -headerHeight) return;
|
|
200
|
-
if (!flatListRef.current) return;
|
|
181
|
+
const { height: headerHeight, scrollState } = navBarStore.getState();
|
|
201
182
|
|
|
202
|
-
|
|
183
|
+
const offsetY = Math.max(0, nativeEvent.contentOffset.y);
|
|
203
184
|
|
|
204
|
-
|
|
185
|
+
if (
|
|
186
|
+
!(scrollState === 0 || scrollState === -headerHeight) &&
|
|
187
|
+
flatListRef.current
|
|
188
|
+
) {
|
|
189
|
+
const offset =
|
|
205
190
|
getNearestValue(Math.round(scrollState), -headerHeight, 0) ===
|
|
206
|
-
-headerHeight
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
191
|
+
-headerHeight
|
|
192
|
+
? Math.round(offsetY + scrollState + headerHeight)
|
|
193
|
+
: Math.round(offsetY + scrollState);
|
|
194
|
+
|
|
195
|
+
flatListRef.current.scrollToOffset({
|
|
196
|
+
animated: true,
|
|
197
|
+
offset,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}, []);
|
|
211
201
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
);
|
|
202
|
+
/* onScrollEnd: Handling snap to expanded/collapsed state ( for navbar ) */
|
|
203
|
+
const _onScrollEndDrag = React.useCallback(({ nativeEvent }) => {
|
|
204
|
+
const { height: headerHeight, scrollState } = navBarStore.getState();
|
|
216
205
|
|
|
217
|
-
|
|
218
|
-
const _onMomentumScrollEnd = React.useCallback(
|
|
219
|
-
({ nativeEvent }) => {
|
|
220
|
-
if (!canMomentum.current) return;
|
|
221
|
-
canMomentum.current = false;
|
|
222
|
-
snapToHeaderState(nativeEvent.contentOffset.y);
|
|
223
|
-
},
|
|
224
|
-
[snapToHeaderState]
|
|
225
|
-
);
|
|
206
|
+
const offsetY = Math.max(0, nativeEvent.contentOffset.y);
|
|
226
207
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
208
|
+
if (
|
|
209
|
+
!(scrollState === 0 || scrollState === -headerHeight) &&
|
|
210
|
+
flatListRef.current &&
|
|
211
|
+
nativeEvent.velocity.y === 0
|
|
212
|
+
) {
|
|
213
|
+
const offset =
|
|
214
|
+
getNearestValue(Math.round(scrollState), -headerHeight, 0) ===
|
|
215
|
+
-headerHeight
|
|
216
|
+
? Math.round(offsetY + scrollState + headerHeight)
|
|
217
|
+
: Math.round(offsetY + scrollState);
|
|
218
|
+
|
|
219
|
+
flatListRef.current.scrollToOffset({
|
|
220
|
+
animated: true,
|
|
221
|
+
offset,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}, []);
|
|
237
225
|
|
|
238
226
|
const onScroll = React.useCallback((event) => {
|
|
239
227
|
hasUserScrolledRef.current = true;
|
|
@@ -257,42 +245,8 @@ function ComponentsMapComponent(props: Props) {
|
|
|
257
245
|
}
|
|
258
246
|
}, []);
|
|
259
247
|
|
|
260
|
-
const onScrollWithEndReached = React.useCallback(
|
|
261
|
-
(event) => {
|
|
262
|
-
onScroll(event);
|
|
263
|
-
|
|
264
|
-
if (!hasUserScrolledRef.current) return;
|
|
265
|
-
if (isScreenWrappedInContainer) return;
|
|
266
|
-
|
|
267
|
-
const {
|
|
268
|
-
nativeEvent: {
|
|
269
|
-
contentOffset: { y },
|
|
270
|
-
layoutMeasurement: { height },
|
|
271
|
-
contentSize: { height: contentHeight },
|
|
272
|
-
},
|
|
273
|
-
} = event;
|
|
274
|
-
|
|
275
|
-
const distanceFromEnd = contentHeight - y - height;
|
|
276
|
-
|
|
277
|
-
if (distanceFromEnd <= height * 0.5) {
|
|
278
|
-
if (!scrollEndReachedRef.current) {
|
|
279
|
-
scrollEndReachedRef.current = true;
|
|
280
|
-
emitScrollEndReached();
|
|
281
|
-
}
|
|
282
|
-
} else {
|
|
283
|
-
scrollEndReachedRef.current = false;
|
|
284
|
-
}
|
|
285
|
-
},
|
|
286
|
-
[onScroll, isScreenWrappedInContainer]
|
|
287
|
-
);
|
|
288
|
-
|
|
289
248
|
const contentContainerStyle = React.useMemo(
|
|
290
|
-
() =>
|
|
291
|
-
isScreenWrappedInContainer
|
|
292
|
-
? {
|
|
293
|
-
flexGrow: 1,
|
|
294
|
-
}
|
|
295
|
-
: screenStyle,
|
|
249
|
+
() => (isScreenWrappedInContainer ? {} : screenStyle),
|
|
296
250
|
[isScreenWrappedInContainer, screenStyle]
|
|
297
251
|
);
|
|
298
252
|
|
|
@@ -303,98 +257,61 @@ function ComponentsMapComponent(props: Props) {
|
|
|
303
257
|
// TODO: support both "isScreenWrappedInContainer" and hasScreenPicker().
|
|
304
258
|
// The Screen Picker in Mobile is completly different than the TV
|
|
305
259
|
// so the various offsets / margins in TV do not apply here.
|
|
306
|
-
// Fix for WebView rerender crashes on Android API 28+
|
|
307
|
-
// https://github.com/react-native-webview/react-native-webview/issues/1915#issuecomment-964035468
|
|
308
|
-
const sharedScrollProps = {
|
|
309
|
-
overScrollMode: isAndroid ? ("never" as const) : ("auto" as const),
|
|
310
|
-
scrollIndicatorInsets,
|
|
311
|
-
onLayout: handleOnLayout,
|
|
312
|
-
contentContainerStyle,
|
|
313
|
-
refreshControl,
|
|
314
|
-
onScrollBeginDrag,
|
|
315
|
-
onMomentumScrollEnd: _onMomentumScrollEnd,
|
|
316
|
-
onScrollEndDrag: _onScrollEndDrag,
|
|
317
|
-
scrollEventThrottle: 16,
|
|
318
|
-
...scrollViewExtraProps,
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
const listContent = useScrollView ? (
|
|
322
|
-
<ScrollView
|
|
323
|
-
testID="components-map-scroll-view"
|
|
324
|
-
// ViewportTracker clones this child and calls its `ref` as a function
|
|
325
|
-
// (childrenRef.current.ref(node)), so a callback ref is required here
|
|
326
|
-
// — an object ref would throw "ref is not a function".
|
|
327
|
-
ref={(ref) => {
|
|
328
|
-
scrollViewRef.current = ref;
|
|
329
|
-
}}
|
|
330
|
-
onScroll={onScrollWithEndReached}
|
|
331
|
-
{...sharedScrollProps}
|
|
332
|
-
>
|
|
333
|
-
{riverComponents.map((item, index) => (
|
|
334
|
-
<React.Fragment key={keyExtractor(item)}>
|
|
335
|
-
{renderRiverItem({ item, index })}
|
|
336
|
-
</React.Fragment>
|
|
337
|
-
))}
|
|
338
|
-
<RiverFooter
|
|
339
|
-
flatListHeight={flatListHeight}
|
|
340
|
-
loadingState={loadingState}
|
|
341
|
-
/>
|
|
342
|
-
</ScrollView>
|
|
343
|
-
) : (
|
|
344
|
-
<FlatList
|
|
345
|
-
testID="components-map-flat-list"
|
|
346
|
-
// ViewportTracker clones this child and calls its `ref` as a function
|
|
347
|
-
// (childrenRef.current.ref(node)), so a callback ref is required here
|
|
348
|
-
// — an object ref would throw "ref is not a function".
|
|
349
|
-
ref={(ref) => {
|
|
350
|
-
flatListRef.current = ref;
|
|
351
|
-
}}
|
|
352
|
-
extraData={feed}
|
|
353
|
-
stickyHeaderIndices={stickyHeaderIndices}
|
|
354
|
-
removeClippedSubviews={isAndroid}
|
|
355
|
-
initialNumToRender={3}
|
|
356
|
-
maxToRenderPerBatch={10}
|
|
357
|
-
windowSize={12}
|
|
358
|
-
keyExtractor={keyExtractor}
|
|
359
|
-
renderItem={renderRiverItem}
|
|
360
|
-
data={riverComponents}
|
|
361
|
-
ListFooterComponent={
|
|
362
|
-
<RiverFooter
|
|
363
|
-
flatListHeight={flatListHeight}
|
|
364
|
-
loadingState={loadingState}
|
|
365
|
-
/>
|
|
366
|
-
}
|
|
367
|
-
onScroll={onScroll}
|
|
368
|
-
onEndReached={
|
|
369
|
-
/* TODO: end-reached detection is inconsistent between the two paths:
|
|
370
|
-
the ScrollView branch uses manual pixel-offset math (onScrollWithEndReached)
|
|
371
|
-
with a scrollEndReachedRef debounce, while this FlatList relies on the
|
|
372
|
-
native onEndReached. Consider unifying the threshold/debounce behavior. */
|
|
373
|
-
/* When wrapped in a parent ScrollView (e.g. tabs),
|
|
374
|
-
this FlatList doesn't scroll so onEndReached can fire repeatedly;
|
|
375
|
-
skip it here and let the parent ScrollView emit scroll-end instead. */
|
|
376
|
-
isScreenWrappedInContainer
|
|
377
|
-
? undefined
|
|
378
|
-
: () => {
|
|
379
|
-
if (!hasUserScrolledRef.current) return;
|
|
380
|
-
emitScrollEndReached();
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
{...sharedScrollProps}
|
|
384
|
-
/>
|
|
385
|
-
);
|
|
386
|
-
|
|
387
260
|
return (
|
|
388
|
-
|
|
389
|
-
// for measuring the list's position/height; it intentionally has no style.
|
|
390
|
-
<View ref={flatListWrapperRef}>
|
|
261
|
+
<View style={styles.container} ref={flatListWrapperRef}>
|
|
391
262
|
<ComponentsMapHeightContext.Provider value={flatListHeight}>
|
|
392
263
|
<ComponentsMapRefContext.Provider value={flatListWrapperRef}>
|
|
393
264
|
<ScreenLoadingMeasurements
|
|
394
265
|
riverId={riverId}
|
|
395
266
|
numberOfComponents={riverComponents.length}
|
|
396
267
|
>
|
|
397
|
-
<ViewportTracker>
|
|
268
|
+
<ViewportTracker>
|
|
269
|
+
<FlatList
|
|
270
|
+
testID="components-map-flat-list"
|
|
271
|
+
ref={(ref) => {
|
|
272
|
+
flatListRef.current = ref;
|
|
273
|
+
}}
|
|
274
|
+
// Fix for WebView rerender crashes on Android API 28+
|
|
275
|
+
// https://github.com/react-native-webview/react-native-webview/issues/1915#issuecomment-964035468
|
|
276
|
+
overScrollMode={isAndroid ? "never" : "auto"}
|
|
277
|
+
scrollIndicatorInsets={scrollIndicatorInsets}
|
|
278
|
+
extraData={feed}
|
|
279
|
+
stickyHeaderIndices={stickyHeaderIndices}
|
|
280
|
+
removeClippedSubviews={isAndroid}
|
|
281
|
+
onLayout={handleOnLayout}
|
|
282
|
+
initialNumToRender={3}
|
|
283
|
+
maxToRenderPerBatch={10}
|
|
284
|
+
windowSize={12}
|
|
285
|
+
keyExtractor={keyExtractor}
|
|
286
|
+
renderItem={renderRiverItem}
|
|
287
|
+
data={riverComponents}
|
|
288
|
+
contentContainerStyle={contentContainerStyle}
|
|
289
|
+
ListFooterComponent={
|
|
290
|
+
<RiverFooter
|
|
291
|
+
flatListHeight={flatListHeight}
|
|
292
|
+
loadingState={loadingState}
|
|
293
|
+
/>
|
|
294
|
+
}
|
|
295
|
+
refreshControl={refreshControl}
|
|
296
|
+
onScrollBeginDrag={onScrollBeginDrag}
|
|
297
|
+
onScroll={onScroll}
|
|
298
|
+
onMomentumScrollEnd={_onMomentumScrollEnd}
|
|
299
|
+
onScrollEndDrag={_onScrollEndDrag}
|
|
300
|
+
scrollEventThrottle={16}
|
|
301
|
+
{...scrollViewExtraProps}
|
|
302
|
+
onEndReached={
|
|
303
|
+
/* When wrapped in a parent ScrollView (e.g. tabs),
|
|
304
|
+
this FlatList doesn't scroll so onEndReached can fire repeatedly;
|
|
305
|
+
skip it here and let the parent ScrollView emit scroll-end instead. */
|
|
306
|
+
isScreenWrappedInContainer
|
|
307
|
+
? undefined
|
|
308
|
+
: () => {
|
|
309
|
+
if (!hasUserScrolledRef.current) return;
|
|
310
|
+
emitScrollEndReached();
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/>
|
|
314
|
+
</ViewportTracker>
|
|
398
315
|
</ScreenLoadingMeasurements>
|
|
399
316
|
</ComponentsMapRefContext.Provider>
|
|
400
317
|
</ComponentsMapHeightContext.Provider>
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
3
|
exports[`componentsMap renders renders components map correctly 1`] = `
|
|
4
|
-
<View
|
|
4
|
+
<View
|
|
5
|
+
style={
|
|
6
|
+
{
|
|
7
|
+
"flex": 1,
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
>
|
|
5
11
|
<View
|
|
6
12
|
onLayout={[Function]}
|
|
13
|
+
style={
|
|
14
|
+
{
|
|
15
|
+
"flex": 1,
|
|
16
|
+
}
|
|
17
|
+
}
|
|
7
18
|
>
|
|
8
19
|
<RCTScrollView
|
|
9
20
|
ListFooterComponent={
|
|
@@ -156,6 +167,11 @@ exports[`componentsMap renders renders components map correctly 1`] = `
|
|
|
156
167
|
>
|
|
157
168
|
<View
|
|
158
169
|
onLayout={[Function]}
|
|
170
|
+
style={
|
|
171
|
+
{
|
|
172
|
+
"flex": 1,
|
|
173
|
+
}
|
|
174
|
+
}
|
|
159
175
|
>
|
|
160
176
|
<View />
|
|
161
177
|
</View>
|
|
@@ -167,6 +183,11 @@ exports[`componentsMap renders renders components map correctly 1`] = `
|
|
|
167
183
|
>
|
|
168
184
|
<View
|
|
169
185
|
onLayout={[Function]}
|
|
186
|
+
style={
|
|
187
|
+
{
|
|
188
|
+
"flex": 1,
|
|
189
|
+
}
|
|
190
|
+
}
|
|
170
191
|
/>
|
|
171
192
|
</View>
|
|
172
193
|
<View
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-ui-components",
|
|
3
|
-
"version": "16.0.0-alpha.
|
|
3
|
+
"version": "16.0.0-alpha.2851031376",
|
|
4
4
|
"description": "Applicaster Zapp React Native ui components for the Quick Brick App",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/applicaster-types": "16.0.0-alpha.
|
|
32
|
-
"@applicaster/zapp-react-native-bridge": "16.0.0-alpha.
|
|
33
|
-
"@applicaster/zapp-react-native-redux": "16.0.0-alpha.
|
|
34
|
-
"@applicaster/zapp-react-native-utils": "16.0.0-alpha.
|
|
31
|
+
"@applicaster/applicaster-types": "16.0.0-alpha.2851031376",
|
|
32
|
+
"@applicaster/zapp-react-native-bridge": "16.0.0-alpha.2851031376",
|
|
33
|
+
"@applicaster/zapp-react-native-redux": "16.0.0-alpha.2851031376",
|
|
34
|
+
"@applicaster/zapp-react-native-utils": "16.0.0-alpha.2851031376",
|
|
35
35
|
"fast-json-stable-stringify": "^2.1.0",
|
|
36
36
|
"promise": "^8.3.0",
|
|
37
37
|
"url": "^0.11.0",
|