Skip to content
Snippets Groups Projects
Commit e3f33ab6 authored by Tainan Felipe's avatar Tainan Felipe
Browse files

Fix row getting bigger than the message content when clear the chat

parent 45307c9f
No related branches found
No related tags found
No related merge requests found
...@@ -42,6 +42,17 @@ const intlMessages = defineMessages({ ...@@ -42,6 +42,17 @@ const intlMessages = defineMessages({
}); });
class MessageList extends Component { class MessageList extends Component {
static getDerivedStateFromProps(props, state) {
const { messages: propMessages } = props;
const { messages: stateMessages } = state;
if (propMessages.length !== 3 && propMessages.length < stateMessages.length) return null;
return {
messages: propMessages,
};
}
constructor(props) { constructor(props) {
super(props); super(props);
this.cache = new CellMeasurerCache({ this.cache = new CellMeasurerCache({
...@@ -63,6 +74,7 @@ class MessageList extends Component { ...@@ -63,6 +74,7 @@ class MessageList extends Component {
shouldScrollToBottom: true, shouldScrollToBottom: true,
shouldScrollToPosition: false, shouldScrollToPosition: false,
scrollPosition: 0, scrollPosition: 0,
messages: [],
}; };
this.listRef = null; this.listRef = null;
...@@ -114,11 +126,10 @@ class MessageList extends Component { ...@@ -114,11 +126,10 @@ class MessageList extends Component {
return false; return false;
} }
componentDidUpdate(prevProps) { componentDidUpdate(prevProps, prevState) {
const { const {
scrollPosition, scrollPosition,
chatId, chatId,
messages,
} = this.props; } = this.props;
const { const {
scrollPosition: prevScrollPosition, scrollPosition: prevScrollPosition,
...@@ -129,8 +140,9 @@ class MessageList extends Component { ...@@ -129,8 +140,9 @@ class MessageList extends Component {
shouldScrollToPosition, shouldScrollToPosition,
scrollPosition: scrollPositionState, scrollPosition: scrollPositionState,
shouldScrollToBottom, shouldScrollToBottom,
messages,
} = this.state; } = this.state;
const { messages: prevMessages } = prevState;
const compareChatId = prevProps.chatId !== chatId; const compareChatId = prevProps.chatId !== chatId;
if (compareChatId) { if (compareChatId) {
...@@ -154,6 +166,11 @@ class MessageList extends Component { ...@@ -154,6 +166,11 @@ class MessageList extends Component {
if (shouldScrollToPosition && scrollArea.scrollTop === scrollPositionState) { if (shouldScrollToPosition && scrollArea.scrollTop === scrollPositionState) {
this.setState({ shouldScrollToPosition: false }); this.setState({ shouldScrollToPosition: false });
} }
if (prevMessages.length < messages.length) {
this.resizeRow(prevMessages.length - 1);
// messages.forEach((i, idx) => this.resizeRow(idx));
}
} }
handleScrollUpdate(position, target) { handleScrollUpdate(position, target) {
...@@ -288,7 +305,6 @@ class MessageList extends Component { ...@@ -288,7 +305,6 @@ class MessageList extends Component {
render() { render() {
const { const {
messages,
intl, intl,
id, id,
} = this.props; } = this.props;
...@@ -297,6 +313,7 @@ class MessageList extends Component { ...@@ -297,6 +313,7 @@ class MessageList extends Component {
shouldScrollToBottom, shouldScrollToBottom,
shouldScrollToPosition, shouldScrollToPosition,
scrollPosition, scrollPosition,
messages,
} = this.state; } = this.state;
const isEmpty = messages.length === 0; const isEmpty = messages.length === 0;
...@@ -334,7 +351,7 @@ class MessageList extends Component { ...@@ -334,7 +351,7 @@ class MessageList extends Component {
rowCount={messages.length} rowCount={messages.length}
height={height} height={height}
width={width} width={width}
overscanRowCount={2} overscanRowCount={15}
deferredMeasurementCache={this.cache} deferredMeasurementCache={this.cache}
onScroll={this.handleScrollChange} onScroll={this.handleScrollChange}
scrollToIndex={shouldScrollToBottom ? messages.length - 1 : undefined} scrollToIndex={shouldScrollToBottom ? messages.length - 1 : undefined}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment