@applicaster/zapp-react-native-utils 15.0.0-rc.50 → 15.0.0-rc.53

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.
@@ -102,7 +102,7 @@ export const getNavbarNode = (focusableTree) => {
102
102
 
103
103
  export const waitForContent = (focusableTree) => {
104
104
  const contentHasAnyChildren = (): boolean => {
105
- const countOfChildren = pathOr(
105
+ const countOfChildren = pathOr<number>(
106
106
  0,
107
107
  ["children", "length"],
108
108
  getContentNode(focusableTree)
@@ -49,7 +49,7 @@ export const findSelectedMenuId = (
49
49
  ) => {
50
50
  const sectionName = QUICK_BRICK_NAVBAR_SECTIONS[sectionKey];
51
51
 
52
- return pathOr(
52
+ return pathOr<string | undefined>(
53
53
  undefined,
54
54
  ["children", index, "id"],
55
55
  focusableTree.find(sectionName)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "15.0.0-rc.50",
3
+ "version": "15.0.0-rc.53",
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-rc.50",
30
+ "@applicaster/applicaster-types": "15.0.0-rc.53",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",
package/utils/index.ts CHANGED
@@ -42,6 +42,13 @@ export {
42
42
  partial,
43
43
  clamp,
44
44
  reverse,
45
+ takeRight,
46
+ fromPairs,
47
+ sortBy,
48
+ merge,
49
+ values,
50
+ head,
51
+ findIndex,
45
52
  set,
46
53
  compact,
47
54
  } from "lodash";
package/utils/path.ts CHANGED
@@ -1,5 +1,8 @@
1
- import { get } from "lodash";
1
+ import { pathOr } from "./pathOr";
2
2
 
3
- export const path = (route, record) => {
4
- return get(record, route, undefined);
3
+ export const path = <T = any>(
4
+ route: (string | number) | (string | number)[],
5
+ record: any
6
+ ) => {
7
+ return pathOr<T>(undefined, route, record);
5
8
  };
package/utils/pathOr.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  import { get } from "lodash";
2
2
 
3
- export const pathOr = (defaultValue, path, record) => {
3
+ export const pathOr = <T = any>(
4
+ defaultValue: T,
5
+ path: (number | string) | (number | string)[],
6
+ record: any
7
+ ): T => {
4
8
  return get(record, path, defaultValue);
5
9
  };
@@ -1,6 +1,6 @@
1
1
  import { useNavigation, useRivers, useScreenContext } from "../../reactHooks";
2
2
  import { createLogger } from "../../logger";
3
- import { useCallback, useMemo } from "react";
3
+ import { useCallback, useMemo, useRef, useEffect } from "react";
4
4
 
5
5
  export enum NavigationCallbackOptions {
6
6
  DEFAULT = "default",
@@ -17,6 +17,7 @@ export enum ResultType {
17
17
  export type CallbackResult = hookCallbackArgs & {
18
18
  options?: {
19
19
  resultType?: ResultType;
20
+ navigator?: QuickBrickAppNavigator;
20
21
  };
21
22
  };
22
23
 
@@ -45,7 +46,7 @@ const legacyMappingKeys = {
45
46
  actionType: "login_completion_action",
46
47
  targetScreen: "navigate_to_login_screen",
47
48
  },
48
- "quick-brick-user-account-ui-component": {
49
+ "quick-brick-user-account-ui-component.login": {
49
50
  actionType: "callbackAction",
50
51
  },
51
52
  "quick-brick-login-multi-login-providers.login": {
@@ -83,7 +84,8 @@ export const getNavigationKeys = (
83
84
  ): NavKeys => {
84
85
  const general = (item?.general ?? {}) as General;
85
86
 
86
- const pluginIdentifier = (item as any).identifier ?? item?.type ?? "";
87
+ const pluginIdentifier =
88
+ (item as any).identifier ?? item?.type ?? item?.component_type ?? "";
87
89
 
88
90
  const legacy =
89
91
  legacyMappingKeys[`${pluginIdentifier}.${resultType}`] ??
@@ -135,6 +137,12 @@ export const useCallbackNavigationAction = (
135
137
  const rivers = useRivers();
136
138
  const screenContext = useScreenContext();
137
139
 
140
+ const navigationRef = useRef(navigation);
141
+
142
+ useEffect(() => {
143
+ navigationRef.current = navigation;
144
+ }, [navigation]);
145
+
138
146
  const overrideCallbackFromComponent = useMemo(() => {
139
147
  log_verbose(`${LogPrefix}: overridden callbackAction by component`);
140
148
 
@@ -168,20 +176,35 @@ export const useCallbackNavigationAction = (
168
176
  return;
169
177
  }
170
178
 
171
- const data = getNavigationKeys(item, args.options?.resultType ?? null);
179
+ let data = getNavigationKeys(item, args.options?.resultType ?? null);
172
180
 
173
181
  if (!data) {
174
- hookCallback?.(args);
182
+ const isScreen = !hookCallback;
175
183
 
176
- return;
184
+ if (isScreen && args.options?.resultType === ResultType.login) {
185
+ log_debug(
186
+ `${LogPrefix} no navigation data found, applying GO BACK for login screen`
187
+ );
188
+
189
+ data = {
190
+ action: NavigationCallbackOptions.GO_BACK,
191
+ targetScreenId: null,
192
+ };
193
+ } else {
194
+ hookCallback?.(args);
195
+
196
+ return;
197
+ }
177
198
  }
178
199
 
179
200
  hookCallback?.({ ...args, success: false, cancelled: true });
201
+ const currentNavigation = navigationRef.current;
180
202
 
181
203
  switch (data.action) {
182
204
  case NavigationCallbackOptions.GO_BACK: {
183
- if (navigation.canGoBack()) {
184
- navigation.goBack();
205
+ if (currentNavigation.canGoBack()) {
206
+ currentNavigation.goBack();
207
+
185
208
  log_info(`${LogPrefix} performing 'GO BACK' action`);
186
209
  } else {
187
210
  log_info(`${LogPrefix} cannot perform 'GO BACK' action — ignoring`);
@@ -191,7 +214,7 @@ export const useCallbackNavigationAction = (
191
214
  }
192
215
 
193
216
  case NavigationCallbackOptions.GO_HOME: {
194
- navigation.goHome();
217
+ currentNavigation.goHome();
195
218
  log_info(`${LogPrefix} performing 'GO HOME' action`);
196
219
  break;
197
220
  }
@@ -207,7 +230,7 @@ export const useCallbackNavigationAction = (
207
230
  const screen = rivers[screenId];
208
231
 
209
232
  if (screen) {
210
- navigation.replace(screen);
233
+ currentNavigation.replace(screen);
211
234
 
212
235
  log_info(
213
236
  `${LogPrefix} performing 'GO TO SCREEN' action to screen: ${screenId}`
@@ -224,7 +247,7 @@ export const useCallbackNavigationAction = (
224
247
  }
225
248
  }
226
249
  },
227
- [item, navigation, rivers]
250
+ [item, rivers]
228
251
  );
229
252
 
230
253
  return overrideCallbackFromComponent || callbackAction;
@@ -20,7 +20,7 @@ const callbackKeyPrefix = (key, prefix, keySeparator = "_") =>
20
20
 
21
21
  const extendManifestWithHookCallback = (prefix = null) => ({
22
22
  group: true,
23
- label: "CallBack Navigation",
23
+ label: `CallBack Navigation: ${prefix}`,
24
24
  folded: true,
25
25
  fields: [
26
26
  {