@applicaster/zapp-react-native-utils 12.0.18-rc.0 → 12.0.19-alpha.1342029112
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="@applicaster/applicaster-types" />
|
|
2
2
|
import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
3
|
-
import React, { createContext, useMemo } from "react";
|
|
3
|
+
import React, { createContext, useEffect, useMemo } from "react";
|
|
4
4
|
import {
|
|
5
5
|
actionExecutor as _actionExecutor,
|
|
6
6
|
ActionResult,
|
|
@@ -19,7 +19,12 @@ import {
|
|
|
19
19
|
EntryResolver,
|
|
20
20
|
resolveObjectValues,
|
|
21
21
|
} from "../appUtils/contextKeysManager/contextResolver";
|
|
22
|
+
import { useNavigation } from "../reactHooks";
|
|
22
23
|
import { get } from "lodash";
|
|
24
|
+
import {
|
|
25
|
+
useContentTypes,
|
|
26
|
+
usePickFromState,
|
|
27
|
+
} from "@applicaster/zapp-react-native-redux/hooks";
|
|
23
28
|
|
|
24
29
|
const { log_error, log_info } = createLogger({
|
|
25
30
|
subsystem: "ActionExecutorContext",
|
|
@@ -251,6 +256,10 @@ export function withActionExecutor(Component) {
|
|
|
251
256
|
prepareDefaultActions(_actionExecutor);
|
|
252
257
|
|
|
253
258
|
return function ActionExecutorComponent(props: Props) {
|
|
259
|
+
const navigator = useNavigation();
|
|
260
|
+
const { rivers } = usePickFromState(["rivers"]);
|
|
261
|
+
const contentTypes = useContentTypes();
|
|
262
|
+
|
|
254
263
|
const handlers = useMemo(() => {
|
|
255
264
|
return {
|
|
256
265
|
unregisterAction: _actionExecutor.unregisterAction,
|
|
@@ -261,6 +270,44 @@ export function withActionExecutor(Component) {
|
|
|
261
270
|
};
|
|
262
271
|
}, []);
|
|
263
272
|
|
|
273
|
+
useEffect(() => {
|
|
274
|
+
return _actionExecutor.registerAction(
|
|
275
|
+
"navigateToScreen",
|
|
276
|
+
async (action: ActionType, context?: Record<string, any>) => {
|
|
277
|
+
const screenType = action.options?.typeMapping;
|
|
278
|
+
|
|
279
|
+
if (!screenType) {
|
|
280
|
+
log_error("navigateToScreen: typeMapping option is missing");
|
|
281
|
+
|
|
282
|
+
return ActionResult.Error;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const screenId = contentTypes?.[screenType]?.screen_id || null;
|
|
286
|
+
|
|
287
|
+
if (!screenId) {
|
|
288
|
+
log_error(
|
|
289
|
+
`navigateToScreen: can not resolve screen type mapping: ${screenType}`
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
return ActionResult.Error;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const river = rivers[screenId];
|
|
296
|
+
|
|
297
|
+
if (!river) {
|
|
298
|
+
log_error("navigateToScreen: can not resolve river");
|
|
299
|
+
|
|
300
|
+
return ActionResult.Error;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
context?.callback?.({ success: false, error: null, abort: true });
|
|
304
|
+
navigator.replace(river);
|
|
305
|
+
|
|
306
|
+
return ActionResult.Success;
|
|
307
|
+
}
|
|
308
|
+
);
|
|
309
|
+
}, [navigator, rivers, contentTypes]);
|
|
310
|
+
|
|
264
311
|
return (
|
|
265
312
|
<ActionExecutorContext.Provider value={handlers}>
|
|
266
313
|
<Component {...props} />
|
|
@@ -56,6 +56,10 @@ export class Hook {
|
|
|
56
56
|
* @param {Array<Any>} args variadic arguments to invoke the handler with
|
|
57
57
|
*/
|
|
58
58
|
setStateAndNotify(event, ...args) {
|
|
59
|
+
if (this.state === hookState(HOOKS_EVENTS.CANCEL)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
59
63
|
this.state = hookState(event);
|
|
60
64
|
this.manager.invokeHandler(event, ...args);
|
|
61
65
|
}
|
|
@@ -76,14 +76,25 @@ export function HooksManager({
|
|
|
76
76
|
* @returns {object} hook with plugin module
|
|
77
77
|
*/
|
|
78
78
|
function getHookModule(hook) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
79
|
+
const plugin = plugins.find((p) => p.identifier === hook.identifier);
|
|
80
|
+
|
|
81
|
+
if (plugin == null) {
|
|
82
|
+
return logMissingHook(hook);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const moduleObj = plugin.module || {};
|
|
86
|
+
|
|
87
|
+
// TODO: Remove this line when Stringify state is removed from the NavigationProvider.tsx
|
|
88
|
+
// Remove context from the module object, because context fall into a loop.
|
|
89
|
+
// NavigationProvider.tsx observer state with JSON.stringify(state) that causes an infinite loop crash
|
|
90
|
+
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
91
|
+
const { context, ...cleanedModule } = moduleObj;
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
...hook,
|
|
95
|
+
module: cleanedModule,
|
|
96
|
+
configuration: plugin.configuration,
|
|
97
|
+
};
|
|
87
98
|
}
|
|
88
99
|
|
|
89
100
|
/**
|
|
@@ -230,6 +241,7 @@ export function HooksManager({
|
|
|
230
241
|
payload = initialPayload,
|
|
231
242
|
callback,
|
|
232
243
|
cancelled,
|
|
244
|
+
abort,
|
|
233
245
|
}) {
|
|
234
246
|
if (error) {
|
|
235
247
|
logHookEvent(
|
|
@@ -267,6 +279,7 @@ export function HooksManager({
|
|
|
267
279
|
hookPlugin.setStateAndNotify(HOOKS_EVENTS.CANCEL, {
|
|
268
280
|
hookPlugin,
|
|
269
281
|
payload,
|
|
282
|
+
abort,
|
|
270
283
|
});
|
|
271
284
|
|
|
272
285
|
const isHookInHomescreen = payload?.home;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.19-alpha.1342029112",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/applicaster-types": "12.0.
|
|
31
|
+
"@applicaster/applicaster-types": "12.0.19-alpha.1342029112",
|
|
32
32
|
"buffer": "^5.2.1",
|
|
33
33
|
"camelize": "^1.0.0",
|
|
34
34
|
"create-react-context": "^0.2.3",
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
2
2
|
import { isNilOrEmpty } from "../reactUtils/helpers";
|
|
3
3
|
import { parseJsonIfNeeded } from "@applicaster/zapp-react-native-utils/functionUtils";
|
|
4
|
+
import {
|
|
5
|
+
StorageOwnedValues,
|
|
6
|
+
NamespaceValues,
|
|
7
|
+
StorageValuesToRemove,
|
|
8
|
+
StorageValuesToAdd,
|
|
9
|
+
} from "./types";
|
|
4
10
|
|
|
5
11
|
const defaultOwnedKey = "owned_keys";
|
|
6
12
|
const DEFAULT_NAMESPACE = "applicaster.v2";
|