question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Automatic scrolling not working (scrollToBottom, onSend)

See original GitHub issue

Issue Description

Follow-up on #975 (closed by stale bot)

Automatic scrolling to bottom does not seem to work at all in my setup. I use inverted=true (the default). I use GiftedChat inside a Navigation with a Tabbar.

  1. when I manually scroll up a bit, and then by myself send a message, the flat listview should scroll automatically down the the new message that was just added (see onSend(), GiftedChat.js:113), but it does nothing.

  2. when I activate scrollToBottom=true, the scroll-to-bottom button is shown, but nothing happens when I tap on it. I would expect the message list to scroll to the bottom (see MessageContainer.js:94)

Expected Results

Automatic scrolling works in both cases.

Additional Information

  • React Native version: 0.59.0
  • react-native-gifted-chat version: 0.9.0
  • Platform(s) (iOS, Android, or both?): iPhone X Simulator (iOS 12.2), Android Simulator (SDK 28)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
hubermatcommented, Jun 6, 2019

This is not a problem of list ordering. If I manually scroll to the middle of the chat and then press the scrollToBottom button oder enter a message, it should scroll in any direction, but it does nothing.

As I wrote, I use GiftedChat inside a Navigation with a Tabbar. Now I did a change to hide the tabbar and et voila - GiftedChat scrolls! I don’t know why this is the case, but for my usecase (with the hidden tabbar) it is working now.

I will leave this issue open though, so that the original issue maybe can be fixed.

1reaction
noelspcommented, Jun 3, 2019

Hi @hubermat, I found my error. In my project, I am using redux, and my message list was not reversed. In the example of GiftedChat you will see that it uses a static method called append and uses it to invert the list of messages.

onSend(messages = []) {
  this.setState(previousState => ({
    messages: GiftedChat.append(previousState.messages, messages),
  }))
}

This is necessary because the entire flat list is inverted to position the scroll at the end of the list by default (This is my deduction).

Then, I solved this by removing the inverted={false} property and making sure that in my list of redux messages the new messages are being added in reverse order. When I get my previous messages I reverse them and when I add a new message to the array I use .unshift()

I hope it serves you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chat box, auto scroll to bottom - Stack Overflow
If user is at bottom then chat page will automatically scroll with new message. and if user scroll up then page will not...
Read more >
Automatic scrolling, only if a user already scrolled the bottom ...
That behavior obviously should get stopped, when a user scrolls through the list and is not viewing that latest item currently.
Read more >
onsen ui page scroll to bottom - Monaca & Onsen UI
Hello every one i am doing a chat app . the only thing that frustrate me write now is after sending the message...
Read more >
Auto scroll to bottom working on all devices EXCEPT iOS
I wanted to make it so that when a user answers a question, the form automatically scrolls to the bottom of the screen...
Read more >
[Solved]-React auto scroll to bottom on a chat container-Reactjs
Coding example for the question React auto scroll to bottom on a chat container-Reactjs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found