Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS migration] Migrate 'SelectionList' component to TypeScript #34008

Merged
merged 32 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9080382
migrate everything that is possible at the moment
SzymczakJ Dec 21, 2023
0286975
Merge branch 'main' into @szymczak/SelectionList
filip-solecki Jan 2, 2024
ccf6799
Merge branch 'main' into @szymczak/SelectionList
filip-solecki Jan 3, 2024
609b1d6
Merge branch 'main' into @szymczak/SelectionList
filip-solecki Jan 4, 2024
8e42f27
Finish SelectionList migration
filip-solecki Jan 4, 2024
49876fc
Fix disabled prop
filip-solecki Jan 5, 2024
8407cd5
Merge branch 'main' into @szymczak/SelectionList
filip-solecki Jan 5, 2024
15bc6e4
Merge branch 'main' into @szymczak/SelectionList
filip-solecki Jan 5, 2024
cc38c94
CR fixes
filip-solecki Jan 5, 2024
1e5f8fa
Merge branch 'main' into @szymczak/SelectionList
filip-solecki Jan 9, 2024
35e32da
CR fixes
filip-solecki Jan 9, 2024
af6f16d
Remove Boolean usage
filip-solecki Jan 9, 2024
376a9eb
Revert netiveID
filip-solecki Jan 9, 2024
da3b58d
Remove last Boolean usage
filip-solecki Jan 9, 2024
1335606
Fix isUserItem check
filip-solecki Jan 9, 2024
92d185c
Fix failing TS check
filip-solecki Jan 9, 2024
f558520
Fixes after CR
filip-solecki Jan 9, 2024
f5e7e0c
Merge branch 'main' into @szymczak/SelectionList
filip-solecki Jan 10, 2024
4948e7c
Merge branch 'main' into @szymczak/SelectionList
filip-solecki Jan 10, 2024
882157b
Merge branch 'main' into @szymczak/SelectionList
filip-solecki Jan 11, 2024
120a02e
Extend SelectionList types
filip-solecki Jan 11, 2024
7beb4dc
Improvements after review
filip-solecki Jan 11, 2024
c9970e4
Make SelectionList Generic component
filip-solecki Jan 11, 2024
cdf56a9
Fix TextInput focus
filip-solecki Jan 11, 2024
83a001e
Merge branch 'main' into @szymczak/SelectionList
filip-solecki Jan 11, 2024
34d8b4f
Extend type after main marge
filip-solecki Jan 11, 2024
c83e106
Fix type error
filip-solecki Jan 11, 2024
ab1cb39
Merge branch 'main' into @szymczak/SelectionList
filip-solecki Jan 14, 2024
364da34
Merge branch 'main' into @szymczak/SelectionList
filip-solecki Jan 17, 2024
275ef32
Remove developer comments
filip-solecki Jan 17, 2024
e030135
Add props description
filip-solecki Jan 17, 2024
7d65ede
Add props descriptions
filip-solecki Jan 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions src/components/SectionList/index.android.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import React, {forwardRef} from 'react';
import type {ForwardedRef} from 'react';
import {SectionList as RNSectionList} from 'react-native';
import type ForwardedSectionList from './types';
import type {SectionListProps} from 'react-native';

// eslint-disable-next-line react/function-component-definition
const SectionListWithRef: 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
/>
);
function SectionListWithRef<ItemT, SectionT>(props: SectionListProps<ItemT, SectionT>, ref: ForwardedRef<RNSectionList<ItemT, SectionT>>) {
return (
<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
/>
);
}

SectionListWithRef.displayName = 'SectionListWithRef';

Expand Down
21 changes: 11 additions & 10 deletions src/components/SectionList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React, {forwardRef} from 'react';
import type {ForwardedRef} from 'react';
import {SectionList as RNSectionList} from 'react-native';
import type ForwardedSectionList from './types';
import type {SectionListProps} from 'react-native';

// 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';
function SectionList<ItemT, SectionT>(props: SectionListProps<ItemT, SectionT>, ref: ForwardedRef<RNSectionList<ItemT, SectionT>>) {
return (
<RNSectionList
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={ref}
/>
);
}

