@applicaster/zapp-react-native-utils 14.0.0-rc.9 → 14.0.0-rc.91
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 -84
- package/actionsExecutor/ScreenActions.ts +164 -0
- package/actionsExecutor/StorageActions.ts +110 -0
- package/actionsExecutor/feedDecorator.ts +171 -0
- package/actionsExecutor/screenResolver.ts +11 -0
- package/analyticsUtils/AnalyticPlayerListener.ts +5 -2
- package/analyticsUtils/AnalyticsEvents/helper.ts +81 -0
- package/analyticsUtils/AnalyticsEvents/sendHeaderClickEvent.ts +1 -1
- package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -1
- package/analyticsUtils/AnalyticsEvents/sendOnClickEvent.ts +14 -4
- package/analyticsUtils/__tests__/analyticsUtils.test.js +3 -0
- package/analyticsUtils/events.ts +8 -0
- package/analyticsUtils/index.tsx +3 -4
- package/analyticsUtils/manager.ts +1 -1
- package/analyticsUtils/playerAnalyticsTracker.ts +2 -1
- package/appUtils/HooksManager/Hook.ts +4 -4
- package/appUtils/HooksManager/index.ts +11 -1
- package/appUtils/accessibilityManager/const.ts +13 -0
- package/appUtils/accessibilityManager/hooks.ts +35 -1
- package/appUtils/accessibilityManager/index.ts +154 -30
- package/appUtils/accessibilityManager/utils.ts +24 -0
- package/appUtils/contextKeysManager/contextResolver.ts +42 -1
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +8 -0
- package/appUtils/focusManager/__tests__/focusManager.test.js +1 -1
- package/appUtils/focusManager/events.ts +2 -0
- package/appUtils/focusManager/index.ios.ts +27 -0
- package/appUtils/focusManager/index.ts +86 -11
- package/appUtils/focusManager/treeDataStructure/Tree/index.js +1 -1
- package/appUtils/focusManagerAux/utils/index.ts +112 -3
- package/appUtils/focusManagerAux/utils/utils.ios.ts +35 -0
- package/appUtils/platform/platformUtils.ts +33 -3
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +91 -16
- package/appUtils/playerManager/OverlayObserver/utils.ts +32 -20
- package/appUtils/playerManager/conts.ts +21 -0
- package/appUtils/playerManager/useChapterMarker.tsx +0 -1
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +16 -0
- package/arrayUtils/__tests__/allTruthy.test.ts +24 -0
- package/arrayUtils/__tests__/anyThruthy.test.ts +24 -0
- package/arrayUtils/__tests__/isEmptyArray.test.ts +63 -0
- package/arrayUtils/__tests__/isFilledArray.test.ts +1 -1
- package/arrayUtils/index.ts +13 -3
- package/audioPlayerUtils/__tests__/getArtworkImage.test.ts +144 -0
- package/audioPlayerUtils/__tests__/getBackgroundImage.test.ts +72 -0
- package/audioPlayerUtils/__tests__/getImageFromEntry.test.ts +110 -0
- package/audioPlayerUtils/assets/index.ts +2 -0
- package/audioPlayerUtils/index.ts +242 -0
- package/componentsUtils/__tests__/isTabsScreen.test.ts +38 -0
- package/componentsUtils/index.ts +4 -1
- package/conf/player/__tests__/selectors.test.ts +34 -0
- package/conf/player/selectors.ts +10 -0
- package/configurationUtils/__tests__/configurationUtils.test.js +0 -31
- package/configurationUtils/__tests__/getMediaItems.test.ts +65 -0
- package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +34 -0
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +546 -0
- package/configurationUtils/index.ts +64 -35
- package/configurationUtils/manifestKeyParser.ts +57 -32
- package/focusManager/FocusManager.ts +104 -20
- package/focusManager/Tree.ts +25 -21
- package/focusManager/__tests__/FocusManager.test.ts +50 -8
- package/focusManager/aux/index.ts +98 -0
- package/focusManager/utils.ts +12 -6
- package/index.d.ts +1 -10
- package/manifestUtils/_internals/getDefaultConfiguration.js +28 -0
- package/manifestUtils/{_internals.js → _internals/index.js} +2 -25
- package/manifestUtils/createConfig.js +4 -1
- package/manifestUtils/defaultManifestConfigurations/player.js +2764 -1539
- package/manifestUtils/index.js +4 -0
- package/manifestUtils/keys.js +33 -0
- package/manifestUtils/progressBar/__tests__/mobileProgressBar.test.js +0 -30
- package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +6 -0
- package/manifestUtils/sharedConfiguration/screenPicker/utils.js +1 -0
- package/navigationUtils/__tests__/mapContentTypesToRivers.test.ts +130 -0
- package/navigationUtils/index.ts +26 -21
- package/package.json +2 -3
- package/playerUtils/PlayerTTS/PlayerTTS.ts +359 -0
- package/playerUtils/PlayerTTS/index.ts +1 -0
- package/playerUtils/__tests__/configurationUtils.test.ts +1 -65
- package/playerUtils/__tests__/getPlayerActionButtons.test.ts +54 -0
- package/playerUtils/_internals/__tests__/utils.test.ts +71 -0
- package/playerUtils/_internals/index.ts +1 -0
- package/playerUtils/_internals/utils.ts +31 -0
- package/playerUtils/configurationUtils.ts +0 -44
- package/playerUtils/getPlayerActionButtons.ts +17 -0
- package/playerUtils/index.ts +53 -0
- package/playerUtils/usePlayerTTS.ts +21 -0
- package/playerUtils/useValidatePlayerConfig.tsx +22 -19
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +15 -14
- package/reactHooks/cell-click/__tests__/index.test.js +3 -0
- package/reactHooks/cell-click/index.ts +8 -1
- package/reactHooks/debugging/__tests__/index.test.js +0 -1
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +47 -90
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +71 -31
- package/reactHooks/feed/index.ts +2 -0
- package/reactHooks/feed/useBatchLoading.ts +17 -10
- package/reactHooks/feed/useFeedLoader.tsx +36 -43
- package/reactHooks/feed/useInflatedUrl.ts +23 -29
- package/reactHooks/feed/useLoadPipesDataDispatch.ts +63 -0
- package/reactHooks/feed/usePipesCacheReset.ts +3 -3
- package/reactHooks/flatList/useSequentialRenderItem.tsx +3 -3
- package/reactHooks/layout/__tests__/index.test.tsx +3 -1
- package/reactHooks/layout/index.ts +1 -1
- package/reactHooks/layout/isTablet/index.ts +12 -5
- 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/useIsScreenActive.ts +9 -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/screen/useScreenContext.ts +1 -1
- package/reactHooks/state/__tests__/ZStoreProvider.test.tsx +2 -1
- package/reactHooks/state/index.ts +1 -1
- package/reactHooks/state/useHomeRiver.ts +4 -2
- package/reactHooks/state/useRivers.ts +7 -8
- package/riverComponetsMeasurementProvider/index.tsx +1 -1
- package/screenPickerUtils/index.ts +13 -0
- package/services/js2native.ts +1 -0
- package/storage/ScreenSingleValueProvider.ts +204 -0
- package/storage/ScreenStateMultiSelectProvider.ts +293 -0
- package/storage/StorageMultiSelectProvider.ts +192 -0
- package/storage/StorageSingleSelectProvider.ts +108 -0
- package/testUtils/index.tsx +7 -8
- package/time/BackgroundTimer.ts +6 -4
- package/utils/__tests__/endsWith.test.ts +30 -0
- package/utils/__tests__/find.test.ts +36 -0
- package/utils/__tests__/mapAccum.test.ts +73 -0
- package/utils/__tests__/omit.test.ts +19 -0
- package/utils/__tests__/path.test.ts +33 -0
- package/utils/__tests__/pathOr.test.ts +37 -0
- package/utils/__tests__/startsWith.test.ts +30 -0
- package/utils/__tests__/take.test.ts +40 -0
- package/utils/endsWith.ts +9 -0
- package/utils/find.ts +3 -0
- package/utils/index.ts +38 -1
- package/utils/mapAccum.ts +23 -0
- package/utils/omit.ts +5 -0
- package/utils/path.ts +5 -0
- package/utils/pathOr.ts +5 -0
- package/utils/startsWith.ts +9 -0
- package/utils/take.ts +5 -0
- package/playerUtils/configurationGenerator.ts +0 -2572
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { MultiSelectProvider } from "./StorageMultiSelectProvider";
|
|
2
|
+
import { BehaviorSubject } from "rxjs";
|
|
3
|
+
import { createLogger } from "../logger";
|
|
4
|
+
import { bridgeLogger } from "../../zapp-react-native-bridge/logger";
|
|
5
|
+
import { useScreenStateStore } from "../reactHooks/navigation/useScreenStateStore";
|
|
6
|
+
|
|
7
|
+
export const { log_debug, log_error } = createLogger({
|
|
8
|
+
category: "ScreenMultiSelectProvider",
|
|
9
|
+
subsystem: "zapp-react-native-bridge",
|
|
10
|
+
parent: bridgeLogger,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export class ScreenMultiSelectProvider implements MultiSelectProvider {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
private itemSubject: BehaviorSubject<string[] | null>;
|
|
16
|
+
private screenStateStoreUnsubscribe: (() => void) | null = null;
|
|
17
|
+
|
|
18
|
+
private static providers: Record<
|
|
19
|
+
string,
|
|
20
|
+
Record<string, MultiSelectProvider>
|
|
21
|
+
> = {};
|
|
22
|
+
|
|
23
|
+
public static getProvider(
|
|
24
|
+
key: string,
|
|
25
|
+
screenRoute: string,
|
|
26
|
+
screenStateStore: ReturnType<typeof useScreenStateStore>
|
|
27
|
+
): MultiSelectProvider {
|
|
28
|
+
if (!key) {
|
|
29
|
+
throw new Error("ScreenMultiSelectProvider: Key is required");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!screenRoute) {
|
|
33
|
+
throw new Error("ScreenMultiSelectProvider: Screen route is required");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!screenStateStore) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
"ScreenMultiSelectProvider: screen state store is required"
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!this.providers[screenRoute]) {
|
|
43
|
+
this.providers[screenRoute] = {};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
if (!this.providers[screenRoute][key]) {
|
|
48
|
+
this.providers[screenRoute][key] = new ScreenMultiSelectProvider(
|
|
49
|
+
key,
|
|
50
|
+
screenRoute,
|
|
51
|
+
screenStateStore
|
|
52
|
+
);
|
|
53
|
+
} else {
|
|
54
|
+
(
|
|
55
|
+
this.providers[screenRoute][key] as ScreenMultiSelectProvider
|
|
56
|
+
).updateStore(screenStateStore);
|
|
57
|
+
}
|
|
58
|
+
} catch (error) {
|
|
59
|
+
log_error("Failed to create provider", { key, screenRoute, error });
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return this.providers[screenRoute][key];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
private constructor(
|
|
68
|
+
private key: string,
|
|
69
|
+
route: string,
|
|
70
|
+
private screenStateStore: ReturnType<typeof useScreenStateStore>
|
|
71
|
+
) {
|
|
72
|
+
if (!key) {
|
|
73
|
+
throw new Error("ScreenMultiSelectProvider: Key is required");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!screenStateStore) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
"ScreenMultiSelectProvider: screen state store is required"
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
this.key = key;
|
|
83
|
+
this.itemSubject = new BehaviorSubject<string[]>([]);
|
|
84
|
+
|
|
85
|
+
this.setupScreenStateSubscription();
|
|
86
|
+
|
|
87
|
+
void this.getSelectedAsync();
|
|
88
|
+
|
|
89
|
+
log_debug("ScreenMultiSelectProvider: Initializing", { key, route });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private updateStore(
|
|
93
|
+
screenStateStore: ReturnType<typeof useScreenStateStore>
|
|
94
|
+
): void {
|
|
95
|
+
if (screenStateStore === this.screenStateStore) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
this.cleanup();
|
|
100
|
+
this.screenStateStore = screenStateStore;
|
|
101
|
+
this.setupScreenStateSubscription();
|
|
102
|
+
void this.getSelectedAsync();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private setupScreenStateSubscription(): void {
|
|
106
|
+
this.screenStateStoreUnsubscribe = this.screenStateStore.subscribe(
|
|
107
|
+
(state) => ({
|
|
108
|
+
value: state.data[this.key],
|
|
109
|
+
exists: this.key in state.data,
|
|
110
|
+
})
|
|
111
|
+
// (current, previous) => {
|
|
112
|
+
// if (!current.exists && previous.exists) {
|
|
113
|
+
// log_debug(
|
|
114
|
+
// `ScreenMultiSelectProvider: Key deleted from store: ${this.key}`
|
|
115
|
+
// );
|
|
116
|
+
|
|
117
|
+
// // TODO: If we need to handle deletion, we can do it here
|
|
118
|
+
// }
|
|
119
|
+
|
|
120
|
+
// if (current.value !== previous.value) {
|
|
121
|
+
// const items = this.parseStoredValue(current.value);
|
|
122
|
+
// this.itemSubject.next(items);
|
|
123
|
+
|
|
124
|
+
// log_debug(`ScreenMultiSelectProvider: Key updated: ${this.key}`, {
|
|
125
|
+
// previous: this.parseStoredValue(previous.value),
|
|
126
|
+
// current: items,
|
|
127
|
+
// });
|
|
128
|
+
// }
|
|
129
|
+
// }
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
log_debug(
|
|
133
|
+
`ScreenMultiSelectProvider: screen state store subscription setup for key: ${this.key}`
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private parseStoredValue(value: string): string[] {
|
|
138
|
+
if (!value) return [];
|
|
139
|
+
|
|
140
|
+
return typeof value === "string"
|
|
141
|
+
? value.split(",").filter((item) => item.length > 0)
|
|
142
|
+
: [];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private formatValueForStorage(items: string[]): string {
|
|
146
|
+
return items.join(",");
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private getCurrentItems(): Set<string> {
|
|
150
|
+
const currentValue = this.screenStateStore.getState().data[this.key];
|
|
151
|
+
const items = this.parseStoredValue(currentValue);
|
|
152
|
+
|
|
153
|
+
return new Set(items);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private updateScreenState(items: Set<string>): void {
|
|
157
|
+
const itemsArray = Array.from(items);
|
|
158
|
+
const formattedValue = this.formatValueForStorage(itemsArray);
|
|
159
|
+
|
|
160
|
+
this.screenStateStore.getState().setValue(this.key, formattedValue);
|
|
161
|
+
const itemsToUpdate = Array.from(items) || [];
|
|
162
|
+
this.itemSubject.next(itemsToUpdate);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private cleanup(): void {
|
|
166
|
+
if (this.screenStateStoreUnsubscribe) {
|
|
167
|
+
this.screenStateStoreUnsubscribe();
|
|
168
|
+
this.screenStateStoreUnsubscribe = null;
|
|
169
|
+
|
|
170
|
+
log_debug(
|
|
171
|
+
`ScreenMultiSelectProvider: Unsubscribed from screen state store for key: ${this.key}`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
addItem(item: string): Promise<void> {
|
|
177
|
+
const items = this.getCurrentItems();
|
|
178
|
+
items.add(item);
|
|
179
|
+
this.updateScreenState(items);
|
|
180
|
+
|
|
181
|
+
log_debug(
|
|
182
|
+
`addItem: item added: ${item}, current items: [${Array.from(items).join(", ")}]`
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
return Promise.resolve();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
addItems(itemsToAdd: string[]): Promise<void> {
|
|
189
|
+
const items = this.getCurrentItems();
|
|
190
|
+
|
|
191
|
+
for (const item of itemsToAdd) {
|
|
192
|
+
items.add(item);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
this.updateScreenState(items);
|
|
196
|
+
|
|
197
|
+
log_debug(
|
|
198
|
+
`addItems: items added: [${itemsToAdd.join(", ")}], current items: [${Array.from(items).join(", ")}]`
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
return Promise.resolve();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
public getObservable = (): BehaviorSubject<string[]> => this.itemSubject;
|
|
205
|
+
|
|
206
|
+
getSelectedAsync(): Promise<string[]> {
|
|
207
|
+
const currentValue = this.screenStateStore.getState().data[this.key] || [];
|
|
208
|
+
const values = this.parseStoredValue(currentValue);
|
|
209
|
+
const selected = this.getSelectedItems();
|
|
210
|
+
|
|
211
|
+
const arraysAreEqual =
|
|
212
|
+
Array.isArray(values) &&
|
|
213
|
+
Array.isArray(selected) &&
|
|
214
|
+
values.length === selected.length &&
|
|
215
|
+
values.every((val, index) => val === selected[index]);
|
|
216
|
+
|
|
217
|
+
const bothEmpty = values.length === 0 && selected.length === 0;
|
|
218
|
+
|
|
219
|
+
if (!this.itemSubject.closed && !arraysAreEqual && !bothEmpty) {
|
|
220
|
+
this.itemSubject.next(values);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return Promise.resolve(values);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
getSelectedItems(): string[] {
|
|
227
|
+
return this.itemSubject.value || [];
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
removeAllItems(): Promise<void> {
|
|
231
|
+
this.screenStateStore.getState().removeValue(this.key);
|
|
232
|
+
this.itemSubject.next([]);
|
|
233
|
+
|
|
234
|
+
log_debug(`removeAllItems: all items removed for key: ${this.key}`);
|
|
235
|
+
|
|
236
|
+
return Promise.resolve();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
removeItem(item: string): Promise<void> {
|
|
240
|
+
const items = this.getCurrentItems();
|
|
241
|
+
items.delete(item);
|
|
242
|
+
|
|
243
|
+
this.updateScreenState(items);
|
|
244
|
+
|
|
245
|
+
log_debug(
|
|
246
|
+
`removeItem: item removed: ${item}, remaining items: ${Array.from(items).join(", ")}`
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
return Promise.resolve();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
removeItems(itemsToRemove: string[]): Promise<void> {
|
|
253
|
+
const items = this.getCurrentItems();
|
|
254
|
+
|
|
255
|
+
for (const item of itemsToRemove) {
|
|
256
|
+
items.delete(item);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
this.updateScreenState(items);
|
|
260
|
+
|
|
261
|
+
log_debug(
|
|
262
|
+
`removeItems: items removed: [${itemsToRemove.join(", ")}], remaining items: [${Array.from(items).join(", ")}]`
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
return Promise.resolve();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
setSelectedItems(items: string[]): Promise<void> {
|
|
269
|
+
this.updateScreenState(new Set(items));
|
|
270
|
+
log_debug(`setSelectedItems: items set to: [${items.join(", ")}]`);
|
|
271
|
+
|
|
272
|
+
return Promise.resolve();
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// TODO: remove if not needed
|
|
276
|
+
|
|
277
|
+
public static cleanupRoute(screenRoute: string): void {
|
|
278
|
+
if (this.providers[screenRoute]) {
|
|
279
|
+
Object.values(this.providers[screenRoute]).forEach((provider) => {
|
|
280
|
+
(provider as ScreenMultiSelectProvider).destroy();
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
delete this.providers[screenRoute];
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// TODO: remove if not needed
|
|
288
|
+
|
|
289
|
+
public destroy(): void {
|
|
290
|
+
this.itemSubject.complete();
|
|
291
|
+
this.cleanup();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
@@ -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,15 +11,17 @@ 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
|
+
amazon: DeviceEventEmitter, // probably does not exist and uses android_tv
|
|
17
18
|
default: undefined,
|
|
18
19
|
});
|
|
19
20
|
|
|
20
21
|
EventEmitter?.addListener("BackgroundTimer.timer.fired", (id: number) => {
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
const callback = this.callbacks[id];
|
|
23
|
+
|
|
24
|
+
if (callback) {
|
|
23
25
|
delete this.callbacks[id];
|
|
24
26
|
callback();
|
|
25
27
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { endsWith } from "../endsWith";
|
|
2
|
+
|
|
3
|
+
describe("endsWith", () => {
|
|
4
|
+
it("returns false when str is null", () => {
|
|
5
|
+
expect(endsWith("a", null)).toBe(false);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("returns false when str is undefined", () => {
|
|
9
|
+
expect(endsWith("a", undefined)).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("returns true when string ends with target", () => {
|
|
13
|
+
expect(endsWith("lo", "hello")).toBe(true);
|
|
14
|
+
expect(endsWith("", "hello")).toBe(true); // empty target always matches
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("returns false when string does not end with target", () => {
|
|
18
|
+
expect(endsWith("yo", "hello")).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("works with single character target", () => {
|
|
22
|
+
expect(endsWith("o", "hello")).toBe(true);
|
|
23
|
+
expect(endsWith("x", "hello")).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("is case-sensitive", () => {
|
|
27
|
+
expect(endsWith("Lo", "hello")).toBe(false);
|
|
28
|
+
expect(endsWith("lo", "hello")).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { find } from "../find";
|
|
2
|
+
|
|
3
|
+
test("example 1", () => {
|
|
4
|
+
const predicate = <T>(_: T, index: number): boolean => index === 0;
|
|
5
|
+
const xs = ["1", "2", "2", "3", "4"];
|
|
6
|
+
|
|
7
|
+
expect(find(predicate, xs)).toBe("1");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test("example 2", () => {
|
|
11
|
+
const predicate = <T>(_: T, index: number): boolean => index === 0;
|
|
12
|
+
const xs: string[] = [];
|
|
13
|
+
|
|
14
|
+
expect(find(predicate, xs)).toBe(undefined);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("example 3", () => {
|
|
18
|
+
const predicate = () => false;
|
|
19
|
+
const xs = ["1", "2", "2", "3"];
|
|
20
|
+
|
|
21
|
+
expect(find(predicate, xs)).toBe(undefined);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("example 4", () => {
|
|
25
|
+
const predicate = <T>(_: T, index: number): boolean => index === 1;
|
|
26
|
+
const xs = ["1", "2", "2", "3"];
|
|
27
|
+
|
|
28
|
+
expect(find(predicate, xs)).toBe("2");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("example 5", () => {
|
|
32
|
+
const predicate = <T>(_: T, index: number): boolean => index === 2;
|
|
33
|
+
const xs = ["1", "2.1", "2", "3", "2", "4"];
|
|
34
|
+
|
|
35
|
+
expect(find(predicate, xs)).toBe("2");
|
|
36
|
+
});
|