Skip to content

Commit

Permalink
remove adjusting section index
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardoj committed Jan 25, 2024
1 parent 0d0b0a8 commit 2fde605
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
12 changes: 1 addition & 11 deletions src/components/OptionsSelector/BaseOptionsSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,17 +433,7 @@ class BaseOptionsSelector extends Component {
return;
}

// Note: react-native's SectionList automatically strips out any empty sections.
// So we need to reduce the sectionIndex to remove any empty sections in front of the one we're trying to scroll to.
// Otherwise, it will cause an index-out-of-bounds error and crash the app.
let adjustedSectionIndex = sectionIndex;
for (let i = 0; i < sectionIndex; i++) {
if (_.isEmpty(lodashGet(this.state.sections, `[${i}].data`))) {
adjustedSectionIndex--;
}
}

this.list.scrollToLocation({sectionIndex: adjustedSectionIndex, itemIndex, animated});
this.list.scrollToLocation({sectionIndex, itemIndex, animated});
}

/**
Expand Down
12 changes: 1 addition & 11 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,7 @@ function BaseSelectionList<TItem extends User | RadioItem>(
const itemIndex = item.index ?? -1;
const sectionIndex = item.sectionIndex ?? -1;

// Note: react-native's SectionList automatically strips out any empty sections.
// So we need to reduce the sectionIndex to remove any empty sections in front of the one we're trying to scroll to.
// Otherwise, it will cause an index-out-of-bounds error and crash the app.
let adjustedSectionIndex = sectionIndex;
for (let i = 0; i < sectionIndex; i++) {
if (sections[i].data) {
adjustedSectionIndex--;
}
}

listRef.current.scrollToLocation({sectionIndex: adjustedSectionIndex, itemIndex, animated, viewOffset: variables.contentHeaderHeight});
listRef.current.scrollToLocation({sectionIndex, itemIndex, animated, viewOffset: variables.contentHeaderHeight});
},

// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down

0 comments on commit 2fde605

Please sign in to comment.