@applicaster/zapp-react-native-ui-components 12.0.0-rc.99 → 13.0.0-alpha.2322412833
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/Cell/Cell.tsx +33 -18
- package/Components/Cell/CellWithFocusable.tsx +1 -1
- package/Components/Cell/TvOSCellComponent.tsx +3 -4
- package/Components/Focusable/__tests__/index.android.test.tsx +72 -0
- package/Components/Focusable/index.android.tsx +15 -9
- package/Components/FocusableList/FocusableChild.ts +2 -2
- package/Components/FocusableList/index.tsx +11 -12
- package/Components/FocusableScrollView/index.tsx +1 -1
- package/Components/FreezeWithCallback/Freeze.tsx +31 -0
- package/Components/FreezeWithCallback/LICENSE +21 -0
- package/Components/FreezeWithCallback/Suspender.tsx +17 -0
- package/Components/FreezeWithCallback/__tests__/index.test.tsx +170 -0
- package/Components/FreezeWithCallback/index.tsx +3 -0
- package/Components/Image/Image.android.tsx +1 -1
- package/Components/MasterCell/DefaultComponents/ActionButton.tsx +11 -7
- package/Components/MasterCell/DefaultComponents/BorderContainerView/index.tsx +1 -7
- package/Components/MasterCell/DefaultComponents/CellBadge/index.tsx +6 -1
- package/Components/MasterCell/DefaultComponents/FocusableView/index.tsx +12 -0
- package/Components/MasterCell/DefaultComponents/Image/Image.ios.tsx +6 -5
- package/Components/MasterCell/DefaultComponents/Image/Image.web.tsx +2 -2
- package/Components/MasterCell/DefaultComponents/ImageBorderContainer/index.ts +71 -0
- package/Components/MasterCell/DefaultComponents/__tests__/image.test.js +1 -1
- package/Components/MasterCell/DefaultComponents/index.ts +2 -0
- package/Components/MasterCell/SharedUI/ProgressBar/hooks/useFillInPercent.ts +7 -1
- package/Components/MasterCell/dataAdapter.ts +21 -7
- package/Components/MasterCell/index.tsx +5 -3
- package/Components/MasterCell/utils/index.ts +3 -4
- package/Components/NativeFocusables/{index.js → index.ts} +4 -2
- package/Components/PlayerContainer/PlayerContainer.tsx +14 -8
- package/Components/Screen/TV/hooks/index.ts +0 -2
- package/Components/Screen/TV/index.web.tsx +32 -19
- package/Components/Screen/__tests__/Screen.test.tsx +0 -49
- package/Components/Screen/index.tsx +2 -20
- package/Components/Screen/navigationHandler.ts +1 -3
- package/Components/Screen/orientationHandler.ts +18 -7
- package/Components/Screen/utils.ts +16 -0
- package/Components/ScreenResolver/index.tsx +6 -11
- package/Components/Transitioner/Scene.tsx +9 -2
- package/Components/Transitioner/Transitioner.tsx +38 -23
- package/Components/Transitioner/__tests__/Scene.test.js +7 -0
- package/Components/Transitioner/__tests__/__snapshots__/transitioner.test.js.snap +1 -0
- package/Components/VideoLive/__tests__/__snapshots__/PlayerLiveImageComponent.test.tsx.snap +5 -0
- package/Components/VideoModal/ModalAnimation/AnimatedPlayerModalWrapper.tsx +3 -9
- package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.tsx +87 -41
- package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.tsx +20 -9
- package/Components/VideoModal/ModalAnimation/AnimationComponent.tsx +41 -22
- package/Components/VideoModal/PlayerDetails.tsx +16 -2
- package/Components/VideoModal/PlayerWrapper.tsx +101 -67
- package/Components/VideoModal/VideoModal.tsx +33 -27
- package/Components/VideoModal/__tests__/PlayerDetails.test.tsx +7 -0
- package/Components/VideoModal/__tests__/__snapshots__/PlayerDetails.test.tsx.snap +2 -0
- package/Components/VideoModal/__tests__/__snapshots__/PlayerWrapper.test.tsx.snap +78 -16
- package/Components/ZappFrameworkComponents/BarView/BarView.tsx +7 -3
- package/Components/ZappFrameworkComponents/BarView/Buttons/BackButton.tsx +7 -2
- package/Components/ZappFrameworkComponents/BarView/Buttons/CloseButton.tsx +7 -2
- package/Components/ZappFrameworkComponents/BarView/__tests__/BarView.test.tsx +87 -0
- package/Components/ZappFrameworkComponents/Buttons/ActionButton.tsx +9 -4
- package/Components/default-cell-renderer/__tests__/__snapshots__/defaultCellRenderer.test.tsx.snap +4 -4
- package/Contexts/CachedDimensionsContext/index.ts +13 -9
- package/Contexts/ConfirmDialogState/index.ts +1 -1
- package/Contexts/ScreenContext/index.tsx +6 -1
- package/Decorators/Analytics/{index.js → index.tsx} +11 -11
- package/README.md +1 -13
- package/const.ts +6 -0
- package/index.js +3 -0
- package/package.json +5 -5
- package/Components/Screen/TV/hooks/useRestoreFocus.ts +0 -22
package/Components/Cell/Cell.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { join,
|
|
2
|
+
import { join, merge, path } from "ramda";
|
|
3
3
|
import { View } from "react-native";
|
|
4
4
|
|
|
5
5
|
import { Focusable } from "@applicaster/zapp-react-native-ui-components/Components/Focusable";
|
|
@@ -14,10 +14,7 @@ import { BaseFocusable } from "../BaseFocusable";
|
|
|
14
14
|
import { AccessibilityManager } from "@applicaster/zapp-react-native-utils/appUtils/accessibilityManager";
|
|
15
15
|
|
|
16
16
|
type Props = {
|
|
17
|
-
item:
|
|
18
|
-
id: string;
|
|
19
|
-
title: string;
|
|
20
|
-
};
|
|
17
|
+
item: ZappEntry;
|
|
21
18
|
index: number;
|
|
22
19
|
shouldScrollHorizontally: (arg1: [any]) => boolean | null | undefined;
|
|
23
20
|
shouldScrollVertically: (...args: any) => boolean | null | undefined;
|
|
@@ -33,10 +30,9 @@ type Props = {
|
|
|
33
30
|
id: string;
|
|
34
31
|
};
|
|
35
32
|
selected?: boolean;
|
|
36
|
-
CellRenderer: React.
|
|
37
|
-
item:
|
|
38
|
-
|
|
39
|
-
}> & { hasFocusableInside: (item: Record<string, string>) => boolean };
|
|
33
|
+
CellRenderer: React.FunctionComponent<any> & {
|
|
34
|
+
hasFocusableInside: (item: ZappEntry) => boolean;
|
|
35
|
+
};
|
|
40
36
|
preferredFocus: boolean;
|
|
41
37
|
navigator: {
|
|
42
38
|
push: (arg1: Record<any, any>) => void;
|
|
@@ -67,6 +63,10 @@ type Props = {
|
|
|
67
63
|
behavior: Behavior;
|
|
68
64
|
};
|
|
69
65
|
|
|
66
|
+
type State = {
|
|
67
|
+
hasFocusableInside: boolean;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
70
|
const baseCellStyles = {
|
|
71
71
|
height: "100%",
|
|
72
72
|
display: "flex",
|
|
@@ -78,7 +78,7 @@ const touchableStyles = {
|
|
|
78
78
|
height: "100%",
|
|
79
79
|
} as const;
|
|
80
80
|
|
|
81
|
-
export class CellComponent extends React.Component<Props> {
|
|
81
|
+
export class CellComponent extends React.Component<Props, State> {
|
|
82
82
|
constructor(props) {
|
|
83
83
|
super(props);
|
|
84
84
|
this.onPress = this.onPress.bind(this);
|
|
@@ -88,6 +88,10 @@ export class CellComponent extends React.Component<Props> {
|
|
|
88
88
|
this.hasReceivedFocus = this.hasReceivedFocus.bind(this);
|
|
89
89
|
this.scrollVertically = this.scrollVertically.bind(this);
|
|
90
90
|
this.scrollToIndex = this.scrollToIndex.bind(this);
|
|
91
|
+
|
|
92
|
+
this.state = {
|
|
93
|
+
hasFocusableInside: props.CellRenderer.hasFocusableInside?.(props.item),
|
|
94
|
+
};
|
|
91
95
|
}
|
|
92
96
|
|
|
93
97
|
setScreenLayout(componentAnchorPointY, screenLayout) {
|
|
@@ -140,10 +144,6 @@ export class CellComponent extends React.Component<Props> {
|
|
|
140
144
|
shouldScrollVertically?.(mouse, focusable, id, title)
|
|
141
145
|
) {
|
|
142
146
|
this.scrollVertically(focusable);
|
|
143
|
-
|
|
144
|
-
const accessibilityManager = AccessibilityManager.getInstance();
|
|
145
|
-
// Text from DSP should be localized already
|
|
146
|
-
accessibilityManager.readText({ text: title });
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
}
|
|
@@ -192,6 +192,16 @@ export class CellComponent extends React.Component<Props> {
|
|
|
192
192
|
return !isFocusable ? false : focused || focusableFocused;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
componentDidUpdate(prevProps: Readonly<Props>) {
|
|
196
|
+
if (prevProps.item !== this.props.item) {
|
|
197
|
+
this.setState({
|
|
198
|
+
hasFocusableInside: this.props.CellRenderer.hasFocusableInside?.(
|
|
199
|
+
this.props.item
|
|
200
|
+
),
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
195
205
|
render() {
|
|
196
206
|
const {
|
|
197
207
|
item,
|
|
@@ -220,9 +230,7 @@ export class CellComponent extends React.Component<Props> {
|
|
|
220
230
|
this.onFocus(focusable, mouse);
|
|
221
231
|
};
|
|
222
232
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (hasFocusableInside) {
|
|
233
|
+
if (this.state.hasFocusableInside) {
|
|
226
234
|
return (
|
|
227
235
|
<CellWithFocusable
|
|
228
236
|
CellRenderer={CellRenderer}
|
|
@@ -260,13 +268,20 @@ export class CellComponent extends React.Component<Props> {
|
|
|
260
268
|
skipFocusManagerRegistration={skipFocusManagerRegistration}
|
|
261
269
|
>
|
|
262
270
|
{(focused, event) => {
|
|
271
|
+
const isFocused = this.isCellFocused(focused);
|
|
272
|
+
|
|
273
|
+
if (isFocused) {
|
|
274
|
+
const accessibilityManager = AccessibilityManager.getInstance();
|
|
275
|
+
accessibilityManager.readText({ text: String(item.title) });
|
|
276
|
+
}
|
|
277
|
+
|
|
263
278
|
return (
|
|
264
279
|
<FocusableCell
|
|
265
280
|
{...{
|
|
266
281
|
index,
|
|
267
282
|
CellRenderer,
|
|
268
283
|
item,
|
|
269
|
-
focused:
|
|
284
|
+
focused: isFocused,
|
|
270
285
|
scrollTo: this.scrollToIndex(event),
|
|
271
286
|
behavior,
|
|
272
287
|
}}
|
|
@@ -36,10 +36,9 @@ type Props = {
|
|
|
36
36
|
component_type: string;
|
|
37
37
|
};
|
|
38
38
|
selected: boolean;
|
|
39
|
-
CellRenderer: React.
|
|
40
|
-
item: any;
|
|
41
|
-
|
|
42
|
-
}> & { hasFocusableInside: (item: any) => boolean };
|
|
39
|
+
CellRenderer: React.FunctionComponent<any> & {
|
|
40
|
+
hasFocusableInside: (item: any) => boolean;
|
|
41
|
+
};
|
|
43
42
|
preferredFocus: boolean;
|
|
44
43
|
navigator: {
|
|
45
44
|
push: (arg1: Record<any, any>) => void;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, act } from "@testing-library/react-native";
|
|
3
|
+
import { Touchable } from "../../Touchable";
|
|
4
|
+
|
|
5
|
+
const mockUseIsRTL = jest.fn();
|
|
6
|
+
|
|
7
|
+
jest.mock("@applicaster/zapp-react-native-utils/localizationUtils", () => ({
|
|
8
|
+
useIsRTL: mockUseIsRTL,
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
const mockUseFocusManager = jest.fn();
|
|
12
|
+
|
|
13
|
+
jest.mock("@applicaster/zapp-react-native-utils/focusManager", () => ({
|
|
14
|
+
useFocusManager: mockUseFocusManager,
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
const mockUsePrevious = jest.fn();
|
|
18
|
+
|
|
19
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/utils", () => ({
|
|
20
|
+
usePrevious: mockUsePrevious,
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
const { Focusable } = require("../index.android");
|
|
24
|
+
|
|
25
|
+
describe("Focusable", () => {
|
|
26
|
+
const mockFocusManager = {
|
|
27
|
+
isFocused: jest.fn(),
|
|
28
|
+
onDisableFocusChange: jest.fn(),
|
|
29
|
+
registerFocusable: jest.fn(),
|
|
30
|
+
focusedId: "test-id",
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
jest.clearAllMocks();
|
|
35
|
+
mockUseIsRTL.mockReturnValue(false);
|
|
36
|
+
mockUseFocusManager.mockReturnValue(mockFocusManager);
|
|
37
|
+
mockUsePrevious.mockReturnValue(false);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("updates disableFocus state when disableFocus prop changes", () => {
|
|
41
|
+
const { rerender } = render(
|
|
42
|
+
<Focusable id="test-id" disableFocus={false}>
|
|
43
|
+
<Touchable testID="touchable" />
|
|
44
|
+
</Focusable>
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
rerender(
|
|
48
|
+
<Focusable id="test-id" disableFocus={true}>
|
|
49
|
+
<Touchable testID="touchable" />
|
|
50
|
+
</Focusable>
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
expect(mockFocusManager.onDisableFocusChange).toHaveBeenCalledWith(
|
|
54
|
+
"test-id"
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("calls focusManager.registerFocusable on mount and unregisters on unmount", () => {
|
|
59
|
+
const unregister = jest.fn();
|
|
60
|
+
mockFocusManager.registerFocusable.mockReturnValue(unregister);
|
|
61
|
+
|
|
62
|
+
const { unmount } = render(
|
|
63
|
+
<Focusable id="test-id">
|
|
64
|
+
<Touchable testID="touchable" />
|
|
65
|
+
</Focusable>
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
expect(mockFocusManager.registerFocusable).toHaveBeenCalled();
|
|
69
|
+
act(() => unmount());
|
|
70
|
+
expect(unregister).toHaveBeenCalled();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -128,7 +128,10 @@ function FocusableComponent(props: Props, forwardedRef) {
|
|
|
128
128
|
|
|
129
129
|
const _onBlur = React.useCallback(
|
|
130
130
|
(ref, options = {}) => {
|
|
131
|
-
|
|
131
|
+
if (ref.props.id !== focusManager.focusedId) {
|
|
132
|
+
setFocused(false);
|
|
133
|
+
}
|
|
134
|
+
|
|
132
135
|
onBlur?.(ref, options);
|
|
133
136
|
},
|
|
134
137
|
[onBlur]
|
|
@@ -148,15 +151,14 @@ function FocusableComponent(props: Props, forwardedRef) {
|
|
|
148
151
|
[isRTL, nextFocusDown, nextFocusUp, nextFocusLeft, nextFocusRight]
|
|
149
152
|
);
|
|
150
153
|
|
|
151
|
-
const contextState = React.useMemo(
|
|
152
|
-
|
|
154
|
+
const contextState = React.useMemo(() => {
|
|
155
|
+
return {
|
|
153
156
|
focused,
|
|
154
157
|
...parentFocus,
|
|
155
158
|
ref: touchableRef,
|
|
156
159
|
setIsFocusable,
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
);
|
|
160
|
+
};
|
|
161
|
+
}, [parentFocus, focused]);
|
|
160
162
|
|
|
161
163
|
return (
|
|
162
164
|
<Touchable
|
|
@@ -173,9 +175,13 @@ function FocusableComponent(props: Props, forwardedRef) {
|
|
|
173
175
|
{...parentFocus}
|
|
174
176
|
>
|
|
175
177
|
<FocusableContext.Provider value={contextState}>
|
|
176
|
-
{
|
|
177
|
-
|
|
178
|
-
|
|
178
|
+
{React.useMemo(
|
|
179
|
+
() =>
|
|
180
|
+
typeof children === "function"
|
|
181
|
+
? children(focused, parentFocus, touchableRef)
|
|
182
|
+
: children,
|
|
183
|
+
[children, focused, parentFocus]
|
|
184
|
+
)}
|
|
179
185
|
</FocusableContext.Provider>
|
|
180
186
|
</Touchable>
|
|
181
187
|
);
|
|
@@ -31,14 +31,14 @@ const useParentFocus = (
|
|
|
31
31
|
|
|
32
32
|
function FocusableChildComponent(props) {
|
|
33
33
|
const { setIsFocusable, ...focusableContext } = useFocusable();
|
|
34
|
+
const focused = useCellState(props.id);
|
|
35
|
+
|
|
34
36
|
const parentFocus = useParentFocus(props, focusableContext);
|
|
35
37
|
|
|
36
38
|
const onLoadFailed = React.useCallback(() => {
|
|
37
39
|
setIsFocusable(false);
|
|
38
40
|
}, []);
|
|
39
41
|
|
|
40
|
-
const focused = useCellState(props.id);
|
|
41
|
-
|
|
42
42
|
return props.renderItem({
|
|
43
43
|
...props,
|
|
44
44
|
focused,
|
|
@@ -88,6 +88,7 @@ function FocusableListComponent<ItemT>(props: Props<ItemT>, ref) {
|
|
|
88
88
|
data = [],
|
|
89
89
|
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
90
90
|
onAllComponentsLoaded, // TODO: re-implement it
|
|
91
|
+
omitPropsPropagation = [],
|
|
91
92
|
} = props;
|
|
92
93
|
|
|
93
94
|
useCheckItemIdsForUnique({ componentId: props.id, items: data });
|
|
@@ -252,9 +253,9 @@ function FocusableListComponent<ItemT>(props: Props<ItemT>, ref) {
|
|
|
252
253
|
]
|
|
253
254
|
);
|
|
254
255
|
|
|
255
|
-
const
|
|
256
|
-
(
|
|
257
|
-
|
|
256
|
+
const getFlatListProps = React.useCallback(
|
|
257
|
+
R.omit(
|
|
258
|
+
[
|
|
258
259
|
"onListElementFocus",
|
|
259
260
|
"onListElementPress",
|
|
260
261
|
"onListElementPressOut",
|
|
@@ -267,17 +268,17 @@ function FocusableListComponent<ItemT>(props: Props<ItemT>, ref) {
|
|
|
267
268
|
"focusableItemProps",
|
|
268
269
|
"renderItem",
|
|
269
270
|
"extraChildrenData",
|
|
270
|
-
"extraData",
|
|
271
|
-
"keyExtractor",
|
|
272
271
|
"onAllComponentsLoaded",
|
|
273
272
|
"focused",
|
|
274
273
|
"id",
|
|
275
274
|
"initialFocusDirection",
|
|
276
275
|
"withStateMemory",
|
|
277
276
|
"useSequentialLoading",
|
|
278
|
-
...
|
|
279
|
-
]
|
|
280
|
-
|
|
277
|
+
...omitPropsPropagation,
|
|
278
|
+
],
|
|
279
|
+
R.__
|
|
280
|
+
),
|
|
281
|
+
[omitPropsPropagation]
|
|
281
282
|
);
|
|
282
283
|
|
|
283
284
|
const onEndReached = React.useCallback(
|
|
@@ -289,7 +290,7 @@ function FocusableListComponent<ItemT>(props: Props<ItemT>, ref) {
|
|
|
289
290
|
|
|
290
291
|
const initialNumToRender = toFiniteNumberWithDefault(
|
|
291
292
|
10,
|
|
292
|
-
|
|
293
|
+
props.initialNumToRender
|
|
293
294
|
);
|
|
294
295
|
|
|
295
296
|
return (
|
|
@@ -298,12 +299,10 @@ function FocusableListComponent<ItemT>(props: Props<ItemT>, ref) {
|
|
|
298
299
|
<FlatList
|
|
299
300
|
focusable={false}
|
|
300
301
|
scrollEnabled={false}
|
|
301
|
-
extraData={props.extraData}
|
|
302
302
|
ref={ref}
|
|
303
|
-
{...
|
|
303
|
+
{...getFlatListProps(props)}
|
|
304
304
|
renderItem={renderItem}
|
|
305
305
|
onEndReached={onEndReached}
|
|
306
|
-
keyExtractor={props.keyExtractor}
|
|
307
306
|
initialNumToRender={initialNumToRender}
|
|
308
307
|
/>
|
|
309
308
|
</ChildrenFocusDeactivatorView>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { usePrevious } from "@applicaster/zapp-react-native-utils/reactHooks/utils";
|
|
2
|
+
import React, { Suspense, useEffect } from "react";
|
|
3
|
+
import { Suspender } from "./Suspender";
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
freeze: boolean;
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
placeholder?: React.ReactNode;
|
|
9
|
+
onRelease?: () => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function Freeze({
|
|
13
|
+
freeze,
|
|
14
|
+
children,
|
|
15
|
+
placeholder = null,
|
|
16
|
+
onRelease,
|
|
17
|
+
}: Props) {
|
|
18
|
+
const prevFreeze = usePrevious(freeze);
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (prevFreeze && !freeze && onRelease) {
|
|
22
|
+
onRelease();
|
|
23
|
+
}
|
|
24
|
+
}, [freeze, onRelease, prevFreeze]);
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Suspense fallback={placeholder}>
|
|
28
|
+
<Suspender freeze={freeze}>{children}</Suspender>
|
|
29
|
+
</Suspense>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Software Mansion
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React, { Fragment } from "react";
|
|
2
|
+
|
|
3
|
+
const infiniteThenable = { then() {} };
|
|
4
|
+
|
|
5
|
+
export const Suspender = ({
|
|
6
|
+
freeze,
|
|
7
|
+
children,
|
|
8
|
+
}: {
|
|
9
|
+
freeze: boolean;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
}) => {
|
|
12
|
+
if (freeze) {
|
|
13
|
+
throw infiniteThenable;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return <Fragment>{children}</Fragment>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import React, { Dispatch, useEffect, useState } from "react";
|
|
2
|
+
import {
|
|
3
|
+
act,
|
|
4
|
+
create,
|
|
5
|
+
ReactTestRenderer,
|
|
6
|
+
ReactTestRendererJSON,
|
|
7
|
+
} from "react-test-renderer";
|
|
8
|
+
import { FreezeWithCallback } from "../index";
|
|
9
|
+
|
|
10
|
+
const SimpleContent = () => <div />;
|
|
11
|
+
|
|
12
|
+
interface InnerProps {
|
|
13
|
+
value: number;
|
|
14
|
+
}
|
|
15
|
+
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
16
|
+
const Inner = ({ value }: InnerProps) => <div />;
|
|
17
|
+
|
|
18
|
+
interface TestSubscriber {
|
|
19
|
+
renderCount: number;
|
|
20
|
+
subscription: Dispatch<number>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function createSubscriberComponent(): [React.FC, TestSubscriber] {
|
|
24
|
+
const testState: TestSubscriber = {
|
|
25
|
+
renderCount: 0,
|
|
26
|
+
subscription: () => {},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const Subscriber: React.FC = () => {
|
|
30
|
+
const [value, setValue] = useState(0);
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
testState.subscription = setValue;
|
|
34
|
+
}, []);
|
|
35
|
+
|
|
36
|
+
testState.renderCount += 1;
|
|
37
|
+
|
|
38
|
+
return <Inner value={value} />;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return [Subscriber, testState];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface ContainerProps {
|
|
45
|
+
freeze: boolean;
|
|
46
|
+
children: React.ReactNode;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const Container = ({ freeze, children }: ContainerProps) => (
|
|
50
|
+
<FreezeWithCallback freeze={freeze}>{children}</FreezeWithCallback>
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
function setupTest(initialFreeze: boolean = false) {
|
|
54
|
+
let testRenderer: ReactTestRenderer | undefined;
|
|
55
|
+
const [Subscriber, subscriberState] = createSubscriberComponent();
|
|
56
|
+
|
|
57
|
+
act(() => {
|
|
58
|
+
testRenderer = create(
|
|
59
|
+
<Container freeze={initialFreeze}>
|
|
60
|
+
<Subscriber />
|
|
61
|
+
</Container>
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
testRenderer,
|
|
67
|
+
testInstance: testRenderer?.root,
|
|
68
|
+
subscriberState,
|
|
69
|
+
updateFreeze: (freeze: boolean) => {
|
|
70
|
+
act(() =>
|
|
71
|
+
testRenderer?.update(
|
|
72
|
+
<Container freeze={freeze}>
|
|
73
|
+
<Subscriber />
|
|
74
|
+
</Container>
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
describe("FreezeWithCallback", () => {
|
|
82
|
+
test("Renders stuff not frozen", () => {
|
|
83
|
+
const testRenderer = create(
|
|
84
|
+
<Container freeze={false}>
|
|
85
|
+
<SimpleContent />
|
|
86
|
+
</Container>
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
expect(testRenderer.root.findByType(SimpleContent)).toBeTruthy();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("Does not render stuff when frozen", () => {
|
|
93
|
+
const testRenderer = create(
|
|
94
|
+
<Container freeze>
|
|
95
|
+
<SimpleContent />
|
|
96
|
+
</Container>
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
expect(testRenderer.root.findAllByType(SimpleContent)).toHaveLength(0);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("Stuff is gone after freeze", () => {
|
|
103
|
+
const testRenderer = create(
|
|
104
|
+
<Container freeze={false}>
|
|
105
|
+
<SimpleContent />
|
|
106
|
+
</Container>
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
expect(testRenderer.root.findByType(SimpleContent)).toBeTruthy();
|
|
110
|
+
|
|
111
|
+
act(() =>
|
|
112
|
+
testRenderer.update(
|
|
113
|
+
<Container freeze>
|
|
114
|
+
<SimpleContent />
|
|
115
|
+
</Container>
|
|
116
|
+
)
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
expect(testRenderer.toJSON()).toBe(null);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("Updates work when not frozen", () => {
|
|
123
|
+
const { testInstance, subscriberState } = setupTest();
|
|
124
|
+
|
|
125
|
+
expect(testInstance?.findByType(Inner).props.value).toEqual(0);
|
|
126
|
+
act(() => subscriberState.subscription(1));
|
|
127
|
+
expect(testInstance?.findByType(Inner).props.value).toEqual(1);
|
|
128
|
+
expect(subscriberState.renderCount).toBe(2);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("Updates does not propagate when frozen", () => {
|
|
132
|
+
const { testInstance, subscriberState, updateFreeze } = setupTest();
|
|
133
|
+
|
|
134
|
+
expect(testInstance?.findByType(Inner).props.value).toEqual(0);
|
|
135
|
+
updateFreeze(true);
|
|
136
|
+
act(() => subscriberState.subscription(1));
|
|
137
|
+
expect(testInstance?.findByType(Inner).props.value).toEqual(0);
|
|
138
|
+
expect(subscriberState.renderCount).toBe(1);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("State persists after defrost", () => {
|
|
142
|
+
const { testInstance, subscriberState, updateFreeze, testRenderer } =
|
|
143
|
+
setupTest();
|
|
144
|
+
|
|
145
|
+
expect(testInstance?.findByType(Inner).props.value).toEqual(0);
|
|
146
|
+
act(() => subscriberState.subscription(1));
|
|
147
|
+
expect(testInstance?.findByType(Inner).props.value).toEqual(1);
|
|
148
|
+
|
|
149
|
+
updateFreeze(true);
|
|
150
|
+
expect(testRenderer?.toJSON()).toBe(null);
|
|
151
|
+
|
|
152
|
+
updateFreeze(false);
|
|
153
|
+
expect((testRenderer?.toJSON() as ReactTestRendererJSON).type).toBe("div");
|
|
154
|
+
expect(testInstance?.findByType(Inner).props.value).toEqual(1);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test("Update propagate after defrost", () => {
|
|
158
|
+
const { testInstance, subscriberState, updateFreeze } = setupTest();
|
|
159
|
+
|
|
160
|
+
updateFreeze(true);
|
|
161
|
+
act(() => subscriberState.subscription(1));
|
|
162
|
+
act(() => subscriberState.subscription(2));
|
|
163
|
+
act(() => subscriberState.subscription(3));
|
|
164
|
+
expect(testInstance?.findByType(Inner).props.value).toEqual(0);
|
|
165
|
+
|
|
166
|
+
updateFreeze(false);
|
|
167
|
+
expect(testInstance?.findByType(Inner).props.value).toEqual(3);
|
|
168
|
+
expect(subscriberState.renderCount).toBe(2);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -8,5 +8,5 @@ import { useImageSource } from "./utils";
|
|
|
8
8
|
export const QBImage = (props: FastImageProps) => {
|
|
9
9
|
const source = useImageSource(props.source);
|
|
10
10
|
|
|
11
|
-
return <FastImage {...props} source={source} />;
|
|
11
|
+
return <FastImage useLastImageAsDefaultSource {...props} source={source} />;
|
|
12
12
|
};
|
|
@@ -66,20 +66,24 @@ export function ActionButton(props: Props) {
|
|
|
66
66
|
);
|
|
67
67
|
|
|
68
68
|
useEffect(() => {
|
|
69
|
-
if (actionDisabled || !actionContext)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}, [actionDisabled, item?.id, actionContext]);
|
|
69
|
+
if (!((actionDisabled || !actionContext) && actionState !== null)) {
|
|
70
|
+
setActionState(actionContext.initialEntryState(item));
|
|
71
|
+
}
|
|
72
|
+
}, [actionDisabled, item?.id, actionContext, action]);
|
|
73
73
|
|
|
74
74
|
const onPress = useCallback(() => {
|
|
75
75
|
actionContext.invokeAction(item, {
|
|
76
|
-
updateState:
|
|
76
|
+
updateState: (state) => {
|
|
77
|
+
setActionState(state);
|
|
78
|
+
},
|
|
77
79
|
});
|
|
78
|
-
}, [actionState, actionContext?.state,
|
|
80
|
+
}, [actionState, actionContext?.state, item?.id]);
|
|
79
81
|
|
|
80
82
|
useEffect(() => {
|
|
81
83
|
if (typeof actionContext?.addListener === "function") {
|
|
82
|
-
return actionContext?.addListener(item.id
|
|
84
|
+
return actionContext?.addListener(String(item.id), (state) => {
|
|
85
|
+
setActionState(state);
|
|
86
|
+
});
|
|
83
87
|
}
|
|
84
88
|
}, [item?.id]);
|
|
85
89
|
|
|
@@ -117,9 +117,6 @@ export const BorderContainerView = (props: Props) => {
|
|
|
117
117
|
children,
|
|
118
118
|
} = props;
|
|
119
119
|
|
|
120
|
-
const borderStyleForMissingBorder =
|
|
121
|
-
style?.borderWidth === 0 || !style?.borderColor ? { borderRadius: 0 } : {};
|
|
122
|
-
|
|
123
120
|
const padding =
|
|
124
121
|
borderPosition === "outside"
|
|
125
122
|
? {
|
|
@@ -131,10 +128,7 @@ export const BorderContainerView = (props: Props) => {
|
|
|
131
128
|
: {};
|
|
132
129
|
|
|
133
130
|
return (
|
|
134
|
-
<View
|
|
135
|
-
{...props}
|
|
136
|
-
style={[style, styles.container, borderStyleForMissingBorder]}
|
|
137
|
-
>
|
|
131
|
+
<View pointerEvents="box-none" {...props} style={[style, styles.container]}>
|
|
138
132
|
<Border style={style} padding={padding} borderPosition={borderPosition} />
|
|
139
133
|
{children}
|
|
140
134
|
</View>
|