@applicaster/zapp-react-dom-app 14.0.0-rc.60 → 14.0.0-rc.62

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.
@@ -7,6 +7,7 @@ jest.mock("@applicaster/zapp-react-native-utils/appUtils", () => ({
7
7
  focusManager: {
8
8
  isFocusOnMenu: jest.fn(),
9
9
  isFocusOnContent: jest.fn(),
10
+ isTabsScreenContentFocused: jest.fn(),
10
11
  },
11
12
  }));
12
13
 
@@ -44,6 +45,20 @@ describe("withBackToTopActionHOC", () => {
44
45
  jest.clearAllMocks();
45
46
  });
46
47
 
48
+ it("returns PLATFORM_BACK when on root screen, and startup hooks", () => {
49
+ expect.assertions(1);
50
+
51
+ (useCurrentScreenIsRoot as jest.Mock).mockReturnValue(true);
52
+
53
+ (useNavigation as jest.Mock).mockReturnValue({
54
+ startUpHooks: ["some_startup_hook"],
55
+ });
56
+
57
+ render(<Wrapped />);
58
+
59
+ expect(receivedProps.backToTopAction()).toBe("PLATFORM_BACK");
60
+ });
61
+
47
62
  it("returns PLATFORM_BACK when on root screen, focus on menu, and is home", () => {
48
63
  expect.assertions(1);
49
64
 
@@ -52,7 +67,7 @@ describe("withBackToTopActionHOC", () => {
52
67
  (useCurrentScreenIsTabs as jest.Mock).mockReturnValue(false);
53
68
 
54
69
  (useNavigation as jest.Mock).mockReturnValue({
55
- getNestedEntry: () => undefined,
70
+ startUpHooks: [],
56
71
  });
57
72
 
58
73
  (focusManager.isFocusOnMenu as jest.Mock).mockReturnValue(true);
@@ -60,9 +75,7 @@ describe("withBackToTopActionHOC", () => {
60
75
 
61
76
  render(<Wrapped />);
62
77
 
63
- expect(receivedProps.backToTopAction()).toEqual({
64
- action: "PLATFORM_BACK",
65
- });
78
+ expect(receivedProps.backToTopAction()).toBe("PLATFORM_BACK");
66
79
  });
67
80
 
68
81
  it("returns GO_HOME when on root screen, focus on menu, and not home", () => {
@@ -73,23 +86,23 @@ describe("withBackToTopActionHOC", () => {
73
86
  (useCurrentScreenIsTabs as jest.Mock).mockReturnValue(false);
74
87
 
75
88
  (useNavigation as jest.Mock).mockReturnValue({
76
- getNestedEntry: () => undefined,
89
+ startUpHooks: [],
77
90
  });
78
91
 
79
92
  (focusManager.isFocusOnMenu as jest.Mock).mockReturnValue(true);
80
93
  (focusManager.isFocusOnContent as jest.Mock).mockReturnValue(false);
81
94
 
82
95
  render(<Wrapped />);
83
- expect(receivedProps.backToTopAction()).toEqual({ action: "GO_HOME" });
96
+ expect(receivedProps.backToTopAction()).toBe("GO_HOME");
84
97
  });
85
98
 
86
- it("returns FOCUS_TOP_NAVIGATION when on root screen and focus on content without tabs_screen", () => {
99
+ it("returns FOCUS_ON_SELECTED_TOP_MENU_ITEM when on root screen and focus on content without tabs_screen", () => {
87
100
  (useCurrentScreenIsRoot as jest.Mock).mockReturnValue(true);
88
101
  (useCurrentScreenIsHome as jest.Mock).mockReturnValue(false);
89
102
  (useCurrentScreenIsTabs as jest.Mock).mockReturnValue(false);
90
103
 
91
104
  (useNavigation as jest.Mock).mockReturnValue({
92
- getNestedEntry: () => "selectedEntry",
105
+ startUpHooks: [],
93
106
  });
94
107
 
95
108
  (focusManager.isFocusOnMenu as jest.Mock).mockReturnValue(false);
@@ -97,36 +110,30 @@ describe("withBackToTopActionHOC", () => {
97
110
 
98
111
  render(<Wrapped />);
99
112
 
100
- expect(receivedProps.backToTopAction()).toEqual({
101
- action: "FOCUS_TOP_NAVIGATION",
102
- payload: {
103
- isTabsScreen: false,
104
- selectedEntry: "selectedEntry",
105
- },
106
- });
113
+ expect(receivedProps.backToTopAction()).toBe(
114
+ "FOCUS_ON_SELECTED_TOP_MENU_ITEM"
115
+ );
107
116
  });
108
117
 
109
- it("returns FOCUS_TOP_NAVIGATION when on root screen and focus on content with tabs_screen", () => {
118
+ it("returns FOCUS_ON_SELECTED_TAB_ITEM when on root screen and focus on content with tabs_screen", () => {
110
119
  (useCurrentScreenIsRoot as jest.Mock).mockReturnValue(true);
111
120
  (useCurrentScreenIsHome as jest.Mock).mockReturnValue(false);
112
121
  (useCurrentScreenIsTabs as jest.Mock).mockReturnValue(true);
113
122
 
114
123
  (useNavigation as jest.Mock).mockReturnValue({
115
- getNestedEntry: () => "selectedEntry",
124
+ startUpHooks: [],
116
125
  });
117
126
 
118
127
  (focusManager.isFocusOnMenu as jest.Mock).mockReturnValue(false);
119
128
  (focusManager.isFocusOnContent as jest.Mock).mockReturnValue(true);
120
129
 
130
+ (focusManager.isTabsScreenContentFocused as jest.Mock).mockReturnValue(
131
+ true
132
+ );
133
+
121
134
  render(<Wrapped />);
122
135
 
123
- expect(receivedProps.backToTopAction()).toEqual({
124
- action: "FOCUS_TOP_NAVIGATION",
125
- payload: {
126
- isTabsScreen: true,
127
- selectedEntry: "selectedEntry",
128
- },
129
- });
136
+ expect(receivedProps.backToTopAction()).toBe("FOCUS_ON_SELECTED_TAB_ITEM");
130
137
  });
131
138
 
132
139
  it("returns GO_BACK in default case", () => {
@@ -137,13 +144,17 @@ describe("withBackToTopActionHOC", () => {
137
144
  (useCurrentScreenIsTabs as jest.Mock).mockReturnValue(false);
138
145
 
139
146
  (useNavigation as jest.Mock).mockReturnValue({
140
- getNestedEntry: () => undefined,
147
+ startUpHooks: [],
141
148
  });
142
149
 
143
150
  (focusManager.isFocusOnMenu as jest.Mock).mockReturnValue(false);
144
151
  (focusManager.isFocusOnContent as jest.Mock).mockReturnValue(false);
145
152
 
153
+ (focusManager.isTabsScreenContentFocused as jest.Mock).mockReturnValue(
154
+ false
155
+ );
156
+
146
157
  render(<Wrapped />);
147
- expect(receivedProps.backToTopAction()).toEqual({ action: "GO_BACK" });
158
+ expect(receivedProps.backToTopAction()).toBe("GO_BACK");
148
159
  });
149
160
  });
@@ -1,5 +1,10 @@
1
1
  import * as React from "react";
2
+ import { isFilledArray } from "@applicaster/zapp-react-native-utils/arrayUtils";
2
3
  import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils";
4
+
5
+ import { useSubscriberFor } from "@applicaster/zapp-react-native-utils/reactHooks/useSubscriberFor";
6
+ import { QBUIComponentEvents } from "@applicaster/zapp-react-native-ui-components/events";
7
+
3
8
  import {
4
9
  useCurrentScreenIsHome,
5
10
  useCurrentScreenIsRoot,
@@ -7,10 +12,12 @@ import {
7
12
  } from "./hooks";
8
13
  import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
9
14
 
10
- export type BACK_TO_TOP_ACTION = {
11
- action: "PLATFORM_BACK" | "GO_HOME" | "FOCUS_TOP_NAVIGATION" | "GO_BACK";
12
- payload?: { isTabsScreen: boolean; selectedEntry: ZappEntry };
13
- };
15
+ export type BACK_TO_TOP_ACTION =
16
+ | "PLATFORM_BACK"
17
+ | "GO_HOME"
18
+ | "GO_BACK"
19
+ | "FOCUS_ON_SELECTED_TOP_MENU_ITEM"
20
+ | "FOCUS_ON_SELECTED_TAB_ITEM";
14
21
 
15
22
  export type BackToTopAction = () => BACK_TO_TOP_ACTION;
16
23
 
@@ -21,36 +28,49 @@ export function withBackToTopActionHOC(Component) {
21
28
  const isTabsScreen = useCurrentScreenIsTabs();
22
29
 
23
30
  const navigator = useNavigation();
24
- const selectedEntry = navigator.getNestedEntry();
25
31
 
26
- const isStartUpHook =
27
- Array.isArray(navigator.startUpHooks) &&
28
- navigator.startUpHooks.length > 0;
32
+ const isStartUpHook = isFilledArray(navigator.startUpHooks);
33
+
34
+ const emitFocusOnSelectedTab = useSubscriberFor(
35
+ QBUIComponentEvents.focusOnSelectedTab
36
+ );
37
+
38
+ const emitFocusOnSelectedTopMenuItem = useSubscriberFor(
39
+ QBUIComponentEvents.focusOnSelectedTopMenuItem
40
+ );
29
41
 
30
42
  const backToTopAction = React.useCallback((): BACK_TO_TOP_ACTION => {
31
43
  if (isRoot && isStartUpHook) {
32
- return { action: "PLATFORM_BACK" };
44
+ return "PLATFORM_BACK";
33
45
  }
34
46
 
35
47
  if (isRoot && focusManager.isFocusOnMenu() && isHome) {
36
- return { action: "PLATFORM_BACK" };
48
+ return "PLATFORM_BACK";
37
49
  }
38
50
 
39
51
  if (isRoot && focusManager.isFocusOnMenu() && !isHome) {
40
- return { action: "GO_HOME" };
52
+ return "GO_HOME";
53
+ }
54
+
55
+ if (isRoot && isTabsScreen && focusManager.isTabsScreenContentFocused()) {
56
+ return "FOCUS_ON_SELECTED_TAB_ITEM";
41
57
  }
42
58
 
43
59
  if (isRoot && focusManager.isFocusOnContent()) {
44
- return {
45
- action: "FOCUS_TOP_NAVIGATION",
46
- payload: { isTabsScreen, selectedEntry },
47
- };
60
+ return "FOCUS_ON_SELECTED_TOP_MENU_ITEM";
48
61
  }
49
62
 
50
63
  // default
51
- return { action: "GO_BACK" };
52
- }, [isHome, isRoot, isTabsScreen, selectedEntry]);
64
+ return "GO_BACK";
65
+ }, [isHome, isRoot, isTabsScreen, isStartUpHook]);
53
66
 
54
- return <Component {...props} backToTopAction={backToTopAction} />;
67
+ return (
68
+ <Component
69
+ {...props}
70
+ backToTopAction={backToTopAction}
71
+ emitFocusOnSelectedTab={emitFocusOnSelectedTab}
72
+ emitFocusOnSelectedTopMenuItem={emitFocusOnSelectedTopMenuItem}
73
+ />
74
+ );
55
75
  };
56
76
  }
@@ -59,7 +59,7 @@ import { withBackToTopActionHOC, BackToTopAction } from "./hoc";
59
59
  const { withXray } = getXray();
60
60
  const globalAny: any = global;
61
61
 
62
- const { log_debug, log_warning } = createLogger({
62
+ const { log_debug, log_warning, log_info } = createLogger({
63
63
  category: "InteractionManager",
64
64
  subsystem: "zapp-react-dom-app",
65
65
  });
@@ -77,6 +77,8 @@ type Props = {
77
77
  xray: XRayContext;
78
78
  confirmDialog: typeof confirmationDialogStore;
79
79
  backToTopAction: BackToTopAction;
80
+ emitFocusOnSelectedTopMenuItem: Callback;
81
+ emitFocusOnSelectedTab: Callback;
80
82
  };
81
83
 
82
84
  interface State {
@@ -392,8 +394,14 @@ class InteractionManagerClass extends React.Component<Props, State> {
392
394
  note: backspace affects the keyboard input, so it behaves differently
393
395
  */
394
396
  onBackPress(event) {
395
- const { displayState, setDisplayState, navigator, backToTopAction } =
396
- this.props;
397
+ const {
398
+ displayState,
399
+ setDisplayState,
400
+ navigator,
401
+ backToTopAction,
402
+ emitFocusOnSelectedTopMenuItem,
403
+ emitFocusOnSelectedTab,
404
+ } = this.props;
397
405
 
398
406
  const { isDialogVisible } = confirmationDialogStore.getState();
399
407
  const { isKeyboardVisible } = this.state;
@@ -413,26 +421,41 @@ class InteractionManagerClass extends React.Component<Props, State> {
413
421
  return;
414
422
  }
415
423
 
416
- const { action, payload } = backToTopAction();
424
+ const action = backToTopAction();
417
425
 
418
426
  switch (displayState) {
419
427
  case DISPLAY_STATES.DEFAULT:
420
428
  if (action === "PLATFORM_BACK") {
429
+ log_info(action);
430
+
421
431
  this.platformBack();
422
432
  }
423
433
 
424
434
  if (action === "GO_HOME") {
435
+ log_info(action);
436
+
425
437
  this.goToHome();
426
438
  }
427
439
 
428
- if (action === "FOCUS_TOP_NAVIGATION") {
429
- focusManager.focusTopNavigation(
430
- payload.isTabsScreen,
431
- payload.selectedEntry
432
- );
440
+ if (action === "FOCUS_ON_SELECTED_TOP_MENU_ITEM") {
441
+ log_info(action);
442
+
443
+ // we don't have enough context at this point to set focus properly on selected top-menu-item, just emit event about it.
444
+ // TopMenu component is supposed to handle this event.
445
+ emitFocusOnSelectedTopMenuItem();
446
+ }
447
+
448
+ if (action === "FOCUS_ON_SELECTED_TAB_ITEM") {
449
+ log_info(action);
450
+
451
+ // we don't have enough context at this point to set focus properly on selected tab-menu-item, just emit event about it
452
+ // Tabs component is supposed to handle this event.
453
+ emitFocusOnSelectedTab();
433
454
  }
434
455
 
435
456
  if (action === "GO_BACK") {
457
+ log_info(action);
458
+
436
459
  if (navigator.canGoBack()) {
437
460
  navigator.goBack();
438
461
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-dom-app",
3
- "version": "14.0.0-rc.60",
3
+ "version": "14.0.0-rc.62",
4
4
  "description": "Zapp App Component for Applicaster's Quick Brick React Native App",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,11 +22,11 @@
22
22
  },
23
23
  "homepage": "https://github.com/applicaster/zapp-react-dom-app#readme",
24
24
  "dependencies": {
25
- "@applicaster/zapp-react-dom-ui-components": "14.0.0-rc.60",
26
- "@applicaster/zapp-react-native-bridge": "14.0.0-rc.60",
27
- "@applicaster/zapp-react-native-redux": "14.0.0-rc.60",
28
- "@applicaster/zapp-react-native-ui-components": "14.0.0-rc.60",
29
- "@applicaster/zapp-react-native-utils": "14.0.0-rc.60",
25
+ "@applicaster/zapp-react-dom-ui-components": "14.0.0-rc.62",
26
+ "@applicaster/zapp-react-native-bridge": "14.0.0-rc.62",
27
+ "@applicaster/zapp-react-native-redux": "14.0.0-rc.62",
28
+ "@applicaster/zapp-react-native-ui-components": "14.0.0-rc.62",
29
+ "@applicaster/zapp-react-native-utils": "14.0.0-rc.62",
30
30
  "abortcontroller-polyfill": "^1.7.5",
31
31
  "typeface-montserrat": "^0.0.54",
32
32
  "video.js": "7.14.3",