Skip to content

Commit

Permalink
fix: used initialScrollIndex instead of implementing initial focus ma…
Browse files Browse the repository at this point in the history
…nually
  • Loading branch information
barttom committed Nov 7, 2023
1 parent da2c79e commit efd8532
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/components/SelectionList/BaseSelectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ function BaseSelectionList({

// If `initiallyFocusedOptionKey` is not passed, we fall back to `-1`, to avoid showing the highlight on the first member
const [focusedIndex, setFocusedIndex] = useState(() => _.findIndex(flattenedSections.allOptions, (option) => option.keyForList === initiallyFocusedOptionKey));
const initialFocusedIndex = focusedIndex > -1 ? focusedIndex : undefined;

// Disable `Enter` shortcut if the active element is a button or checkbox
const disableEnterShortcut = activeElement && [CONST.ACCESSIBILITY_ROLE.BUTTON, CONST.ACCESSIBILITY_ROLE.CHECKBOX].includes(activeElement.role);
Expand Down Expand Up @@ -307,14 +308,9 @@ function BaseSelectionList({
/>
);
};

const scrollToFocusedIndexOnFirstRender = useCallback(() => {
if (!firstLayoutRef.current) {
return;
}
scrollToIndex(focusedIndex, false);
const handleFirstLayout = useCallback(() => {
firstLayoutRef.current = false;
}, [focusedIndex, scrollToIndex]);
}, []);

const updateAndScrollToFocusedIndex = useCallback(
(newFocusedIndex) => {
Expand Down Expand Up @@ -454,7 +450,8 @@ function BaseSelectionList({
viewabilityConfig={{viewAreaCoveragePercentThreshold: 95}}
testID="selection-list"
style={[styles.flexGrow0]}
onLayout={scrollToFocusedIndexOnFirstRender}
onLayout={handleFirstLayout}
initialScrollIndex={initialFocusedIndex}
/>
{children}
</>
Expand Down

0 comments on commit efd8532

Please sign in to comment.