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

New chat page list refactor 2 #38610

Merged
merged 9 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
6 changes: 3 additions & 3 deletions src/components/SelectionList/InviteMemberListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
import BaseListItem from './BaseListItem';
import type {InviteMemberListItemProps} from './types';
import type {InviteMemberListItemProps, ListItem} from './types';

function InviteMemberListItem({
function InviteMemberListItem<TItem extends ListItem>({
item,
isFocused,
showTooltip,
Expand All @@ -26,7 +26,7 @@ function InviteMemberListItem({
onDismissError,
shouldPreventDefaultFocusOnSelectRow,
rightHandSideComponent,
}: InviteMemberListItemProps) {
}: InviteMemberListItemProps<TItem>) {
const styles = useThemeStyles();
const theme = useTheme();
const StyleUtils = useStyleUtils();
Expand Down
6 changes: 3 additions & 3 deletions src/components/SelectionList/RadioListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import TextWithTooltip from '@components/TextWithTooltip';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
import BaseListItem from './BaseListItem';
import type {RadioListItemProps} from './types';
import type {ListItem, RadioListItemProps} from './types';

function RadioListItem({
function RadioListItem<TItem extends ListItem>({
item,
isFocused,
showTooltip,
Expand All @@ -16,7 +16,7 @@ function RadioListItem({
shouldPreventDefaultFocusOnSelectRow,
rightHandSideComponent,
isMultilineSupported = false,
}: RadioListItemProps) {
}: RadioListItemProps<TItem>) {
const styles = useThemeStyles();
const fullTitle = isMultilineSupported ? item.text?.trimStart() : item.text;
const indentsLength = (item.text?.length ?? 0) - (fullTitle?.length ?? 0);
Expand Down
6 changes: 3 additions & 3 deletions src/components/SelectionList/TableListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
import BaseListItem from './BaseListItem';
import type {TableListItemProps} from './types';
import type {ListItem, TableListItemProps} from './types';

function TableListItem({
function TableListItem<TItem extends ListItem>({
item,
isFocused,
showTooltip,
Expand All @@ -23,7 +23,7 @@ function TableListItem({
onDismissError,
shouldPreventDefaultFocusOnSelectRow,
rightHandSideComponent,
}: TableListItemProps) {
}: TableListItemProps<TItem>) {
const styles = useThemeStyles();
const theme = useTheme();
const StyleUtils = useStyleUtils();
Expand Down
6 changes: 3 additions & 3 deletions src/components/SelectionList/UserListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
import BaseListItem from './BaseListItem';
import type {UserListItemProps} from './types';
import type {ListItem, UserListItemProps} from './types';

function UserListItem({
function UserListItem<TItem extends ListItem>({
item,
isFocused,
showTooltip,
Expand All @@ -27,7 +27,7 @@ function UserListItem({
onDismissError,
shouldPreventDefaultFocusOnSelectRow,
rightHandSideComponent,
}: UserListItemProps) {
}: UserListItemProps<TItem>) {
const styles = useThemeStyles();
const theme = useTheme();
const StyleUtils = useStyleUtils();
Expand Down
18 changes: 9 additions & 9 deletions src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type RadioListItem from './RadioListItem';
import type TableListItem from './TableListItem';
import type UserListItem from './UserListItem';

type CommonListItemProps<TItem> = {
type CommonListItemProps<TItem extends ListItem> = {
/** Whether this item is focused (for arrow key controls) */
isFocused?: boolean;

Expand Down Expand Up @@ -116,9 +116,9 @@ type ListItem = {
brickRoadIndicator?: BrickRoad | '' | null;
};

type ListItemProps = CommonListItemProps<ListItem> & {
type ListItemProps<TItem extends ListItem> = CommonListItemProps<TItem> & {
/** The section list item */
item: ListItem;
item: TItem;

/** Additional styles to apply to text */
style?: StyleProp<TextStyle>;
Expand All @@ -140,10 +140,10 @@ type BaseListItemProps<TItem extends ListItem> = CommonListItemProps<TItem> & {
errors?: Errors | ReceiptErrors | null;
pendingAction?: PendingAction | null;
FooterComponent?: ReactElement;
children?: ReactElement<ListItemProps> | ((hovered: boolean) => ReactElement<ListItemProps>);
children?: ReactElement<ListItemProps<TItem>> | ((hovered: boolean) => ReactElement<ListItemProps<TItem>>);
};

type UserListItemProps = ListItemProps & {
type UserListItemProps<TItem extends ListItem> = ListItemProps<TItem> & {
/** Errors that this user may contain */
errors?: Errors | ReceiptErrors | null;

Expand All @@ -154,11 +154,11 @@ type UserListItemProps = ListItemProps & {
FooterComponent?: ReactElement;
};

type InviteMemberListItemProps = UserListItemProps;
type InviteMemberListItemProps<TItem extends ListItem> = UserListItemProps<TItem>;

type RadioListItemProps = ListItemProps;
type RadioListItemProps<TItem extends ListItem> = ListItemProps<TItem>;

type TableListItemProps = ListItemProps;
type TableListItemProps<TItem extends ListItem> = ListItemProps<TItem>;

type ValidListItem = typeof RadioListItem | typeof UserListItem | typeof TableListItem | typeof InviteMemberListItem;

Expand Down Expand Up @@ -288,7 +288,7 @@ type BaseSelectionListProps<TItem extends ListItem> = Partial<ChildrenProps> & {
shouldDelayFocus?: boolean;

/** Component to display on the right side of each child */
rightHandSideComponent?: ((item: ListItem) => ReactElement<ListItem> | null) | ReactElement | null;
rightHandSideComponent?: ((item: TItem) => ReactElement<TItem> | null) | ReactElement | null;

/** Whether to show the loading indicator for new options */
isLoadingNewOptions?: boolean;
Expand Down
37 changes: 37 additions & 0 deletions src/hooks/useStyledSafeAreaInsets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// eslint-disable-next-line no-restricted-imports
import {useSafeAreaInsets} from 'react-native-safe-area-context';
import useStyleUtils from './useStyleUtils';

/**
* Custom hook to get the styled safe area insets.
* This hook utilizes the `SafeAreaInsetsContext` to retrieve the current safe area insets
* and applies styling adjustments using the `useStyleUtils` hook.
*
* @returns An object containing the styled safe area insets and additional styles.
* @returns .paddingTop The top padding adjusted for safe area.
* @returns .paddingBottom The bottom padding adjusted for safe area.
* @returns .insets The safe area insets object or undefined if not available.
* @returns .safeAreaPaddingBottomStyle An object containing the bottom padding style adjusted for safe area.
*
* @example
* // How to use this hook in a component
* function MyComponent() {
* const { paddingTop, paddingBottom, safeAreaPaddingBottomStyle } = useStyledSafeAreaInsets();
*
* // Use these values to style your component accordingly
* }
*/
function useStyledSafeAreaInsets() {
const StyleUtils = useStyleUtils();
const insets = useSafeAreaInsets();

const {paddingTop, paddingBottom} = StyleUtils.getSafeAreaPadding(insets ?? undefined);
return {
paddingTop,
paddingBottom,
insets: insets ?? undefined,
safeAreaPaddingBottomStyle: {paddingBottom},
};
}

export default useStyledSafeAreaInsets;
15 changes: 14 additions & 1 deletion src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2216,6 +2216,18 @@ function formatSectionsFromSearchTerm(
};
}

/**
* Helper method to get the `keyForList` for the first option in the OptionsList
*/
function getFirstKeyForList(data?: Option[] | null) {
if (!data?.length) {
return '';
}

const firstNonEmptyDataObj = data[0];

return firstNonEmptyDataObj.keyForList ? firstNonEmptyDataObj.keyForList : '';
}
/**
* Filters options based on the search input value
*/
Expand Down Expand Up @@ -2337,6 +2349,7 @@ export {
createOptionFromReport,
getReportOption,
getTaxRatesSection,
getFirstKeyForList,
};

export type {MemberForList, CategorySection, CategoryTreeSection, Options, OptionList, SearchOption, PayeePersonalDetails, Category, TaxRatesOption};
export type {MemberForList, CategorySection, CategoryTreeSection, Options, OptionList, SearchOption, PayeePersonalDetails, Category, TaxRatesOption, Option};
Loading
Loading