Do not scroll center channel to bottom when posting in RHS (#6852)

Этот коммит содержится в:
Joram Wilander
2017-07-05 16:28:32 -04:00
коммит произвёл enahum
родитель d59cac0314
Коммит 04e364f4f7
3 изменённых файлов: 16 добавлений и 15 удалений

Просмотреть файл

@@ -551,8 +551,9 @@ export function redirectUserToDefaultTeam() {
} }
} }
export function postListScrollChange() { export function postListScrollChange(forceScrollToBottom = false) {
AppDispatcher.handleViewAction({ AppDispatcher.handleViewAction({
type: EventTypes.POST_LIST_SCROLL_CHANGE type: EventTypes.POST_LIST_SCROLL_CHANGE,
value: forceScrollToBottom
}); });
} }

Просмотреть файл

@@ -261,7 +261,8 @@ export default class CreatePost extends React.Component {
}); });
} }
PostActions.createPost(post, this.state.fileInfos, null, PostActions.createPost(post, this.state.fileInfos,
() => GlobalActions.postListScrollChange(true),
(err) => { (err) => {
if (err.id === 'api.post.create_post.root_id.app_error') { if (err.id === 'api.post.create_post.root_id.app_error') {
// this should never actually happen since you can't reply from this textbox // this should never actually happen since you can't reply from this textbox

Просмотреть файл

@@ -117,12 +117,12 @@ export default class PostList extends React.PureComponent {
this.loadPosts(this.props.channel.id, this.props.focusedPostId); this.loadPosts(this.props.channel.id, this.props.focusedPostId);
GlobalEventEmitter.addListener(EventTypes.POST_LIST_SCROLL_CHANGE, this.handleResize); GlobalEventEmitter.addListener(EventTypes.POST_LIST_SCROLL_CHANGE, this.handleResize);
window.addEventListener('resize', this.handleResize); window.addEventListener('resize', () => this.handleResize());
} }
componentWillUnmount() { componentWillUnmount() {
GlobalEventEmitter.removeListener(EventTypes.POST_LIST_SCROLL_CHANGE, this.handleResize); GlobalEventEmitter.removeListener(EventTypes.POST_LIST_SCROLL_CHANGE, this.handleResize);
window.removeEventListener('resize', this.handleResize); window.removeEventListener('resize', () => this.handleResize());
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
@@ -210,20 +210,18 @@ export default class PostList extends React.PureComponent {
} }
if (postList && prevPosts && posts && posts[0] && prevPosts[0]) { if (postList && prevPosts && posts && posts[0] && prevPosts[0]) {
// A new message was posted, so scroll to bottom if it was from current user // A new message was posted, so scroll to bottom if user
// or if user was already scrolled close to bottom // was already scrolled close to bottom
let doScrollToBottom = false; let doScrollToBottom = false;
if (posts[0].id !== prevPosts[0].id && posts[0].pending_post_id !== prevPosts[0].pending_post_id) { const postId = posts[0].id;
const prevPostId = prevPosts[0].id;
const pendingPostId = posts[0].pending_post_id;
if (postId !== prevPostId && pendingPostId !== prevPostId) {
// If already scrolled to bottom // If already scrolled to bottom
if (this.wasAtBottom()) { if (this.wasAtBottom()) {
doScrollToBottom = true; doScrollToBottom = true;
} }
// If new post was by current user
if (posts[0].user_id === this.props.currentUserId) {
doScrollToBottom = true;
}
// If new post was ephemeral // If new post was ephemeral
if (Utils.isPostEphemeral(posts[0])) { if (Utils.isPostEphemeral(posts[0])) {
doScrollToBottom = true; doScrollToBottom = true;
@@ -252,10 +250,11 @@ export default class PostList extends React.PureComponent {
return this.previousClientHeight + this.previousScrollTop >= this.previousScrollHeight - CLOSE_TO_BOTTOM_SCROLL_MARGIN; return this.previousClientHeight + this.previousScrollTop >= this.previousScrollHeight - CLOSE_TO_BOTTOM_SCROLL_MARGIN;
} }
handleResize = () => { handleResize = (forceScrollToBottom) => {
const postList = this.refs.postlist; const postList = this.refs.postlist;
const doScrollToBottom = this.wasAtBottom() || forceScrollToBottom;
if (postList && this.wasAtBottom()) { if (postList && doScrollToBottom) {
postList.scrollTop = postList.scrollHeight; postList.scrollTop = postList.scrollHeight;
this.previousScrollHeight = postList.scrollHeight; this.previousScrollHeight = postList.scrollHeight;