@applicaster/zapp-react-native-ui-components 16.0.0-rc.2 → 16.0.0-rc.20
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/Components/BackgroundImage/BackgroundImage.tsx +42 -0
- package/Components/BackgroundImage/BackgroundImage.tv.android.tsx +28 -0
- package/Components/BackgroundImage/BackgroundImage.tv.ios.tsx +24 -0
- package/Components/BackgroundImage/index.ts +1 -0
- package/Components/CellRendererResolver/index.ts +1 -1
- package/Components/ComponentResolver/__tests__/componentResolver.test.js +1 -1
- package/Components/FocusableGroup/FocusableTvOS.tsx +11 -7
- package/Components/GeneralContentScreen/GeneralContentScreenHookAdapter.tsx +39 -0
- package/Components/GeneralContentScreen/__tests__/GeneralContentScreenHookAdapter.test.tsx +64 -0
- package/Components/GeneralContentScreen/__tests__/HookContentFocusGroup.web.test.tsx +91 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/networkService.test.ts +74 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/runInBackground.test.ts +139 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/validationHelper.test.ts +124 -0
- package/Components/GeneralContentScreen/hookAdapter/logger.ts +6 -0
- package/Components/GeneralContentScreen/hookAdapter/networkService.ts +53 -0
- package/Components/GeneralContentScreen/hookAdapter/runInBackground.ts +48 -0
- package/Components/GeneralContentScreen/hookAdapter/validationHelper.ts +72 -0
- package/Components/GeneralContentScreen/hookFocus/index.tsx +13 -0
- package/Components/GeneralContentScreen/hookFocus/index.web.tsx +69 -0
- package/Components/GeneralContentScreen/index.ts +2 -0
- package/Components/Layout/TV/ScreenContainer.tsx +5 -0
- package/Components/Layout/TV/__tests__/__snapshots__/index.test.tsx.snap +0 -1
- package/Components/Layout/TV/index.tsx +3 -4
- package/Components/Layout/TV/index.web.tsx +2 -3
- package/Components/MasterCell/DefaultComponents/ActionButton.tsx +16 -5
- package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.tsx +1 -1
- package/Components/PlayerContainer/PlayerContainer.tsx +7 -7
- package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +284 -0
- package/Components/Screen/TV/hooks/__tests__/useAfterPaint.test.ts +60 -0
- package/Components/Screen/TV/hooks/index.ts +2 -0
- package/Components/Screen/TV/hooks/useAfterPaint.ts +23 -0
- package/Components/Screen/TV/index.web.tsx +16 -7
- package/Components/ScreenRevealManager/Overlay.tsx +34 -0
- package/Components/ScreenRevealManager/__tests__/Overlay.test.tsx +88 -0
- package/Components/ScreenRevealManager/withScreenRevealManager.tsx +8 -19
- package/Components/VideoLive/LiveImageManager.ts +56 -45
- package/Components/VideoLive/PlayerLiveImageComponent.tsx +4 -2
- package/Components/VideoModal/utils.ts +6 -1
- package/Helpers/ComponentCellSelectionHelper/index.js +0 -6
- package/Helpers/index.js +7 -40
- package/package.json +5 -5
- package/Components/Layout/TV/LayoutBackground.tsx +0 -31
- package/Helpers/Analytics/index.js +0 -95
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { render } from "@testing-library/react-native";
|
|
3
|
+
|
|
4
|
+
jest.mock(
|
|
5
|
+
"@applicaster/zapp-react-native-utils/appUtils/playerManager",
|
|
6
|
+
() => ({
|
|
7
|
+
playerManager: {
|
|
8
|
+
invokeHandler: jest.fn(),
|
|
9
|
+
getPluginConfiguration: jest.fn(() => ({})),
|
|
10
|
+
isRegistered: jest.fn(() => true),
|
|
11
|
+
on: jest.fn().mockReturnThis(),
|
|
12
|
+
removeHandler: jest.fn().mockReturnThis(),
|
|
13
|
+
getActivePlayer: jest.fn(() => null),
|
|
14
|
+
closeNativePlayer: jest.fn(),
|
|
15
|
+
},
|
|
16
|
+
})
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactUtils", () => ({
|
|
20
|
+
isTV: jest.fn(() => false),
|
|
21
|
+
isAndroidTVPlatform: jest.fn(() => false),
|
|
22
|
+
isTvOSPlatform: jest.fn(() => false),
|
|
23
|
+
platformSelect: jest.fn(({ native }) => native),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
jest.mock("@applicaster/zapp-react-native-utils/playerUtils", () => ({
|
|
27
|
+
isAudioItem: jest.fn(() => false),
|
|
28
|
+
isInlineTV: jest.fn(() => false),
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
jest.mock(
|
|
32
|
+
"@applicaster/zapp-react-native-tvos-ui-components/Components/TVEventHandlerComponent",
|
|
33
|
+
() => ({
|
|
34
|
+
TVEventHandlerComponent: ({ children }) => children,
|
|
35
|
+
})
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/utils", () => ({
|
|
39
|
+
usePrevious: jest.fn(),
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks", () => {
|
|
43
|
+
const navigator = {
|
|
44
|
+
closeVideoModal: jest.fn(),
|
|
45
|
+
minimiseVideoModal: jest.fn(),
|
|
46
|
+
maximiseVideoModal: jest.fn(),
|
|
47
|
+
fullscreenVideoModal: jest.fn(),
|
|
48
|
+
isVideoModalDocked: jest.fn(() => false),
|
|
49
|
+
goBack: jest.fn(),
|
|
50
|
+
replaceTop: jest.fn(),
|
|
51
|
+
push: jest.fn(),
|
|
52
|
+
setPlayNextOverlay: jest.fn(),
|
|
53
|
+
currentRoute: "/playable/entry-1",
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const backHandlerRef: { current: (() => boolean) | null } = {
|
|
57
|
+
current: null,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
useBackHandler: jest.fn((cb) => {
|
|
62
|
+
backHandlerRef.current = cb;
|
|
63
|
+
}),
|
|
64
|
+
useNavigation: jest.fn(() => navigator),
|
|
65
|
+
__navigator: navigator,
|
|
66
|
+
__backHandlerRef: backHandlerRef,
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
jest.mock("@applicaster/zapp-react-native-bridge/QuickBrick", () => ({
|
|
71
|
+
QUICK_BRICK_EVENTS: {
|
|
72
|
+
IDLE_TIMER_DISABLED: "IDLE_TIMER_DISABLED",
|
|
73
|
+
MOVE_APP_TO_BACKGROUND: "MOVE_APP_TO_BACKGROUND",
|
|
74
|
+
},
|
|
75
|
+
sendQuickBrickEvent: jest.fn(),
|
|
76
|
+
}));
|
|
77
|
+
|
|
78
|
+
jest.mock("../ProgramInfo", () => ({
|
|
79
|
+
ProgramInfo: () => null,
|
|
80
|
+
}));
|
|
81
|
+
|
|
82
|
+
jest.mock("../../AudioPlayer", () => ({
|
|
83
|
+
AudioPlayer: () => null,
|
|
84
|
+
}));
|
|
85
|
+
|
|
86
|
+
jest.mock("../logger", () => ({
|
|
87
|
+
log_debug: jest.fn(),
|
|
88
|
+
log_info: jest.fn(),
|
|
89
|
+
log_warning: jest.fn(),
|
|
90
|
+
playerContainerLogger: { error: jest.fn() },
|
|
91
|
+
}));
|
|
92
|
+
|
|
93
|
+
jest.mock(
|
|
94
|
+
"@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayer",
|
|
95
|
+
() => {
|
|
96
|
+
const player = {
|
|
97
|
+
addListener: jest.fn(),
|
|
98
|
+
removeListener: jest.fn(),
|
|
99
|
+
isPaused: jest.fn(() => false),
|
|
100
|
+
isAd: jest.fn(() => false),
|
|
101
|
+
seekTo: jest.fn(),
|
|
102
|
+
getPluginConfiguration: jest.fn(() => ({})),
|
|
103
|
+
getOverlayObservable: jest.fn(() => ({ getPlayNextEntry: () => null })),
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
usePlayer: jest.fn(() => player),
|
|
108
|
+
__player: player,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
jest.mock(
|
|
114
|
+
"@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayNextOverlay",
|
|
115
|
+
() => ({
|
|
116
|
+
usePlayNextOverlay: jest.fn(() => null),
|
|
117
|
+
})
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
jest.mock(
|
|
121
|
+
"@applicaster/zapp-react-native-utils/appUtils/playerManager/playerNativeCommand",
|
|
122
|
+
() => ({
|
|
123
|
+
PlayerNativeCommandTypes: { clearPlayerData: "clearPlayerData" },
|
|
124
|
+
PlayerNativeSendCommand: jest.fn(),
|
|
125
|
+
})
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
jest.mock(
|
|
129
|
+
"@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext",
|
|
130
|
+
() => ({
|
|
131
|
+
useSetNavbarState: jest.fn(() => ({ setVisible: jest.fn() })),
|
|
132
|
+
})
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
jest.mock(
|
|
136
|
+
"@applicaster/zapp-react-native-utils/reactHooks/screen/useTargetScreenData",
|
|
137
|
+
() => ({
|
|
138
|
+
useTargetScreenData: jest.fn(() => ({ id: "screen-id", styles: {} })),
|
|
139
|
+
})
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
jest.mock("../PlayerContainerContext", () => {
|
|
143
|
+
const ReactActual = require("react");
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
PlayerContainerContext: ReactActual.createContext({
|
|
147
|
+
isLanguageOverlayVisible: false,
|
|
148
|
+
bottomFocusableId: "bottom",
|
|
149
|
+
showComponentsContainer: false,
|
|
150
|
+
refs: null,
|
|
151
|
+
}),
|
|
152
|
+
PlayerContainerContextProvider: ({ children }) => children,
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
jest.mock(
|
|
157
|
+
"@applicaster/zapp-react-native-ui-components/Components/FocusableGroup",
|
|
158
|
+
() => ({
|
|
159
|
+
FocusableGroup: ({ children }) => children,
|
|
160
|
+
})
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
jest.mock("../WappersView/PlayerFocusableWrapperView", () => ({
|
|
164
|
+
PlayerFocusableWrapperView: ({ children }) => children,
|
|
165
|
+
}));
|
|
166
|
+
|
|
167
|
+
jest.mock("../WappersView/ComponentFocusableWrapperView", () => ({
|
|
168
|
+
ComponentFocusableWrapperView: () => null,
|
|
169
|
+
}));
|
|
170
|
+
|
|
171
|
+
jest.mock("../index", () => ({
|
|
172
|
+
FocusableGroupMainContainerId: "player-container-general",
|
|
173
|
+
}));
|
|
174
|
+
|
|
175
|
+
jest.mock(
|
|
176
|
+
"@applicaster/zapp-react-native-utils/navigationUtils/itemTypeMatchers",
|
|
177
|
+
() => ({
|
|
178
|
+
isPlayable: jest.fn(() => true),
|
|
179
|
+
})
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
jest.mock("../../GeneralContentScreen", () => ({
|
|
183
|
+
GeneralContentScreen: () => null,
|
|
184
|
+
}));
|
|
185
|
+
|
|
186
|
+
jest.mock("@applicaster/zapp-react-native-redux", () => ({
|
|
187
|
+
useAppData: jest.fn(() => ({ isTabletPortrait: false })),
|
|
188
|
+
}));
|
|
189
|
+
|
|
190
|
+
import { PlayerContainer, VideoModalMode } from "../PlayerContainer";
|
|
191
|
+
|
|
192
|
+
const { __navigator: mockNavigator, __backHandlerRef: mockBackHandlerRef } =
|
|
193
|
+
jest.requireMock("@applicaster/zapp-react-native-utils/reactHooks");
|
|
194
|
+
|
|
195
|
+
const { playerManager: mockPlayerManager } = jest.requireMock(
|
|
196
|
+
"@applicaster/zapp-react-native-utils/appUtils/playerManager"
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
const { __player: mockPlayer } = jest.requireMock(
|
|
200
|
+
"@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayer"
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
const Player = React.forwardRef(() => null);
|
|
204
|
+
|
|
205
|
+
const item = {
|
|
206
|
+
id: "entry-1",
|
|
207
|
+
title: "Test entry",
|
|
208
|
+
summary: "",
|
|
209
|
+
content: { src: "https://example.com/video.m3u8" },
|
|
210
|
+
extensions: {},
|
|
211
|
+
} as any;
|
|
212
|
+
|
|
213
|
+
const renderPlayerContainer = (props = {}) =>
|
|
214
|
+
render(
|
|
215
|
+
<PlayerContainer
|
|
216
|
+
Player={Player}
|
|
217
|
+
item={item}
|
|
218
|
+
style={{}}
|
|
219
|
+
loadPipesData={jest.fn()}
|
|
220
|
+
isModal={true}
|
|
221
|
+
mode={VideoModalMode.MAXIMIZED}
|
|
222
|
+
{...props}
|
|
223
|
+
/>
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
const pressHardwareBack = () => {
|
|
227
|
+
if (!mockBackHandlerRef.current) {
|
|
228
|
+
throw new Error("back handler was not registered via useBackHandler");
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return mockBackHandlerRef.current();
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
describe("PlayerContainer hardware back handling", () => {
|
|
235
|
+
beforeEach(() => {
|
|
236
|
+
jest.clearAllMocks();
|
|
237
|
+
mockBackHandlerRef.current = null;
|
|
238
|
+
mockPlayer.getPluginConfiguration.mockReturnValue({});
|
|
239
|
+
mockPlayer.isPaused.mockReturnValue(false);
|
|
240
|
+
mockPlayer.isAd.mockReturnValue(false);
|
|
241
|
+
|
|
242
|
+
mockPlayer.getOverlayObservable.mockReturnValue({
|
|
243
|
+
getPlayNextEntry: () => null,
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
mockPlayerManager.getPluginConfiguration.mockReturnValue({});
|
|
247
|
+
mockPlayerManager.on.mockReturnThis();
|
|
248
|
+
mockPlayerManager.removeHandler.mockReturnThis();
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it("minimises the video modal on back press when mini player is enabled", () => {
|
|
252
|
+
renderPlayerContainer();
|
|
253
|
+
|
|
254
|
+
const handled = pressHardwareBack();
|
|
255
|
+
|
|
256
|
+
expect(mockNavigator.minimiseVideoModal).toHaveBeenCalled();
|
|
257
|
+
expect(mockNavigator.closeVideoModal).not.toHaveBeenCalled();
|
|
258
|
+
expect(handled).toBe(true);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("closes the video modal on back press when mini player is disabled", () => {
|
|
262
|
+
mockPlayer.getPluginConfiguration.mockReturnValue({
|
|
263
|
+
disable_mini_player_when_inline: true,
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
renderPlayerContainer();
|
|
267
|
+
|
|
268
|
+
const handled = pressHardwareBack();
|
|
269
|
+
|
|
270
|
+
expect(mockNavigator.closeVideoModal).toHaveBeenCalled();
|
|
271
|
+
expect(mockNavigator.minimiseVideoModal).not.toHaveBeenCalled();
|
|
272
|
+
expect(handled).toBe(true);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("does not handle back press when the player is already minimised", () => {
|
|
276
|
+
renderPlayerContainer({ mode: VideoModalMode.MINIMIZED });
|
|
277
|
+
|
|
278
|
+
const handled = pressHardwareBack();
|
|
279
|
+
|
|
280
|
+
expect(handled).toBe(false);
|
|
281
|
+
expect(mockNavigator.minimiseVideoModal).not.toHaveBeenCalled();
|
|
282
|
+
expect(mockNavigator.closeVideoModal).not.toHaveBeenCalled();
|
|
283
|
+
});
|
|
284
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { renderHook, act } from "@testing-library/react-native";
|
|
2
|
+
|
|
3
|
+
import { useAfterPaint } from "../useAfterPaint";
|
|
4
|
+
|
|
5
|
+
describe("useAfterPaint", () => {
|
|
6
|
+
let frameCallbacks: FrameRequestCallback[];
|
|
7
|
+
let originalRaf: typeof requestAnimationFrame;
|
|
8
|
+
let originalCancelRaf: typeof cancelAnimationFrame;
|
|
9
|
+
|
|
10
|
+
const flushFrame = () => {
|
|
11
|
+
const callbacks = frameCallbacks;
|
|
12
|
+
frameCallbacks = [];
|
|
13
|
+
|
|
14
|
+
act(() => {
|
|
15
|
+
callbacks.forEach((cb) => cb(0));
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
frameCallbacks = [];
|
|
21
|
+
originalRaf = global.requestAnimationFrame;
|
|
22
|
+
originalCancelRaf = global.cancelAnimationFrame;
|
|
23
|
+
|
|
24
|
+
global.requestAnimationFrame = jest.fn((cb: FrameRequestCallback) => {
|
|
25
|
+
frameCallbacks.push(cb);
|
|
26
|
+
|
|
27
|
+
return frameCallbacks.length;
|
|
28
|
+
}) as unknown as typeof requestAnimationFrame;
|
|
29
|
+
|
|
30
|
+
global.cancelAnimationFrame = jest.fn();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
global.requestAnimationFrame = originalRaf;
|
|
35
|
+
global.cancelAnimationFrame = originalCancelRaf;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("returns false on the initial render", () => {
|
|
39
|
+
const { result } = renderHook(() => useAfterPaint());
|
|
40
|
+
|
|
41
|
+
expect(result.current).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("stays false after only one animation frame (before paint completes)", () => {
|
|
45
|
+
const { result } = renderHook(() => useAfterPaint());
|
|
46
|
+
|
|
47
|
+
flushFrame();
|
|
48
|
+
|
|
49
|
+
expect(result.current).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("returns true after two animation frames (a real post-paint boundary)", () => {
|
|
53
|
+
const { result } = renderHook(() => useAfterPaint());
|
|
54
|
+
|
|
55
|
+
flushFrame();
|
|
56
|
+
flushFrame();
|
|
57
|
+
|
|
58
|
+
expect(result.current).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
export const useAfterPaint = (): boolean => {
|
|
4
|
+
const [painted, setPainted] = React.useState(false);
|
|
5
|
+
|
|
6
|
+
React.useEffect(() => {
|
|
7
|
+
let secondFrame: number | undefined;
|
|
8
|
+
|
|
9
|
+
const firstFrame = requestAnimationFrame(() => {
|
|
10
|
+
secondFrame = requestAnimationFrame(() => setPainted(true));
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
return () => {
|
|
14
|
+
cancelAnimationFrame(firstFrame);
|
|
15
|
+
|
|
16
|
+
if (secondFrame !== undefined) {
|
|
17
|
+
cancelAnimationFrame(secondFrame);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}, []);
|
|
21
|
+
|
|
22
|
+
return painted;
|
|
23
|
+
};
|
|
@@ -21,7 +21,7 @@ import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/he
|
|
|
21
21
|
|
|
22
22
|
import { NavBarContainer } from "../../Layout/TV/NavBarContainer";
|
|
23
23
|
import { ScreenResolver } from "../../ScreenResolver";
|
|
24
|
-
import { useInitialFocus } from "./hooks";
|
|
24
|
+
import { useInitialFocus, useAfterPaint } from "./hooks";
|
|
25
25
|
import { isPlayerPlugin } from "@applicaster/zapp-react-native-utils/pluginUtils";
|
|
26
26
|
import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils";
|
|
27
27
|
import { FreezeWithCallback } from "../../FreezeWithCallback";
|
|
@@ -157,6 +157,13 @@ export const Screen = ({ route, Components }: Props) => {
|
|
|
157
157
|
|
|
158
158
|
const isScreenActive = useIsScreenActive();
|
|
159
159
|
|
|
160
|
+
// We need to render menu first and then proceed with screen content,
|
|
161
|
+
// otherwise screen will stay black until everything is loaded and screen
|
|
162
|
+
// rendering put huge load the CPU pushing rendering even further.
|
|
163
|
+
// With this approach, menu will be rendered immediately and screen content
|
|
164
|
+
// will be rendered after paint, which makes it more responsive and prevents black screen.
|
|
165
|
+
const isContentReady = useAfterPaint();
|
|
166
|
+
|
|
160
167
|
return (
|
|
161
168
|
<FreezeWithCallback freeze={!isScreenActive} onRelease={onRelease}>
|
|
162
169
|
<View style={[styles.container, { backgroundColor }]}>
|
|
@@ -167,12 +174,14 @@ export const Screen = ({ route, Components }: Props) => {
|
|
|
167
174
|
navigationProps={navigationProps}
|
|
168
175
|
/>
|
|
169
176
|
</NavBarContainer>
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
177
|
+
{isContentReady ? (
|
|
178
|
+
<ScreenResolver
|
|
179
|
+
screenType={screenType}
|
|
180
|
+
screenId={screenId}
|
|
181
|
+
screenData={screenData}
|
|
182
|
+
groupId={route}
|
|
183
|
+
/>
|
|
184
|
+
) : null}
|
|
176
185
|
</View>
|
|
177
186
|
</FreezeWithCallback>
|
|
178
187
|
);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Animated, StyleSheet } from "react-native";
|
|
3
|
+
|
|
4
|
+
import { BackgroundImage } from "@applicaster/zapp-react-native-ui-components/Components/BackgroundImage";
|
|
5
|
+
|
|
6
|
+
const styles = StyleSheet.create({
|
|
7
|
+
container: {
|
|
8
|
+
...StyleSheet.absoluteFillObject,
|
|
9
|
+
position: "absolute",
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export const Overlay = ({
|
|
14
|
+
opacity,
|
|
15
|
+
backgroundColor,
|
|
16
|
+
}: {
|
|
17
|
+
opacity: Animated.Value;
|
|
18
|
+
backgroundColor: string;
|
|
19
|
+
}) => {
|
|
20
|
+
return (
|
|
21
|
+
<Animated.View
|
|
22
|
+
style={[
|
|
23
|
+
styles.container,
|
|
24
|
+
{
|
|
25
|
+
opacity,
|
|
26
|
+
backgroundColor,
|
|
27
|
+
},
|
|
28
|
+
]}
|
|
29
|
+
testID="animated-component"
|
|
30
|
+
>
|
|
31
|
+
<BackgroundImage />
|
|
32
|
+
</Animated.View>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Animated } from "react-native";
|
|
3
|
+
import { render } from "@testing-library/react-native";
|
|
4
|
+
|
|
5
|
+
jest.mock(
|
|
6
|
+
"@applicaster/zapp-react-native-ui-components/Components/BackgroundImage",
|
|
7
|
+
() => {
|
|
8
|
+
const { Text } = require("react-native");
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
BackgroundImage: () => (
|
|
12
|
+
<Text testID="background-image">BackgroundImage</Text>
|
|
13
|
+
),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
import { Overlay } from "../Overlay";
|
|
19
|
+
|
|
20
|
+
const flattenStyle = (style: unknown): Record<string, unknown> => {
|
|
21
|
+
if (!style) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (Array.isArray(style)) {
|
|
26
|
+
return style.reduce<Record<string, unknown>>(
|
|
27
|
+
(acc, item) => ({ ...acc, ...flattenStyle(item) }),
|
|
28
|
+
{}
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (typeof style === "object") {
|
|
33
|
+
return style as Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return {};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
describe("Overlay", () => {
|
|
40
|
+
it("renders the animated overlay container", () => {
|
|
41
|
+
const opacity = new Animated.Value(1);
|
|
42
|
+
|
|
43
|
+
const { getByTestId } = render(
|
|
44
|
+
<Overlay opacity={opacity} backgroundColor="#000000" />
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
expect(getByTestId("animated-component")).toBeTruthy();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("applies opacity and backgroundColor to the overlay", () => {
|
|
51
|
+
const opacity = new Animated.Value(0.5);
|
|
52
|
+
|
|
53
|
+
const { getByTestId } = render(
|
|
54
|
+
<Overlay opacity={opacity} backgroundColor="#ff0000" />
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const style = flattenStyle(getByTestId("animated-component").props.style);
|
|
58
|
+
|
|
59
|
+
expect(style.backgroundColor).toBe("#ff0000");
|
|
60
|
+
expect(style.opacity).toBe(0.5);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("positions the overlay with absolute fill layout", () => {
|
|
64
|
+
const opacity = new Animated.Value(1);
|
|
65
|
+
|
|
66
|
+
const { getByTestId } = render(
|
|
67
|
+
<Overlay opacity={opacity} backgroundColor="#000000" />
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const style = flattenStyle(getByTestId("animated-component").props.style);
|
|
71
|
+
|
|
72
|
+
expect(style.position).toBe("absolute");
|
|
73
|
+
expect(style.top).toBe(0);
|
|
74
|
+
expect(style.left).toBe(0);
|
|
75
|
+
expect(style.right).toBe(0);
|
|
76
|
+
expect(style.bottom).toBe(0);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("renders BackgroundImage inside the overlay", () => {
|
|
80
|
+
const opacity = new Animated.Value(1);
|
|
81
|
+
|
|
82
|
+
const { getByTestId } = render(
|
|
83
|
+
<Overlay opacity={opacity} backgroundColor="#000000" />
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
expect(getByTestId("background-image")).toBeTruthy();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { Animated
|
|
2
|
+
import { Animated } from "react-native";
|
|
3
|
+
|
|
3
4
|
import { isFirstComponentScreenPicker } from "@applicaster/zapp-react-native-utils/componentsUtils";
|
|
4
5
|
import { useRefWithInitialValue } from "@applicaster/zapp-react-native-utils/reactHooks/state/useRefWithInitialValue";
|
|
5
6
|
import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
|
|
7
|
+
import { Overlay } from "./Overlay";
|
|
6
8
|
|
|
7
9
|
import { ScreenRevealManager } from "./ScreenRevealManager";
|
|
8
10
|
import {
|
|
@@ -10,13 +12,6 @@ import {
|
|
|
10
12
|
emitScreenRevealManagerIsNotReadyToShow,
|
|
11
13
|
} from "./utils";
|
|
12
14
|
|
|
13
|
-
const styles = StyleSheet.create({
|
|
14
|
-
container: {
|
|
15
|
-
...StyleSheet.absoluteFillObject,
|
|
16
|
-
position: "absolute",
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
|
|
20
15
|
export const TIMEOUT = 300; // 300 ms
|
|
21
16
|
|
|
22
17
|
const HIDDEN = 0; // opacity = 0
|
|
@@ -93,17 +88,11 @@ export const withScreenRevealManager = (Component) => {
|
|
|
93
88
|
onLoadFailedFromScreenRevealManager={managerRef.current.onLoadFailed}
|
|
94
89
|
/>
|
|
95
90
|
{isShowOverlay ? (
|
|
96
|
-
<
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
// TODO: we should support background image as well, but for now we will use background color from theme
|
|
102
|
-
backgroundColor:
|
|
103
|
-
props.backgroundColor ?? theme.app_background_color,
|
|
104
|
-
},
|
|
105
|
-
]}
|
|
106
|
-
testID="animated-component"
|
|
91
|
+
<Overlay
|
|
92
|
+
opacity={opacityRef.current}
|
|
93
|
+
backgroundColor={
|
|
94
|
+
props.backgroundColor ?? theme.app_background_color
|
|
95
|
+
}
|
|
107
96
|
/>
|
|
108
97
|
) : null}
|
|
109
98
|
</>
|