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

loadMoreAction fires prematurely #82

Closed
daniel-de-wit opened this issue Aug 27, 2015 · 12 comments
Closed

loadMoreAction fires prematurely #82

daniel-de-wit opened this issue Aug 27, 2015 · 12 comments

Comments

@daniel-de-wit
Copy link

In my app I have many scrollable divs nested. This causes the loadMoreAction to fire prematurely from the component. Even when defining the scrollable attribute on the component.

I lack experience to really test en provide a working solution for everyone. By changing the way the offset is calculated when position is other than relative fixed my issue.

For relative ( original ):

var selfOffset  = this.$().offset().top;
var scrollableBottom = scrollable.height() + scrollable.scrollTop();


For fixed / absolute:

var selfOffset  = this.$().position().top;
var scrollableBottom = scrollable.height();

ember-infinity/addon/components/infinity-loader.js
Original:

_checkIfInView() {
  var selfOffset       = this.$().offset().top;
  var scrollable       = this.get("scrollable");
  var scrollableBottom = scrollable.height() + scrollable.scrollTop();

  var inView = selfOffset < scrollableBottom;

  if (inView && !this.get('developmentMode')) {
    this.sendAction('loadMoreAction');
  }
},

Edited ( works for me ):

_checkIfInView() {

  var scrollable = this.get("scrollable");
  var selfOffset;

  var scrollableBottom;



  if(scrollable.css('position') == 'relative') {

    selfOffset       = this.$().offset().top;

    scrollableBottom = scrollable.height() + scrollable.scrollTop();

  } else {

    selfOffset = this.$().position().top;

    scrollableBottom = scrollable.height();

  }



  var inView = selfOffset < scrollableBottom;



  if (inView && !this.get('developmentMode')) {

    this.sendAction('loadMoreAction');

  }

},
@hhff
Copy link
Collaborator

hhff commented Aug 27, 2015

Inneresting. I think catering for every use case is outside of the scope of this library. However I think maybe we should make this hook public, so that people who want to control how this check works can easily override it.

@daniel-de-wit would u be down to submit a PR to make this public, and document your use case in the README?

@daniel-de-wit
Copy link
Author

Thanks for your reply, I was on vacation so didn't see your message..

I believe there must be a proper way we can detect if the component is on screen. There are some jQuery plugins that work with nested scrollable divs, I think. Maybe I can extract a good solution for every use case since we just want it to fire when visible to the user on screen.

I definitely like your idea of making the hook public.

It might take me a little while to fix this as I have never actually commited something to an open-source project. But I will try to do it :)

Thanks again for making this wonderfull addon 👍

@hhff
Copy link
Collaborator

hhff commented Sep 1, 2015

I wonder if we can use this somehow?
https://github.com/poteto/ember-in-viewport-demo

On Tue, 1 Sep 2015 at 15:50 Daniel de Wit [email protected] wrote:

Thanks for your reply, I was on vacation so didn't see your message..

I believe there must be a proper way we can detect if the component is on
screen. There are some jQuery plugins that work with nested scrollable
divs, I think. Maybe I can extract a good solution for every use case since
we just want it to fire when visible to the user on screen.

I definitely like your idea of making the hook public.

It might take me a little while to fix this as I have never actually
commited something to an open-source project. But I will try to do it :)

Thanks again for making this wonderfull addon [image: 👍]


Reply to this email directly or view it on GitHub
#82 (comment).

@hhff
Copy link
Collaborator

hhff commented Sep 1, 2015

@hhff
Copy link
Collaborator

hhff commented Sep 1, 2015

Yeah! We totally can...

wanna have a go at it? I can help with the OSS stuff 👍

@daniel-de-wit
Copy link
Author

Yes sounds like a fun challenge ;)

I wonder if the ember-in-viewport supports nested scrollable divs. I'll go fiddle with it.
I'll keep you posted.

@hhff
Copy link
Collaborator

hhff commented Sep 1, 2015

awesome @daniel-de-wit !!!

@ghost
Copy link

ghost commented Sep 1, 2015 via email

@hhff
Copy link
Collaborator

hhff commented Sep 1, 2015

pretty sure ember-in-viewport supports offsets out of the box 👍

@hhff
Copy link
Collaborator

hhff commented Sep 1, 2015

jah it does

export default Ember.Component.extend(InViewportMixin, {
  viewportOptionsOverride: Ember.on('didInsertElement', function() {
    Ember.setProperties(this, {
      viewportUseRAF            : true,
      viewportSpy               : false,
      viewportScrollSensitivity : 1,
      viewportRefreshRate       : 150,
      viewportTolerance: {
        top    : 50,
        bottom : 50,
        left   : 20,
        right  : 20
      }
    });
  })
});

@ghost
Copy link

ghost commented Sep 1, 2015

Cool :).

2015-09-01 16:16 GMT+02:00 Hugh Francis [email protected]:

jah it does

export default Ember.Component.extend(InViewportMixin, {
viewportOptionsOverride: Ember.on('didInsertElement', function() {
Ember.setProperties(this, {
viewportUseRAF : true,
viewportSpy : false,
viewportScrollSensitivity : 1,
viewportRefreshRate : 150,
viewportTolerance: {
top : 50,
bottom : 50,
left : 20,
right : 20
}
});
})
});


Reply to this email directly or view it on GitHub
#82 (comment).

@andrewhavens
Copy link

I also was having an issue where the loading component was not triggering the loadMoreAction when it came into view. I also tried the InViewportMixin and it worked for me! Here is the code that I used to achieve the results that I needed (note that I start loading 1500px before the loader comes into the viewport):

import Ember from 'ember';
import InfinityLoaderComponent from 'ember-infinity/components/infinity-loader';
import InViewportMixin from 'ember-in-viewport';

export default InfinityLoaderComponent.extend(InViewportMixin, {
  viewportOptionsOverride: Ember.on('didInsertElement', function() {
    Ember.setProperties(this, {
      viewportSpy: true,
      viewportTolerance: {
        bottom: 1500,
      }
    });
  }),

  didEnterViewport() {
    this.sendAction('loadMoreAction')
  },

});

@hhff hhff closed this as completed Aug 5, 2016
sporkexec added a commit to CashCacheTracker/cashcache-web that referenced this issue Nov 26, 2016
We're not scrolling the window (which is the default behavior), manually
specifying a scrollable just loads everything, and rolling our own with
ember-in-viewport doesn't work in Ember 2.9 for now. I'll just leave
this half-baked branch here. Maybe we can add a button to manually load
more until the dust settles? Maybe we should just fully roll our own?

And reminder: "total pages" in ember-infinity seems to actually mean
"total records".

adopted-ember-addons/ember-infinity#97
adopted-ember-addons/ember-infinity#82 (comment)
DockYard/ember-in-viewport#95
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants