MCPcopy Create free account
hub / github.com/CommE2E/comm / componentDidUpdate

Method componentDidUpdate

web/chat/chat-message-list.react.js:120–164  ·  view source on GitHub ↗
(prevProps: Props, prevState: State, snapshot: ?Snapshot)

Source from the content-addressed store, hash-verified

118 }
119
120 componentDidUpdate(prevProps: Props, prevState: State, snapshot: ?Snapshot) {
121 const { messageListData } = this.props;
122 const prevMessageListData = prevProps.messageListData;
123
124 const { messageContainer } = this;
125 if (
126 messageContainer &&
127 prevMessageListData !== messageListData &&
128 messageContainer.scrollTop === 0
129 ) {
130 this.onScroll();
131 }
132
133 // We'll scroll to the bottom if the user was already scrolled to the bottom
134 // before the new message, or if the new message was composed locally
135 const hasNewMessage = ChatMessageList.hasNewMessage(this.props, prevProps);
136 if (
137 this.props.activeChatThreadID !== prevProps.activeChatThreadID ||
138 (hasNewMessage &&
139 messageListData &&
140 messageListData[0].itemType === 'message' &&
141 messageListData[0].messageInfoType === 'composable' &&
142 messageListData[0].messageInfo.localID) ||
143 (hasNewMessage &&
144 snapshot &&
145 Math.abs(snapshot.scrollTop) <= 1 &&
146 !this.props.isEditState)
147 ) {
148 this.scrollToBottom();
149 } else if (hasNewMessage && messageContainer && snapshot) {
150 const { scrollTop, scrollHeight } = messageContainer;
151 if (
152 scrollHeight > snapshot.scrollHeight &&
153 scrollTop === snapshot.scrollTop
154 ) {
155 const newHeight = scrollHeight - snapshot.scrollHeight;
156 const newScrollTop = Math.abs(scrollTop) + newHeight;
157 if (supportsReverseFlex) {
158 messageContainer.scrollTop = -1 * newScrollTop;
159 } else {
160 messageContainer.scrollTop = newScrollTop;
161 }
162 }
163 }
164 }
165
166 scrollToBottom() {
167 if (this.messageContainer) {

Callers

nothing calls this directly

Calls 2

scrollToBottomMethod · 0.95
hasNewMessageMethod · 0.80

Tested by

no test coverage detected