@applicaster/zapp-react-native-utils 12.0.0-alpha.5040434238 → 12.0.0-alpha.5061452310
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/cellUtils/index.ts +3 -1
- package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +2 -1
- package/package.json +2 -2
- package/playerUtils/configurationGenerator.ts +3 -1
- package/reactHooks/autoscrolling/__tests__/{useTrackedView.test.ts → useTrackedView.test.tsx} +16 -1
- package/reactHooks/layout/__tests__/{index.test.js → index.test.tsx} +43 -29
- package/reactHooks/layout/getDeviceInfo/index.ts +4 -3
- package/reactHooks/layout/types/index.ts +1 -1
- package/reactHooks/layout/useDimensions/useDimensions.ts +5 -2
- package/reactHooks/navigation/index.ts +52 -18
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* global tizen */
|
|
2
2
|
const isTizen = typeof tizen !== "undefined";
|
|
3
3
|
|
|
4
|
+
import { isVizioPlatform } from "@applicaster/zapp-react-dom-app/App/Loader/utils/platform";
|
|
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 };
|
package/cellUtils/index.ts
CHANGED
|
@@ -460,7 +460,9 @@ export const getColorFromData = ({
|
|
|
460
460
|
}: GetColorFromData): string => {
|
|
461
461
|
const value = getValue(key);
|
|
462
462
|
|
|
463
|
-
|
|
463
|
+
// Temporary hack to fix color validation when alpha is floating point number
|
|
464
|
+
// https://github.com/dreamyguy/validate-color/issues/44
|
|
465
|
+
if (validateColor(value.replace(".00", ""))) {
|
|
464
466
|
return value;
|
|
465
467
|
}
|
|
466
468
|
|
|
@@ -1663,7 +1663,8 @@ function getPlayerConfiguration({ platform }) {
|
|
|
1663
1663
|
platform.includes("lg") ||
|
|
1664
1664
|
platform.includes("samsung") ||
|
|
1665
1665
|
platform.includes("android_tv") ||
|
|
1666
|
-
platform.includes("amazon")
|
|
1666
|
+
platform.includes("amazon") ||
|
|
1667
|
+
platform.includes("vizio")
|
|
1667
1668
|
) {
|
|
1668
1669
|
styles.fields.push(
|
|
1669
1670
|
// Captions Menu
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "12.0.0-alpha.
|
|
3
|
+
"version": "12.0.0-alpha.5061452310",
|
|
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-alpha.
|
|
31
|
+
"@applicaster/applicaster-types": "12.0.0-alpha.5061452310",
|
|
32
32
|
"buffer": "^5.2.1",
|
|
33
33
|
"camelize": "^1.0.0",
|
|
34
34
|
"create-react-context": "^0.2.3",
|
|
@@ -22,6 +22,7 @@ function getDevice(platform) {
|
|
|
22
22
|
case "android_tv_for_quickbrick":
|
|
23
23
|
case "lg_tv":
|
|
24
24
|
case "samsung_tv":
|
|
25
|
+
case "vizio":
|
|
25
26
|
case "web":
|
|
26
27
|
return "tv";
|
|
27
28
|
}
|
|
@@ -1659,7 +1660,8 @@ function getPlayerConfiguration({ platform }) {
|
|
|
1659
1660
|
platform.includes("lg") ||
|
|
1660
1661
|
platform.includes("samsung") ||
|
|
1661
1662
|
platform.includes("android_tv") ||
|
|
1662
|
-
platform.includes("amazon")
|
|
1663
|
+
platform.includes("amazon") ||
|
|
1664
|
+
platform.includes("vizio")
|
|
1663
1665
|
) {
|
|
1664
1666
|
styles.fields.push(
|
|
1665
1667
|
// Captions Menu for TV
|
package/reactHooks/autoscrolling/__tests__/{useTrackedView.test.ts → useTrackedView.test.tsx}
RENAMED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
1
3
|
import { act, renderHook } from "@testing-library/react-hooks";
|
|
4
|
+
import { Provider } from "react-redux";
|
|
5
|
+
import configureStore from "redux-mock-store";
|
|
2
6
|
|
|
3
7
|
const mockUpdateComponentsPositions = jest.fn();
|
|
4
8
|
|
|
@@ -19,11 +23,22 @@ jest.useFakeTimers();
|
|
|
19
23
|
|
|
20
24
|
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation");
|
|
21
25
|
|
|
26
|
+
const mockStore = configureStore();
|
|
27
|
+
|
|
28
|
+
const store = mockStore({ appData: {} });
|
|
29
|
+
|
|
30
|
+
const Wrapper = ({ children }: { children: React.ReactChild }) => (
|
|
31
|
+
/* @ts-ignore */
|
|
32
|
+
<Provider store={store}>{children}</Provider>
|
|
33
|
+
);
|
|
34
|
+
|
|
22
35
|
const { useTrackedView } = require("../useTrackedView");
|
|
23
36
|
|
|
24
37
|
describe("useTrackCurrentAutoScrollingElement", () => {
|
|
25
38
|
it("should update position for selected component", async () => {
|
|
26
|
-
const { result } = renderHook(() => useTrackedView("123")
|
|
39
|
+
const { result } = renderHook(() => useTrackedView("123"), {
|
|
40
|
+
wrapper: Wrapper,
|
|
41
|
+
});
|
|
27
42
|
|
|
28
43
|
// Fast-forward until all timers have been executed
|
|
29
44
|
jest.advanceTimersByTime(3000);
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
1
3
|
import { cleanup, renderHook } from "@testing-library/react-hooks";
|
|
4
|
+
import { Provider } from "react-redux";
|
|
5
|
+
import configureStore from "redux-mock-store";
|
|
2
6
|
|
|
3
7
|
import * as ReactNative from "react-native";
|
|
4
8
|
|
|
@@ -48,19 +52,43 @@ jest.mock("../../navigation", () => ({
|
|
|
48
52
|
}));
|
|
49
53
|
|
|
50
54
|
const { Dimensions } = require("react-native");
|
|
51
|
-
const { useDimensions } = require("
|
|
55
|
+
const { useDimensions } = require("..");
|
|
56
|
+
|
|
57
|
+
const mockStore = configureStore();
|
|
58
|
+
|
|
59
|
+
const getWrapper = () => {
|
|
60
|
+
const store = mockStore({ appData: {} });
|
|
61
|
+
|
|
62
|
+
const Wrapper = ({ children }: { children: React.ReactChild }) => (
|
|
63
|
+
/* @ts-ignore */
|
|
64
|
+
<Provider store={store}>{children}</Provider>
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
return Wrapper;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const testHook = (context, params?) => {
|
|
71
|
+
const wrapper = getWrapper();
|
|
72
|
+
|
|
73
|
+
const {
|
|
74
|
+
result,
|
|
75
|
+
result: { current: dimensions },
|
|
76
|
+
} = renderHook(() => useDimensions(context, params), {
|
|
77
|
+
wrapper,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return { result, dimensions };
|
|
81
|
+
};
|
|
52
82
|
|
|
53
83
|
describe("useDimensions", () => {
|
|
54
84
|
it("renders", () => {
|
|
55
|
-
const { result } =
|
|
56
|
-
useDimensions("window", { fullDimensions: true })
|
|
57
|
-
);
|
|
85
|
+
const { result } = testHook("window", { fullDimensions: true });
|
|
58
86
|
|
|
59
87
|
expect(result).toBeDefined();
|
|
60
88
|
});
|
|
61
89
|
|
|
62
90
|
it("sets event listener", () => {
|
|
63
|
-
|
|
91
|
+
testHook("window", { fullDimensions: true });
|
|
64
92
|
|
|
65
93
|
expect(Dimensions.addEventListener).toBeCalledWith(
|
|
66
94
|
"change",
|
|
@@ -69,16 +97,14 @@ describe("useDimensions", () => {
|
|
|
69
97
|
});
|
|
70
98
|
|
|
71
99
|
it("removes event listener", () => {
|
|
72
|
-
|
|
100
|
+
testHook("window", { fullDimensions: true });
|
|
73
101
|
cleanup();
|
|
74
102
|
|
|
75
103
|
expect(mockRemoveFn).toBeCalled();
|
|
76
104
|
});
|
|
77
105
|
|
|
78
106
|
it("Returns full dimensions object", () => {
|
|
79
|
-
const {
|
|
80
|
-
result: { current: dimensions },
|
|
81
|
-
} = renderHook(() => useDimensions("window", { fullDimensions: true }));
|
|
107
|
+
const { dimensions } = testHook("window", { fullDimensions: true });
|
|
82
108
|
|
|
83
109
|
expect(dimensions).toHaveProperty("height");
|
|
84
110
|
expect(dimensions).toHaveProperty("width");
|
|
@@ -87,20 +113,17 @@ describe("useDimensions", () => {
|
|
|
87
113
|
});
|
|
88
114
|
|
|
89
115
|
it("Returns shorthand dimensions object", () => {
|
|
90
|
-
const {
|
|
91
|
-
result: { current: dimensions },
|
|
92
|
-
} = renderHook(() => useDimensions("window"));
|
|
116
|
+
const { dimensions } = testHook("window");
|
|
93
117
|
|
|
94
118
|
expect(dimensions).toHaveProperty("height");
|
|
95
119
|
expect(dimensions).toHaveProperty("width");
|
|
96
120
|
});
|
|
97
121
|
|
|
98
122
|
it("Returns the device info object", () => {
|
|
99
|
-
const {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
);
|
|
123
|
+
const { dimensions } = testHook("window", {
|
|
124
|
+
fullDimensions: true,
|
|
125
|
+
deviceInfo: true,
|
|
126
|
+
});
|
|
104
127
|
|
|
105
128
|
expect(dimensions).toHaveProperty("height");
|
|
106
129
|
expect(dimensions).toHaveProperty("width");
|
|
@@ -113,10 +136,7 @@ describe("useDimensions", () => {
|
|
|
113
136
|
it("applies the scale on TV, and screen context", () => {
|
|
114
137
|
tv_flag = true;
|
|
115
138
|
const { screen } = mocked_return_value(tv_flag);
|
|
116
|
-
|
|
117
|
-
const {
|
|
118
|
-
result: { current: dimensions },
|
|
119
|
-
} = renderHook(() => useDimensions("screen"));
|
|
139
|
+
const { dimensions } = testHook("screen");
|
|
120
140
|
|
|
121
141
|
expect(dimensions).toHaveProperty("height", screen.height * screen.scale);
|
|
122
142
|
expect(dimensions).toHaveProperty("width", screen.width * screen.scale);
|
|
@@ -128,10 +148,7 @@ describe("useDimensions", () => {
|
|
|
128
148
|
it("doesn't apply the scale on mobile with screen context", () => {
|
|
129
149
|
tv_flag = false;
|
|
130
150
|
const { screen } = mocked_return_value(tv_flag);
|
|
131
|
-
|
|
132
|
-
const {
|
|
133
|
-
result: { current: dimensions },
|
|
134
|
-
} = renderHook(() => useDimensions("screen"));
|
|
151
|
+
const { dimensions } = testHook("screen");
|
|
135
152
|
|
|
136
153
|
expect(dimensions).toHaveProperty("height", screen.height);
|
|
137
154
|
expect(dimensions).toHaveProperty("width", screen.width);
|
|
@@ -141,10 +158,7 @@ describe("useDimensions", () => {
|
|
|
141
158
|
it("doesn't apply the scale on TV with window context", () => {
|
|
142
159
|
tv_flag = true;
|
|
143
160
|
const { window } = mocked_return_value(tv_flag);
|
|
144
|
-
|
|
145
|
-
const {
|
|
146
|
-
result: { current: dimensions },
|
|
147
|
-
} = renderHook(() => useDimensions("window"));
|
|
161
|
+
const { dimensions } = testHook("window");
|
|
148
162
|
|
|
149
163
|
expect(dimensions).toHaveProperty("height", window.height);
|
|
150
164
|
expect(dimensions).toHaveProperty("width", window.width);
|
|
@@ -3,14 +3,15 @@ import { isTablet } from "../isTablet";
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns an object with additional device info that can be used to determine if tablet
|
|
5
5
|
* @param {Number} dimensions - Dimensions object passed to the function
|
|
6
|
+
* @param {Object} appData - application data object passed to the function
|
|
6
7
|
* @returns {DeviceInfo} deviceInfo - returns an object with scale, isTablet, and orientation
|
|
7
8
|
*/
|
|
8
|
-
export const getDeviceInfo = (dimensions) => {
|
|
9
|
+
export const getDeviceInfo = (dimensions, appData) => {
|
|
9
10
|
const scale = dimensions?.scale;
|
|
10
11
|
const isLandscape = dimensions?.width > dimensions?.height;
|
|
11
12
|
const orientation = isLandscape ? "landscape" : "portrait";
|
|
12
13
|
const tablet = isTablet(dimensions, orientation) || false;
|
|
13
|
-
const
|
|
14
|
+
const isTabletLandscape = tablet && !appData?.isTabletPortrait;
|
|
14
15
|
|
|
15
|
-
return { scale, isTablet: tablet, orientation,
|
|
16
|
+
return { scale, isTablet: tablet, orientation, isTabletLandscape };
|
|
16
17
|
};
|
|
@@ -3,6 +3,8 @@ import { useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
|
3
3
|
import * as R from "ramda";
|
|
4
4
|
|
|
5
5
|
import { Dimensions, Platform, StatusBar } from "react-native";
|
|
6
|
+
import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
|
|
7
|
+
|
|
6
8
|
import { isTV } from "../../../reactUtils";
|
|
7
9
|
|
|
8
10
|
import { Options, UseDimensions } from "../types";
|
|
@@ -36,6 +38,7 @@ export const useDimensions: UseDimensions = (
|
|
|
36
38
|
fullDimensions = { fullDimensions: false, updateForInactiveScreens: true }
|
|
37
39
|
) => {
|
|
38
40
|
const isActive = useIsScreenActive();
|
|
41
|
+
const { appData } = usePickFromState(["appData"]);
|
|
39
42
|
|
|
40
43
|
if (typeof fullDimensions === "boolean") {
|
|
41
44
|
// eslint-disable-next-line no-console
|
|
@@ -50,7 +53,7 @@ export const useDimensions: UseDimensions = (
|
|
|
50
53
|
: { ...fullDimensions };
|
|
51
54
|
|
|
52
55
|
const [dimensions, setDimensions] = useState(getInitialDimensions(context));
|
|
53
|
-
const deviceInfo = useRef(getDeviceInfo(dimensions));
|
|
56
|
+
const deviceInfo = useRef(getDeviceInfo(dimensions, appData));
|
|
54
57
|
|
|
55
58
|
const applyOptions = R.compose(
|
|
56
59
|
R.when(() => options.deviceInfo, R.assoc("deviceInfo", deviceInfo.current)),
|
|
@@ -85,7 +88,7 @@ export const useDimensions: UseDimensions = (
|
|
|
85
88
|
// eslint-disable-next-line no-console
|
|
86
89
|
console.log("change: wrong values - width equal to height, ignoring");
|
|
87
90
|
} else if (isActive || options.updateForInactiveScreens) {
|
|
88
|
-
deviceInfo.current = getDeviceInfo(newDimensions);
|
|
91
|
+
deviceInfo.current = getDeviceInfo(newDimensions, appData);
|
|
89
92
|
setDimensions(newDimensions);
|
|
90
93
|
}
|
|
91
94
|
};
|
|
@@ -146,6 +146,15 @@ export const useRoute = (): {
|
|
|
146
146
|
pathname: string;
|
|
147
147
|
} => {
|
|
148
148
|
const pathname = usePathname() || "";
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* compose `useRoute()` output data
|
|
152
|
+
*/
|
|
153
|
+
const composeRouteData = (screenData: VariousScreenData) => ({
|
|
154
|
+
screenData,
|
|
155
|
+
pathname,
|
|
156
|
+
});
|
|
157
|
+
|
|
149
158
|
const navigator = useNavigation();
|
|
150
159
|
|
|
151
160
|
const { plugins, contentTypes, rivers } = usePickFromState([
|
|
@@ -157,9 +166,7 @@ export const useRoute = (): {
|
|
|
157
166
|
const currentStack = navigator.getStackForPathname(pathname);
|
|
158
167
|
const { modalState } = useModalStore();
|
|
159
168
|
const hookModalState = useZappHooksModalState();
|
|
160
|
-
|
|
161
169
|
const modalScreenData = modalState.screen;
|
|
162
|
-
|
|
163
170
|
const hookModalScreenData = hookModalState.state.screenData?.payload;
|
|
164
171
|
|
|
165
172
|
const videoModalScreenData =
|
|
@@ -193,36 +200,63 @@ export const useRoute = (): {
|
|
|
193
200
|
// if path is hook grab screenData from screenData
|
|
194
201
|
|
|
195
202
|
if (isModalPathname(pathname)) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
return { screenData, pathname };
|
|
203
|
+
return composeRouteData(modalScreenData ?? ({} as ZappEntry));
|
|
199
204
|
}
|
|
200
205
|
|
|
201
206
|
if (isVideoModalPathname(pathname)) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return { screenData, pathname };
|
|
207
|
+
return composeRouteData(videoModalScreenData as LegacyNavigationScreenData);
|
|
205
208
|
}
|
|
206
209
|
|
|
207
210
|
if (isHookModalPathname(pathname)) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
return { screenData, pathname };
|
|
211
|
+
return composeRouteData(hookModalScreenData);
|
|
211
212
|
}
|
|
212
213
|
|
|
213
214
|
if (isHookPathname(pathname)) {
|
|
214
|
-
|
|
215
|
+
/**
|
|
216
|
+
* HACK
|
|
217
|
+
*
|
|
218
|
+
* This condition relies on hacky approach to get the current hook screen data
|
|
219
|
+
* using navigator.screenData for some cases.
|
|
220
|
+
* This is used when hook is in sequence.
|
|
221
|
+
*/
|
|
222
|
+
|
|
223
|
+
// case 1: stack not yet updated in navigator context, but navigator.screenData is updated already.
|
|
224
|
+
if (!currentStack) {
|
|
225
|
+
return composeRouteData(navigator.screenData);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const isValidHookInCurrentRouteScreenData =
|
|
215
229
|
"hookPlugin" in currentRouteScreenData &&
|
|
216
|
-
currentRouteScreenData.hookPlugin
|
|
217
|
-
|
|
218
|
-
|
|
230
|
+
!!currentRouteScreenData.hookPlugin?.module;
|
|
231
|
+
|
|
232
|
+
let screenData;
|
|
233
|
+
|
|
234
|
+
// case 2: stack has valid hook data
|
|
235
|
+
if (isValidHookInCurrentRouteScreenData) {
|
|
236
|
+
screenData = currentRouteScreenData;
|
|
237
|
+
}
|
|
219
238
|
|
|
220
|
-
|
|
239
|
+
const navigatorScreenData = navigator.screenData as NavigatorEntry;
|
|
240
|
+
|
|
241
|
+
// case 3: current hookPlugin is missing weight, but navigator.screenData has weight, use navigator.screenData
|
|
242
|
+
if (
|
|
243
|
+
screenData.hookPlugin.identifier ===
|
|
244
|
+
navigatorScreenData?.hookPlugin?.identifier &&
|
|
245
|
+
!screenData.hookPlugin?.weight &&
|
|
246
|
+
navigatorScreenData?.hookPlugin?.weight
|
|
247
|
+
) {
|
|
248
|
+
screenData = navigator.screenData;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return composeRouteData(screenData);
|
|
221
252
|
}
|
|
222
253
|
|
|
223
|
-
|
|
254
|
+
// case 1: stack not yet updated in navigator context, but navigator.screenData is updated already.
|
|
255
|
+
if (!currentStack) {
|
|
256
|
+
return composeRouteData(navigator.screenData);
|
|
257
|
+
}
|
|
224
258
|
|
|
225
|
-
return
|
|
259
|
+
return composeRouteData(currentRouteScreenData);
|
|
226
260
|
};
|
|
227
261
|
|
|
228
262
|
type Callbacks = Partial<{
|