@applicaster/zapp-react-native-utils 14.0.0-alpha.6242515303 → 14.0.0-alpha.6391068513
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 +60 -83
- package/actionsExecutor/ScreenActions.ts +163 -0
- package/actionsExecutor/StorageActions.ts +110 -0
- package/actionsExecutor/feedDecorator.ts +171 -0
- package/actionsExecutor/screenResolver.ts +11 -0
- package/analyticsUtils/AnalyticsEvents/helper.ts +1 -1
- package/analyticsUtils/AnalyticsEvents/sendHeaderClickEvent.ts +1 -1
- package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -1
- package/analyticsUtils/index.tsx +3 -4
- package/analyticsUtils/manager.ts +1 -1
- package/appUtils/HooksManager/Hook.ts +4 -4
- package/appUtils/HooksManager/index.ts +11 -1
- package/appUtils/accessibilityManager/index.ts +3 -3
- package/appUtils/contextKeysManager/contextResolver.ts +14 -1
- package/appUtils/focusManager/treeDataStructure/Tree/index.js +1 -1
- package/arrayUtils/index.ts +1 -1
- package/componentsUtils/__tests__/isTabsScreen.test.ts +38 -0
- package/componentsUtils/index.ts +4 -1
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +547 -0
- package/configurationUtils/manifestKeyParser.ts +57 -32
- package/index.d.ts +0 -9
- package/manifestUtils/defaultManifestConfigurations/player.js +0 -148
- package/manifestUtils/keys.js +0 -12
- package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +0 -6
- package/navigationUtils/__tests__/mapContentTypesToRivers.test.ts +130 -0
- package/navigationUtils/index.ts +6 -4
- package/package.json +2 -2
- package/playerUtils/index.ts +51 -0
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +15 -14
- package/reactHooks/cell-click/index.ts +8 -1
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +39 -88
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +20 -0
- package/reactHooks/feed/useBatchLoading.ts +8 -6
- package/reactHooks/feed/useFeedLoader.tsx +25 -12
- package/reactHooks/feed/usePipesCacheReset.ts +2 -2
- package/reactHooks/flatList/useSequentialRenderItem.tsx +3 -3
- package/reactHooks/layout/__tests__/index.test.tsx +3 -1
- package/reactHooks/layout/isTablet/index.ts +7 -3
- package/reactHooks/layout/useDimensions/__tests__/useDimensions.test.ts +34 -36
- package/reactHooks/layout/useDimensions/useDimensions.ts +2 -3
- package/reactHooks/layout/useLayoutVersion.ts +5 -5
- package/reactHooks/navigation/index.ts +7 -5
- package/reactHooks/navigation/useRoute.ts +7 -2
- package/reactHooks/navigation/useScreenStateStore.ts +8 -0
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +4 -0
- package/reactHooks/state/useRivers.ts +7 -8
- package/storage/ScreenSingleValueProvider.ts +201 -0
- package/storage/ScreenStateMultiSelectProvider.ts +290 -0
- package/storage/StorageMultiSelectProvider.ts +192 -0
- package/storage/StorageSingleSelectProvider.ts +108 -0
- package/testUtils/index.tsx +7 -8
- package/time/BackgroundTimer.ts +1 -1
- package/utils/index.ts +1 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { bridgeLogger } from "../../zapp-react-native-bridge/logger";
|
|
2
|
+
import { BehaviorSubject } from "rxjs";
|
|
3
|
+
import { Storage } from "@applicaster/zapp-react-native-bridge/ZappStorage/Storage";
|
|
4
|
+
import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
5
|
+
import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
|
|
6
|
+
import { StorageType } from "../appUtils/contextKeysManager/consts";
|
|
7
|
+
import { getNamespaceAndKey } from "../appUtils/contextKeysManager/utils";
|
|
8
|
+
import { createLogger } from "../logger";
|
|
9
|
+
|
|
10
|
+
export const { log_verbose, log_debug, log_warning, log_info, log_error } =
|
|
11
|
+
createLogger({
|
|
12
|
+
category: "StorageMultiSelectProvider",
|
|
13
|
+
subsystem: "zapp-react-native-bridge",
|
|
14
|
+
parent: bridgeLogger,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export interface MultiSelectProvider {
|
|
18
|
+
getObservable(): BehaviorSubject<string[]>;
|
|
19
|
+
|
|
20
|
+
addItem(item: string): Promise<void>;
|
|
21
|
+
|
|
22
|
+
addItems(items: string[]): Promise<void>;
|
|
23
|
+
|
|
24
|
+
setSelectedItems(items: string[]): Promise<void>;
|
|
25
|
+
|
|
26
|
+
removeItem(item: string): Promise<void>;
|
|
27
|
+
|
|
28
|
+
removeItems(items: string[]): Promise<void>;
|
|
29
|
+
|
|
30
|
+
removeAllItems(): Promise<void>;
|
|
31
|
+
|
|
32
|
+
getSelectedItems(): string[];
|
|
33
|
+
|
|
34
|
+
getSelectedAsync(): Promise<string[]>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class StorageMultiSelectProvider implements MultiSelectProvider {
|
|
38
|
+
// TODO: Unsubscribe and remove when there is no listeners
|
|
39
|
+
private static multiSelectProviders: Record<
|
|
40
|
+
StorageType,
|
|
41
|
+
Record<string, StorageMultiSelectProvider>
|
|
42
|
+
> = {
|
|
43
|
+
[StorageType.local]: {},
|
|
44
|
+
[StorageType.session]: {},
|
|
45
|
+
// TODO: not implemented yet
|
|
46
|
+
[StorageType.secure]: {},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
public static getProvider(
|
|
50
|
+
keyNamespace: string,
|
|
51
|
+
storage: StorageType = StorageType.local
|
|
52
|
+
): MultiSelectProvider {
|
|
53
|
+
if (!this.multiSelectProviders[storage][keyNamespace]) {
|
|
54
|
+
const storageImpl =
|
|
55
|
+
storage === StorageType.session ? sessionStorage : localStorage;
|
|
56
|
+
|
|
57
|
+
this.multiSelectProviders[storage][keyNamespace] =
|
|
58
|
+
new StorageMultiSelectProvider(keyNamespace, storageImpl);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return this.multiSelectProviders[storage][keyNamespace];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private itemSubject: BehaviorSubject<string[] | null>;
|
|
65
|
+
|
|
66
|
+
private readonly key: string;
|
|
67
|
+
private readonly namespace: string;
|
|
68
|
+
|
|
69
|
+
private constructor(
|
|
70
|
+
keyNamespace: string,
|
|
71
|
+
private storage: Storage
|
|
72
|
+
) {
|
|
73
|
+
const { namespace, key } = getNamespaceAndKey(keyNamespace);
|
|
74
|
+
|
|
75
|
+
if (!key) {
|
|
76
|
+
throw new Error("StorageMultiSelectProvider: Key is required");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
this.key = key;
|
|
80
|
+
this.namespace = namespace;
|
|
81
|
+
this.storage.addListener?.({ key, namespace }, this.reloadItems);
|
|
82
|
+
|
|
83
|
+
this.itemSubject = new BehaviorSubject([]);
|
|
84
|
+
|
|
85
|
+
void this.getSelectedAsync();
|
|
86
|
+
log_debug("StorageMultiSelectProvider: Initializing");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private reloadItems = async ({ value }: StorageListenerArgs) => {
|
|
90
|
+
const selectedItems = value ? value.split(",") : [];
|
|
91
|
+
|
|
92
|
+
log_debug(
|
|
93
|
+
`reloadItems: request to reload items for value: ${value}`,
|
|
94
|
+
selectedItems
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
this.itemSubject.next(selectedItems);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
public getObservable = (): BehaviorSubject<string[]> => this.itemSubject;
|
|
101
|
+
|
|
102
|
+
private async getSetOfCurrentItems() {
|
|
103
|
+
const currentResult: string = await this.storage.getItem(
|
|
104
|
+
this.key,
|
|
105
|
+
this.namespace
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
return new Set(currentResult ? currentResult.split(",") : []);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private async updateItemsAndNotifyObservers(currentItems: Set<string>) {
|
|
112
|
+
const arrayOfItems = Array.from(currentItems);
|
|
113
|
+
const newValue = arrayOfItems.join(",");
|
|
114
|
+
await this.storage.setItem(this.key, newValue, this.namespace);
|
|
115
|
+
|
|
116
|
+
this.itemSubject.next(arrayOfItems);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public addItem = async (item: string): Promise<void> => {
|
|
120
|
+
const currentItems = await this.getSetOfCurrentItems();
|
|
121
|
+
currentItems.add(item);
|
|
122
|
+
log_debug(`addItem: Adding new item: ${item}`);
|
|
123
|
+
|
|
124
|
+
await this.updateItemsAndNotifyObservers(currentItems);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
public addItems = async (items: string[]): Promise<void> => {
|
|
128
|
+
const currentItems = await this.getSetOfCurrentItems();
|
|
129
|
+
|
|
130
|
+
items.forEach((item) => currentItems.add(item));
|
|
131
|
+
|
|
132
|
+
log_debug(
|
|
133
|
+
`addItems: Adding new items: ${items.join(
|
|
134
|
+
","
|
|
135
|
+
)}, current items: ${Array.from(currentItems).join(",")}`
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
await this.updateItemsAndNotifyObservers(currentItems);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
public removeItem = async (item: string): Promise<void> => {
|
|
142
|
+
const currentItems = await this.getSetOfCurrentItems();
|
|
143
|
+
currentItems.delete(item);
|
|
144
|
+
|
|
145
|
+
log_debug(
|
|
146
|
+
`removeItem: Removing item: ${item}, current items: ${Array.from(
|
|
147
|
+
currentItems
|
|
148
|
+
).join(",")}`
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
await this.updateItemsAndNotifyObservers(currentItems);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
public removeItems = async (items: string[]): Promise<void> => {
|
|
155
|
+
const currentItems = await this.getSetOfCurrentItems();
|
|
156
|
+
|
|
157
|
+
items.forEach((item) => currentItems.delete(item));
|
|
158
|
+
|
|
159
|
+
log_debug(
|
|
160
|
+
`removeItems: Removing items: ${items.join(
|
|
161
|
+
","
|
|
162
|
+
)}, current items: ${Array.from(currentItems).join(",")}`
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
await this.updateItemsAndNotifyObservers(currentItems);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
public removeAllItems = async (): Promise<void> => {
|
|
169
|
+
await this.storage.removeItem(this.key, this.namespace);
|
|
170
|
+
log_debug(`removeAllItems: Removing all items, current items: ${[]}`);
|
|
171
|
+
|
|
172
|
+
this.itemSubject.next([]);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
public getSelectedAsync = async (): Promise<string[]> => {
|
|
176
|
+
const value = await this.storage.getItem(this.key, this.namespace);
|
|
177
|
+
const selectedItems = value ? value.split(",") : [];
|
|
178
|
+
this.itemSubject.next(selectedItems);
|
|
179
|
+
|
|
180
|
+
return selectedItems;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
public getSelectedItems = (): string[] => {
|
|
184
|
+
return this.itemSubject.getValue();
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
setSelectedItems = async (items: string[]): Promise<void> => {
|
|
188
|
+
log_debug(`setSelectedItems: Setting selected items: ${items.join(",")}`);
|
|
189
|
+
|
|
190
|
+
await this.updateItemsAndNotifyObservers(new Set(items));
|
|
191
|
+
};
|
|
192
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { bridgeLogger } from "../../zapp-react-native-bridge/logger";
|
|
2
|
+
import { BehaviorSubject } from "rxjs";
|
|
3
|
+
import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
4
|
+
import { getNamespaceAndKey } from "../appUtils/contextKeysManager/utils";
|
|
5
|
+
import { createLogger } from "../logger";
|
|
6
|
+
|
|
7
|
+
export const { log_verbose, log_debug, log_warning, log_info, log_error } =
|
|
8
|
+
createLogger({
|
|
9
|
+
category: "StorageSingleValueProvider",
|
|
10
|
+
subsystem: "zapp-react-native-bridge",
|
|
11
|
+
parent: bridgeLogger,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export interface SingleValueProvider {
|
|
15
|
+
getObservable(): BehaviorSubject<string | null>;
|
|
16
|
+
|
|
17
|
+
setValue(value: string): Promise<void>;
|
|
18
|
+
getValue(): string | null;
|
|
19
|
+
getValueAsync(): Promise<string | null>;
|
|
20
|
+
clearValue(): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface StorageListenerArgs {
|
|
24
|
+
value: string | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class StorageSingleValueProvider implements SingleValueProvider {
|
|
28
|
+
// Static cache of providers by namespace
|
|
29
|
+
private static singleValueProviders: Record<
|
|
30
|
+
string,
|
|
31
|
+
StorageSingleValueProvider
|
|
32
|
+
> = {};
|
|
33
|
+
|
|
34
|
+
public static getProvider(keyNamespace: string): SingleValueProvider {
|
|
35
|
+
if (!this.singleValueProviders[keyNamespace]) {
|
|
36
|
+
this.singleValueProviders[keyNamespace] = new StorageSingleValueProvider(
|
|
37
|
+
keyNamespace
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return this.singleValueProviders[keyNamespace];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private valueSubject: BehaviorSubject<string | null>;
|
|
45
|
+
|
|
46
|
+
private readonly key: string;
|
|
47
|
+
private readonly namespace: string;
|
|
48
|
+
|
|
49
|
+
private constructor(keyNamespace: string) {
|
|
50
|
+
const { namespace, key } = getNamespaceAndKey(keyNamespace);
|
|
51
|
+
|
|
52
|
+
if (!key) {
|
|
53
|
+
throw new Error("StorageSingleValueProvider: Key is required");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
this.key = key;
|
|
57
|
+
this.namespace = namespace;
|
|
58
|
+
localStorage.addListener?.({ key, namespace }, this.reloadValue);
|
|
59
|
+
|
|
60
|
+
this.valueSubject = new BehaviorSubject<string | null>(null);
|
|
61
|
+
|
|
62
|
+
void this.getValueAsync();
|
|
63
|
+
log_debug("StorageSingleValueProvider: Initializing");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private reloadValue = async ({ value }: StorageListenerArgs) => {
|
|
67
|
+
log_debug(`reloadValue: request to reload value: ${value}`);
|
|
68
|
+
|
|
69
|
+
this.valueSubject.next(value);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
public getObservable = (): BehaviorSubject<string | null> =>
|
|
73
|
+
this.valueSubject;
|
|
74
|
+
|
|
75
|
+
private async updateValueAndNotifyObservers(value: string | null) {
|
|
76
|
+
if (value === null) {
|
|
77
|
+
await localStorage.removeItem(this.key, this.namespace);
|
|
78
|
+
} else {
|
|
79
|
+
await localStorage.setItem(this.key, value, this.namespace);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
this.valueSubject.next(value);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public setValue = async (value: string): Promise<void> => {
|
|
86
|
+
log_debug(`setValue: Setting new value: ${value}`);
|
|
87
|
+
|
|
88
|
+
await this.updateValueAndNotifyObservers(value);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
public clearValue = async (): Promise<void> => {
|
|
92
|
+
await localStorage.removeItem(this.key, this.namespace);
|
|
93
|
+
log_debug("clearValue: Removing value");
|
|
94
|
+
|
|
95
|
+
this.valueSubject.next(null);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
public getValueAsync = async (): Promise<string | null> => {
|
|
99
|
+
const value = await localStorage.getItem(this.key, this.namespace);
|
|
100
|
+
this.valueSubject.next(value);
|
|
101
|
+
|
|
102
|
+
return value;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
public getValue = (): string | null => {
|
|
106
|
+
return this.valueSubject.getValue();
|
|
107
|
+
};
|
|
108
|
+
}
|
package/testUtils/index.tsx
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { SafeAreaProvider } from "react-native-safe-area-context";
|
|
2
|
+
import { render } from "@testing-library/react-native";
|
|
3
3
|
import React, { PropsWithChildren } from "react";
|
|
4
|
-
import
|
|
5
|
-
|
|
4
|
+
import configureStore from "redux-mock-store";
|
|
6
5
|
import { Provider } from "react-redux";
|
|
6
|
+
import { View } from "react-native";
|
|
7
7
|
import thunk from "redux-thunk";
|
|
8
|
-
import
|
|
9
|
-
|
|
8
|
+
import * as R from "ramda";
|
|
9
|
+
|
|
10
10
|
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
11
11
|
|
|
12
|
-
import { render } from "@testing-library/react-native";
|
|
13
|
-
import { AnalyticsProvider } from "../analyticsUtils";
|
|
14
12
|
import { ThemeContext } from "../theme";
|
|
13
|
+
import { AnalyticsProvider } from "../analyticsUtils";
|
|
15
14
|
|
|
16
15
|
export { getByTestId } from "./getByTestId";
|
|
17
16
|
|
package/time/BackgroundTimer.ts
CHANGED
|
@@ -11,7 +11,7 @@ class BackgroundTimer {
|
|
|
11
11
|
this.uniqueId = 0;
|
|
12
12
|
this.callbacks = {};
|
|
13
13
|
|
|
14
|
-
const EventEmitter = platformSelect({
|
|
14
|
+
const EventEmitter: typeof DeviceEventEmitter | undefined = platformSelect({
|
|
15
15
|
android: DeviceEventEmitter,
|
|
16
16
|
android_tv: DeviceEventEmitter,
|
|
17
17
|
amazon: DeviceEventEmitter, // probably does not exist and uses android_tv
|