Skip to content

Commit 511f263

Browse files
Show provider content again on Android TV (#45)
* Show provider content again on Android TV #43 set removeClippedSubviews={false} on the content browser list but not on the loading skeleton list. React reuses the skeleton's native list for the real one, and flipping the flag on it drops every tile, so every provider showed an empty grid. Set it on both lists so it never changes. * Pin removeClippedSubviews=false on both content browser lists --------- Co-authored-by: Charlie Carson <charlie@churchapps.org>
1 parent 1fa8828 commit 511f263

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

‎src/screens/ContentBrowserScreen.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ export const ContentBrowserScreen = (props: Props) => {
446446
<FlatList
447447
data={skeletonData}
448448
numColumns={3}
449+
// Must match the real list below: React reuses this native list, and flipping the flag on it drops every tile.
450+
removeClippedSubviews={false}
449451
keyExtractor={item => item.id}
450452
renderItem={() => (
451453
<View style={{ ...styles.item, padding: 10 }}>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Render ContentBrowserScreen as a plain function call with hooks stubbed, then check the FlatList it mounts.
2+
// React reuses the skeleton's native list for the real one, so both must pin removeClippedSubviews to false:
3+
// leaving it undefined (Android's default) and flipping it later drops every tile on Android TV.
4+
let mockState: any[] = [];
5+
jest.mock("react", () => {
6+
const actual = jest.requireActual("react");
7+
let call = 0;
8+
return {
9+
...actual,
10+
useState: (init: any) => {
11+
const value = call < mockState.length ? mockState[call] : init;
12+
call++;
13+
return [value, () => {}];
14+
},
15+
useRef: (init: any) => ({ current: init }),
16+
useEffect: () => {},
17+
__resetCalls: () => { call = 0; }
18+
};
19+
});
20+
jest.mock("react-native", () => ({
21+
Dimensions: { get: () => ({ width: 1920, height: 1080 }), addEventListener: () => ({ remove: () => {} }) },
22+
Platform: { OS: "android", isTV: true, select: (o: any) => o.android ?? o.default },
23+
StyleSheet: { create: (s: any) => s, flatten: (s: any) => s },
24+
ActivityIndicator: "ActivityIndicator",
25+
Image: "Image",
26+
View: "View",
27+
FlatList: "FlatList",
28+
Text: "Text",
29+
TouchableHighlight: "TouchableHighlight",
30+
BackHandler: { addEventListener: () => ({ remove: () => {} }) }
31+
}));
32+
jest.mock("react-i18next", () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
33+
jest.mock("react-native-vector-icons/MaterialIcons", () => "Icon");
34+
jest.mock("react-native-svg", () => ({ SvgUri: "SvgUri" }));
35+
jest.mock("../../helpers", () => {
36+
const styles = jest.requireActual("../../helpers/Styles");
37+
return {
38+
Styles: styles.Styles,
39+
Colors: styles.Colors,
40+
Typography: styles.Typography,
41+
CachedData: { lastFocusedIndex: {}, savedFocusIndex: () => undefined },
42+
ProviderAuthHelper: {},
43+
ProviderSettingsHelper: {},
44+
AnnouncementsHelper: {}
45+
};
46+
});
47+
jest.mock("../../components", () => ({ MenuHeader: "MenuHeader", SkeletonCard: "SkeletonCard", EmptyState: "EmptyState" }));
48+
jest.mock("../../providers", () => ({ getProvider: () => ({ name: "Test Provider", logos: { dark: "" } }) }));
49+
50+
import React from "react";
51+
import { ContentBrowserScreen } from "../ContentBrowserScreen";
52+
53+
function findType(node: any, type: string): any {
54+
if (!node || typeof node !== "object") return null;
55+
if (Array.isArray(node)) { for (const n of node) { const f = findType(n, type); if (f) return f; } return null; }
56+
if (node.type === type) return node;
57+
return findType(node.props?.children, type);
58+
}
59+
60+
function render(state: any[]) {
61+
mockState = state;
62+
(React as any).__resetCalls();
63+
return ContentBrowserScreen({ navigateTo: () => {}, sidebarState: () => {}, providerId: "test" }) as any;
64+
}
65+
66+
describe("ContentBrowserScreen list on Android TV", () => {
67+
it("mounts the skeleton list with subview clipping off", () => {
68+
const list = findType(render([]), "FlatList");
69+
expect(list.props.data[0].id).toBe("skeleton-0");
70+
expect(list.props.removeClippedSubviews).toBe(false);
71+
});
72+
73+
it("keeps subview clipping off once the items load", () => {
74+
const items = [{ type: "folder", id: "f1", title: "Folder 1", path: "/f1" }];
75+
const list = findType(render([items, false]), "FlatList");
76+
expect(list.props.data).toBe(items);
77+
expect(list.props.removeClippedSubviews).toBe(false);
78+
});
79+
});

0 commit comments

Comments
 (0)