_scrollToBottom () { let scrollProperties = this.chatListView.scrollProperties; // 如果组件没有挂载完全,则不进行内容偏移 if (!scrollProperties.visibleLength) { return; } // 如果是刷新操作,则不进行滑动 if (!this._userReachEnd) { return; } // 如果组件内元素还没渲染完全,则不进行底部偏移 if (socketStore.currentChatRoomHistory.length - this.currentMaxRowId > 11) { return; } // 这里是一个大坑,在测试环境的时候,由于运行速度较慢,scrollProperties.contentLength 总能 // 获取到正确的值,生产环境需要加个延时,用来保证 `renderRow` 执行完毕 // 这里设置了 130ms 的延时 setTimeout(() => { let offsetY = scrollProperties.contentLength - scrollProperties.visibleLength; this.chatListView.scrollTo({ y: offsetY > 0 ? offsetY : 0, animated: this._userHasBeenInputed }); }, this._userHasBeenInputed ? 0 : 130); }
onEndReachedThreshold={10} ref={(reference) => { this.chatListView = reference; }} dataSource={this.ds.cloneWithRows(socketStore.currentChatRoomHistory.slice())} enableEmptySections={true} onLayout={