Skip to content

Commit

Permalink
[TS migration] Migrate 'SectionList' component to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
BartoszGrajdek committed Oct 19, 2023
1 parent a0def82 commit 5454bde
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
34 changes: 18 additions & 16 deletions src/components/SectionList/index.android.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import React, {ForwardedRef, forwardRef} from 'react';
import {SectionListProps, SectionList} from 'react-native';
import React, {forwardRef} from 'react';
import {SectionList as RNSectionList} from 'react-native';
import ForwardedSectionList from './types';

function SectionListWithoutSubviews(props: SectionListProps<SectionList>, ref: ForwardedRef<SectionList>) {
return (
<SectionList
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={ref}
// For Android we want to use removeClippedSubviews since it helps manage memory consumption. When we
// run out memory images stop loading and appear as grey circles
// eslint-disable-next-line react/jsx-props-no-multi-spaces
removeClippedSubviews
/>
);
}
// eslint-disable-next-line react/function-component-definition
const SectionList: ForwardedSectionList = (props, ref) => (
<RNSectionList
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={ref}
// For Android we want to use removeClippedSubviews since it helps manage memory consumption. When we
// run out memory images stop loading and appear as grey circles
// eslint-disable-next-line react/jsx-props-no-multi-spaces
removeClippedSubviews
/>
);

export default forwardRef(SectionListWithoutSubviews);
SectionList.displayName = 'SectionList';

export default forwardRef(SectionList);
17 changes: 15 additions & 2 deletions src/components/SectionList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
import {SectionList} from 'react-native';
import React, {forwardRef} from 'react';
import {SectionList as RNSectionList} from 'react-native';
import ForwardedSectionList from './types';

export default SectionList;
// eslint-disable-next-line react/function-component-definition
const SectionList: ForwardedSectionList = (props, ref) => (
<RNSectionList
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={ref}
/>
);

SectionList.displayName = 'SectionList';

export default forwardRef(SectionList);
9 changes: 9 additions & 0 deletions src/components/SectionList/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {ForwardedRef} from 'react';
import {SectionList, SectionListProps} from 'react-native';

type ForwardedSectionList = {
(props: SectionListProps<SectionList>, ref: ForwardedRef<SectionList>): React.ReactNode;
displayName: string;
};

export default ForwardedSectionList;

0 comments on commit 5454bde

Please sign in to comment.