@applicaster/zapp-react-native-utils 13.0.0-rc.91 → 13.0.0-rc.93
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 +10 -0
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +1 -0
- package/appUtils/focusManager/index.ts +13 -0
- package/modalState/__tests__/index.test.ts +51 -0
- package/modalState/index.ts +32 -2
- package/numberUtils/__tests__/toPositiveNumberWithDefault.test.ts +23 -3
- package/numberUtils/index.ts +4 -0
- package/package.json +2 -2
- package/reactHooks/advertising/index.ts +5 -5
- package/reactHooks/navigation/useRoute.ts +2 -2
|
@@ -234,6 +234,16 @@ const prepareDefaultActions = (actionExecutor) => {
|
|
|
234
234
|
if (selectedItems.includes(tag)) {
|
|
235
235
|
await multiSelectProvider.removeItem(tag);
|
|
236
236
|
} else {
|
|
237
|
+
const maxItems = action.options?.max_items;
|
|
238
|
+
|
|
239
|
+
if (maxItems && selectedItems.length >= maxItems) {
|
|
240
|
+
log_info(
|
|
241
|
+
`handleAction: localStorageToggleFlag event reached max items limit: ${maxItems}, cannot add tag: ${tag}`
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
return ActionResult.Cancel;
|
|
245
|
+
}
|
|
246
|
+
|
|
237
247
|
await multiSelectProvider.addItem(tag);
|
|
238
248
|
}
|
|
239
249
|
} else {
|
|
@@ -534,6 +534,18 @@ export const focusManager = (function () {
|
|
|
534
534
|
|
|
535
535
|
const { on, invokeHandler, removeHandler } = eventHandler;
|
|
536
536
|
|
|
537
|
+
function findPreferredFocusChild(id) {
|
|
538
|
+
const node = getCurrentFocusNode(id);
|
|
539
|
+
|
|
540
|
+
const preferredFocus = findPriorityItem([node]);
|
|
541
|
+
|
|
542
|
+
if (isNilOrEmpty(preferredFocus)) {
|
|
543
|
+
return undefined;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
return preferredFocus[0];
|
|
547
|
+
}
|
|
548
|
+
|
|
537
549
|
/**
|
|
538
550
|
* this is the list of the functions available externally
|
|
539
551
|
* when importing the focus manager
|
|
@@ -563,5 +575,6 @@ export const focusManager = (function () {
|
|
|
563
575
|
isGroupItemFocused,
|
|
564
576
|
recoverFocus,
|
|
565
577
|
isCurrentFocusOnTheTopScreen,
|
|
578
|
+
findPreferredFocusChild,
|
|
566
579
|
};
|
|
567
580
|
})();
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { modalStore } from "../";
|
|
2
|
+
|
|
3
|
+
describe("Modal State", () => {
|
|
4
|
+
it("should have initial state", () => {
|
|
5
|
+
const state = modalStore.getState();
|
|
6
|
+
|
|
7
|
+
expect(state).toMatchObject({
|
|
8
|
+
modalState: {
|
|
9
|
+
visible: false,
|
|
10
|
+
screen: null,
|
|
11
|
+
options: {},
|
|
12
|
+
props: {},
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
expect(state.openModal).toBeDefined();
|
|
17
|
+
expect(state.dismissModal).toBeDefined();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe("opening and dismissing modal", () => {
|
|
21
|
+
it("should open modal", () => {
|
|
22
|
+
const item = { id: "test", name: "Test Modal" };
|
|
23
|
+
const options = { animated: true, animationType: "slide" };
|
|
24
|
+
const props = { customProp: "value" };
|
|
25
|
+
|
|
26
|
+
modalStore.getState().openModal({ item, options, props });
|
|
27
|
+
|
|
28
|
+
const state = modalStore.getState();
|
|
29
|
+
|
|
30
|
+
expect(state.modalState).toMatchObject({
|
|
31
|
+
visible: true,
|
|
32
|
+
screen: item,
|
|
33
|
+
options,
|
|
34
|
+
props,
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should dismiss modal", () => {
|
|
39
|
+
modalStore.getState().dismissModal();
|
|
40
|
+
|
|
41
|
+
const state = modalStore.getState();
|
|
42
|
+
|
|
43
|
+
expect(state.modalState).toMatchObject({
|
|
44
|
+
visible: false,
|
|
45
|
+
screen: null,
|
|
46
|
+
options: {},
|
|
47
|
+
props: {},
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
package/modalState/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useStore, createStore } from "zustand";
|
|
2
2
|
|
|
3
3
|
interface ModalState {
|
|
4
4
|
visible: boolean;
|
|
@@ -25,7 +25,7 @@ const initialModalState: ModalState = {
|
|
|
25
25
|
props: {},
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
export const
|
|
28
|
+
export const modalStore = createStore<ModalStore>((set) => ({
|
|
29
29
|
modalState: initialModalState,
|
|
30
30
|
setModalState: (newState) =>
|
|
31
31
|
set((state) => ({
|
|
@@ -51,3 +51,33 @@ export const useModalStore = create<ModalStore>((set) => ({
|
|
|
51
51
|
}),
|
|
52
52
|
dismissModal: () => set(() => ({ modalState: initialModalState })),
|
|
53
53
|
}));
|
|
54
|
+
|
|
55
|
+
export const useModalStore = <T>(selector: (state: ModalStore) => T) =>
|
|
56
|
+
useStore(modalStore, selector);
|
|
57
|
+
|
|
58
|
+
export const openModal = modalStore.getInitialState().openModal;
|
|
59
|
+
|
|
60
|
+
export const dismissModal = modalStore.getInitialState().dismissModal;
|
|
61
|
+
|
|
62
|
+
export const openBottomSheetModal = ({
|
|
63
|
+
ModalBottomSheetContent,
|
|
64
|
+
modalBottomSheetContentProps,
|
|
65
|
+
props = {},
|
|
66
|
+
options = {},
|
|
67
|
+
}: OpenModalBottomSheetArgs) => {
|
|
68
|
+
openModal({
|
|
69
|
+
item: {
|
|
70
|
+
ModalBottomSheetContent,
|
|
71
|
+
modalBottomSheetContentProps,
|
|
72
|
+
},
|
|
73
|
+
props,
|
|
74
|
+
options: {
|
|
75
|
+
animationType: "none",
|
|
76
|
+
animated: false,
|
|
77
|
+
...options,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const useModalStoreState = (): ModalState =>
|
|
83
|
+
useModalStore<ModalState>((state) => state.modalState);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { toPositiveNumberWithDefault } from "..";
|
|
2
2
|
|
|
3
|
-
describe("
|
|
3
|
+
describe("toPositiveNumberWithDefault", () => {
|
|
4
4
|
const DEFAULT = 5;
|
|
5
5
|
|
|
6
6
|
it("return number if input is positive number", () => {
|
|
7
|
-
const inputs = [
|
|
7
|
+
const inputs = [1, 2, 100, 200.12, Infinity];
|
|
8
8
|
expect.assertions(inputs.length);
|
|
9
9
|
|
|
10
10
|
inputs.forEach((input) => {
|
|
@@ -14,7 +14,7 @@ describe("toNumber", () => {
|
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it("return number if input is positive number as string", () => {
|
|
17
|
-
const inputs = ["
|
|
17
|
+
const inputs = ["1", "2", "100", "200.12"];
|
|
18
18
|
expect.assertions(inputs.length);
|
|
19
19
|
|
|
20
20
|
inputs.forEach((input) => {
|
|
@@ -63,4 +63,24 @@ describe("toNumber", () => {
|
|
|
63
63
|
expect(output).toBe(DEFAULT);
|
|
64
64
|
});
|
|
65
65
|
});
|
|
66
|
+
|
|
67
|
+
it("return default if input is zero number", () => {
|
|
68
|
+
const inputs = [0, -0];
|
|
69
|
+
expect.assertions(inputs.length);
|
|
70
|
+
|
|
71
|
+
inputs.forEach((input) => {
|
|
72
|
+
const output = toPositiveNumberWithDefault(DEFAULT, input);
|
|
73
|
+
expect(output).toBe(DEFAULT);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("return default if input is zero string", () => {
|
|
78
|
+
const inputs = ["0", "-0"];
|
|
79
|
+
expect.assertions(inputs.length);
|
|
80
|
+
|
|
81
|
+
inputs.forEach((input) => {
|
|
82
|
+
const output = toPositiveNumberWithDefault(DEFAULT, input);
|
|
83
|
+
expect(output).toBe(DEFAULT);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
66
86
|
});
|
package/numberUtils/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "13.0.0-rc.
|
|
3
|
+
"version": "13.0.0-rc.93",
|
|
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": "13.0.0-rc.
|
|
30
|
+
"@applicaster/applicaster-types": "13.0.0-rc.93",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|
|
@@ -5,6 +5,7 @@ import * as R from "ramda";
|
|
|
5
5
|
import { useNavigation } from "../navigation";
|
|
6
6
|
import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
|
|
7
7
|
import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
8
|
+
import { dismissModal, openModal } from "../../modalState";
|
|
8
9
|
|
|
9
10
|
const GOOGLE_ADS_IDENTIFIER = "google-admob-ads-qb";
|
|
10
11
|
|
|
@@ -14,9 +15,8 @@ const ModalContainer = platformSelect({
|
|
|
14
15
|
});
|
|
15
16
|
|
|
16
17
|
export function useAdvertisingInterstitial() {
|
|
17
|
-
const
|
|
18
|
+
const { screenData, currentRoute } = useNavigation();
|
|
18
19
|
const { plugins } = usePickFromState();
|
|
19
|
-
const { screenData } = navigator;
|
|
20
20
|
|
|
21
21
|
return useEffect(() => {
|
|
22
22
|
// TODD: typing problem: fix any type
|
|
@@ -26,7 +26,7 @@ export function useAdvertisingInterstitial() {
|
|
|
26
26
|
plugins
|
|
27
27
|
);
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
openModal({
|
|
30
30
|
item: {},
|
|
31
31
|
options: {
|
|
32
32
|
ModalContainer,
|
|
@@ -36,11 +36,11 @@ export function useAdvertisingInterstitial() {
|
|
|
36
36
|
screenType: "hooks",
|
|
37
37
|
screenData: {
|
|
38
38
|
payload: screenData,
|
|
39
|
-
callback:
|
|
39
|
+
callback: dismissModal,
|
|
40
40
|
hookPlugin: GoogleAdsPlugin,
|
|
41
41
|
},
|
|
42
42
|
},
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
-
}, [
|
|
45
|
+
}, [currentRoute, screenData?.id]);
|
|
46
46
|
}
|
|
@@ -11,7 +11,7 @@ import { getTargetScreenData } from "../screen/useTargetScreenData";
|
|
|
11
11
|
import { useHookModalScreenData } from "../hookModal/hooks/useHookModalScreenData";
|
|
12
12
|
|
|
13
13
|
import { useNavigation } from "./useNavigation";
|
|
14
|
-
import {
|
|
14
|
+
import { useModalStoreState } from "../../modalState";
|
|
15
15
|
import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
|
|
16
16
|
import { usePathname } from "./usePathname";
|
|
17
17
|
|
|
@@ -43,7 +43,7 @@ export const useRoute = (): {
|
|
|
43
43
|
"contentTypes",
|
|
44
44
|
]);
|
|
45
45
|
|
|
46
|
-
const
|
|
46
|
+
const modalState = useModalStoreState();
|
|
47
47
|
|
|
48
48
|
const modalScreenData = modalState.screen;
|
|
49
49
|
|