@applicaster/zapp-react-native-utils 13.0.0-rc.99 → 14.0.0-alpha.1235043154
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 +55 -6
- package/actionsExecutor/consts.ts +4 -0
- 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/__tests__/__snapshots__/localizationsHelper.test.ts.snap +151 -0
- package/appUtils/__tests__/allZappLocales.ts +79 -0
- package/appUtils/__tests__/{localizationsHelper.test.js → localizationsHelper.test.ts} +11 -0
- package/appUtils/accessibilityManager/const.ts +18 -0
- package/appUtils/accessibilityManager/index.ts +4 -1
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +1 -0
- package/appUtils/focusManager/index.ios.ts +14 -4
- package/appUtils/focusManager/utils/__tests__/findChild.test.ts +35 -0
- package/appUtils/focusManager/utils/index.ts +5 -0
- package/appUtils/localizationsHelper.ts +10 -2
- package/appUtils/playerManager/playerHooks/usePlayerCurrentTime.tsx +11 -7
- package/arrayUtils/__tests__/isEmptyArray.test.ts +63 -0
- package/arrayUtils/__tests__/isFilledArray.test.ts +1 -1
- package/arrayUtils/index.ts +7 -2
- 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/cellUtils/index.ts +9 -5
- package/componentsUtils/index.ts +8 -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/index.ts +63 -34
- package/localizationUtils/index.ts +3 -3
- 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/generalContent.js +13 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +1228 -205
- package/manifestUtils/index.js +2 -0
- package/manifestUtils/keys.js +27 -2
- package/manifestUtils/progressBar/__tests__/mobileProgressBar.test.js +0 -30
- package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +1 -2
- package/navigationUtils/__tests__/navigationUtils.test.js +0 -65
- package/navigationUtils/index.ts +0 -31
- package/package.json +2 -2
- 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 +25 -0
- package/playerUtils/useValidatePlayerConfig.tsx +22 -19
- package/reactHooks/app/useAppState.ts +2 -2
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +12 -13
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +39 -88
- package/reactHooks/feed/useBatchLoading.ts +12 -14
- package/reactHooks/navigation/{useGetTabBarHeight.ts → getTabBarHeight.ts} +1 -1
- package/reactHooks/navigation/index.ts +2 -2
- package/reactHooks/navigation/useGetBottomTabBarHeight.ts +10 -3
- package/reactHooks/navigation/useNavigationPluginData.ts +8 -4
- package/reactHooks/navigation/useNavigationType.ts +4 -2
- package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +69 -0
- package/reactHooks/screen/useScreenBackgroundColor.ts +3 -15
- package/reactHooks/state/README.md +79 -0
- package/reactHooks/state/ZStoreProvider.tsx +71 -0
- package/reactHooks/state/__tests__/ZStoreProvider.test.tsx +66 -0
- package/reactHooks/state/index.ts +2 -0
- package/reactHooks/useListenEventBusEvent.ts +1 -1
- package/reactUtils/index.ts +9 -0
- package/testUtils/index.tsx +7 -8
- package/typeGuards/index.ts +3 -0
- package/utils/index.ts +12 -1
- package/zappFrameworkUtils/localStorageHelper.ts +32 -10
- package/playerUtils/configurationGenerator.ts +0 -2588
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import React, { createContext, useContext, ReactNode, useMemo } from "react";
|
|
2
|
+
import { create, UseBoundStore } from "zustand";
|
|
3
|
+
|
|
4
|
+
interface ZStoreContextType {
|
|
5
|
+
stores: Map<string, UseBoundStore<any>>;
|
|
6
|
+
registerStore: (name: string, store: UseBoundStore<any>) => void;
|
|
7
|
+
getStore: (name: string) => UseBoundStore<any> | undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const ZStoreContext = createContext<ZStoreContextType | null>(null);
|
|
11
|
+
|
|
12
|
+
interface ZStoreProviderProps {
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
name: string;
|
|
15
|
+
value: any;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const ZStoreProvider: React.FC<ZStoreProviderProps> = ({
|
|
19
|
+
children,
|
|
20
|
+
name,
|
|
21
|
+
value,
|
|
22
|
+
}) => {
|
|
23
|
+
const parentContext = useContext(ZStoreContext);
|
|
24
|
+
|
|
25
|
+
const context = useMemo(() => {
|
|
26
|
+
if (parentContext) {
|
|
27
|
+
// If parent context exists, create a new store and register it
|
|
28
|
+
const store = create(() => value);
|
|
29
|
+
parentContext.registerStore(name, store);
|
|
30
|
+
|
|
31
|
+
return parentContext;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Create a new context if none exists
|
|
35
|
+
const stores = new Map<string, UseBoundStore<any>>();
|
|
36
|
+
|
|
37
|
+
// Create a store from the provided value
|
|
38
|
+
const store = create(() => value);
|
|
39
|
+
stores.set(name, store);
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
stores,
|
|
43
|
+
registerStore: (storeName: string, storeInstance: UseBoundStore<any>) => {
|
|
44
|
+
stores.set(storeName, storeInstance);
|
|
45
|
+
},
|
|
46
|
+
getStore: (storeName: string) => stores.get(storeName),
|
|
47
|
+
};
|
|
48
|
+
}, [parentContext, name, value]);
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<ZStoreContext.Provider value={context}>{children}</ZStoreContext.Provider>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const useZStore = (name: string): UseBoundStore<any> => {
|
|
56
|
+
const context = useContext(ZStoreContext);
|
|
57
|
+
|
|
58
|
+
if (!context) {
|
|
59
|
+
throw new Error("useZStore must be used within a ZStoreProvider");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const store = context.getStore(name);
|
|
63
|
+
|
|
64
|
+
if (!store) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
`Store with name "${name}" not found. Make sure it's provided by a ZStoreProvider.`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return store;
|
|
71
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, screen } from "@testing-library/react-native";
|
|
3
|
+
import { Text } from "react-native";
|
|
4
|
+
import { ZStoreProvider, useZStore } from "../ZStoreProvider";
|
|
5
|
+
import { useStore } from "zustand";
|
|
6
|
+
|
|
7
|
+
interface TestState {
|
|
8
|
+
value: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Test component that uses the store
|
|
12
|
+
const TestComponent = ({ storeName }: { storeName: string }) => {
|
|
13
|
+
const store = useZStore(storeName);
|
|
14
|
+
const value = useStore(store, (state: any) => (state as TestState).value);
|
|
15
|
+
|
|
16
|
+
return <Text testID="test-value">{value}</Text>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Test component that provides a store
|
|
20
|
+
const TestProvider = ({ children }: { children: React.ReactNode }) => {
|
|
21
|
+
return (
|
|
22
|
+
<ZStoreProvider name="testStore" value={{ value: "test-value" }}>
|
|
23
|
+
{children}
|
|
24
|
+
</ZStoreProvider>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
describe("ZStoreProvider and useZStore", () => {
|
|
29
|
+
it("should provide a store and allow access via useZStore", () => {
|
|
30
|
+
render(
|
|
31
|
+
<TestProvider>
|
|
32
|
+
<TestComponent storeName="testStore" />
|
|
33
|
+
</TestProvider>
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
expect(screen.getByTestId("test-value").props.children).toBe("test-value");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should throw error when useZStore is used outside provider", () => {
|
|
40
|
+
// Suppress console.error for this test
|
|
41
|
+
const originalError = console.error;
|
|
42
|
+
console.error = jest.fn();
|
|
43
|
+
|
|
44
|
+
expect(() => {
|
|
45
|
+
render(<TestComponent storeName="testStore" />);
|
|
46
|
+
}).toThrow("useZStore must be used within a ZStoreProvider");
|
|
47
|
+
|
|
48
|
+
console.error = originalError;
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("should throw error when store name is not found", () => {
|
|
52
|
+
// Suppress console.error for this test
|
|
53
|
+
const originalError = console.error;
|
|
54
|
+
console.error = jest.fn();
|
|
55
|
+
|
|
56
|
+
expect(() => {
|
|
57
|
+
render(
|
|
58
|
+
<TestProvider>
|
|
59
|
+
<TestComponent storeName="nonExistentStore" />
|
|
60
|
+
</TestProvider>
|
|
61
|
+
);
|
|
62
|
+
}).toThrow('Store with name "nonExistentStore" not found');
|
|
63
|
+
|
|
64
|
+
console.error = originalError;
|
|
65
|
+
});
|
|
66
|
+
});
|
package/reactUtils/index.ts
CHANGED
|
@@ -187,3 +187,12 @@ export const hasVizioAPIs = () => {
|
|
|
187
187
|
|
|
188
188
|
return hasAPIs;
|
|
189
189
|
};
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Checks if the Android version is at least the expected version
|
|
193
|
+
* @param expectedVersion The version to compare against
|
|
194
|
+
* @returns True if the current Android version is at least the expected version, false otherwise
|
|
195
|
+
*/
|
|
196
|
+
export const isAndroidVersionAtLeast = (expectedVersion: number) => {
|
|
197
|
+
return parseFloat(Platform.Version.toString()) >= expectedVersion;
|
|
198
|
+
};
|
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/utils/index.ts
CHANGED
|
@@ -2,4 +2,15 @@ export { chunk } from "./chunk";
|
|
|
2
2
|
|
|
3
3
|
export { times } from "./times";
|
|
4
4
|
|
|
5
|
-
export {
|
|
5
|
+
export {
|
|
6
|
+
cloneDeep as clone,
|
|
7
|
+
flatten,
|
|
8
|
+
drop,
|
|
9
|
+
size,
|
|
10
|
+
isNil,
|
|
11
|
+
isEmpty,
|
|
12
|
+
get,
|
|
13
|
+
has,
|
|
14
|
+
flatMap,
|
|
15
|
+
difference,
|
|
16
|
+
} from "lodash";
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
StorageValuesToRemove,
|
|
8
8
|
StorageValuesToAdd,
|
|
9
9
|
} from "./types";
|
|
10
|
+
import { Storage } from "@applicaster/zapp-react-native-bridge/ZappStorage/Storage";
|
|
10
11
|
|
|
11
12
|
const defaultOwnedKey = "owned_keys";
|
|
12
13
|
const DEFAULT_NAMESPACE = "applicaster.v2";
|
|
@@ -50,8 +51,9 @@ function mapOwnedKeysToAdd(
|
|
|
50
51
|
return mappedData;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
export async function
|
|
54
|
-
storageValues: StorageValuesToAdd
|
|
54
|
+
export async function batchSave(
|
|
55
|
+
storageValues: StorageValuesToAdd,
|
|
56
|
+
storage: Storage
|
|
55
57
|
) {
|
|
56
58
|
if (isNilOrEmpty(storageValues)) {
|
|
57
59
|
return false;
|
|
@@ -64,24 +66,37 @@ export async function batchSaveToLocalStorage(
|
|
|
64
66
|
const value = namespaceData[key];
|
|
65
67
|
|
|
66
68
|
if (!isNilOrEmpty(value)) {
|
|
67
|
-
await
|
|
69
|
+
await storage.setItem(key, value, namespace);
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
export async function
|
|
74
|
-
storageValues:
|
|
75
|
+
export async function batchSaveToLocalStorage(
|
|
76
|
+
storageValues: StorageValuesToAdd
|
|
77
|
+
) {
|
|
78
|
+
return await batchSave(storageValues, localStorage);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function batchRemoveFromStorage(
|
|
82
|
+
storageValues: StorageValuesToRemove,
|
|
83
|
+
storage: Storage = localStorage
|
|
75
84
|
) {
|
|
76
85
|
for (const namespace of Object.keys(storageValues)) {
|
|
77
86
|
const namespaceData = storageValues[namespace];
|
|
78
87
|
|
|
79
88
|
for (const key of namespaceData) {
|
|
80
|
-
await
|
|
89
|
+
await storage.removeItem(key, namespace);
|
|
81
90
|
}
|
|
82
91
|
}
|
|
83
92
|
}
|
|
84
93
|
|
|
94
|
+
export async function batchRemoveFromLocalStorage(
|
|
95
|
+
storageValues: StorageValuesToRemove
|
|
96
|
+
) {
|
|
97
|
+
await batchRemoveFromStorage(storageValues, localStorage);
|
|
98
|
+
}
|
|
99
|
+
|
|
85
100
|
async function addOwnedKeys({
|
|
86
101
|
newKeys,
|
|
87
102
|
ownershipKey,
|
|
@@ -224,13 +239,20 @@ export async function batchRemoveOwnedNamespaceKeys({
|
|
|
224
239
|
});
|
|
225
240
|
}
|
|
226
241
|
|
|
227
|
-
export async function
|
|
228
|
-
|
|
242
|
+
export async function batchRemoveAllFromNamespaceForStorage(
|
|
243
|
+
namespace: string,
|
|
244
|
+
storage: Storage
|
|
245
|
+
) {
|
|
246
|
+
const allDataInNamespace = await storage.getAllItems(namespace);
|
|
229
247
|
const keysToRemove = Object.keys(allDataInNamespace);
|
|
230
248
|
|
|
231
|
-
const dataToRemove = {
|
|
249
|
+
const dataToRemove: StorageValuesToRemove = {
|
|
232
250
|
[namespace]: keysToRemove,
|
|
233
251
|
};
|
|
234
252
|
|
|
235
|
-
await
|
|
253
|
+
await batchRemoveFromStorage(dataToRemove, storage);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export async function batchRemoveAllFromNamespace(namespace: string) {
|
|
257
|
+
await batchRemoveAllFromNamespaceForStorage(namespace, localStorage);
|
|
236
258
|
}
|