@applicaster/zapp-react-native-utils 15.1.11-rc.1 → 15.1.12-rc.0
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/actionsExecutor/ActionExecutorContext.tsx +16 -0
- package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
- package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
- package/actionsExecutor/actions/goBack.ts +60 -0
- package/actionsExecutor/actions/goHome.ts +31 -0
- package/actionsExecutor/actions/index.ts +4 -0
- package/manifestUtils/_internals/index.js +8 -3
- package/package.json +2 -2
|
@@ -18,6 +18,8 @@ import { createLogger } from "../logger";
|
|
|
18
18
|
import {
|
|
19
19
|
appRestartAction,
|
|
20
20
|
confirmDialogAction,
|
|
21
|
+
createGoBackAction,
|
|
22
|
+
createGoHomeAction,
|
|
21
23
|
createNavigateToScreenAction,
|
|
22
24
|
localStorageRemoveAction,
|
|
23
25
|
localStorageSetAction,
|
|
@@ -135,6 +137,20 @@ export function withActionExecutor(Component) {
|
|
|
135
137
|
);
|
|
136
138
|
}, [navigator, rivers, contentTypes]);
|
|
137
139
|
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
return _actionExecutor.registerAction(
|
|
142
|
+
"goBack",
|
|
143
|
+
createGoBackAction(navigator)
|
|
144
|
+
);
|
|
145
|
+
}, [navigator]);
|
|
146
|
+
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
return _actionExecutor.registerAction(
|
|
149
|
+
"goHome",
|
|
150
|
+
createGoHomeAction(navigator)
|
|
151
|
+
);
|
|
152
|
+
}, [navigator]);
|
|
153
|
+
|
|
138
154
|
return (
|
|
139
155
|
<ActionExecutorContext.Provider value={handlers}>
|
|
140
156
|
<Component {...props} />
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createGoBackAction } from "../goBack";
|
|
2
|
+
import { ActionResult } from "../../ActionExecutor";
|
|
3
|
+
|
|
4
|
+
function createNavigator(canGoBack = true) {
|
|
5
|
+
return {
|
|
6
|
+
goBack: jest.fn(),
|
|
7
|
+
canGoBack: jest.fn().mockReturnValue(canGoBack),
|
|
8
|
+
} as unknown as QuickBrickAppNavigator;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
describe("goBack", () => {
|
|
12
|
+
it("goes back with fallbackToHome enabled when no options are provided", async () => {
|
|
13
|
+
const navigator = createNavigator();
|
|
14
|
+
|
|
15
|
+
const result = await createGoBackAction(navigator)({ type: "goBack" });
|
|
16
|
+
|
|
17
|
+
expect(navigator.goBack).toHaveBeenCalledWith(true, false, false);
|
|
18
|
+
expect(result).toBe(ActionResult.Success);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("forwards backToTop", async () => {
|
|
22
|
+
const navigator = createNavigator();
|
|
23
|
+
|
|
24
|
+
const action = {
|
|
25
|
+
type: "goBack",
|
|
26
|
+
options: { backToTop: true },
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const result = await createGoBackAction(navigator)(action);
|
|
30
|
+
|
|
31
|
+
expect(navigator.goBack).toHaveBeenCalledWith(true, false, true);
|
|
32
|
+
expect(result).toBe(ActionResult.Success);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("goes back without falling back to home when the stack allows it", async () => {
|
|
36
|
+
const navigator = createNavigator(true);
|
|
37
|
+
|
|
38
|
+
const action = {
|
|
39
|
+
type: "goBack",
|
|
40
|
+
options: { fallbackToHome: false },
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const result = await createGoBackAction(navigator)(action);
|
|
44
|
+
|
|
45
|
+
expect(navigator.goBack).toHaveBeenCalledWith(false, false, false);
|
|
46
|
+
expect(result).toBe(ActionResult.Success);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("does nothing when there is nothing to go back to and fallbackToHome is off", async () => {
|
|
50
|
+
const navigator = createNavigator(false);
|
|
51
|
+
|
|
52
|
+
const action = {
|
|
53
|
+
type: "goBack",
|
|
54
|
+
options: { fallbackToHome: false },
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const result = await createGoBackAction(navigator)(action);
|
|
58
|
+
|
|
59
|
+
expect(navigator.goBack).not.toHaveBeenCalled();
|
|
60
|
+
expect(result).toBe(ActionResult.Error);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createGoHomeAction } from "../goHome";
|
|
2
|
+
import { ActionResult } from "../../ActionExecutor";
|
|
3
|
+
|
|
4
|
+
function createNavigator() {
|
|
5
|
+
return {
|
|
6
|
+
goHome: jest.fn(),
|
|
7
|
+
} as unknown as QuickBrickAppNavigator;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
describe("goHome", () => {
|
|
11
|
+
it("navigates to the home screen", async () => {
|
|
12
|
+
const navigator = createNavigator();
|
|
13
|
+
|
|
14
|
+
const result = await createGoHomeAction(navigator)({ type: "goHome" });
|
|
15
|
+
|
|
16
|
+
expect(navigator.goHome).toHaveBeenCalledWith();
|
|
17
|
+
expect(result).toBe(ActionResult.Success);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
+
import { ActionResult } from "../ActionExecutor";
|
|
3
|
+
import { ActionHandler } from "../types";
|
|
4
|
+
import { createLogger } from "../../logger";
|
|
5
|
+
|
|
6
|
+
const { log_info } = createLogger({
|
|
7
|
+
subsystem: "ActionExecutorContext",
|
|
8
|
+
category: "General",
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Options for the goBack action.
|
|
13
|
+
*/
|
|
14
|
+
export interface GoBackOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Navigate to the home screen when there is no screen to go back to.
|
|
17
|
+
* Defaults to true.
|
|
18
|
+
*/
|
|
19
|
+
fallbackToHome?: boolean;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Go back to the first screen of the stack instead of the previous one.
|
|
23
|
+
* Defaults to false.
|
|
24
|
+
*/
|
|
25
|
+
backToTop?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Creates a go back action handler with the provided dependencies.
|
|
30
|
+
* This factory pattern allows the action to access navigation state at runtime.
|
|
31
|
+
*
|
|
32
|
+
* @param navigator - The app navigator performing the back navigation
|
|
33
|
+
* @returns An action handler that navigates back
|
|
34
|
+
*/
|
|
35
|
+
export function createGoBackAction(
|
|
36
|
+
navigator: QuickBrickAppNavigator
|
|
37
|
+
): ActionHandler<GoBackOptions> {
|
|
38
|
+
return async function goBackAction(action): Promise<ActionResult> {
|
|
39
|
+
const fallbackToHome = action.options?.fallbackToHome ?? true;
|
|
40
|
+
const backToTop = action.options?.backToTop ?? false;
|
|
41
|
+
|
|
42
|
+
// With fallbackToHome on, the navigator goes home on an empty stack by
|
|
43
|
+
// itself. The guard only matters when the caller opted out of that.
|
|
44
|
+
if (!fallbackToHome && !navigator.canGoBack()) {
|
|
45
|
+
log_info(
|
|
46
|
+
"goBack: no screen to go back to and fallbackToHome is disabled, ignoring"
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
return ActionResult.Error;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
log_info(
|
|
53
|
+
`goBack: navigating back, fallbackToHome: ${fallbackToHome}, backToTop: ${backToTop}`
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
navigator.goBack(fallbackToHome, false, backToTop);
|
|
57
|
+
|
|
58
|
+
return ActionResult.Success;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
+
import { ActionResult } from "../ActionExecutor";
|
|
3
|
+
import { ActionHandler } from "../types";
|
|
4
|
+
import { createLogger } from "../../logger";
|
|
5
|
+
|
|
6
|
+
const { log_info } = createLogger({
|
|
7
|
+
subsystem: "ActionExecutorContext",
|
|
8
|
+
category: "General",
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates a go home action handler with the provided dependencies.
|
|
13
|
+
* This factory pattern allows the action to access navigation state at runtime.
|
|
14
|
+
*
|
|
15
|
+
* The navigator's `initialLaunch` flag is intentionally not exposed: it selects
|
|
16
|
+
* the offline home river during app bootstrap and is not a per-action choice.
|
|
17
|
+
*
|
|
18
|
+
* @param navigator - The app navigator performing the navigation
|
|
19
|
+
* @returns An action handler that navigates to the home screen
|
|
20
|
+
*/
|
|
21
|
+
export function createGoHomeAction(
|
|
22
|
+
navigator: QuickBrickAppNavigator
|
|
23
|
+
): ActionHandler {
|
|
24
|
+
return async function goHomeAction(): Promise<ActionResult> {
|
|
25
|
+
log_info("goHome: navigating to the home screen");
|
|
26
|
+
|
|
27
|
+
navigator.goHome();
|
|
28
|
+
|
|
29
|
+
return ActionResult.Success;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -27,4 +27,8 @@ export { screenToggleFlagAction } from "./screenToggleFlag";
|
|
|
27
27
|
|
|
28
28
|
export { createNavigateToScreenAction } from "./navigateToScreen";
|
|
29
29
|
|
|
30
|
+
export { createGoBackAction } from "./goBack";
|
|
31
|
+
|
|
32
|
+
export { createGoHomeAction } from "./goHome";
|
|
33
|
+
|
|
30
34
|
export { showToastAction } from "./showToast";
|
|
@@ -135,7 +135,8 @@ function generateFieldsFromDefaults(label, defaults, fields) {
|
|
|
135
135
|
function generateFieldsFromDefaultsWithoutPrefixedLabel(
|
|
136
136
|
label,
|
|
137
137
|
defaults,
|
|
138
|
-
fields
|
|
138
|
+
fields,
|
|
139
|
+
{ withStyle = false } = {}
|
|
139
140
|
) {
|
|
140
141
|
const keyPrefix = toSnakeCase(label);
|
|
141
142
|
|
|
@@ -151,7 +152,9 @@ function generateFieldsFromDefaultsWithoutPrefixedLabel(
|
|
|
151
152
|
const generatedField = {
|
|
152
153
|
...fieldProps,
|
|
153
154
|
label: capitalizeFirstLetter(field.suffix),
|
|
154
|
-
key:
|
|
155
|
+
key: withStyle
|
|
156
|
+
? `${keyPrefix}_style_${toSnakeCase(field.suffix)}`
|
|
157
|
+
: `${keyPrefix}_${toSnakeCase(field.suffix)}`,
|
|
155
158
|
initial_value: R.when(R.is(Array), R.head)(initialValue),
|
|
156
159
|
};
|
|
157
160
|
|
|
@@ -164,7 +167,9 @@ function generateFieldsFromDefaultsWithoutPrefixedLabel(
|
|
|
164
167
|
const section = condition.section ? `${condition.section}/` : "";
|
|
165
168
|
|
|
166
169
|
return {
|
|
167
|
-
key:
|
|
170
|
+
key: withStyle
|
|
171
|
+
? `${section}${keyPrefix}_style_${toSnakeCase(condition.key)}`
|
|
172
|
+
: `${section}${keyPrefix}_${toSnakeCase(condition.key)}`,
|
|
168
173
|
condition_value: condition.value,
|
|
169
174
|
};
|
|
170
175
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "15.1.
|
|
3
|
+
"version": "15.1.12-rc.0",
|
|
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.1.
|
|
30
|
+
"@applicaster/applicaster-types": "15.1.12-rc.0",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|