Skip to content

Commit

Permalink
Improve the scrolling
Browse files Browse the repository at this point in the history
Fixes #46 (maybe)
  • Loading branch information
tgolen committed Aug 11, 2020
1 parent 6925281 commit 07e235d
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/page/HomePage/Report/ReportHistoryView.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,11 @@ class ReportHistoryView extends React.Component {
constructor(props) {
super(props);

// Keeps track of the history length so that when length changes, the list is scrolled to the bottom
this.previousReportHistoryLength = 0;

this.recordlastReadActionID = _.debounce(this.recordlastReadActionID.bind(this), 1000, true);
}

componentDidUpdate(prevProps) {
if (prevProps.reportID !== this.props.reportID) {
this.previousReportHistoryLength = 0;
if (this.historyItemList) {
this.historyItemList.scrollToEnd({animated: false});
}
}
this.scrollToBottomWhenListSizeChanges = this.scrollToBottomWhenListSizeChanges.bind(this);
}

/**
Expand Down Expand Up @@ -107,25 +100,29 @@ class ReportHistoryView extends React.Component {
});
}

scrollToBottomWhenListSizeChanges(el) {
if (el) {
const filteredHistory = this.getFilteredReportHistory();
console.log(this.previousReportHistoryLength, filteredHistory.length);
if (this.previousReportHistoryLength < filteredHistory.length) {
console.log('scroll')
el.scrollToEnd({animated: false});
}

this.previousReportHistoryLength = filteredHistory.length;
}
}

render() {
const filteredHistory = this.getFilteredReportHistory();

if (filteredHistory.length === 0) {
return <Text>Be the first person to comment!</Text>;
}

console.log(this.previousReportHistoryLength, filteredHistory.length);
if (this.previousReportHistoryLength < filteredHistory.length) {
if (this.historyItemList) {
console.log('scroll')
this.historyItemList.scrollToEnd({animated: false});
}
}

this.previousReportHistoryLength = filteredHistory.length;

return (
<ScrollView ref={el => this.historyItemList = el}>
<ScrollView ref={this.scrollToBottomWhenListSizeChanges}>
{_.map(filteredHistory, (item, index) => (
<ReportHistoryItem
key={item.sequenceNumber}
Expand Down

0 comments on commit 07e235d

Please sign in to comment.