@applicaster/zapp-react-native-ui-components 12.0.0-alpha.6329273868 → 12.0.0-alpha.6393691216
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/Screen/TV/hooks/index.ts +2 -0
- package/Components/Screen/TV/hooks/useRestoreFocus.ts +22 -0
- package/Components/Screen/TV/index.web.tsx +19 -32
- package/package.json +5 -5
- package/Components/FreezeWithCallback/Freeze.tsx +0 -31
- package/Components/FreezeWithCallback/LICENSE +0 -21
- package/Components/FreezeWithCallback/Suspender.tsx +0 -17
- package/Components/FreezeWithCallback/__tests__/index.test.tsx +0 -170
- package/Components/FreezeWithCallback/index.tsx +0 -3
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { isNil } from "ramda";
|
|
3
|
+
import { useIsScreenActive } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
|
|
4
|
+
import { usePrevious } from "@applicaster/zapp-react-native-utils/reactHooks/utils";
|
|
5
|
+
import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils/focusManager";
|
|
6
|
+
|
|
7
|
+
export const useRestoreFocus = (): void => {
|
|
8
|
+
const isScreenActive = useIsScreenActive();
|
|
9
|
+
const previousIsScreenActive = usePrevious(isScreenActive);
|
|
10
|
+
|
|
11
|
+
React.useEffect(() => {
|
|
12
|
+
if (isNil(previousIsScreenActive)) {
|
|
13
|
+
// it's initial mounting of the screen, do nothing here
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!previousIsScreenActive && isScreenActive) {
|
|
18
|
+
// restore focus when we go back from next screen
|
|
19
|
+
focusManager.setInitialFocus();
|
|
20
|
+
}
|
|
21
|
+
}, [previousIsScreenActive, isScreenActive]);
|
|
22
|
+
};
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import * as React from "react";
|
|
2
2
|
import { last } from "ramda";
|
|
3
|
-
import {
|
|
3
|
+
import { View, StyleSheet } from "react-native";
|
|
4
4
|
import {
|
|
5
5
|
findMenuPlugin,
|
|
6
6
|
getNavigationProps,
|
|
7
7
|
getPathAttributes,
|
|
8
8
|
} from "@applicaster/zapp-react-native-utils/navigationUtils";
|
|
9
|
-
import {
|
|
10
|
-
useIsScreenActive,
|
|
11
|
-
useNavigation,
|
|
12
|
-
} from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
9
|
+
import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
13
10
|
import { noop } from "@applicaster/zapp-react-native-utils/functionUtils";
|
|
14
11
|
import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
|
|
15
12
|
import {
|
|
@@ -20,10 +17,8 @@ import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/he
|
|
|
20
17
|
|
|
21
18
|
import { NavBarContainer } from "../../Layout/TV/NavBarContainer";
|
|
22
19
|
import { ScreenResolver } from "../../ScreenResolver";
|
|
23
|
-
import { useInitialFocus } from "./hooks";
|
|
20
|
+
import { useInitialFocus, useRestoreFocus } from "./hooks";
|
|
24
21
|
import { isPlayerPlugin } from "@applicaster/zapp-react-native-utils/pluginUtils";
|
|
25
|
-
import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils";
|
|
26
|
-
import { FreezeWithCallback } from "../../FreezeWithCallback";
|
|
27
22
|
|
|
28
23
|
const styles = StyleSheet.create({
|
|
29
24
|
container: {
|
|
@@ -108,6 +103,7 @@ export const Screen = ({ route, Components }: Props) => {
|
|
|
108
103
|
const backgroundColor = useScreenBackgroundColor(screenId);
|
|
109
104
|
|
|
110
105
|
useInitialFocus();
|
|
106
|
+
useRestoreFocus();
|
|
111
107
|
|
|
112
108
|
const activeRiver = getActiveRiver({
|
|
113
109
|
screenId,
|
|
@@ -149,30 +145,21 @@ export const Screen = ({ route, Components }: Props) => {
|
|
|
149
145
|
? routeState?.state?.entry
|
|
150
146
|
: routeState?.state?.screen;
|
|
151
147
|
|
|
152
|
-
const isScreenActive = useIsScreenActive();
|
|
153
|
-
|
|
154
148
|
return (
|
|
155
|
-
<
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
<View style={[styles.container, { backgroundColor }]}>
|
|
162
|
-
<NavBarContainer isVisible={isNavBarVisible} onReady={noop}>
|
|
163
|
-
<NavBar
|
|
164
|
-
isVisible={isNavBarVisible}
|
|
165
|
-
menuPlugin={menuPlugin}
|
|
166
|
-
navigationProps={navigationProps}
|
|
167
|
-
/>
|
|
168
|
-
</NavBarContainer>
|
|
169
|
-
<ScreenResolver
|
|
170
|
-
screenType={screenType}
|
|
171
|
-
screenId={screenId}
|
|
172
|
-
screenData={screenData}
|
|
173
|
-
groupId={route}
|
|
149
|
+
<View style={[styles.container, { backgroundColor }]}>
|
|
150
|
+
<NavBarContainer isVisible={isNavBarVisible} onReady={noop}>
|
|
151
|
+
<NavBar
|
|
152
|
+
isVisible={isNavBarVisible}
|
|
153
|
+
menuPlugin={menuPlugin}
|
|
154
|
+
navigationProps={navigationProps}
|
|
174
155
|
/>
|
|
175
|
-
</
|
|
176
|
-
|
|
156
|
+
</NavBarContainer>
|
|
157
|
+
<ScreenResolver
|
|
158
|
+
screenType={screenType}
|
|
159
|
+
screenId={screenId}
|
|
160
|
+
screenData={screenData}
|
|
161
|
+
groupId={route}
|
|
162
|
+
/>
|
|
163
|
+
</View>
|
|
177
164
|
);
|
|
178
165
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-ui-components",
|
|
3
|
-
"version": "12.0.0-alpha.
|
|
3
|
+
"version": "12.0.0-alpha.6393691216",
|
|
4
4
|
"description": "Applicaster Zapp React Native ui components for the Quick Brick App",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"redux-mock-store": "^1.5.3"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@applicaster/applicaster-types": "12.0.0-alpha.
|
|
38
|
-
"@applicaster/zapp-react-native-bridge": "12.0.0-alpha.
|
|
39
|
-
"@applicaster/zapp-react-native-redux": "12.0.0-alpha.
|
|
40
|
-
"@applicaster/zapp-react-native-utils": "12.0.0-alpha.
|
|
37
|
+
"@applicaster/applicaster-types": "12.0.0-alpha.6393691216",
|
|
38
|
+
"@applicaster/zapp-react-native-bridge": "12.0.0-alpha.6393691216",
|
|
39
|
+
"@applicaster/zapp-react-native-redux": "12.0.0-alpha.6393691216",
|
|
40
|
+
"@applicaster/zapp-react-native-utils": "12.0.0-alpha.6393691216",
|
|
41
41
|
"promise": "^8.3.0",
|
|
42
42
|
"react-router-native": "^5.1.2",
|
|
43
43
|
"url": "^0.11.0",
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
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.
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,170 +0,0 @@
|
|
|
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
|
-
});
|