vertical-collection icon indicating copy to clipboard operation
vertical-collection copied to clipboard

Autoscroll to bottom?

Open NullVoxPopuli opened this issue 6 years ago • 8 comments

This is kind of a question / feature request? maybe?

anywho, I have a messaging app, and when the app loads, I would like to be able to scroll to the bottom of the chat.

I'm using renderFromLast=true, and I know there is this issue: https://github.com/html-next/vertical-collection/issues/158

I have this in my component:

import Component from '@ember/component';

export default class ChatHistory extends Component {
  didRender() {
    this.scrollMessagesContainer();
  }

  scrollMessagesContainer() {
    const element = this.element.querySelector('.messages') as HTMLElement;
    const lastMessage = element.querySelector('.message:last-child') as HTMLElement;

    if (lastMessage) {
      element.scrollTop = lastMessage.offsetTop + lastMessage.offsetHeight;
    }
  }
}

but it seems to not always work with vertical-collection. Is this a feature that makes sense to be in vertical-collection?

NullVoxPopuli avatar Jun 25 '18 12:06 NullVoxPopuli

Yup, this would also be covered by the fix to #158. We need a generic way to imperatively tell VC to scroll, the main issue being that it’s impossible for anything but VC to accurately react to dynamic heights.

It’s hard to say what’s happening in your case, but if your item heights are dynamic, it’s very likely that VC renders occluded content for it’s predicted item height (say 100px), then you scroll the container to the bottom, then it measures the actual item height (200px), which pushes the real bottom down further.

pzuraq avatar Jun 25 '18 14:06 pzuraq

hmm. cool. I'll do some more investigation tonight to figure out what the specific issue is.

NullVoxPopuli avatar Jun 25 '18 14:06 NullVoxPopuli

Any luck on this? I'm working on the exact same thing - messaging app and needing to scroll to bottom.

josiahbryan avatar Aug 08 '18 04:08 josiahbryan

Any luck on this? I'm working on the exact same thing - messaging app and needing to scroll to bottom.

Now . Are u ok? I am facing with this issue.

mgkyawzayya avatar Feb 20 '20 09:02 mgkyawzayya

This is kind of a question / feature request? maybe?

anywho, I have a messaging app, and when the app loads, I would like to be able to scroll to the bottom of the chat.

I'm using renderFromLast=true, and I know there is this issue: #158

I have this in my component:

import Component from '@ember/component';

export default class ChatHistory extends Component {
  didRender() {
    this.scrollMessagesContainer();
  }

  scrollMessagesContainer() {
    const element = this.element.querySelector('.messages') as HTMLElement;
    const lastMessage = element.querySelector('.message:last-child') as HTMLElement;

    if (lastMessage) {
      element.scrollTop = lastMessage.offsetTop + lastMessage.offsetHeight;
    }
  }
}

but it seems to not always work with vertical-collection. Is this a feature that makes sense to be in vertical-collection?

Are u ok in Ember Octane?

mgkyawzayya avatar Feb 20 '20 10:02 mgkyawzayya

@mgkyawzayya Can you try this PR if it works. We need to pass index so that it scrolls exactly to the item. https://github.com/html-next/vertical-collection/pull/302

ahamedalthaf avatar Feb 20 '20 10:02 ahamedalthaf

@mgkyawzayya Can you try this PR if it works. We need to pass index so that it scrolls exactly to the item. #302

I don't understand how this PR work.

mgkyawzayya avatar Feb 20 '20 17:02 mgkyawzayya

I'm trying out the technique here: https://codepen.io/Craafter/pen/xBLVqZ

which gets around the whole scrolling issue by flipping everything upside down twice.

However, it looks like this breaks vertical-collection's calculations :(

Getting this error: image

NullVoxPopuli avatar Jun 29 '20 03:06 NullVoxPopuli