@applicaster/zapp-react-native-ui-components 12.0.0-alpha.4054240460 → 12.0.0-alpha.4081044014
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/BaseFocusable/index.tsx +2 -2
- package/Components/Cell/Cell.tsx +33 -14
- package/Components/Cell/CellWithFocusable.tsx +6 -4
- package/Components/Cell/TvOSCellComponent.tsx +3 -7
- package/Components/Focusable/Focusable.tsx +6 -1
- package/Components/Focusable/__tests__/index.android.test.tsx +72 -0
- package/Components/Focusable/index.android.tsx +15 -9
- package/Components/FocusableGroup/index.tsx +10 -2
- 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/Layout/TV/ScreenContainer.tsx +79 -5
- package/Components/Layout/TV/__tests__/ScreenContainer.test.tsx +38 -28
- package/Components/Layout/TV/__tests__/__snapshots__/ScreenContainer.test.tsx.snap +25 -13
- package/Components/Layout/TV/__tests__/index.test.tsx +2 -1
- package/Components/Layout/TV/index.tsx +11 -65
- package/Components/MasterCell/DefaultComponents/ActionButton.tsx +12 -7
- package/Components/MasterCell/DefaultComponents/BorderContainerView/index.tsx +8 -9
- package/Components/MasterCell/DefaultComponents/CellBadge/index.tsx +6 -1
- package/Components/MasterCell/DefaultComponents/FocusableView/index.tsx +16 -1
- 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/LiveImage/index.tsx +20 -0
- package/Components/MasterCell/DefaultComponents/__tests__/image.test.js +1 -1
- package/Components/MasterCell/DefaultComponents/index.ts +2 -0
- package/Components/MasterCell/DefaultComponents/tv/ButtonContainerView/index.tsx +6 -1
- 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/__tests__/insertBetween.test.js +9 -0
- package/Components/MasterCell/utils/index.ts +3 -4
- package/Components/Navigator/StackNavigator.tsx +14 -5
- package/Components/PlayerContainer/PlayerContainer.tsx +16 -13
- package/Components/Screen/TV/hooks/index.ts +0 -2
- package/Components/Screen/TV/index.web.tsx +40 -41
- package/Components/Screen/__tests__/Screen.test.tsx +0 -49
- package/Components/Screen/index.tsx +28 -77
- package/Components/Screen/navigationHandler.ts +6 -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 +20 -12
- package/Components/Transitioner/Transitioner.tsx +38 -23
- package/Components/Transitioner/__tests__/Scene.test.js +7 -0
- package/Components/Transitioner/__tests__/__snapshots__/Scene.test.js.snap +8 -4
- package/Components/Transitioner/__tests__/__snapshots__/transitioner.test.js.snap +1 -0
- package/Components/VideoLive/LiveImageManager.ts +10 -0
- package/Components/VideoLive/PlayerLiveImageComponent.tsx +52 -24
- package/Components/VideoLive/__tests__/__snapshots__/PlayerLiveImageComponent.test.tsx.snap +31 -24
- package/Components/VideoModal/ModalAnimation/AnimatedPlayerModalWrapper.tsx +3 -21
- package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.tsx +92 -43
- package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.tsx +24 -10
- package/Components/VideoModal/ModalAnimation/AnimationComponent.tsx +51 -37
- package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +32 -4
- package/Components/VideoModal/ModalAnimation/utils.ts +7 -4
- package/Components/VideoModal/PlayerDetails.tsx +16 -2
- package/Components/VideoModal/PlayerWrapper.tsx +41 -11
- 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 +134 -22
- package/Components/VideoModal/hooks/useModalSize.ts +10 -12
- 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/FocusableGroupContext/FocusableGroupContext.ts +3 -0
- package/Contexts/FocusableGroupContext/FocusableGroupContextProvider.tsx +16 -0
- package/Contexts/FocusableGroupContext/__tests__/FocusableGroupContextProvider.test.tsx +22 -0
- package/Contexts/FocusableGroupContext/__tests__/withFocusableContext.test.tsx +26 -0
- package/Contexts/FocusableGroupContext/index.ts +7 -0
- package/Contexts/FocusableGroupContext/withFocusableContext.tsx +17 -0
- package/Contexts/ScreenContext/index.tsx +6 -1
- 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/FocusableGroup/{index.android.js → index.android.ts} +0 -0
- /package/Components/FocusableGroup/{index.ios.js → index.ios.ts} +0 -0
|
@@ -71,9 +71,9 @@ export class BaseFocusable<
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
getId(props?: { id: string; groupId: string }) {
|
|
74
|
-
const { id
|
|
74
|
+
const { id } = props || this.props;
|
|
75
75
|
|
|
76
|
-
return
|
|
76
|
+
return id;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
getRect() {
|
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";
|
|
@@ -11,10 +11,7 @@ import { noop } from "@applicaster/zapp-react-native-utils/functionUtils";
|
|
|
11
11
|
|
|
12
12
|
import { CellWithFocusable } from "./CellWithFocusable";
|
|
13
13
|
import { BaseFocusable } from "../BaseFocusable";
|
|
14
|
-
import {
|
|
15
|
-
isVizioPlatform,
|
|
16
|
-
TTSManager,
|
|
17
|
-
} from "@applicaster/zapp-react-native-utils/appUtils/platform/platformUtils";
|
|
14
|
+
import { AccessibilityManager } from "@applicaster/zapp-react-native-utils/appUtils/accessibilityManager";
|
|
18
15
|
|
|
19
16
|
type Props = {
|
|
20
17
|
item: {
|
|
@@ -70,6 +67,10 @@ type Props = {
|
|
|
70
67
|
behavior: Behavior;
|
|
71
68
|
};
|
|
72
69
|
|
|
70
|
+
type State = {
|
|
71
|
+
hasFocusableInside: boolean;
|
|
72
|
+
};
|
|
73
|
+
|
|
73
74
|
const baseCellStyles = {
|
|
74
75
|
height: "100%",
|
|
75
76
|
display: "flex",
|
|
@@ -81,7 +82,7 @@ const touchableStyles = {
|
|
|
81
82
|
height: "100%",
|
|
82
83
|
} as const;
|
|
83
84
|
|
|
84
|
-
export class CellComponent extends React.Component<Props> {
|
|
85
|
+
export class CellComponent extends React.Component<Props, State> {
|
|
85
86
|
constructor(props) {
|
|
86
87
|
super(props);
|
|
87
88
|
this.onPress = this.onPress.bind(this);
|
|
@@ -91,6 +92,10 @@ export class CellComponent extends React.Component<Props> {
|
|
|
91
92
|
this.hasReceivedFocus = this.hasReceivedFocus.bind(this);
|
|
92
93
|
this.scrollVertically = this.scrollVertically.bind(this);
|
|
93
94
|
this.scrollToIndex = this.scrollToIndex.bind(this);
|
|
95
|
+
|
|
96
|
+
this.state = {
|
|
97
|
+
hasFocusableInside: props.CellRenderer.hasFocusableInside?.(props.item),
|
|
98
|
+
};
|
|
94
99
|
}
|
|
95
100
|
|
|
96
101
|
setScreenLayout(componentAnchorPointY, screenLayout) {
|
|
@@ -144,10 +149,9 @@ export class CellComponent extends React.Component<Props> {
|
|
|
144
149
|
) {
|
|
145
150
|
this.scrollVertically(focusable);
|
|
146
151
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
152
|
+
const accessibilityManager = AccessibilityManager.getInstance();
|
|
153
|
+
// Text from DSP should be localized already
|
|
154
|
+
accessibilityManager.readText({ text: title });
|
|
151
155
|
}
|
|
152
156
|
}
|
|
153
157
|
}
|
|
@@ -196,6 +200,16 @@ export class CellComponent extends React.Component<Props> {
|
|
|
196
200
|
return !isFocusable ? false : focused || focusableFocused;
|
|
197
201
|
}
|
|
198
202
|
|
|
203
|
+
componentDidUpdate(prevProps: Readonly<Props>) {
|
|
204
|
+
if (prevProps.item !== this.props.item) {
|
|
205
|
+
this.setState({
|
|
206
|
+
hasFocusableInside: this.props.CellRenderer.hasFocusableInside?.(
|
|
207
|
+
this.props.item
|
|
208
|
+
),
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
199
213
|
render() {
|
|
200
214
|
const {
|
|
201
215
|
item,
|
|
@@ -224,9 +238,7 @@ export class CellComponent extends React.Component<Props> {
|
|
|
224
238
|
this.onFocus(focusable, mouse);
|
|
225
239
|
};
|
|
226
240
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
if (hasFocusableInside) {
|
|
241
|
+
if (this.state.hasFocusableInside) {
|
|
230
242
|
return (
|
|
231
243
|
<CellWithFocusable
|
|
232
244
|
CellRenderer={CellRenderer}
|
|
@@ -264,13 +276,20 @@ export class CellComponent extends React.Component<Props> {
|
|
|
264
276
|
skipFocusManagerRegistration={skipFocusManagerRegistration}
|
|
265
277
|
>
|
|
266
278
|
{(focused, event) => {
|
|
279
|
+
const isFocused = this.isCellFocused(focused);
|
|
280
|
+
|
|
281
|
+
if (isFocused) {
|
|
282
|
+
const accessibilityManager = AccessibilityManager.getInstance();
|
|
283
|
+
accessibilityManager.readText({ text: item.title });
|
|
284
|
+
}
|
|
285
|
+
|
|
267
286
|
return (
|
|
268
287
|
<FocusableCell
|
|
269
288
|
{...{
|
|
270
289
|
index,
|
|
271
290
|
CellRenderer,
|
|
272
291
|
item,
|
|
273
|
-
focused:
|
|
292
|
+
focused: isFocused,
|
|
274
293
|
scrollTo: this.scrollToIndex(event),
|
|
275
294
|
behavior,
|
|
276
295
|
}}
|
|
@@ -3,6 +3,8 @@ import * as React from "react";
|
|
|
3
3
|
import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils/focusManager";
|
|
4
4
|
import * as FOCUS_EVENTS from "@applicaster/zapp-react-native-utils/appUtils/focusManager/events";
|
|
5
5
|
import { noop } from "@applicaster/zapp-react-native-utils/functionUtils";
|
|
6
|
+
import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
|
|
7
|
+
|
|
6
8
|
import { isAppleTV } from "../../Helpers/Platform";
|
|
7
9
|
import { useCellState } from "../MasterCell/utils";
|
|
8
10
|
|
|
@@ -54,7 +56,7 @@ type Props = {
|
|
|
54
56
|
skipFocusManagerRegistration?: boolean;
|
|
55
57
|
isFocusable?: boolean;
|
|
56
58
|
behavior: Behavior;
|
|
57
|
-
|
|
59
|
+
focused?: boolean;
|
|
58
60
|
};
|
|
59
61
|
|
|
60
62
|
export function CellWithFocusable(props: Props) {
|
|
@@ -70,7 +72,7 @@ export function CellWithFocusable(props: Props) {
|
|
|
70
72
|
skipFocusManagerRegistration,
|
|
71
73
|
isFocusable,
|
|
72
74
|
behavior,
|
|
73
|
-
|
|
75
|
+
focused,
|
|
74
76
|
} = props;
|
|
75
77
|
|
|
76
78
|
const isFocused = useCellFocusedState(
|
|
@@ -82,8 +84,7 @@ export function CellWithFocusable(props: Props) {
|
|
|
82
84
|
const state = useCellState({
|
|
83
85
|
id: item.id,
|
|
84
86
|
behavior,
|
|
85
|
-
focused: isFocused,
|
|
86
|
-
selected,
|
|
87
|
+
focused: isFocused || toBooleanWithDefaultFalse(focused),
|
|
87
88
|
});
|
|
88
89
|
|
|
89
90
|
const [focusedButtonId, setFocusedButtonId] = React.useState(undefined);
|
|
@@ -114,6 +115,7 @@ export function CellWithFocusable(props: Props) {
|
|
|
114
115
|
preferredFocus={preferredFocus}
|
|
115
116
|
skipFocusManagerRegistration={skipFocusManagerRegistration}
|
|
116
117
|
isFocusable={isFocusable}
|
|
118
|
+
focused={focused}
|
|
117
119
|
/>
|
|
118
120
|
);
|
|
119
121
|
}
|
|
@@ -226,13 +226,7 @@ export class TvOSCellComponent extends React.Component<Props, State> {
|
|
|
226
226
|
|
|
227
227
|
hasReceivedFocus() {}
|
|
228
228
|
|
|
229
|
-
scrollTo(
|
|
230
|
-
// Workaround for HL autoscroll/autoloop feature, we scroll manually on tvOS.
|
|
231
|
-
// Should be removed after refactoring autoscroll/autoloop feature
|
|
232
|
-
if (this.props.component?.component_type !== "horizontal_list_qb") {
|
|
233
|
-
this.props?.scrollToIndex?.(index);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
229
|
+
scrollTo() {}
|
|
236
230
|
|
|
237
231
|
render() {
|
|
238
232
|
const {
|
|
@@ -279,7 +273,9 @@ export class TvOSCellComponent extends React.Component<Props, State> {
|
|
|
279
273
|
index={index}
|
|
280
274
|
scrollTo={this.scrollTo}
|
|
281
275
|
preferredFocus={preferredFocus}
|
|
276
|
+
focused={this.props.focused}
|
|
282
277
|
behavior={behavior}
|
|
278
|
+
isFocusable={isFocusable}
|
|
283
279
|
/>
|
|
284
280
|
</View>
|
|
285
281
|
);
|
|
@@ -4,6 +4,7 @@ import * as R from "ramda";
|
|
|
4
4
|
import { BaseFocusable } from "../BaseFocusable";
|
|
5
5
|
import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils/focusManager";
|
|
6
6
|
import { LONG_KEY_PRESS_TIMEOUT } from "@applicaster/quick-brick-core/const";
|
|
7
|
+
import { withFocusableContext } from "../../Contexts/FocusableGroupContext/withFocusableContext";
|
|
7
8
|
|
|
8
9
|
type Props = {
|
|
9
10
|
initialFocus?: boolean;
|
|
@@ -23,7 +24,7 @@ type Props = {
|
|
|
23
24
|
style?: React.CSSProperties;
|
|
24
25
|
};
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
class Focusable extends BaseFocusable<Props> {
|
|
27
28
|
isGroup: boolean;
|
|
28
29
|
mouse: boolean;
|
|
29
30
|
longPressTimeout = null;
|
|
@@ -198,3 +199,7 @@ export class Focusable extends BaseFocusable<Props> {
|
|
|
198
199
|
);
|
|
199
200
|
}
|
|
200
201
|
}
|
|
202
|
+
|
|
203
|
+
const FocusableWithFocusableContext = withFocusableContext(Focusable);
|
|
204
|
+
|
|
205
|
+
export { FocusableWithFocusableContext as Focusable };
|
|
@@ -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
|
);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
|
|
3
3
|
import { BaseFocusable } from "../BaseFocusable";
|
|
4
|
+
import { FocusableGroupContextProvider } from "../../Contexts/FocusableGroupContext";
|
|
5
|
+
import { withFocusableContext } from "../../Contexts/FocusableGroupContext/withFocusableContext";
|
|
4
6
|
|
|
5
7
|
type Props = {
|
|
6
8
|
testID?: string;
|
|
@@ -29,7 +31,7 @@ type Props = {
|
|
|
29
31
|
excludeFromFocusSearching?: boolean;
|
|
30
32
|
};
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
class FocusableGroup extends BaseFocusable<Props> {
|
|
33
35
|
constructor(props) {
|
|
34
36
|
super(props);
|
|
35
37
|
this.isGroup = true;
|
|
@@ -82,8 +84,14 @@ export class FocusableGroup extends BaseFocusable<Props> {
|
|
|
82
84
|
style={style}
|
|
83
85
|
ref={this.ref}
|
|
84
86
|
>
|
|
85
|
-
{
|
|
87
|
+
<FocusableGroupContextProvider id={id}>
|
|
88
|
+
{children}
|
|
89
|
+
</FocusableGroupContextProvider>
|
|
86
90
|
</div>
|
|
87
91
|
);
|
|
88
92
|
}
|
|
89
93
|
}
|
|
94
|
+
|
|
95
|
+
const FocusableGroupWithFocusableContext = withFocusableContext(FocusableGroup);
|
|
96
|
+
|
|
97
|
+
export { FocusableGroupWithFocusableContext as FocusableGroup };
|
|
@@ -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
|
+
};
|