Skip to content

Commit

Permalink
Merge pull request #32777 from barttom/feat/29780/hide-list-while-ini…
Browse files Browse the repository at this point in the history
…tial-scrolling

Feat/29780/hide list while initial scrolling
  • Loading branch information
deetergp authored Dec 11, 2023
2 parents d23d793 + 996f159 commit bc77287
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/components/SelectionList/BaseSelectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ function BaseSelectionList({
const theme = useTheme();
const styles = useThemeStyles();
const {translate} = useLocalize();
const firstLayoutRef = useRef(true);
const listRef = useRef(null);
const textInputRef = useRef(null);
const focusTimeoutRef = useRef(null);
Expand All @@ -73,6 +72,8 @@ function BaseSelectionList({
const activeElement = useActiveElement();
const isFocused = useIsFocused();
const [maxToRenderPerBatch, setMaxToRenderPerBatch] = useState(shouldUseDynamicMaxToRenderPerBatch ? 0 : CONST.MAX_TO_RENDER_PER_BATCH.DEFAULT);
const [isInitialRender, setIsInitialRender] = useState(true);
const wrapperStyles = useMemo(() => ({opacity: isInitialRender ? 0 : 1}), [isInitialRender]);

/**
* Iterates through the sections and items inside each section, and builds 3 arrays along the way:
Expand Down Expand Up @@ -325,13 +326,13 @@ function BaseSelectionList({
setMaxToRenderPerBatch((Math.ceil(listHeight / itemHeight) || 0) + CONST.MAX_TO_RENDER_PER_BATCH.DEFAULT);
}

if (!firstLayoutRef.current) {
if (!isInitialRender) {
return;
}
scrollToIndex(focusedIndex, false);
firstLayoutRef.current = false;
setIsInitialRender(false);
},
[focusedIndex, scrollToIndex, shouldUseDynamicMaxToRenderPerBatch],
[focusedIndex, isInitialRender, scrollToIndex, shouldUseDynamicMaxToRenderPerBatch],
);

const updateAndScrollToFocusedIndex = useCallback(
Expand Down Expand Up @@ -359,7 +360,7 @@ function BaseSelectionList({

useEffect(() => {
// do not change focus on the first render, as it should focus on the selected item
if (firstLayoutRef.current) {
if (isInitialRender) {
return;
}

Expand Down Expand Up @@ -394,7 +395,7 @@ function BaseSelectionList({
>
<SafeAreaConsumer>
{({safeAreaPaddingBottomStyle}) => (
<View style={[styles.flex1, !isKeyboardShown && safeAreaPaddingBottomStyle]}>
<View style={[styles.flex1, !isKeyboardShown && safeAreaPaddingBottomStyle, wrapperStyles]}>
{shouldShowTextInput && (
<View style={[styles.ph5, styles.pb3]}>
<TextInput
Expand Down

0 comments on commit bc77287

Please sign in to comment.