@applicaster/zapp-react-native-ui-components 12.0.0-rc.117 → 12.0.0-rc.118
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/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/Screen/TV/hooks/index.ts +0 -2
- package/Components/Screen/TV/index.web.tsx +32 -19
- package/package.json +5 -5
- package/Components/Screen/TV/hooks/useRestoreFocus.ts +0 -22
|
@@ -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
|
+
});
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from "react";
|
|
2
2
|
import { last } from "ramda";
|
|
3
|
-
import {
|
|
3
|
+
import { StyleSheet, View } 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 {
|
|
9
|
+
import {
|
|
10
|
+
useIsScreenActive,
|
|
11
|
+
useNavigation,
|
|
12
|
+
} from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
10
13
|
import { noop } from "@applicaster/zapp-react-native-utils/functionUtils";
|
|
11
14
|
import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
|
|
12
15
|
import {
|
|
@@ -17,8 +20,10 @@ import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/he
|
|
|
17
20
|
|
|
18
21
|
import { NavBarContainer } from "../../Layout/TV/NavBarContainer";
|
|
19
22
|
import { ScreenResolver } from "../../ScreenResolver";
|
|
20
|
-
import { useInitialFocus
|
|
23
|
+
import { useInitialFocus } from "./hooks";
|
|
21
24
|
import { isPlayerPlugin } from "@applicaster/zapp-react-native-utils/pluginUtils";
|
|
25
|
+
import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils";
|
|
26
|
+
import { FreezeWithCallback } from "../../FreezeWithCallback";
|
|
22
27
|
|
|
23
28
|
const styles = StyleSheet.create({
|
|
24
29
|
container: {
|
|
@@ -103,7 +108,6 @@ export const Screen = ({ route, Components }: Props) => {
|
|
|
103
108
|
const backgroundColor = useScreenBackgroundColor(screenId);
|
|
104
109
|
|
|
105
110
|
useInitialFocus();
|
|
106
|
-
useRestoreFocus();
|
|
107
111
|
|
|
108
112
|
const activeRiver = getActiveRiver({
|
|
109
113
|
screenId,
|
|
@@ -145,21 +149,30 @@ export const Screen = ({ route, Components }: Props) => {
|
|
|
145
149
|
? routeState?.state?.entry
|
|
146
150
|
: routeState?.state?.screen;
|
|
147
151
|
|
|
152
|
+
const isScreenActive = useIsScreenActive();
|
|
153
|
+
|
|
148
154
|
return (
|
|
149
|
-
<
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
+
<FreezeWithCallback
|
|
156
|
+
freeze={!isScreenActive}
|
|
157
|
+
onRelease={() => {
|
|
158
|
+
focusManager.setInitialFocus();
|
|
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}
|
|
155
174
|
/>
|
|
156
|
-
</
|
|
157
|
-
|
|
158
|
-
screenType={screenType}
|
|
159
|
-
screenId={screenId}
|
|
160
|
-
screenData={screenData}
|
|
161
|
-
groupId={route}
|
|
162
|
-
/>
|
|
163
|
-
</View>
|
|
175
|
+
</View>
|
|
176
|
+
</FreezeWithCallback>
|
|
164
177
|
);
|
|
165
178
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-ui-components",
|
|
3
|
-
"version": "12.0.0-rc.
|
|
3
|
+
"version": "12.0.0-rc.118",
|
|
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-rc.
|
|
38
|
-
"@applicaster/zapp-react-native-bridge": "12.0.0-rc.
|
|
39
|
-
"@applicaster/zapp-react-native-redux": "12.0.0-rc.
|
|
40
|
-
"@applicaster/zapp-react-native-utils": "12.0.0-rc.
|
|
37
|
+
"@applicaster/applicaster-types": "12.0.0-rc.118",
|
|
38
|
+
"@applicaster/zapp-react-native-bridge": "12.0.0-rc.118",
|
|
39
|
+
"@applicaster/zapp-react-native-redux": "12.0.0-rc.118",
|
|
40
|
+
"@applicaster/zapp-react-native-utils": "12.0.0-rc.118",
|
|
41
41
|
"promise": "^8.3.0",
|
|
42
42
|
"react-router-native": "^5.1.2",
|
|
43
43
|
"url": "^0.11.0",
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
};
|