-
Notifications
You must be signed in to change notification settings - Fork 3.2k
#35712 selection list refactor #37000
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
Merged
luacmartins
merged 21 commits into
Expensify:main
from
burczu:refactor/35712-selection-list-refactor
Feb 21, 2024
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0348111
render item prop exposed
burczu 9b44d95
render item prop handled where selection list used
burczu bc397c3
list item definition extracted from base list item
burczu 65abacf
list item styling moved to specific list style elements instead of ba…
burczu 1551fac
base list items used by specific list elements instead coupling with …
burczu eba4f51
prettier and lint fixes
burczu 5fdb270
type mismatch fixed
burczu 277e565
ability to use children explicitly added
burczu ed67986
wrapper and select multiple styles exposed outside the base list item
burczu d64e8a1
prettier fixes applied
burczu c4a621b
switched from renderItem to ListItem prop
burczu 7697efc
used correct ListItem in all the confusing places
burczu 9fbf025
Merge branch 'main' into refactor/35712-selection-list-refactor
burczu 909ae4d
selection list performance test fixed
burczu 66ba2dd
prettier fixed
burczu 432a450
unnecessary commented code removed
burczu 742d5f2
allowing only expected types as ListItem
burczu 24ff7de
prettier, one more time
burczu caeed9a
user specific props added
burczu 01d08cd
common styles extracted to StyleUtils
burczu 45fd85b
missing comment added
burczu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,61 +2,107 @@ import React from 'react'; | |
import {View} from 'react-native'; | ||
import MultipleAvatars from '@components/MultipleAvatars'; | ||
import SubscriptAvatar from '@components/SubscriptAvatar'; | ||
import Text from '@components/Text'; | ||
import TextWithTooltip from '@components/TextWithTooltip'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useStyleUtils from '@hooks/useStyleUtils'; | ||
import useTheme from '@hooks/useTheme'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import type {ListItemProps} from './types'; | ||
import BaseListItem from './BaseListItem'; | ||
import type {UserListItemProps} from './types'; | ||
|
||
function UserListItem({item, textStyles, alternateTextStyles, showTooltip, style, isFocused, isHovered}: ListItemProps) { | ||
function UserListItem({ | ||
item, | ||
isFocused, | ||
showTooltip, | ||
isDisabled, | ||
canSelectMultiple, | ||
onSelectRow, | ||
onDismissError, | ||
shouldPreventDefaultFocusOnSelectRow, | ||
rightHandSideComponent, | ||
}: UserListItemProps) { | ||
const styles = useThemeStyles(); | ||
const theme = useTheme(); | ||
const StyleUtils = useStyleUtils(); | ||
const {translate} = useLocalize(); | ||
|
||
const focusedBackgroundColor = styles.sidebarLinkActive.backgroundColor; | ||
const subscriptAvatarBorderColor = isFocused ? focusedBackgroundColor : theme.sidebar; | ||
const hoveredBackgroundColor = !!styles.sidebarLinkHover && 'backgroundColor' in styles.sidebarLinkHover ? styles.sidebarLinkHover.backgroundColor : theme.sidebar; | ||
|
||
return ( | ||
<> | ||
{!!item.icons && ( | ||
<BaseListItem | ||
item={item} | ||
wrapperStyle={[styles.flex1, styles.justifyContentBetween, styles.sidebarLinkInner, styles.userSelectNone, styles.peopleRow, isFocused && styles.sidebarLinkActive]} | ||
selectMultipleStyle={[StyleUtils.getCheckboxContainerStyle(20), StyleUtils.getMultiselectListStyles(!!item.isSelected, !!item.isDisabled)]} | ||
isFocused={isFocused} | ||
isDisabled={isDisabled} | ||
showTooltip={showTooltip} | ||
canSelectMultiple={canSelectMultiple} | ||
onSelectRow={onSelectRow} | ||
onDismissError={onDismissError} | ||
shouldPreventDefaultFocusOnSelectRow={shouldPreventDefaultFocusOnSelectRow} | ||
rightHandSideComponent={rightHandSideComponent} | ||
errors={item.errors} | ||
pendingAction={item.pendingAction} | ||
FooterComponent={ | ||
item.invitedSecondaryLogin ? ( | ||
<Text style={[styles.ml9, styles.ph5, styles.pb3, styles.textLabelSupporting]}> | ||
{translate('workspace.people.invitedBySecondaryLogin', {secondaryLogin: item.invitedSecondaryLogin})} | ||
</Text> | ||
) : undefined | ||
} | ||
keyForList={item.keyForList} | ||
> | ||
{(hovered) => ( | ||
<> | ||
{item.shouldShowSubscript ? ( | ||
<SubscriptAvatar | ||
mainAvatar={item.icons[0]} | ||
secondaryAvatar={item.icons[1]} | ||
showTooltip={showTooltip} | ||
backgroundColor={isHovered && !isFocused ? hoveredBackgroundColor : subscriptAvatarBorderColor} | ||
/> | ||
) : ( | ||
<MultipleAvatars | ||
icons={item.icons ?? []} | ||
{!!item.icons && ( | ||
<> | ||
{item.shouldShowSubscript ? ( | ||
<SubscriptAvatar | ||
mainAvatar={item.icons[0]} | ||
secondaryAvatar={item.icons[1]} | ||
showTooltip={showTooltip} | ||
backgroundColor={hovered && !isFocused ? hoveredBackgroundColor : subscriptAvatarBorderColor} | ||
/> | ||
) : ( | ||
<MultipleAvatars | ||
icons={item.icons ?? []} | ||
shouldShowTooltip={showTooltip} | ||
secondAvatarStyle={[ | ||
StyleUtils.getBackgroundAndBorderStyle(theme.sidebar), | ||
isFocused ? StyleUtils.getBackgroundAndBorderStyle(focusedBackgroundColor) : undefined, | ||
hovered && !isFocused ? StyleUtils.getBackgroundAndBorderStyle(hoveredBackgroundColor) : undefined, | ||
burczu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
]} | ||
/> | ||
)} | ||
</> | ||
)} | ||
<View style={[styles.flex1, styles.flexColumn, styles.justifyContentCenter, styles.alignItemsStretch, styles.optionRow]}> | ||
<TextWithTooltip | ||
shouldShowTooltip={showTooltip} | ||
secondAvatarStyle={[ | ||
StyleUtils.getBackgroundAndBorderStyle(theme.sidebar), | ||
isFocused ? StyleUtils.getBackgroundAndBorderStyle(focusedBackgroundColor) : undefined, | ||
isHovered && !isFocused ? StyleUtils.getBackgroundAndBorderStyle(hoveredBackgroundColor) : undefined, | ||
text={item.text} | ||
textStyles={[ | ||
styles.optionDisplayName, | ||
isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText, | ||
styles.sidebarLinkTextBold, | ||
styles.pre, | ||
item.alternateText ? styles.mb1 : null, | ||
]} | ||
/> | ||
)} | ||
{!!item.alternateText && ( | ||
<TextWithTooltip | ||
shouldShowTooltip={showTooltip} | ||
text={item.alternateText} | ||
textStyles={[styles.textLabelSupporting, styles.lh16, styles.pre]} | ||
/> | ||
)} | ||
</View> | ||
{!!item.rightElement && item.rightElement} | ||
</> | ||
)} | ||
<View style={[styles.flex1, styles.flexColumn, styles.justifyContentCenter, styles.alignItemsStretch, styles.optionRow]}> | ||
<TextWithTooltip | ||
shouldShowTooltip={showTooltip} | ||
text={item.text} | ||
textStyles={[textStyles, style]} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
/> | ||
{!!item.alternateText && ( | ||
<TextWithTooltip | ||
shouldShowTooltip={showTooltip} | ||
text={item.alternateText} | ||
textStyles={[alternateTextStyles, style]} | ||
/> | ||
)} | ||
</View> | ||
{!!item.rightElement && item.rightElement} | ||
</> | ||
</BaseListItem> | ||
); | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.