Skip to content

Commit

Permalink
fix: move hiding only to the SectionList
Browse files Browse the repository at this point in the history
  • Loading branch information
barttom committed Jan 2, 2024
1 parent 320ff54 commit 3ffec3a
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/components/SelectionList/BaseSelectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ 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]);
const [isInitialSectionListRender, setIsInitialSectionListRender] = useState(true);

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

if (!isInitialRender) {
if (!isInitialSectionListRender) {
return;
}
scrollToIndex(focusedIndex, false);
setIsInitialRender(false);
setIsInitialSectionListRender(false);
},
[focusedIndex, isInitialRender, scrollToIndex, shouldUseDynamicMaxToRenderPerBatch],
[focusedIndex, isInitialSectionListRender, scrollToIndex, shouldUseDynamicMaxToRenderPerBatch],
);

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

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

Expand Down Expand Up @@ -401,7 +400,7 @@ function BaseSelectionList({
{/* <View style={[styles.flex1, !isKeyboardShown && safeAreaPaddingBottomStyle, wrapperStyle]}> */}
<SafeAreaConsumer>
{({safeAreaPaddingBottomStyle}) => (
<View style={[styles.flex1, !isKeyboardShown && safeAreaPaddingBottomStyle, wrapperStyles, StyleUtils.parseStyleAsArray(containerStyle)]}>
<View style={[styles.flex1, !isKeyboardShown && safeAreaPaddingBottomStyle, StyleUtils.parseStyleAsArray(containerStyle)]}>
{shouldShowTextInput && (
<View style={[styles.ph5, styles.pb3]}>
<TextInput
Expand Down Expand Up @@ -479,7 +478,7 @@ function BaseSelectionList({
viewabilityConfig={{viewAreaCoveragePercentThreshold: 95}}
testID="selection-list"
onLayout={scrollToFocusedIndexOnFirstRender}
style={!maxToRenderPerBatch && styles.opacity0}
style={(!maxToRenderPerBatch || isInitialSectionListRender) && styles.opacity0}
/>
{children}
</>
Expand Down

0 comments on commit 3ffec3a

Please sign in to comment.