Skip to content

Commit

Permalink
Merge pull request Expensify#13230 from Expensify/revert-12124-fix/11…
Browse files Browse the repository at this point in the history
…584-web-jump-to-unread-message

Revert "fix: 11584 web jump to unread message"
  • Loading branch information
marcaaron authored Dec 8, 2022
2 parents 367119d + ba63606 commit 5501ff5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
7 changes: 6 additions & 1 deletion src/components/InvertedFlatList/BaseInvertedFlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ class BaseInvertedFlatList extends Component {
measureItemLayout(nativeEvent, index) {
const computedHeight = nativeEvent.layout.height;

// We've already measured this item so we don't need to
// measure it again.
if (this.sizeMap[index]) {
return;
}

const previousItem = this.sizeMap[index - 1] || {};

// If there is no previousItem this can mean we haven't yet measured
Expand Down Expand Up @@ -135,7 +141,6 @@ class BaseInvertedFlatList extends Component {
{...this.props}
ref={this.props.innerRef}
renderItem={this.renderItem}
sizeMap={this.sizeMap}

// Native platforms do not need to measure items and work fine without this.
// Web requires that items be measured or else crazy things happen when scrolling.
Expand Down
15 changes: 2 additions & 13 deletions src/libs/ReportScrollManager/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import React from 'react';
import _ from 'underscore';
import lodashGet from 'lodash/get';

// This ref is created using React.createRef here because this function is used by a component that doesn't have access
// to the original ref.
Expand All @@ -17,17 +15,8 @@ function scrollToIndex(index, isEditing) {
if (isEditing) {
return;
}
const sizeMap = lodashGet(flatListRef, 'current.props.sizeMap');
const scrollableNode = flatListRef.current.getScrollableNode();
const clientHeight = lodashGet(scrollableNode, 'clientHeight', 0);
const paddingTop = parseFloat(lodashGet(scrollableNode, 'childNodes[0].style.paddingTop', '0px'));
const sizeArray = _.map(_.values(sizeMap), s => s.length);
const currentOffset = _.reduce(sizeArray.slice(0, (index.index)), (acc, val) => acc + val);
const offset = (currentOffset + paddingTop + (index.viewOffset || 0)) - (clientHeight * (index.viewPosition || 0));
flatListRef.current.scrollToOffset({
animated: index.animated,
offset,
});

flatListRef.current.scrollToIndex(index);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ReportActionsView extends React.Component {
this.toggleFloatingMessageCounter = this.toggleFloatingMessageCounter.bind(this);
this.loadMoreChats = this.loadMoreChats.bind(this);
this.recordTimeToMeasureItemLayout = this.recordTimeToMeasureItemLayout.bind(this);
this.scrollToUnreadMsgAndMarkReportAsRead = this.scrollToUnreadMsgAndMarkReportAsRead.bind(this);
this.scrollToBottomAndMarkReportAsRead = this.scrollToBottomAndMarkReportAsRead.bind(this);
this.openReportIfNecessary = this.openReportIfNecessary.bind(this);
}

Expand Down Expand Up @@ -298,8 +298,8 @@ class ReportActionsView extends React.Component {
Report.readOldestAction(this.props.report.reportID, oldestActionSequenceNumber);
}

scrollToUnreadMsgAndMarkReportAsRead() {
ReportScrollManager.scrollToIndex({animated: true, index: this.props.report.maxSequenceNumber - this.state.newMarkerSequenceNumber}, false);
scrollToBottomAndMarkReportAsRead() {
ReportScrollManager.scrollToBottom();
Report.readNewestAction(this.props.report.reportID);
}

Expand Down Expand Up @@ -358,7 +358,7 @@ class ReportActionsView extends React.Component {
<>
<FloatingMessageCounter
isActive={this.state.isFloatingMessageCounterVisible && this.state.newMarkerSequenceNumber > 0}
onClick={this.scrollToUnreadMsgAndMarkReportAsRead}
onClick={this.scrollToBottomAndMarkReportAsRead}
/>
<ReportActionsList
report={this.props.report}
Expand Down

0 comments on commit 5501ff5

Please sign in to comment.