@applicaster/zapp-react-native-utils 15.0.0-alpha.4515904047 → 15.0.0-alpha.5740530237
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/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.5740530237",
|
|
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.5740530237",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|
|
@@ -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
|
}
|
|
@@ -15,7 +15,7 @@ export enum ResultType {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export type CallbackResult = hookCallbackArgs & {
|
|
18
|
-
options
|
|
18
|
+
options?: {
|
|
19
19
|
resultType?: ResultType;
|
|
20
20
|
};
|
|
21
21
|
};
|
|
@@ -36,7 +36,7 @@ type General = Record<string, unknown>;
|
|
|
36
36
|
|
|
37
37
|
const LogPrefix = "useCallbackNavigationAction:";
|
|
38
38
|
|
|
39
|
-
const { log_info, log_verbose,
|
|
39
|
+
const { log_info, log_verbose, log_debug } = createLogger({
|
|
40
40
|
subsystem: "hook-navigation-callback",
|
|
41
41
|
});
|
|
42
42
|
|
|
@@ -58,21 +58,23 @@ const legacyMappingKeys = {
|
|
|
58
58
|
},
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
const isNonEmptyString = (v: unknown): v is string =>
|
|
62
|
-
typeof v === "string" && v.trim().length > 0;
|
|
63
|
-
|
|
64
61
|
const NAV_ACTIONS = Object.values(NavigationCallbackOptions) as string[];
|
|
65
62
|
|
|
66
63
|
const isNavAction = (v: unknown): v is NavigationCallbackOptions =>
|
|
67
|
-
typeof v === "string" && NAV_ACTIONS.includes(v
|
|
64
|
+
typeof v === "string" && NAV_ACTIONS.includes(v);
|
|
68
65
|
|
|
69
66
|
export const getNavigationKeys = (
|
|
70
67
|
item?: ZappUIComponent | ZappRiver,
|
|
71
|
-
resultType: ResultType = null
|
|
68
|
+
resultType: ResultType | null = null
|
|
72
69
|
): NavKeys => {
|
|
73
70
|
const general = (item?.general ?? {}) as General;
|
|
74
|
-
|
|
75
|
-
const
|
|
71
|
+
|
|
72
|
+
const pluginIdentifier = (item as any).identifier ?? item?.type ?? "";
|
|
73
|
+
|
|
74
|
+
const legacy =
|
|
75
|
+
legacyMappingKeys[`${pluginIdentifier}.${resultType}`] ??
|
|
76
|
+
legacyMappingKeys[pluginIdentifier] ??
|
|
77
|
+
{};
|
|
76
78
|
|
|
77
79
|
const actionKey = resultType
|
|
78
80
|
? `${resultType}_${CALLBACK_NAVIGATION_KEY}`
|
|
@@ -82,29 +84,27 @@ export const getNavigationKeys = (
|
|
|
82
84
|
(general as General)[actionKey] ??
|
|
83
85
|
(legacy.actionType ? (general as General)[legacy.actionType] : undefined);
|
|
84
86
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const trimmed = rawAction.trim();
|
|
89
|
-
action = isNavAction(trimmed) ? trimmed : null;
|
|
90
|
-
}
|
|
87
|
+
const action: NavigationCallbackOptions | null = isNavAction(rawAction)
|
|
88
|
+
? rawAction
|
|
89
|
+
: null;
|
|
91
90
|
|
|
92
91
|
if (!action) return null;
|
|
93
92
|
|
|
94
93
|
let targetScreenId: string | null = null;
|
|
95
94
|
|
|
96
95
|
if (action === NavigationCallbackOptions.GO_TO_SCREEN) {
|
|
96
|
+
const screenKey = resultType
|
|
97
|
+
? `${resultType}_${CALLBACK_NAVIGATION_GO_TO_SCREEN_KEY}`
|
|
98
|
+
: CALLBACK_NAVIGATION_GO_TO_SCREEN_KEY;
|
|
99
|
+
|
|
97
100
|
const screenId: string | null =
|
|
98
|
-
((general as General)[
|
|
101
|
+
((general as General)[screenKey] as string) ??
|
|
99
102
|
(legacy.targetScreen
|
|
100
103
|
? ((general as General)[legacy.targetScreen] as string)
|
|
101
104
|
: undefined);
|
|
102
105
|
|
|
103
106
|
if (screenId) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
targetScreenId =
|
|
107
|
-
trimmedTargetScreenId.length > 0 ? trimmedTargetScreenId : null;
|
|
107
|
+
targetScreenId = screenId.length > 0 ? screenId : null;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
@@ -113,10 +113,12 @@ export const getNavigationKeys = (
|
|
|
113
113
|
|
|
114
114
|
export const useCallbackNavigationAction = (
|
|
115
115
|
item?: ZappUIComponent | ZappRiver
|
|
116
|
-
): ((
|
|
116
|
+
): ((
|
|
117
|
+
args: CallbackResult,
|
|
118
|
+
hookCallback?: hookCallback
|
|
119
|
+
) => void | undefined) => {
|
|
117
120
|
const navigation = useNavigation();
|
|
118
121
|
const rivers = useRivers();
|
|
119
|
-
const enabled = Boolean(item?.general?.[CALLBACK_NAVIGATION_KEY]);
|
|
120
122
|
const screenContext = useScreenContext();
|
|
121
123
|
|
|
122
124
|
const overrideCallbackFromComponent = useMemo(() => {
|
|
@@ -131,23 +133,36 @@ export const useCallbackNavigationAction = (
|
|
|
131
133
|
}
|
|
132
134
|
|
|
133
135
|
const callbackAction = useCallback<hookCallback>(
|
|
134
|
-
(args: CallbackResult) => {
|
|
136
|
+
(args: CallbackResult, hookCallback: hookCallback = null) => {
|
|
135
137
|
if (!args.success) {
|
|
136
|
-
|
|
138
|
+
log_debug(
|
|
139
|
+
`${LogPrefix} callback called with no success, use original callback`
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
hookCallback?.(args);
|
|
137
143
|
|
|
138
144
|
return;
|
|
139
145
|
}
|
|
140
146
|
|
|
141
147
|
if (args.cancelled) {
|
|
142
|
-
|
|
148
|
+
log_debug(
|
|
149
|
+
`${LogPrefix} callback called but cancelled, use original callback`
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
hookCallback?.(args);
|
|
153
|
+
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const data = getNavigationKeys(item, args.options?.resultType ?? null);
|
|
158
|
+
|
|
159
|
+
if (!data) {
|
|
160
|
+
hookCallback?.(args);
|
|
143
161
|
|
|
144
162
|
return;
|
|
145
163
|
}
|
|
146
164
|
|
|
147
|
-
|
|
148
|
-
action: NavigationCallbackOptions.DEFAULT,
|
|
149
|
-
targetScreenId: null,
|
|
150
|
-
};
|
|
165
|
+
hookCallback?.({ ...args, success: false, cancelled: true });
|
|
151
166
|
|
|
152
167
|
switch (data.action) {
|
|
153
168
|
case NavigationCallbackOptions.GO_BACK: {
|
|
@@ -198,5 +213,5 @@ export const useCallbackNavigationAction = (
|
|
|
198
213
|
[item, navigation, rivers]
|
|
199
214
|
);
|
|
200
215
|
|
|
201
|
-
return
|
|
216
|
+
return overrideCallbackFromComponent || callbackAction;
|
|
202
217
|
};
|
|
@@ -12,13 +12,7 @@ export const useCallbackActions = (
|
|
|
12
12
|
|
|
13
13
|
return useCallback(
|
|
14
14
|
async (data: CallbackResult) => {
|
|
15
|
-
|
|
16
|
-
hookCallback?.({ ...data, success: false, cancelled: true });
|
|
17
|
-
|
|
18
|
-
navigationAction(data);
|
|
19
|
-
} else {
|
|
20
|
-
hookCallback?.(data);
|
|
21
|
-
}
|
|
15
|
+
navigationAction(data, hookCallback);
|
|
22
16
|
},
|
|
23
17
|
[navigationAction, hookCallback]
|
|
24
18
|
);
|