Skip to content

Commit

Permalink
Merge pull request #35129 from bernhardoj/fix/34112-wrong-scroll-loca…
Browse files Browse the repository at this point in the history
…tion

Fix highlighted user in new chat page is covered by referral view
  • Loading branch information
dangrous authored Jan 29, 2024
2 parents b9b0d4d + a9c3fbe commit 19f542a
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 19f542a

Please sign in to comment.