Skip to content
Source
Sign inSign up
Open History to see the last commit

require-registered-list-scroll.ts

40 lines1.5 KB

1import { defineRule } from "@oxlint/plugins";
2​
3// LegendList takes a render function; KeyboardAwareLegendList takes the component itself.
4const SCROLL_COMPONENT_PROP: Readonly<Record<string, string>> = {
5 LegendList: "renderScrollComponent",
6 AnimatedLegendList: "renderScrollComponent",
7 KeyboardAwareLegendList: "ScrollViewComponent",
8};
9​
10// A screen's list must scroll in a scroll view registered with its header, or the header loses
11// its scroll-edge blur (and, on the iPhone Duo, the blur's reach under the vertical bar).
12export default defineRule({
13 meta: {
14 type: "problem",
15 docs: {
16 description:
17 "Require mobile lists to render through a header-registered scroll view (renderScrollComponent).",
18 },
19 },
20 create(context) {
21 return {
22 JSXOpeningElement(node) {
23 if (node.name.type !== "JSXIdentifier") return;
24 const prop = SCROLL_COMPONENT_PROP[node.name.name];
25 if (!prop) return;
26 const registered = node.attributes.some(
27 (attribute) =>
28 attribute.type === "JSXAttribute" &&
29 attribute.name.type === "JSXIdentifier" &&
30 attribute.name.name === prop,
31 );
32 if (registered) return;
33 context.report({
34 node,
35 message: `Pass ${prop} so the list scrolls in a header-registered scroll view: NativeScrollView on iOS, or a component wrapping NativeScrollViewMarker. A list nested in another scroll surface or sheet can suppress this with a reason.`,
36 });
37 },
38 };
39 },
40});