Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep chat stickied to the bottom on resize #346

Merged
merged 1 commit into from
Jun 5, 2016

Conversation

maxpoulin64
Copy link
Member

Fixes the chat not staying at the bottom when opening the on-screen keyboard on mobile.

@maxpoulin64 maxpoulin64 added Type: Bug Issues that report and PRs that solve any defects that cause unexpected behaviors. second review needed labels May 25, 2016
return this.unbind(".sticky");
};

$.fn.sticky = function() {
var self = this;
var stuckToBottom = true;
var windowResizeHandler = function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename it to something more generic and make "msg.sticky" event use this callback too (it's same code).

@maxpoulin64 maxpoulin64 force-pushed the sticky-fix branch 2 times, most recently from 65e51b9 to 7bcac1b Compare May 25, 2016 08:58
@maxpoulin64
Copy link
Member Author

@xPaw Do you like that version better?

@xPaw
Copy link
Member

xPaw commented May 25, 2016

Sure. Need to test it now.

@maxpoulin64
Copy link
Member Author

It works decently well for its intended use. I tried to make it a bit more solid when doing weird violent horizontal resizing, but it still manages to unstick once in a while. Probably a race condition between resize and scroll not firing at the same rate that end up unstickying it.

@xPaw xPaw added this to the 2.0.0 milestone May 25, 2016
@astorije
Copy link
Member

Just checking (I haven't tested yet): if scrolling back, then switching to horizontal mode, do we properly stay where we were, instead of being sent to the bottom?

@maxpoulin64
Copy link
Member Author

@astorije: yes, it only restick to bottom if it already was. If you scroll up it doesn't do anything (same as when receiving a message in the channel which uses the same function).

@xPaw
Copy link
Member

xPaw commented May 28, 2016

I've tested this, and it does work. As you already noted, horizontal resizing causes it to unstick. I'm not sure if there's any easy solution to this problem, but maybe try looking at it one more time?

I'm 👍 with this PR, even with horizontal bugginess.

Fixes the chat not staying at the bottom when opening the on-screen keyboard on mobile.
@maxpoulin64
Copy link
Member Author

@xPaw: Fixed it. I'm not a fan of using time like that, but since the issue is effectively an async timing issue, that's the only solution. It still will unstick if the browser lags for more than 250ms during the resizing. According to some logging I did, it's very, very unpredictable. 250ms should cover most cases, but it's still possible it unsticks. I also tried with timers and other things, but in the end it doesn't change that we have a race condition between the time the resize event is triggered, and the time the scroll event is triggered when the rendering engine is done reflowing the page. Yay async!

.on("scrollBottom.sticky", function() {
stuckToBottom = true;
lastStick = Date.now();
this.scrollTop = this.scrollHeight;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable is never used

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What variable? this in this context is the element, so this scrolls to the bottom. Would be silly to wrap this in jQuery to end up doing the exact same thing.

Copy link
Member

@xPaw xPaw Jun 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDIT: I am an idiot.

@xPaw xPaw merged commit b6fa447 into thelounge:master Jun 5, 2016
@maxpoulin64 maxpoulin64 deleted the sticky-fix branch July 4, 2016 23:50
matburnham pushed a commit to matburnham/lounge that referenced this pull request Sep 6, 2017
Keep chat stickied to the bottom on resize
@xPaw xPaw removed their assignment Mar 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issues that report and PRs that solve any defects that cause unexpected behaviors.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants