@applicaster/zapp-react-native-utils 15.0.0-alpha.2239032089 → 15.0.0-alpha.2413435535
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/analyticsUtils/AnalyticPlayerListener.ts +5 -2
- package/appUtils/RiverFocusManager/{index.ts → index.js} +18 -25
- package/appUtils/accessibilityManager/hooks.ts +8 -6
- package/appUtils/accessibilityManager/index.ts +28 -1
- package/appUtils/accessibilityManager/utils.ts +36 -5
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +1 -3
- package/appUtils/focusManager/index.ios.ts +15 -33
- package/appUtils/focusManagerAux/utils/index.ts +18 -0
- package/appUtils/focusManagerAux/utils/utils.ios.ts +24 -52
- package/appUtils/platform/platformUtils.ts +107 -23
- package/appUtils/playerManager/conts.ts +21 -0
- package/arrayUtils/__tests__/allTruthy.test.ts +24 -0
- package/arrayUtils/__tests__/anyThruthy.test.ts +24 -0
- package/arrayUtils/index.ts +5 -0
- package/cellUtils/index.ts +40 -1
- package/navigationUtils/index.ts +19 -16
- package/package.json +2 -2
- package/playerUtils/usePlayerTTS.ts +5 -2
- package/reactHooks/feed/useBatchLoading.ts +7 -1
- package/reactHooks/feed/useFeedLoader.tsx +0 -9
- package/reactHooks/feed/useInflatedUrl.ts +23 -29
- package/reactHooks/feed/usePipesCacheReset.ts +3 -1
- package/reactHooks/layout/index.ts +1 -1
- package/utils/__tests__/mapAccum.test.ts +73 -0
- package/utils/index.ts +6 -0
- package/utils/mapAccum.ts +23 -0
- package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +98 -31
- package/zappFrameworkUtils/HookCallback/hookCallbackManifestExtensions.config.js +25 -9
- package/zappFrameworkUtils/HookCallback/useCallbackActions.ts +6 -9
- package/appUtils/focusManagerAux/utils/index.ios.ts +0 -104
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { anyTruthy } from "..";
|
|
2
|
+
|
|
3
|
+
describe("anyTruthy", () => {
|
|
4
|
+
it("should return true when at least one value is true", () => {
|
|
5
|
+
expect(anyTruthy([false, true, false])).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("should return false when all values are false", () => {
|
|
9
|
+
expect(anyTruthy([false, false, false])).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("should return true when all values are true", () => {
|
|
13
|
+
expect(anyTruthy([true, true, true])).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should return false for an empty array", () => {
|
|
17
|
+
expect(anyTruthy([])).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should handle single-element arrays correctly", () => {
|
|
21
|
+
expect(anyTruthy([true])).toBe(true);
|
|
22
|
+
expect(anyTruthy([false])).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
});
|
package/arrayUtils/index.ts
CHANGED
package/cellUtils/index.ts
CHANGED
|
@@ -9,7 +9,10 @@ import {
|
|
|
9
9
|
} from "@applicaster/zapp-react-native-utils/stringUtils";
|
|
10
10
|
import { cellUtilsLogger } from "@applicaster/zapp-react-native-utils/cellUtils/logger";
|
|
11
11
|
import { isWeb } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
isNotNil,
|
|
14
|
+
isNilOrEmpty,
|
|
15
|
+
} from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
|
|
13
16
|
|
|
14
17
|
import { toNumberWithDefault, toNumberWithDefaultZero } from "../numberUtils";
|
|
15
18
|
|
|
@@ -505,3 +508,39 @@ export const getImageContainerMarginStyles = ({ value }: { value: any }) => {
|
|
|
505
508
|
marginRight: value("image_margin_right"),
|
|
506
509
|
};
|
|
507
510
|
};
|
|
511
|
+
|
|
512
|
+
export const withoutNilOrEmpty = (arr: string[]): string[] =>
|
|
513
|
+
arr.filter((item) => !isNilOrEmpty(item));
|
|
514
|
+
|
|
515
|
+
export const isTextLabel = (key: string): boolean =>
|
|
516
|
+
key.includes("text_label_") && key.endsWith("_switch");
|
|
517
|
+
|
|
518
|
+
export const hasTextLabelsEnabled = (
|
|
519
|
+
configuration: Record<string, any>
|
|
520
|
+
): boolean => {
|
|
521
|
+
const textLabelsKeys = Object.keys(configuration).filter(isTextLabel);
|
|
522
|
+
|
|
523
|
+
const picked = textLabelsKeys.reduce(
|
|
524
|
+
(acc, key) => {
|
|
525
|
+
acc[key] = configuration[key];
|
|
526
|
+
|
|
527
|
+
return acc;
|
|
528
|
+
},
|
|
529
|
+
{} as Record<string, any>
|
|
530
|
+
);
|
|
531
|
+
|
|
532
|
+
const pickedValues = Object.values(picked);
|
|
533
|
+
|
|
534
|
+
// Check if any switch value is truthy (true, "true", "1", etc.)
|
|
535
|
+
return pickedValues.some((value) => {
|
|
536
|
+
if (typeof value === "boolean") {
|
|
537
|
+
return value === true;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
if (typeof value === "string") {
|
|
541
|
+
return value !== "" && value.toLowerCase() !== "false";
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
return Boolean(value);
|
|
545
|
+
});
|
|
546
|
+
};
|
package/navigationUtils/index.ts
CHANGED
|
@@ -575,24 +575,27 @@ export function routeIsPlayerScreen(currentRoute) {
|
|
|
575
575
|
return currentRoute?.includes("/playable");
|
|
576
576
|
}
|
|
577
577
|
|
|
578
|
-
export const getNavBarProps =
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
578
|
+
export const getNavBarProps = (
|
|
579
|
+
currentRiver: ZappRiver,
|
|
580
|
+
pathname: string,
|
|
581
|
+
title: string
|
|
582
|
+
) => {
|
|
583
|
+
const props = getNavigationPropsV2({
|
|
584
|
+
currentRiver,
|
|
585
|
+
title,
|
|
586
|
+
category: "nav_bar",
|
|
587
|
+
});
|
|
585
588
|
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
589
|
+
if (props) {
|
|
590
|
+
return {
|
|
591
|
+
...props,
|
|
592
|
+
id: pathname,
|
|
593
|
+
pathname: pathname,
|
|
594
|
+
};
|
|
595
|
+
}
|
|
593
596
|
|
|
594
|
-
|
|
595
|
-
|
|
597
|
+
return null;
|
|
598
|
+
};
|
|
596
599
|
|
|
597
600
|
export const findMenuPlugin = (
|
|
598
601
|
navigations: ZappNavigation[],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "15.0.0-alpha.
|
|
3
|
+
"version": "15.0.0-alpha.2413435535",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@applicaster/applicaster-types": "15.0.0-alpha.
|
|
30
|
+
"@applicaster/applicaster-types": "15.0.0-alpha.2413435535",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|
|
@@ -7,8 +7,11 @@ export const usePlayerTTS = () => {
|
|
|
7
7
|
const player = usePlayer();
|
|
8
8
|
const accessibilityManager = useAccessibilityManager({});
|
|
9
9
|
|
|
10
|
+
const isScreenReaderEnabled =
|
|
11
|
+
accessibilityManager.accessibilityManagerState.screenReaderEnabled;
|
|
12
|
+
|
|
10
13
|
React.useEffect(() => {
|
|
11
|
-
if (player && accessibilityManager) {
|
|
14
|
+
if (player && accessibilityManager && isScreenReaderEnabled) {
|
|
12
15
|
const playerTTS = new PlayerTTS(player, accessibilityManager);
|
|
13
16
|
const unsubscribe = playerTTS.init();
|
|
14
17
|
|
|
@@ -17,5 +20,5 @@ export const usePlayerTTS = () => {
|
|
|
17
20
|
playerTTS.destroy();
|
|
18
21
|
};
|
|
19
22
|
}
|
|
20
|
-
}, [player, accessibilityManager]);
|
|
23
|
+
}, [player, accessibilityManager, isScreenReaderEnabled]);
|
|
21
24
|
};
|
|
@@ -151,7 +151,13 @@ export const useBatchLoading = (
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
});
|
|
154
|
-
}, [
|
|
154
|
+
}, [
|
|
155
|
+
batchComponents,
|
|
156
|
+
feeds,
|
|
157
|
+
getUrl,
|
|
158
|
+
loadPipesDataDispatcher,
|
|
159
|
+
options.riverId,
|
|
160
|
+
]);
|
|
155
161
|
|
|
156
162
|
React.useEffect(() => {
|
|
157
163
|
runBatchLoading();
|
|
@@ -37,15 +37,6 @@ export const useFeedLoader = ({
|
|
|
37
37
|
mapping,
|
|
38
38
|
pipesOptions = {},
|
|
39
39
|
}: Props): FeedLoaderResponse => {
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
if (!feedUrl) {
|
|
42
|
-
logger.warning({
|
|
43
|
-
message: "Required parameter feedUrl is missing",
|
|
44
|
-
data: { feedUrl },
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}, []);
|
|
48
|
-
|
|
49
40
|
const isInitialRender = useIsInitialRender();
|
|
50
41
|
|
|
51
42
|
const callableFeedUrl = useInflatedUrl({ feedUrl, mapping });
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
} from "@applicaster/zapp-pipes-v2-client";
|
|
19
19
|
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
20
20
|
import { ENDPOINT_TAGS } from "../../types";
|
|
21
|
+
import { isNilOrEmpty } from "../../reactUtils/helpers";
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* will match any occurrence in a string of one or more word characters
|
|
@@ -75,15 +76,19 @@ export const getInflatedDataSourceUrl: GetInflatedDataSourceUrl = ({
|
|
|
75
76
|
* https://foo.com/shows/A1234
|
|
76
77
|
*/
|
|
77
78
|
|
|
78
|
-
if (!
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
if (!isNilOrEmpty(mapping)) {
|
|
80
|
+
if (!source) {
|
|
81
|
+
if (__DEV__) {
|
|
82
|
+
// eslint-disable-next-line no-console
|
|
83
|
+
throw new Error(
|
|
84
|
+
"getInflatedDataSourceUrl: source is empty while mapping is provided"
|
|
85
|
+
);
|
|
86
|
+
}
|
|
85
87
|
|
|
86
|
-
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
return source || null;
|
|
87
92
|
}
|
|
88
93
|
|
|
89
94
|
// Hack because in tv we expect to get key names instead of values from the fake entry
|
|
@@ -193,28 +198,17 @@ export function useInflatedUrl({
|
|
|
193
198
|
|
|
194
199
|
const url = useMemo(
|
|
195
200
|
() =>
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
: feedUrl,
|
|
207
|
-
[feedUrl, mapping]
|
|
201
|
+
getInflatedDataSourceUrl({
|
|
202
|
+
source: feedUrl,
|
|
203
|
+
contexts: {
|
|
204
|
+
entry: entryContext,
|
|
205
|
+
screen: screenContext,
|
|
206
|
+
search: getSearchContext(searchContext, mapping),
|
|
207
|
+
},
|
|
208
|
+
mapping,
|
|
209
|
+
}),
|
|
210
|
+
[entryContext, feedUrl, mapping, screenContext, searchContext]
|
|
208
211
|
);
|
|
209
212
|
|
|
210
|
-
if (!feedUrl) {
|
|
211
|
-
logger.warning({
|
|
212
|
-
message: "Required parameter feedUrl is missing",
|
|
213
|
-
data: { feedUrl },
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
return null;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
213
|
return url;
|
|
220
214
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { mapAccum } from "../mapAccum";
|
|
2
|
+
|
|
3
|
+
describe("mapAccum", () => {
|
|
4
|
+
it("using standard ramda test", () => {
|
|
5
|
+
const digits = ["1", "2", "3", "4"];
|
|
6
|
+
const appender = (a, b) => [a + b, a + b];
|
|
7
|
+
|
|
8
|
+
const [acc, result] = mapAccum(appender, 0, digits); //= > ['01234', ['01', '012', '0123', '01234']]
|
|
9
|
+
expect(acc).toBe("01234");
|
|
10
|
+
expect(result).toEqual(["01", "012", "0123", "01234"]);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("maps and accumulates over an array", () => {
|
|
14
|
+
const fn = (acc, x) => [acc + x, x * 2];
|
|
15
|
+
const [acc, result] = mapAccum(fn, 0, [1, 2, 3]);
|
|
16
|
+
|
|
17
|
+
expect(acc).toBe(6); // final accumulator (0 + 1 + 2 + 3)
|
|
18
|
+
expect(result).toEqual([2, 4, 6]); // mapped values (acc + x*2 at each step)
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("returns initial accumulator for empty array", () => {
|
|
22
|
+
const fn = (acc, x) => [acc + x, acc * x];
|
|
23
|
+
const [acc, result] = mapAccum(fn, 10, []);
|
|
24
|
+
|
|
25
|
+
expect(acc).toBe(10);
|
|
26
|
+
expect(result).toEqual([]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("accumulates strings correctly", () => {
|
|
30
|
+
const fn = (acc, x) => [acc + x, acc + x];
|
|
31
|
+
const [acc, result] = mapAccum(fn, "A", ["B", "C", "D"]);
|
|
32
|
+
|
|
33
|
+
expect(acc).toBe("ABCD");
|
|
34
|
+
expect(result).toEqual(["AB", "ABC", "ABCD"]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("works with objects as accumulator", () => {
|
|
38
|
+
const fn = (acc, x) => {
|
|
39
|
+
const newAcc = { sum: acc.sum + x };
|
|
40
|
+
|
|
41
|
+
return [newAcc, newAcc.sum];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const [acc, result] = mapAccum(fn, { sum: 0 }, [1, 2, 3]);
|
|
45
|
+
|
|
46
|
+
expect(acc).toEqual({ sum: 6 });
|
|
47
|
+
expect(result).toEqual([1, 3, 6]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("is curried", () => {
|
|
51
|
+
const fn = (acc, x) => [acc + x, x * 2];
|
|
52
|
+
const mapWithFn = mapAccum(fn);
|
|
53
|
+
const withInit = mapWithFn(2);
|
|
54
|
+
const [acc, result] = withInit([1, 2, 3]);
|
|
55
|
+
|
|
56
|
+
expect(acc).toBe(8);
|
|
57
|
+
expect(result).toEqual([2, 4, 6]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("does not mutate the original array", () => {
|
|
61
|
+
const arr = [1, 2, 3];
|
|
62
|
+
mapAccum((acc, x) => [acc + x, acc + x], 0, arr);
|
|
63
|
+
expect(arr).toEqual([1, 2, 3]);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("handles mixed types in accumulator and result", () => {
|
|
67
|
+
const fn = (acc, x) => [acc + x.length, acc + "-" + x];
|
|
68
|
+
const [acc, result] = mapAccum(fn, 0, ["a", "bb", "ccc"]);
|
|
69
|
+
|
|
70
|
+
expect(acc).toBe(6);
|
|
71
|
+
expect(result).toEqual(["0-a", "1-bb", "3-ccc"]);
|
|
72
|
+
});
|
|
73
|
+
});
|
package/utils/index.ts
CHANGED
|
@@ -16,6 +16,8 @@ export { endsWith } from "./endsWith";
|
|
|
16
16
|
|
|
17
17
|
export { take } from "./take";
|
|
18
18
|
|
|
19
|
+
export { mapAccum } from "./mapAccum";
|
|
20
|
+
|
|
19
21
|
export {
|
|
20
22
|
cloneDeep as clone,
|
|
21
23
|
flatten,
|
|
@@ -34,5 +36,9 @@ export {
|
|
|
34
36
|
last,
|
|
35
37
|
toLower,
|
|
36
38
|
isEqual as equals,
|
|
39
|
+
uniq,
|
|
40
|
+
uniqWith,
|
|
37
41
|
flowRight as compose,
|
|
42
|
+
partial,
|
|
43
|
+
reverse,
|
|
38
44
|
} from "lodash";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { curry } from "lodash";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A native reimplementation of Ramda's mapAccum.
|
|
5
|
+
*
|
|
6
|
+
* @template A, B, C
|
|
7
|
+
* @param {(acc: A, value: B) => [A, C]} fn - Function returning [newAcc, mappedValue]
|
|
8
|
+
* @param {A} acc - Initial accumulator
|
|
9
|
+
* @param {B[]} list - List to process
|
|
10
|
+
* @returns {[A, C[]]} - Tuple of [final accumulator, mapped array]
|
|
11
|
+
*/
|
|
12
|
+
export const mapAccum = curry((fn, acc, list) => {
|
|
13
|
+
const result = [];
|
|
14
|
+
let currentAcc = acc;
|
|
15
|
+
|
|
16
|
+
for (let i = 0; i < list.length; i++) {
|
|
17
|
+
const [nextAcc, mapped] = fn(currentAcc, list[i]);
|
|
18
|
+
currentAcc = nextAcc;
|
|
19
|
+
result.push(mapped);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return [currentAcc, result];
|
|
23
|
+
});
|
|
@@ -9,10 +9,23 @@ export enum NavigationCallbackOptions {
|
|
|
9
9
|
GO_TO_SCREEN = "go_to_screen",
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export
|
|
12
|
+
export enum ResultType {
|
|
13
|
+
login = "login",
|
|
14
|
+
logout = "logout",
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type CallbackResult = hookCallbackArgs & {
|
|
18
|
+
options?: {
|
|
19
|
+
resultType?: ResultType;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type ScreenResultCallback = (args: CallbackResult) => void | undefined;
|
|
24
|
+
|
|
25
|
+
export const CALLBACK_NAVIGATION_KEY = "completion_action";
|
|
13
26
|
|
|
14
27
|
export const CALLBACK_NAVIGATION_GO_TO_SCREEN_KEY =
|
|
15
|
-
"
|
|
28
|
+
"completion_action_navigation_go_to_screen";
|
|
16
29
|
|
|
17
30
|
type NavKeys = {
|
|
18
31
|
action: NavigationCallbackOptions;
|
|
@@ -23,7 +36,7 @@ type General = Record<string, unknown>;
|
|
|
23
36
|
|
|
24
37
|
const LogPrefix = "useCallbackNavigationAction:";
|
|
25
38
|
|
|
26
|
-
const { log_info, log_verbose } = createLogger({
|
|
39
|
+
const { log_info, log_verbose, log_debug } = createLogger({
|
|
27
40
|
subsystem: "hook-navigation-callback",
|
|
28
41
|
});
|
|
29
42
|
|
|
@@ -35,50 +48,77 @@ const legacyMappingKeys = {
|
|
|
35
48
|
"quick-brick-user-account-ui-component": {
|
|
36
49
|
actionType: "callbackAction",
|
|
37
50
|
},
|
|
51
|
+
"quick-brick-login-multi-login-providers.login": {
|
|
52
|
+
actionType: "login_completion_action",
|
|
53
|
+
targetScreen: "navigate_to_login_screen",
|
|
54
|
+
},
|
|
55
|
+
"quick-brick-login-multi-login-providers.logout": {
|
|
56
|
+
actionType: "logout_completion_action",
|
|
57
|
+
targetScreen: "navigate_to_logout_screen",
|
|
58
|
+
},
|
|
59
|
+
"quick-brick-storefront": {
|
|
60
|
+
actionType: "purchase_completion_action",
|
|
61
|
+
targetScreen: "navigate_to_screen_after_purchase",
|
|
62
|
+
},
|
|
63
|
+
"zapp_login_plugin_oauth_tv_2_0.login": {
|
|
64
|
+
actionType: "login_completion_action",
|
|
65
|
+
targetScreen: "navigate_to_login_screen",
|
|
66
|
+
},
|
|
67
|
+
"zapp_login_plugin_oauth_tv_2_0.logout": {
|
|
68
|
+
actionType: "logout_completion_action",
|
|
69
|
+
targetScreen: "navigate_to_logout_screen",
|
|
70
|
+
},
|
|
38
71
|
};
|
|
39
72
|
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const NAV_ACTIONS = Object.values(NavigationCallbackOptions) as string[];
|
|
73
|
+
const NAV_ACTIONS = (
|
|
74
|
+
Object.values(NavigationCallbackOptions) as string[]
|
|
75
|
+
).filter((value) => value !== NavigationCallbackOptions.DEFAULT);
|
|
44
76
|
|
|
45
77
|
const isNavAction = (v: unknown): v is NavigationCallbackOptions =>
|
|
46
|
-
typeof v === "string" && NAV_ACTIONS.includes(v
|
|
78
|
+
typeof v === "string" && NAV_ACTIONS.includes(v);
|
|
47
79
|
|
|
48
80
|
export const getNavigationKeys = (
|
|
49
|
-
item?: ZappUIComponent | ZappRiver
|
|
81
|
+
item?: ZappUIComponent | ZappRiver,
|
|
82
|
+
resultType: ResultType | null = null
|
|
50
83
|
): NavKeys => {
|
|
51
84
|
const general = (item?.general ?? {}) as General;
|
|
52
|
-
|
|
53
|
-
const
|
|
85
|
+
|
|
86
|
+
const pluginIdentifier = (item as any).identifier ?? item?.type ?? "";
|
|
87
|
+
|
|
88
|
+
const legacy =
|
|
89
|
+
legacyMappingKeys[`${pluginIdentifier}.${resultType}`] ??
|
|
90
|
+
legacyMappingKeys[pluginIdentifier] ??
|
|
91
|
+
{};
|
|
92
|
+
|
|
93
|
+
const actionKey = resultType
|
|
94
|
+
? `${resultType}_${CALLBACK_NAVIGATION_KEY}`
|
|
95
|
+
: CALLBACK_NAVIGATION_KEY;
|
|
54
96
|
|
|
55
97
|
const rawAction =
|
|
56
|
-
(general as General)
|
|
98
|
+
(general as General)[actionKey] ??
|
|
57
99
|
(legacy.actionType ? (general as General)[legacy.actionType] : undefined);
|
|
58
100
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const trimmed = rawAction.trim();
|
|
63
|
-
action = isNavAction(trimmed) ? trimmed : null;
|
|
64
|
-
}
|
|
101
|
+
const action: NavigationCallbackOptions | null = isNavAction(rawAction)
|
|
102
|
+
? rawAction
|
|
103
|
+
: null;
|
|
65
104
|
|
|
66
105
|
if (!action) return null;
|
|
67
106
|
|
|
68
107
|
let targetScreenId: string | null = null;
|
|
69
108
|
|
|
70
109
|
if (action === NavigationCallbackOptions.GO_TO_SCREEN) {
|
|
110
|
+
const screenKey = resultType
|
|
111
|
+
? `${resultType}_${CALLBACK_NAVIGATION_GO_TO_SCREEN_KEY}`
|
|
112
|
+
: CALLBACK_NAVIGATION_GO_TO_SCREEN_KEY;
|
|
113
|
+
|
|
71
114
|
const screenId: string | null =
|
|
72
|
-
((general as General)[
|
|
115
|
+
((general as General)[screenKey] as string) ??
|
|
73
116
|
(legacy.targetScreen
|
|
74
117
|
? ((general as General)[legacy.targetScreen] as string)
|
|
75
118
|
: undefined);
|
|
76
119
|
|
|
77
120
|
if (screenId) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
targetScreenId =
|
|
81
|
-
trimmedTargetScreenId.length > 0 ? trimmedTargetScreenId : null;
|
|
121
|
+
targetScreenId = screenId.length > 0 ? screenId : null;
|
|
82
122
|
}
|
|
83
123
|
}
|
|
84
124
|
|
|
@@ -87,10 +127,12 @@ export const getNavigationKeys = (
|
|
|
87
127
|
|
|
88
128
|
export const useCallbackNavigationAction = (
|
|
89
129
|
item?: ZappUIComponent | ZappRiver
|
|
90
|
-
):
|
|
130
|
+
): ((
|
|
131
|
+
args: CallbackResult,
|
|
132
|
+
hookCallback?: hookCallback
|
|
133
|
+
) => void | undefined) => {
|
|
91
134
|
const navigation = useNavigation();
|
|
92
135
|
const rivers = useRivers();
|
|
93
|
-
const enabled = Boolean(item?.general?.[CALLBACK_NAVIGATION_KEY]);
|
|
94
136
|
const screenContext = useScreenContext();
|
|
95
137
|
|
|
96
138
|
const overrideCallbackFromComponent = useMemo(() => {
|
|
@@ -105,11 +147,36 @@ export const useCallbackNavigationAction = (
|
|
|
105
147
|
}
|
|
106
148
|
|
|
107
149
|
const callbackAction = useCallback<hookCallback>(
|
|
108
|
-
(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
150
|
+
(args: CallbackResult, hookCallback: hookCallback = null) => {
|
|
151
|
+
if (!args.success) {
|
|
152
|
+
log_debug(
|
|
153
|
+
`${LogPrefix} callback called with no success, use original callback`
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
hookCallback?.(args);
|
|
157
|
+
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (args.cancelled) {
|
|
162
|
+
log_debug(
|
|
163
|
+
`${LogPrefix} callback called but cancelled, use original callback`
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
hookCallback?.(args);
|
|
167
|
+
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const data = getNavigationKeys(item, args.options?.resultType ?? null);
|
|
172
|
+
|
|
173
|
+
if (!data) {
|
|
174
|
+
hookCallback?.(args);
|
|
175
|
+
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
hookCallback?.({ ...args, success: false, cancelled: true });
|
|
113
180
|
|
|
114
181
|
switch (data.action) {
|
|
115
182
|
case NavigationCallbackOptions.GO_BACK: {
|
|
@@ -160,5 +227,5 @@ export const useCallbackNavigationAction = (
|
|
|
160
227
|
[item, navigation, rivers]
|
|
161
228
|
);
|
|
162
229
|
|
|
163
|
-
return
|
|
230
|
+
return overrideCallbackFromComponent || callbackAction;
|
|
164
231
|
};
|
|
@@ -5,20 +5,32 @@ const NavigationCallbackOptions = {
|
|
|
5
5
|
GO_TO_SCREEN: "go_to_screen",
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const ResultType = {
|
|
9
|
+
login: "login",
|
|
10
|
+
logout: "logout",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const CALLBACK_NAVIGATION_KEY = "completion_action";
|
|
9
14
|
|
|
10
15
|
const CALLBACK_NAVIGATION_GO_TO_SCREEN_KEY =
|
|
11
|
-
"
|
|
16
|
+
"completion_action_navigation_go_to_screen";
|
|
17
|
+
|
|
18
|
+
const callbackKeyPrefix = (key, prefix, keySeparator = "_") =>
|
|
19
|
+
prefix ? `${prefix}${keySeparator}${key}` : key;
|
|
12
20
|
|
|
13
|
-
const extendManifestWithHookCallback = () => ({
|
|
21
|
+
const extendManifestWithHookCallback = (prefix = null) => ({
|
|
14
22
|
group: true,
|
|
15
23
|
label: "CallBack Navigation",
|
|
16
24
|
folded: true,
|
|
17
25
|
fields: [
|
|
18
26
|
{
|
|
19
27
|
type: "select",
|
|
20
|
-
key: CALLBACK_NAVIGATION_KEY,
|
|
21
|
-
label:
|
|
28
|
+
key: callbackKeyPrefix(CALLBACK_NAVIGATION_KEY, prefix),
|
|
29
|
+
label: callbackKeyPrefix(
|
|
30
|
+
"Callback Navigation",
|
|
31
|
+
prefix?.toUpperCase(),
|
|
32
|
+
" "
|
|
33
|
+
),
|
|
22
34
|
label_tooltip:
|
|
23
35
|
"Defines what navigation action should be performed after the callback is called.",
|
|
24
36
|
options: [
|
|
@@ -43,13 +55,17 @@ const extendManifestWithHookCallback = () => ({
|
|
|
43
55
|
},
|
|
44
56
|
{
|
|
45
57
|
type: "screen_selector",
|
|
46
|
-
key: CALLBACK_NAVIGATION_GO_TO_SCREEN_KEY,
|
|
47
|
-
label:
|
|
58
|
+
key: callbackKeyPrefix(CALLBACK_NAVIGATION_GO_TO_SCREEN_KEY, prefix),
|
|
59
|
+
label: callbackKeyPrefix(
|
|
60
|
+
"Navigate to screen",
|
|
61
|
+
prefix?.toUpperCase(),
|
|
62
|
+
" "
|
|
63
|
+
),
|
|
48
64
|
label_tooltip: "Screen you wish to navigate to after success purchase",
|
|
49
65
|
rules: "conditional",
|
|
50
66
|
conditional_fields: [
|
|
51
67
|
{
|
|
52
|
-
key: `general/${CALLBACK_NAVIGATION_KEY}`,
|
|
68
|
+
key: `general/${callbackKeyPrefix(CALLBACK_NAVIGATION_KEY, prefix)}`,
|
|
53
69
|
condition_value: NavigationCallbackOptions.GO_TO_SCREEN,
|
|
54
70
|
},
|
|
55
71
|
],
|
|
@@ -57,4 +73,4 @@ const extendManifestWithHookCallback = () => ({
|
|
|
57
73
|
],
|
|
58
74
|
});
|
|
59
75
|
|
|
60
|
-
module.exports = { extendManifestWithHookCallback };
|
|
76
|
+
module.exports = { extendManifestWithHookCallback, ResultType };
|