@applicaster/zapp-react-native-utils 13.0.0-rc.96 → 13.0.0-rc.98
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/appUtils/localizationsHelper.ts +23 -0
- package/componentsUtils/__tests__/isFirstComponentGallery.test.ts +33 -0
- package/componentsUtils/__tests__/isFirstComponentScreenPicker.test.ts +33 -0
- package/componentsUtils/__tests__/isGallery.test.ts +33 -0
- package/componentsUtils/__tests__/isScreenPicker.test.ts +33 -0
- package/componentsUtils/index.ts +32 -0
- package/dateUtils/index.ts +17 -0
- package/localizationUtils/index.ts +5 -10
- package/package.json +2 -2
|
@@ -65,6 +65,29 @@ export function getUILanguage() {
|
|
|
65
65
|
return getLanguageCode();
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
export const toDayJSLocaleMap = (code) => {
|
|
69
|
+
const map = {
|
|
70
|
+
hy: "hy-am",
|
|
71
|
+
fj: null,
|
|
72
|
+
la: null,
|
|
73
|
+
no: null,
|
|
74
|
+
pa: "pa-in",
|
|
75
|
+
qu: null,
|
|
76
|
+
"es-LA": "es",
|
|
77
|
+
sm: null,
|
|
78
|
+
to: null,
|
|
79
|
+
xh: null,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
if (map[code] === null) {
|
|
83
|
+
return "en";
|
|
84
|
+
} else if (map[code]) {
|
|
85
|
+
return map[code];
|
|
86
|
+
} else {
|
|
87
|
+
return code;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
68
91
|
/**
|
|
69
92
|
* returns the localization for the app based on the locale. If the locale is null
|
|
70
93
|
* or undefined, or if the given locale doesn't exist in the localizations,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isFirstComponentGallery } from "../index";
|
|
2
|
+
|
|
3
|
+
describe("isFirstComponentGallery", () => {
|
|
4
|
+
it("should return true if the first component is a gallery", () => {
|
|
5
|
+
const components = [
|
|
6
|
+
{ component_type: "gallery-qb" },
|
|
7
|
+
{ component_type: "other-component" },
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
expect(isFirstComponentGallery(components)).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should return false if the first component is not a gallery", () => {
|
|
14
|
+
const components = [
|
|
15
|
+
{ component_type: "other-component" },
|
|
16
|
+
{ component_type: "gallery-qb" },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
expect(isFirstComponentGallery(components)).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should return false if the components array is empty", () => {
|
|
23
|
+
const components = [];
|
|
24
|
+
|
|
25
|
+
expect(isFirstComponentGallery(components)).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should return false if the components array is undefined", () => {
|
|
29
|
+
const components = undefined;
|
|
30
|
+
|
|
31
|
+
expect(isFirstComponentGallery(components)).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isFirstComponentScreenPicker } from "..";
|
|
2
|
+
|
|
3
|
+
describe("isFirstComponentScreenPicker", () => {
|
|
4
|
+
it("should return true if the first component screen-picker", () => {
|
|
5
|
+
const items = [{ component_type: "screen-picker-qb-tv" }];
|
|
6
|
+
expect(isFirstComponentScreenPicker(items)).toBe(true);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it("should return false if the first component type is not screen-picker", () => {
|
|
10
|
+
const items = [{ component_type: "other-component" }];
|
|
11
|
+
expect(isFirstComponentScreenPicker(items)).toBe(false);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("should return false if the component type is undefined", () => {
|
|
15
|
+
const items = [{ component_type: undefined }];
|
|
16
|
+
expect(isFirstComponentScreenPicker(items)).toBe(false);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should return false if the item is null", () => {
|
|
20
|
+
const items = null;
|
|
21
|
+
expect(isFirstComponentScreenPicker(items)).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should return false if the item is undefined", () => {
|
|
25
|
+
const items = undefined;
|
|
26
|
+
expect(isFirstComponentScreenPicker(items)).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should return false if the item is an empty object", () => {
|
|
30
|
+
const items = {};
|
|
31
|
+
expect(isFirstComponentScreenPicker(items)).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isGallery } from "..";
|
|
2
|
+
|
|
3
|
+
describe("isGallery", () => {
|
|
4
|
+
it("should return true if the component type is 'gallery-qb'", () => {
|
|
5
|
+
const item = { component_type: "gallery-qb" };
|
|
6
|
+
expect(isGallery(item)).toBe(true);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it("should return false if the component type is not 'gallery-qb'", () => {
|
|
10
|
+
const item = { component_type: "other-component" };
|
|
11
|
+
expect(isGallery(item)).toBe(false);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("should return false if the component type is undefined", () => {
|
|
15
|
+
const item = { component_type: undefined };
|
|
16
|
+
expect(isGallery(item)).toBe(false);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should return false if the item is null", () => {
|
|
20
|
+
const item = null;
|
|
21
|
+
expect(isGallery(item)).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should return false if the item is undefined", () => {
|
|
25
|
+
const item = undefined;
|
|
26
|
+
expect(isGallery(item)).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should return false if the item is an empty object", () => {
|
|
30
|
+
const item = {};
|
|
31
|
+
expect(isGallery(item)).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isScreenPicker } from "..";
|
|
2
|
+
|
|
3
|
+
describe("isScreenPicker", () => {
|
|
4
|
+
it("should return true if the component type is 'screen-picker-qb-tv'", () => {
|
|
5
|
+
const item = { component_type: "screen-picker-qb-tv" };
|
|
6
|
+
expect(isScreenPicker(item)).toBe(true);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it("should return false if the component type is not 'screen-picker-qb-tv'", () => {
|
|
10
|
+
const item = { component_type: "other-component" };
|
|
11
|
+
expect(isScreenPicker(item)).toBe(false);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("should return false if the component type is undefined", () => {
|
|
15
|
+
const item = { component_type: undefined };
|
|
16
|
+
expect(isScreenPicker(item)).toBe(false);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should return false if the item is null", () => {
|
|
20
|
+
const item = null;
|
|
21
|
+
expect(isScreenPicker(item)).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should return false if the item is undefined", () => {
|
|
25
|
+
const item = undefined;
|
|
26
|
+
expect(isScreenPicker(item)).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should return false if the item is an empty object", () => {
|
|
30
|
+
const item = {};
|
|
31
|
+
expect(isScreenPicker(item)).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const GROUP = "group-qb";
|
|
2
|
+
const GROUP_INFO = "group-info-qb";
|
|
3
|
+
const EMPTY_GROUP_COMPONENT = "empty_group_component";
|
|
4
|
+
|
|
5
|
+
const GALLERY = "gallery-qb";
|
|
6
|
+
|
|
7
|
+
const SCREEN_PICKER = "screen-picker-qb-tv";
|
|
8
|
+
|
|
9
|
+
export const isGallery = (item): boolean => item?.component_type === GALLERY;
|
|
10
|
+
|
|
11
|
+
export const isScreenPicker = (item): boolean =>
|
|
12
|
+
item?.component_type === SCREEN_PICKER;
|
|
13
|
+
|
|
14
|
+
export const isFirstComponentScreenPicker = (
|
|
15
|
+
components: ZappUIComponent[]
|
|
16
|
+
): boolean => {
|
|
17
|
+
return isScreenPicker(components?.[0]);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const isFirstComponentGallery = (
|
|
21
|
+
components: ZappUIComponent[]
|
|
22
|
+
): boolean => {
|
|
23
|
+
return isGallery(components?.[0]);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const isGroup = (item): boolean => item?.component_type === GROUP;
|
|
27
|
+
|
|
28
|
+
export const isEmptyGroup = (item): boolean =>
|
|
29
|
+
item?.component_type === EMPTY_GROUP_COMPONENT;
|
|
30
|
+
|
|
31
|
+
export const isGroupInfo = (item): boolean =>
|
|
32
|
+
item?.component_type === GROUP_INFO;
|
package/dateUtils/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import utc from "dayjs/plugin/utc";
|
|
|
3
3
|
import timezone from "dayjs/plugin/timezone";
|
|
4
4
|
import isoWeek from "dayjs/plugin/isoWeek";
|
|
5
5
|
import duration from "dayjs/plugin/duration";
|
|
6
|
+
import relativeTime from "dayjs/plugin/relativeTime";
|
|
6
7
|
|
|
7
8
|
// Extend dayjs with plugins
|
|
8
9
|
dayjs.extend(utc);
|
|
@@ -10,4 +11,20 @@ dayjs.extend(timezone);
|
|
|
10
11
|
dayjs.extend(isoWeek);
|
|
11
12
|
dayjs.extend(duration);
|
|
12
13
|
|
|
14
|
+
dayjs.extend(relativeTime, {
|
|
15
|
+
thresholds: [
|
|
16
|
+
{ l: "s", r: 1 },
|
|
17
|
+
{ l: "m", r: 1 },
|
|
18
|
+
{ l: "mm", r: 59, d: "minute" },
|
|
19
|
+
{ l: "h", r: 1 },
|
|
20
|
+
{ l: "hh", r: 23, d: "hour" },
|
|
21
|
+
{ l: "d", r: 1 },
|
|
22
|
+
{ l: "dd", r: 29, d: "day" },
|
|
23
|
+
{ l: "M", r: 1 },
|
|
24
|
+
{ l: "MM", r: 11, d: "month" },
|
|
25
|
+
{ l: "y", r: 1 },
|
|
26
|
+
{ l: "yy", d: "year" },
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
|
|
13
30
|
export { dayjs };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as R from "ramda";
|
|
2
1
|
import { ViewStyle } from "react-native";
|
|
3
2
|
|
|
4
3
|
import { useMemo } from "react";
|
|
@@ -29,14 +28,16 @@ const RTL_LOCALES = [
|
|
|
29
28
|
"yi", // Yiddish
|
|
30
29
|
];
|
|
31
30
|
|
|
32
|
-
export function useLocalizedStrings({ localizations }) {
|
|
31
|
+
export function useLocalizedStrings({ localizations = {} }) {
|
|
33
32
|
const languageCode = getUILanguage();
|
|
34
33
|
|
|
35
34
|
// TODO: probably we can call getLocalizations here from localizationsHelper.js
|
|
36
35
|
const result = useMemo(
|
|
37
36
|
() =>
|
|
38
37
|
localizations?.[languageCode] ||
|
|
39
|
-
|
|
38
|
+
Object.values(localizations).find(
|
|
39
|
+
(value) => typeof value === "object" && value !== null
|
|
40
|
+
) ||
|
|
40
41
|
{},
|
|
41
42
|
[languageCode, localizations]
|
|
42
43
|
);
|
|
@@ -53,13 +54,7 @@ export function getIsRTL(): boolean {
|
|
|
53
54
|
return false;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const lowerCaseLanguageCode = languageCode.toLocaleLowerCase();
|
|
59
|
-
|
|
60
|
-
const isRTL = R.contains(lowerCaseLanguageCode, RTL_LOCALES);
|
|
61
|
-
|
|
62
|
-
return isRTL;
|
|
57
|
+
return RTL_LOCALES.includes(uiLanguage.split("-")[0].toLocaleLowerCase());
|
|
63
58
|
}
|
|
64
59
|
|
|
65
60
|
export function useIsRTL(): boolean {
|
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.98",
|
|
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.98",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|