export default forwardRef(SectionList);
9 changes: 0 additions & 9 deletions src/components/SectionList/types.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import lodashGet from 'lodash/get';
import React from 'react';
import {View} from 'react-native';
import Icon from '@components/Icon';
Expand All @@ -12,10 +11,10 @@ import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
import RadioListItem from './RadioListItem';
import {baseListItemPropTypes} from './selectionListPropTypes';
import type {BaseListItemProps, RadioItem, User} from './types';
import UserListItem from './UserListItem';

function BaseListItem({
function BaseListItem<TItem extends User | RadioItem>({
item,
isFocused = false,
isDisabled = false,
Expand All @@ -26,13 +25,12 @@ function BaseListItem({
onDismissError = () => {},
rightHandSideComponent,
keyForList,
}) {
}: BaseListItemProps<TItem>) {
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
const isUserItem = lodashGet(item, 'icons.length', 0) > 0;
const ListItem = isUserItem ? UserListItem : RadioListItem;
const isRadioItem = item.rightElement === undefined;

filip-solecki marked this conversation as resolved.
Show resolved Hide resolved
const rightHandSideComponentRender = () => {
if (canSelectMultiple || !rightHandSideComponent) {
Expand Down Expand Up @@ -70,7 +68,7 @@ function BaseListItem({
styles.justifyContentBetween,
styles.sidebarLinkInner,
styles.userSelectNone,
isUserItem ? styles.peopleRow : styles.optionRow,
isRadioItem ? styles.optionRow : styles.peopleRow,
isFocused && styles.sidebarLinkActive,
]}
>
Expand Down Expand Up @@ -100,20 +98,38 @@ function BaseListItem({
</View>
</View>
)}
<ListItem
item={item}
textStyles={[
styles.optionDisplayName,
isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText,
isUserItem || item.isSelected || item.alternateText ? styles.sidebarLinkTextBold : null,
styles.pre,
item.alternateText ? styles.mb1 : null,
]}
alternateTextStyles={[styles.optionAlternateText, styles.textLabelSupporting, isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText, styles.pre]}
isDisabled={isDisabled}
onSelectRow={onSelectRow}
showTooltip={showTooltip}
/>

{isRadioItem ? (
<RadioListItem
item={item}
textStyles={[
styles.optionDisplayName,
isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText,
item.isSelected ?? item.alternateText ? styles.sidebarLinkTextBold : null,
styles.pre,
item.alternateText ? styles.mb1 : null,
]}
alternateTextStyles={[styles.optionAlternateText, styles.textLabelSupporting, isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText, styles.pre]}
isDisabled={isDisabled}
onSelectRow={() => onSelectRow(item)}
showTooltip={showTooltip}
/>
) : (
<UserListItem
item={item}
textStyles={[
styles.optionDisplayName,
isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText,
styles.sidebarLinkTextBold,
styles.pre,
item.alternateText ? styles.mb1 : null,
]}
alternateTextStyles={[styles.optionAlternateText, styles.textLabelSupporting, isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText, styles.pre]}
isDisabled={isDisabled}
onSelectRow={() => onSelectRow(item)}
showTooltip={showTooltip}
/>
)}
{!canSelectMultiple && item.isSelected && !rightHandSideComponent && (
<View
style={[styles.flexRow, styles.alignItemsCenter, styles.ml3]}
Expand All @@ -129,7 +145,7 @@ function BaseListItem({
)}
{rightHandSideComponentRender()}
</View>
{Boolean(item.invitedSecondaryLogin) && (
{!!item.invitedSecondaryLogin && (
<Text style={[styles.ml9, styles.ph5, styles.pb3, styles.textLabelSupporting]}>
{translate('workspace.people.invitedBySecondaryLogin', {secondaryLogin: item.invitedSecondaryLogin})}
</Text>
Expand All @@ -140,6 +156,5 @@ function BaseListItem({
}

BaseListItem.displayName = 'BaseListItem';
BaseListItem.propTypes = baseListItemPropTypes;

export default BaseListItem;
Loading
Loading