-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Web - Profile - When selecting the last country or state extra space is displayed for a while #31737
Merged
mountiny
merged 7 commits into
Expensify:main
from
ZhenjaHorbach:web-profile-when-selecting-the-last-country-or-state-extra-space-is-displayed-for-a-while
Nov 27, 2023
Merged
Web - Profile - When selecting the last country or state extra space is displayed for a while #31737
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6c876c4
Fix bug with Web - Profile - When selecting the last country or state…
ZhenjaHorbach a175205
Update value to increase
ZhenjaHorbach 2b22aa7
Fix lint warning
ZhenjaHorbach 2749bfd
Fix bug with mobile
ZhenjaHorbach 5e1acdc
Optimize the list while transitioning between screens
ZhenjaHorbach 6cf91f6
Add constants for maxToRenderPerBatch
ZhenjaHorbach 31b15b1
Fix conflicts
ZhenjaHorbach 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 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 |
---|---|---|
|
@@ -59,6 +59,7 @@ function BaseSelectionList({ | |
disableKeyboardShortcuts = false, | ||
children, | ||
shouldStopPropagation = false, | ||
shouldUseDynamicMaxToRenderPerBatch = false, | ||
}) { | ||
const theme = useTheme(); | ||
const styles = useThemeStyles(); | ||
|
@@ -71,6 +72,8 @@ function BaseSelectionList({ | |
const shouldShowSelectAll = Boolean(onSelectAll); | ||
const activeElement = useActiveElement(); | ||
const isFocused = useIsFocused(); | ||
const [maxToRenderPerBatch, setMaxToRenderPerBatch] = useState(shouldUseDynamicMaxToRenderPerBatch ? 0 : 5); | ||
|
||
/** | ||
* Iterates through the sections and items inside each section, and builds 3 arrays along the way: | ||
* - `allOptions`: Contains all the items in the list, flattened, regardless of section | ||
|
@@ -301,6 +304,7 @@ function BaseSelectionList({ | |
item={item} | ||
isFocused={isItemFocused} | ||
isDisabled={isDisabled} | ||
isHide={!maxToRenderPerBatch} | ||
showTooltip={showTooltip} | ||
canSelectMultiple={canSelectMultiple} | ||
onSelectRow={() => selectRow(item, true)} | ||
|
@@ -310,13 +314,23 @@ function BaseSelectionList({ | |
); | ||
}; | ||
|
||
const scrollToFocusedIndexOnFirstRender = useCallback(() => { | ||
if (!firstLayoutRef.current) { | ||
return; | ||
} | ||
scrollToIndex(focusedIndex, false); | ||
firstLayoutRef.current = false; | ||
}, [focusedIndex, scrollToIndex]); | ||
const scrollToFocusedIndexOnFirstRender = useCallback( | ||
({nativeEvent}) => { | ||
if (shouldUseDynamicMaxToRenderPerBatch) { | ||
const listHeight = lodashGet(nativeEvent, 'layout.height', 0); | ||
const itemHeight = lodashGet(nativeEvent, 'layout.y', 0); | ||
|
||
setMaxToRenderPerBatch((Math.ceil(listHeight / itemHeight) || 0) + 5); | ||
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. Is this |
||
} | ||
|
||
if (!firstLayoutRef.current) { | ||
return; | ||
} | ||
scrollToIndex(focusedIndex, false); | ||
firstLayoutRef.current = false; | ||
}, | ||
[focusedIndex, scrollToIndex, shouldUseDynamicMaxToRenderPerBatch], | ||
); | ||
|
||
const updateAndScrollToFocusedIndex = useCallback( | ||
(newFocusedIndex) => { | ||
|
@@ -451,11 +465,12 @@ function BaseSelectionList({ | |
keyboardShouldPersistTaps="always" | ||
showsVerticalScrollIndicator={showScrollIndicator} | ||
initialNumToRender={12} | ||
maxToRenderPerBatch={5} | ||
maxToRenderPerBatch={maxToRenderPerBatch} | ||
windowSize={5} | ||
viewabilityConfig={{viewAreaCoveragePercentThreshold: 95}} | ||
testID="selection-list" | ||
onLayout={scrollToFocusedIndexOnFirstRender} | ||
style={!maxToRenderPerBatch && styles.opacity0} | ||
/> | ||
{children} | ||
</> | ||
|
This file contains 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 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could extract this
5
to some constant with meaningful name.