@applicaster/zapp-react-native-ui-components 16.0.0-rc.77 → 16.0.0-rc.79
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/ModalComponent/SortableList.web.tsx +2 -70
- package/Components/ModalComponent/__tests__/SortableList.web.test.tsx +16 -0
- package/Components/ScreenRevealManager/ScreenRevealManager.ts +18 -2
- package/Components/ScreenRevealManager/__tests__/ScreenRevealManager.test.ts +36 -0
- package/Components/ScreenRevealManager/__tests__/withScreenRevealManager.test.tsx +56 -0
- package/Components/ScreenRevealManager/withScreenRevealManager.tsx +20 -3
- package/package.json +5 -5
|
@@ -1,37 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
const DEFAULT_HEADERS: any[] = [];
|
|
5
|
-
const DEFAULT_SORTABLE_DATA: any[] = [];
|
|
6
|
-
|
|
7
|
-
const renderHeaderComponent = (component: any) => {
|
|
8
|
-
if (!component) return null;
|
|
9
|
-
if (React.isValidElement(component)) return component;
|
|
10
|
-
|
|
11
|
-
if (typeof component === "function") {
|
|
12
|
-
const HeaderComponent = component;
|
|
13
|
-
|
|
14
|
-
return <HeaderComponent />;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return null;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const SortableListHeader = ({
|
|
21
|
-
title,
|
|
22
|
-
style,
|
|
23
|
-
}: {
|
|
24
|
-
title?: string;
|
|
25
|
-
style?: ViewStyle;
|
|
26
|
-
}) => {
|
|
27
|
-
const displayTitle = typeof title === "string" ? title : String(title ?? "");
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<View style={style}>
|
|
31
|
-
{displayTitle ? <Text>{displayTitle}</Text> : null}
|
|
32
|
-
</View>
|
|
33
|
-
);
|
|
34
|
-
};
|
|
2
|
+
import type { ViewStyle } from "react-native";
|
|
35
3
|
|
|
36
4
|
export type SortableListProps = {
|
|
37
5
|
scrollViewStyle?: ViewStyle;
|
|
@@ -63,40 +31,4 @@ export type SortableListProps = {
|
|
|
63
31
|
}) => void;
|
|
64
32
|
};
|
|
65
33
|
|
|
66
|
-
export const SortableList = (
|
|
67
|
-
scrollViewStyle,
|
|
68
|
-
contentContainerStyle,
|
|
69
|
-
itemStyle,
|
|
70
|
-
headerStyle,
|
|
71
|
-
keyExtractor = (item, index) =>
|
|
72
|
-
`sortable-item-${item?.id ?? item?.title ?? index}`,
|
|
73
|
-
renderItem,
|
|
74
|
-
sortableData = DEFAULT_SORTABLE_DATA,
|
|
75
|
-
headers = DEFAULT_HEADERS,
|
|
76
|
-
}: SortableListProps) => {
|
|
77
|
-
return (
|
|
78
|
-
<ScrollView
|
|
79
|
-
style={scrollViewStyle}
|
|
80
|
-
contentContainerStyle={contentContainerStyle}
|
|
81
|
-
>
|
|
82
|
-
{(headers || []).map((header, idx) => (
|
|
83
|
-
<View key={`static-header-${idx}`} style={headerStyle}>
|
|
84
|
-
{header.title ? (
|
|
85
|
-
<SortableListHeader title={header.title} />
|
|
86
|
-
) : (
|
|
87
|
-
renderHeaderComponent(header.component)
|
|
88
|
-
)}
|
|
89
|
-
</View>
|
|
90
|
-
))}
|
|
91
|
-
{(sortableData || []).map((item, index) => (
|
|
92
|
-
<View key={keyExtractor(item, index)} style={itemStyle}>
|
|
93
|
-
{renderItem({
|
|
94
|
-
item,
|
|
95
|
-
index,
|
|
96
|
-
renderHandle: (children) => children,
|
|
97
|
-
})}
|
|
98
|
-
</View>
|
|
99
|
-
))}
|
|
100
|
-
</ScrollView>
|
|
101
|
-
);
|
|
102
|
-
};
|
|
34
|
+
export const SortableList = (_props: SortableListProps) => null;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@testing-library/react-native";
|
|
3
|
+
import { SortableList } from "../SortableList.web";
|
|
4
|
+
|
|
5
|
+
describe("SortableList.web", () => {
|
|
6
|
+
it("renders nothing", () => {
|
|
7
|
+
const { toJSON } = render(
|
|
8
|
+
<SortableList
|
|
9
|
+
renderItem={() => null}
|
|
10
|
+
sortableData={[{ id: "1", title: "Track 1" }]}
|
|
11
|
+
/>
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
expect(toJSON()).toBeNull();
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -42,9 +42,25 @@ export class ScreenRevealManager {
|
|
|
42
42
|
private subject$ = new Subject<void>();
|
|
43
43
|
private subscription: Subscription;
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
/**
|
|
46
|
+
* @param initialNumberToLoad how many components to wait for before revealing
|
|
47
|
+
* the screen. Staggering exists so a screen full of network-backed components
|
|
48
|
+
* does not load them all at once. A caller that has nothing to stagger - see
|
|
49
|
+
* `disableIncrementalLoading` on the HOC - passes the full count here so the
|
|
50
|
+
* reveal waits for exactly what gets rendered. Omitted, the count is derived
|
|
51
|
+
* from the components themselves.
|
|
52
|
+
*/
|
|
53
|
+
constructor(
|
|
54
|
+
componentsToRender: ZappUIComponent[],
|
|
55
|
+
callback: Callback,
|
|
56
|
+
initialNumberToLoad?: number
|
|
57
|
+
) {
|
|
46
58
|
this.numberOfComponentsWaitToLoadBeforePresent =
|
|
47
|
-
|
|
59
|
+
initialNumberToLoad == null
|
|
60
|
+
? getNumberOfComponentsWaitToLoadBeforePresent(componentsToRender)
|
|
61
|
+
: // Clamped like the computed path: waiting for components that do not
|
|
62
|
+
// exist would hold the screen behind its overlay until the timeout.
|
|
63
|
+
Math.min(initialNumberToLoad, componentsToRender.length);
|
|
48
64
|
|
|
49
65
|
this.renderingState = makeListOf<ComponentLoadingState>(
|
|
50
66
|
COMPONENT_LOADING_STATE.UNKNOWN,
|
|
@@ -22,6 +22,42 @@ import { makeListOf } from "@applicaster/zapp-react-native-utils/arrayUtils";
|
|
|
22
22
|
import { isFirstComponentGallery } from "@applicaster/zapp-react-native-utils/componentsUtils";
|
|
23
23
|
import { withTimeout$ } from "@applicaster/zapp-react-native-utils/idleUtils";
|
|
24
24
|
|
|
25
|
+
describe("ScreenRevealManager explicit component count", () => {
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
(isFirstComponentGallery as jest.Mock).mockReturnValue(false);
|
|
28
|
+
|
|
29
|
+
(makeListOf as jest.Mock).mockImplementation((value, length) =>
|
|
30
|
+
Array(length).fill(value)
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
(withTimeout$ as jest.Mock).mockReturnValue(new Subject());
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("waits for the number of components it is given, not the computed default", () => {
|
|
37
|
+
const components = Array(6).fill({}) as any;
|
|
38
|
+
|
|
39
|
+
const manager = new ScreenRevealManager(components, jest.fn(), 6);
|
|
40
|
+
|
|
41
|
+
expect(manager.numberOfComponentsWaitToLoadBeforePresent).toBe(6);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("never waits for more components than it was handed", () => {
|
|
45
|
+
const components = Array(3).fill({}) as any;
|
|
46
|
+
|
|
47
|
+
const manager = new ScreenRevealManager(components, jest.fn(), 10);
|
|
48
|
+
|
|
49
|
+
expect(manager.numberOfComponentsWaitToLoadBeforePresent).toBe(3);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("falls back to the computed default when given no explicit count", () => {
|
|
53
|
+
const components = Array(6).fill({}) as any;
|
|
54
|
+
|
|
55
|
+
const manager = new ScreenRevealManager(components, jest.fn());
|
|
56
|
+
|
|
57
|
+
expect(manager.numberOfComponentsWaitToLoadBeforePresent).toBe(3);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
25
61
|
describe("ScreenRevealManager", () => {
|
|
26
62
|
let mockCallback: jest.Mock;
|
|
27
63
|
let timeout$: Subject<void>;
|
|
@@ -9,6 +9,12 @@ import {
|
|
|
9
9
|
TIMEOUT,
|
|
10
10
|
} from "../withScreenRevealManager";
|
|
11
11
|
|
|
12
|
+
jest.mock("@applicaster/zapp-react-native-utils/theme", () => ({
|
|
13
|
+
useTheme: () => ({ app_background_color: "#000000" }),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
jest.mock("../Overlay", () => ({ Overlay: () => null }));
|
|
17
|
+
|
|
12
18
|
// jest.mock("react-native/Libraries/Animated/NativeAnimatedHelper");
|
|
13
19
|
|
|
14
20
|
const MockComponent = ({
|
|
@@ -37,6 +43,56 @@ const MockComponent = ({
|
|
|
37
43
|
|
|
38
44
|
const WrappedComponent = withScreenRevealManager(MockComponent);
|
|
39
45
|
|
|
46
|
+
describe("withScreenRevealManager disableIncrementalLoading", () => {
|
|
47
|
+
const components = (count: number) =>
|
|
48
|
+
Array(count).fill({ component_type: "grid-qb" });
|
|
49
|
+
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
jest.clearAllMocks();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("asks for every component at once when incremental loading is disabled", () => {
|
|
55
|
+
render(
|
|
56
|
+
<WrappedComponent
|
|
57
|
+
componentsToRender={components(6)}
|
|
58
|
+
disableIncrementalLoading
|
|
59
|
+
/>
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
expect(screen.getByTestId("mock-component").props.initialNumberToLoad).toBe(
|
|
63
|
+
6
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("still tracks the component count after it changes", () => {
|
|
68
|
+
const { rerender } = render(
|
|
69
|
+
<WrappedComponent
|
|
70
|
+
componentsToRender={components(6)}
|
|
71
|
+
disableIncrementalLoading
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
rerender(
|
|
76
|
+
<WrappedComponent
|
|
77
|
+
componentsToRender={components(9)}
|
|
78
|
+
disableIncrementalLoading
|
|
79
|
+
/>
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
expect(screen.getByTestId("mock-component").props.initialNumberToLoad).toBe(
|
|
83
|
+
9
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("loads incrementally when the flag is not set", () => {
|
|
88
|
+
render(<WrappedComponent componentsToRender={components(6)} />);
|
|
89
|
+
|
|
90
|
+
expect(screen.getByTestId("mock-component").props.initialNumberToLoad).toBe(
|
|
91
|
+
3
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
40
96
|
describe.skip("withScreenRevealManager", () => {
|
|
41
97
|
beforeEach(() => {
|
|
42
98
|
jest.clearAllMocks();
|
|
@@ -21,11 +21,23 @@ export const SHOWN = 1; // opacity = 1
|
|
|
21
21
|
type Props = {
|
|
22
22
|
componentsToRender: ZappUIComponent[];
|
|
23
23
|
backgroundColor?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Renders every component at once instead of revealing them a few at a time.
|
|
26
|
+
*
|
|
27
|
+
* For a screen that builds its own components and holds all of them already -
|
|
28
|
+
* a form, say - staggering buys nothing and costs: each rebuild of the list
|
|
29
|
+
* tears it back down to the first few and lets the rest crawl in again.
|
|
30
|
+
*
|
|
31
|
+
* This is a flag rather than a count on purpose. A count would have to be
|
|
32
|
+
* re-read whenever the number of components changes, while "do not stagger"
|
|
33
|
+
* stays true whatever the screen ends up holding.
|
|
34
|
+
*/
|
|
35
|
+
disableIncrementalLoading?: boolean;
|
|
24
36
|
};
|
|
25
37
|
|
|
26
38
|
export const withScreenRevealManager = (Component) => {
|
|
27
39
|
return function WithScreenRevealManager(props: Props) {
|
|
28
|
-
const { componentsToRender } = props;
|
|
40
|
+
const { componentsToRender, disableIncrementalLoading } = props;
|
|
29
41
|
|
|
30
42
|
const [isContentReadyToBeShown, setIsContentReadyToBeShown] =
|
|
31
43
|
React.useState(false);
|
|
@@ -42,7 +54,8 @@ export const withScreenRevealManager = (Component) => {
|
|
|
42
54
|
() =>
|
|
43
55
|
new ScreenRevealManager(
|
|
44
56
|
componentsToRender,
|
|
45
|
-
handleSetIsContentReadyToBeShown
|
|
57
|
+
handleSetIsContentReadyToBeShown,
|
|
58
|
+
disableIncrementalLoading ? componentsToRender.length : undefined
|
|
46
59
|
)
|
|
47
60
|
);
|
|
48
61
|
|
|
@@ -80,7 +93,11 @@ export const withScreenRevealManager = (Component) => {
|
|
|
80
93
|
<Component
|
|
81
94
|
{...props}
|
|
82
95
|
initialNumberToLoad={
|
|
83
|
-
|
|
96
|
+
// Recomputed on every render, so the count follows the components
|
|
97
|
+
// even though the manager settled its own expectation at mount.
|
|
98
|
+
disableIncrementalLoading
|
|
99
|
+
? componentsToRender.length
|
|
100
|
+
: managerRef.current.numberOfComponentsWaitToLoadBeforePresent
|
|
84
101
|
}
|
|
85
102
|
onLoadFinishedFromScreenRevealManager={
|
|
86
103
|
managerRef.current.onLoadFinished
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-ui-components",
|
|
3
|
-
"version": "16.0.0-rc.
|
|
3
|
+
"version": "16.0.0-rc.79",
|
|
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",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/applicaster-types": "16.0.0-rc.
|
|
32
|
-
"@applicaster/zapp-react-native-bridge": "16.0.0-rc.
|
|
33
|
-
"@applicaster/zapp-react-native-redux": "16.0.0-rc.
|
|
34
|
-
"@applicaster/zapp-react-native-utils": "16.0.0-rc.
|
|
31
|
+
"@applicaster/applicaster-types": "16.0.0-rc.79",
|
|
32
|
+
"@applicaster/zapp-react-native-bridge": "16.0.0-rc.79",
|
|
33
|
+
"@applicaster/zapp-react-native-redux": "16.0.0-rc.79",
|
|
34
|
+
"@applicaster/zapp-react-native-utils": "16.0.0-rc.79",
|
|
35
35
|
"fast-json-stable-stringify": "^2.1.0",
|
|
36
36
|
"promise": "^8.3.0",
|
|
37
37
|
"react-native-sortables": "1.7.1",
|