@applicaster/zapp-react-native-utils 12.0.0-rc.75 → 12.0.0-rc.76
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/keyCodes/keys.web.js +8 -0
- package/appUtils/keyCodes/keysByPlatform.js +11 -1
- package/appUtils/platform/const.ts +18 -0
- package/appUtils/platform/index.ts +1 -0
- package/appUtils/platform/platformUtils.ts +1 -0
- package/appUtils/platform/platformUtils.web.ts +49 -0
- package/booleanUtils/index.ts +4 -4
- package/keyboardState/index.ts +0 -0
- package/package.json +2 -2
- package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +6 -2
- package/reactHooks/feed/useFeedRefresh.tsx +9 -7
- package/reactUtils/index.ts +98 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* global tizen */
|
|
2
2
|
const isTizen = typeof tizen !== "undefined";
|
|
3
3
|
|
|
4
|
+
import { isVizioPlatform } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
4
5
|
import * as platformKeys from "./keysByPlatform";
|
|
5
6
|
import { Platform } from "react-native";
|
|
6
7
|
|
|
@@ -21,6 +22,13 @@ export const ARROW_KEYS = [
|
|
|
21
22
|
KEYS.ArrowRight,
|
|
22
23
|
];
|
|
23
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Platform.OS currently identifies Vizio as LG_TV, therefore we are using isVizioPlatform to identify platform and add keys.
|
|
27
|
+
*/
|
|
28
|
+
if (isVizioPlatform()) {
|
|
29
|
+
Object.assign(KEYS, platformKeys.vizio);
|
|
30
|
+
}
|
|
31
|
+
|
|
24
32
|
/**
|
|
25
33
|
* In TizenOS we need to register all of the keys that we are going to use.
|
|
26
34
|
* You need to register using the name Tizen has for the key.
|
|
@@ -102,4 +102,14 @@ const tvos = {
|
|
|
102
102
|
Menu: { code: "Menu", eventType: "menu" },
|
|
103
103
|
};
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
const vizio = {
|
|
106
|
+
...samsung_tv,
|
|
107
|
+
Exit: { code: "Exit", keyCode: 27 },
|
|
108
|
+
PageUp: { code: "PageUp", keyCode: 33 },
|
|
109
|
+
PageDown: { code: "PageDown", keyCode: 34 },
|
|
110
|
+
MediaTrackNext: { code: "MediaTrackNext", keyCode: 418 },
|
|
111
|
+
MediaTrackPrevious: { code: "MediaTrackPrevious", keyCode: 419 },
|
|
112
|
+
PrevCh: { code: "PrevCh", keyCode: 500 },
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export { lg_tv, samsung_tv, web, tvos, android_tv, vizio };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platforms found in userAgent string, please note that simulators
|
|
3
|
+
* might not have the same agents that the devices have
|
|
4
|
+
*/
|
|
5
|
+
export const PLATFORMS = {
|
|
6
|
+
webos: "Web0S",
|
|
7
|
+
tizen: "Tizen",
|
|
8
|
+
samsung: "SMART-TV",
|
|
9
|
+
mac: "Mac",
|
|
10
|
+
win: "Win",
|
|
11
|
+
linux: "Linux",
|
|
12
|
+
iphone: "iPhone",
|
|
13
|
+
android: "Android",
|
|
14
|
+
mobile: "Mobile",
|
|
15
|
+
vizio: "VIZIO",
|
|
16
|
+
smartcast: "SmartCast",
|
|
17
|
+
conjure: "Conjure",
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./platformUtils";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { PLATFORMS } from "./const";
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
applicaster: {
|
|
6
|
+
vizioLibraryDidLoad: boolean;
|
|
7
|
+
useOnScreenKeyboard: boolean;
|
|
8
|
+
};
|
|
9
|
+
VIZIO?: {
|
|
10
|
+
exitApplication: () => void;
|
|
11
|
+
setClosedCaptionHandler: (
|
|
12
|
+
callback: (isCCEnabled: boolean) => void
|
|
13
|
+
) => void;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const getUserAgent = () =>
|
|
19
|
+
window?.navigator?.userAgent || global?.navigator?.userAgent;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Checks if we are on the Vizio platform by using the userAgent string
|
|
23
|
+
*
|
|
24
|
+
* Use this method when you need to identify the platform on runtime
|
|
25
|
+
* before the VIZIO Companion Library has loaded
|
|
26
|
+
*/
|
|
27
|
+
export const isVizioPlatform = () => {
|
|
28
|
+
const userAgent = getUserAgent();
|
|
29
|
+
|
|
30
|
+
const isVizioAgent =
|
|
31
|
+
userAgent.includes(PLATFORMS.vizio) ||
|
|
32
|
+
userAgent.includes(PLATFORMS.smartcast) ||
|
|
33
|
+
userAgent.includes(PLATFORMS.conjure);
|
|
34
|
+
|
|
35
|
+
return isVizioAgent;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Checks if we are on the Vizio platform by checking for the global VIZIO object
|
|
40
|
+
* and the VIZIO Companion Library. This method does not use the userAgent string,
|
|
41
|
+
* because it mainly checks whether we have access to apis, which may not be available yet
|
|
42
|
+
*/
|
|
43
|
+
export const hasVizioAPIs = () => {
|
|
44
|
+
const hasAPIs =
|
|
45
|
+
typeof window.VIZIO !== "undefined" &&
|
|
46
|
+
window?.applicaster?.vizioLibraryDidLoad;
|
|
47
|
+
|
|
48
|
+
return hasAPIs;
|
|
49
|
+
};
|
package/booleanUtils/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { is, toLower } from "ramda";
|
|
2
2
|
|
|
3
3
|
export const toBoolean = (value: any): boolean | undefined => {
|
|
4
|
-
if (
|
|
4
|
+
if (is(Boolean, value)) {
|
|
5
5
|
return value;
|
|
6
6
|
}
|
|
7
7
|
|
|
@@ -17,12 +17,12 @@ export const toBooleanWithDefaultTrue = toBooleanWithDefault(true);
|
|
|
17
17
|
|
|
18
18
|
export const toBooleanWithDefaultFalse = toBooleanWithDefault(false);
|
|
19
19
|
|
|
20
|
-
export const isTrue = (value:
|
|
20
|
+
export const isTrue = (value: unknown): boolean => {
|
|
21
21
|
if (value === true) {
|
|
22
22
|
return true;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
if (
|
|
25
|
+
if (is(String, value) && toLower(value) === "true") {
|
|
26
26
|
return true;
|
|
27
27
|
}
|
|
28
28
|
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "12.0.0-rc.
|
|
3
|
+
"version": "12.0.0-rc.76",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/applicaster-types": "12.0.0-rc.
|
|
31
|
+
"@applicaster/applicaster-types": "12.0.0-rc.76",
|
|
32
32
|
"buffer": "^5.2.1",
|
|
33
33
|
"camelize": "^1.0.0",
|
|
34
34
|
"create-react-context": "^0.2.3",
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { renderHook } from "@testing-library/react-hooks";
|
|
2
2
|
|
|
3
|
-
import { useFeedRefresh, feedRefreshLogger } from "../";
|
|
4
|
-
|
|
5
3
|
jest.useFakeTimers();
|
|
6
4
|
|
|
5
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation", () => ({
|
|
6
|
+
useIsScreenActive: () => true,
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
const { useFeedRefresh, feedRefreshLogger } = require("..");
|
|
10
|
+
|
|
7
11
|
describe("useFeedRefresh", () => {
|
|
8
12
|
const reloadData = jest.fn();
|
|
9
13
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import
|
|
2
|
+
import { path, max } from "ramda";
|
|
3
3
|
import { isTrue } from "@applicaster/zapp-react-native-utils/booleanUtils";
|
|
4
4
|
import { toNumberWithDefault } from "@applicaster/zapp-react-native-utils/numberUtils";
|
|
5
|
+
import { useIsScreenActive } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
|
|
5
6
|
|
|
6
7
|
import { reactHooksLogger } from "../logger";
|
|
7
8
|
import { ReloadDataFunction } from "./useFeedLoader";
|
|
@@ -18,9 +19,8 @@ const minimumRefreshingInterval = 5;
|
|
|
18
19
|
const defaultRefreshInterval = 60;
|
|
19
20
|
|
|
20
21
|
export const useFeedRefresh = ({ reloadData, component }: Props): void => {
|
|
21
|
-
const
|
|
22
|
-
["rules", "enable_data_refreshing"],
|
|
23
|
-
component
|
|
22
|
+
const isDataRefreshingEnabled = isTrue(
|
|
23
|
+
path(["rules", "enable_data_refreshing"], component)
|
|
24
24
|
);
|
|
25
25
|
|
|
26
26
|
const refreshing_interval = toNumberWithDefault(
|
|
@@ -29,10 +29,12 @@ export const useFeedRefresh = ({ reloadData, component }: Props): void => {
|
|
|
29
29
|
);
|
|
30
30
|
|
|
31
31
|
const refreshingIntervalInMilliseconds =
|
|
32
|
-
|
|
32
|
+
max(refreshing_interval, minimumRefreshingInterval) * 1000;
|
|
33
|
+
|
|
34
|
+
const isScreenActive = useIsScreenActive();
|
|
33
35
|
|
|
34
36
|
React.useEffect(() => {
|
|
35
|
-
if (
|
|
37
|
+
if (isDataRefreshingEnabled && refreshing_interval && isScreenActive) {
|
|
36
38
|
if (refreshing_interval < minimumRefreshingInterval) {
|
|
37
39
|
feedRefreshLogger.warning({
|
|
38
40
|
message: `You set your feed refresh interval to ${refreshing_interval} when minimum value is ${minimumRefreshingInterval}seconds.Your feed will refresh after ${minimumRefreshingInterval}seconds.`,
|
|
@@ -59,5 +61,5 @@ export const useFeedRefresh = ({ reloadData, component }: Props): void => {
|
|
|
59
61
|
clearInterval(refreshInterval);
|
|
60
62
|
};
|
|
61
63
|
}
|
|
62
|
-
}, [reloadData]);
|
|
64
|
+
}, [reloadData, isScreenActive]);
|
|
63
65
|
};
|
package/reactUtils/index.ts
CHANGED
|
@@ -108,3 +108,101 @@ export const isAndroidPlatform = () => Platform.OS === "android";
|
|
|
108
108
|
export const isTvOSPlatform = () => getPlatform() === "tvos";
|
|
109
109
|
|
|
110
110
|
export const isAndroidTVPlatform = () => getPlatform() === "android_tv";
|
|
111
|
+
|
|
112
|
+
declare global {
|
|
113
|
+
interface Window {
|
|
114
|
+
VIZIO?: {
|
|
115
|
+
exitApplication: () => void;
|
|
116
|
+
setClosedCaptionHandler: (
|
|
117
|
+
callback: (isCCEnabled: boolean) => void
|
|
118
|
+
) => void;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Platforms found in userAgent string, please note that simulators
|
|
125
|
+
* might not have the same agents that the devices have
|
|
126
|
+
*/
|
|
127
|
+
export const PLATFORMS = {
|
|
128
|
+
webos: "Web0S",
|
|
129
|
+
tizen: "Tizen",
|
|
130
|
+
samsung: "SMART-TV",
|
|
131
|
+
mac: "Mac",
|
|
132
|
+
win: "Win",
|
|
133
|
+
linux: "Linux",
|
|
134
|
+
iphone: "iPhone",
|
|
135
|
+
android: "Android",
|
|
136
|
+
mobile: "Mobile",
|
|
137
|
+
vizio: "VIZIO",
|
|
138
|
+
smartcast: "SmartCast",
|
|
139
|
+
conjure: "Conjure",
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Simple way of identifying if we have access to the tizen APIs
|
|
144
|
+
*/
|
|
145
|
+
export const hasTizen = typeof window?.tizen !== "undefined";
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Simple way of identifying if we have access to the webOS APIs
|
|
149
|
+
*/
|
|
150
|
+
export const hasWebOS = typeof window?.webOS !== "undefined";
|
|
151
|
+
|
|
152
|
+
export const getUserAgent = () =>
|
|
153
|
+
window?.navigator?.userAgent || global?.navigator?.userAgent;
|
|
154
|
+
|
|
155
|
+
export const isLgPlatform = () => {
|
|
156
|
+
const userAgent = getUserAgent();
|
|
157
|
+
|
|
158
|
+
if (!userAgent) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Note: LG uses the number 0 in their userAgent, possibly because of Palm WebOS
|
|
163
|
+
return hasWebOS || userAgent.includes(PLATFORMS.webos);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export const isSamsungPlatform = () => {
|
|
167
|
+
const userAgent = getUserAgent();
|
|
168
|
+
|
|
169
|
+
if (!userAgent) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
hasTizen ||
|
|
175
|
+
userAgent.includes(PLATFORMS.samsung) ||
|
|
176
|
+
userAgent.includes(PLATFORMS.tizen)
|
|
177
|
+
);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Checks if we are on the Vizio platform by using the userAgent string
|
|
182
|
+
*
|
|
183
|
+
* Use this method when you need to identify the platform on runtime
|
|
184
|
+
* before the VIZIO Companion Library has loaded
|
|
185
|
+
*/
|
|
186
|
+
export const isVizioPlatform = () => {
|
|
187
|
+
const userAgent = getUserAgent();
|
|
188
|
+
|
|
189
|
+
const isVizioAgent =
|
|
190
|
+
userAgent.includes(PLATFORMS.vizio) ||
|
|
191
|
+
userAgent.includes(PLATFORMS.smartcast) ||
|
|
192
|
+
userAgent.includes(PLATFORMS.conjure);
|
|
193
|
+
|
|
194
|
+
return isVizioAgent;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Checks if we are on the Vizio platform by checking for the global VIZIO object
|
|
199
|
+
* and the VIZIO Companion Library. This method does not use the userAgent string,
|
|
200
|
+
* because it mainly checks whether we have access to apis, which may not be available yet
|
|
201
|
+
*/
|
|
202
|
+
export const hasVizioAPIs = () => {
|
|
203
|
+
const hasAPIs =
|
|
204
|
+
typeof window.VIZIO !== "undefined" &&
|
|
205
|
+
window?.applicaster?.vizioLibraryDidLoad;
|
|
206
|
+
|
|
207
|
+
return hasAPIs;
|
|
208
|
+
};
|