-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
feat(infinite): add scroll in opposite direction #8099
Conversation
somebody will react to this pull request? |
I've been using it and it works great for me. You do need to hook into the right viewcycle events to save the current and set the new scroll position or the browser will jump up with the new content. This implementation will differ per situation and should not be integrated (I think), but some documentation about it might be good. |
@jgw96 could you check this great pull request? |
@Manduro thanks for the PR and yes we I will look into it, but right now ionic 2 is feature freeze until 2.0 final. The whole team is focusing efforts to fix as much bugs as possible. does it make sense? |
Sure, makes a lot of sense! |
Hi @Manduro, thanks for this PR! Until Ionic merges this in, how can we use this in our own projects? Do we need to go into the node_modules and modify the JS files to reflect exactly your changes? Or is there a way to maybe install this file into our projects using the command line? I have a chat feature in our app and would love to use this :) |
@jpbullalayao I'm not sure what's the proper way to do that. Maybe someone from the Ionic team can chime in? Editing inside your |
Hi @Manduro, I'm using this code for the chat feature in my app; I was wondering how you implemented your HTML/CSS in order to handle the UI for this? As you said, we need to perhaps set the new scroll position in order to prevent the browser from jumping with the new content. How did you implement the Typescript/JS for this in your situation? |
Code removed as it's incompatible and outdated with the current Ionic version. |
@Manduro Thanks so much!! This is helping a lot, I'll be happy to provide any feedback I might have after fully implementing this UI part. Another question I have. What's |
My |
Does anyone know when Ionic will implement this feature with their version? |
I am also following this one with great interest. I need it for a chat in my app very soon. |
This would be great for me as well for RC5/Final Release! |
Rebased on current master! |
@Manduro Is it possible to see this PR in the ionic milestones? |
Thank you @Manduro @brandyscarney @manucorporat Is it possible to see this PR in the ionic milestones? |
@jgw96 Pleeeeease accept this PR |
@theromis We'll take a look at it for the 2.1.0 release, thanks! |
@jgw96 I've added code to correctly maintain the scroll position when loading more at the top, give it a try!
|
We also need this feature. Will it be in version 2.3.0 ? |
Can I use this now? or Do I have to wait for it to be merged to master? |
@Manduro the code looks pretty good, I will try to merge this in 2.3 |
src/components/content/content.ts
Outdated
*/ | ||
@Input() | ||
get scrollDownOnLoad(): boolean { | ||
return !!this._scrollDownOnLoad; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!! is probably not needed, right? since we are using isTrueProperty() in the setter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, this can be removed if you'd like. I just copied the getter and setter from @Input() fullscreen
.
set position(val: string) { | ||
if (val === POSITION_TOP || val === POSITION_BOTTOM) { | ||
this._position = val; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add here a console.error()
telling val was an invalid value, and the two possible valid values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!
@@ -267,7 +286,23 @@ export class InfiniteScroll { | |||
* to `enabled`. | |||
*/ | |||
complete() { | |||
if (this.state === STATE_LOADING) { | |||
if (this._position === POSITION_TOP) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain a little bit the algorithm used here?
how many frames does it take? and why?
I think I get it, but still... you probably know better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! I'll add a few more comments as well.
New content is being added at the top, but the scrollTop
position stays the same, which causes a scroll jump visually. This algorithm makes sure to prevent this.
(Frame 1)
complete()
is called, but the UI hasn't had time to update yet.- Save the current content dimensions.
- Wait for the next frame using
_dom.read
, so the UI will be updated.
(Frame 2)
- Read the new content dimensions.
- Calculate the height difference and the new scroll position.
- Delay the scroll position change until other possible dom reads are done using
_dom.write
to be performant.
(Still frame 2, if I'm correct)
- Change the scroll position (= visually maintain the scroll position).
- Change the state to re-enable the InfiniteScroll. This should be after changing the scroll position, or it could cause the InfiniteScroll to be triggered again immediately.
(Frame 3)
@manucorporat Thanks! I've made some slight changes as requested. Haven't squashed to keep the history, so make sure to do that when merging. Thanks for building this amazing framework :) |
Merged! I also made a minor change: Thanks a lot for the PR! awesome new feature! |
Hi @Manduro , I am trying to implement a chat application and I am using the infinite-scroll on top but unfortunatly I haven't been able to use your "Maintains scroll position when adding content to the top." feature. Once new data has loaded, it automatically scrolls back to the top, and then infinitely loading more and more. |
Im also having the same issue.. |
@AlanChauchet I'm also trying to implement a chat application and i'm also having the same issue.. |
There are 2 issues in current implementation:
|
created a bug #12598 going to send PR shortly |
created a fix #12599 |
Short description of what this resolves:
This adds support for infinite scrolling towards the top of a view.
Changes proposed in this pull request:
InfiniteScroll
component.scrollDownOnLoad
input toContent
.Ionic Version: 2.x
Fixes: #6696 #9237