amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

FR: Infinite scroll

Open ericlindley-g opened this issue 9 years ago • 21 comments

Thinking through this, but first idea is allowing scroll events to trigger amp-list[src] update if a) w/in certain distance of bottom of document and b) target amp-list element is last child of <body>

Though there may be a better approach (e.g. w/ an entirely custom element)

ericlindley-g avatar May 18 '17 21:05 ericlindley-g

I think a dedicated element would be the way to go, ideally we'd be able to bring in a section of another amp page and have it display the part we want and bring in any needed amp extensions that were not on the page already.

We also want the new page to be able to refresh the config so that we could specify the next page dynamically.

Might need to start trimming stuff at the top of the page to save memory ...

jpettitt avatar Jun 12 '17 22:06 jpettitt

hi, I need this solution too, any workaround approach for this please ?

leonahliang90 avatar Nov 23 '17 12:11 leonahliang90

Brother when you will complete this task my company is wait for trigger !

haroon8iconglobal avatar Jan 15 '18 18:01 haroon8iconglobal

if an amp-position-observer component could trigger setState actions, we could implement an amp-list with infinite scroll without additional components. is it possible to loosen this restriction in some situations? this would also work if amp-position-observer component could trigger a form submit action.

cpapazian avatar Jan 20 '18 21:01 cpapazian

I think in scroll event at a time shows only 5 itmes as per screen, so if someone scroll down upward items should remove or if respectively scroll up ward so at top most blow items must remove so at the time as per mentioned item should be only shows

On Jan 21, 2018 2:39 AM, "Chris Papazian" [email protected] wrote:

if an amp-position-observer component could trigger setState actions, we could implement an amp-list with infinite scroll without additional components. is it possible to loosen this restriction in some situations?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ampproject/amphtml/issues/9423#issuecomment-359204203, or mute the thread https://github.com/notifications/unsubscribe-auth/Ah0r52p2w9L6VdYH71XI6mleH5PD4tPQks5tMlz0gaJpZM4NfzjB .

haroon8iconglobal avatar Jan 21 '18 04:01 haroon8iconglobal

@cpapazian — that's a good point, though creating a new infinite scroll component in order to manage that use case offers the ability to manage other aspects of the UX and make performance optimizations with this use case in mind. It also means that bind stays simpler (and doesn't need to risk cases where forms submit without explicit user intent).

ericlindley-g avatar Jan 22 '18 17:01 ericlindley-g

@haroon8iconglobal I think you might be talking about something like DOM recycling (?) https://developers.google.com/web/updates/2016/07/infinite-scroller It's a good point that we need to manage performance somehow, and this is one way that we're looking into it. Thanks!

ericlindley-g avatar Jan 22 '18 17:01 ericlindley-g

@ericlindley-g -- allowing form submit on change and especially input-debounced is already stretching explicit user intent, though I agree that scrolling the page stretches things even further.

We could still put some limits on this. the amp-position-observer component could be required to be int he form's subtree to submit actions, or we could limit to forms with method=GET.

setState would be a bit more kludgey, but would avoid the form submit issues.

A new component is fine, too. Though, in my mind, it ends up looking pretty much identical to the existing amp-position-observer component, though I am surely missing some edge cases ...

cpapazian avatar Jan 22 '18 17:01 cpapazian

@ericlindley-g @aghassemi @lswang1618 @sebastianbenz Flagging a possibility to have both client-side filtering with infinite scroll if we bundle this into amp-list and amp-bind. Mostly useful for the e-commerce use case.

Combining a metaprogramming idea from another thread:

<amp-list 
    filter="item.color == 'red' && item.inStock"
    [filter]="condition1 + operator + condition2"
    auto-fetch-on-scroll="page">
  • filter contains an amp-bind expression
  • [filter] allows you to configure filter to change filter conditions
  • auto-fetch-on-scroll enables infinite scroll feature and is the name of a query param that is automatically added to the URL e.g. ?page=3 for the third fetch

dreamofabear avatar Jan 24 '18 23:01 dreamofabear

@choumx how would the filter attribute work in amp-list's single-item mode? Sometimes you're forced to use single-item mode even for lists (e.g. when combining amp-list with amp-carousel).

sebastianbenz avatar Jan 25 '18 07:01 sebastianbenz

Filtering would still work -- the item will either be filtered or won't be. The amp-list could render zero items. Prototype here: #13028

dreamofabear avatar Jan 25 '18 17:01 dreamofabear

@choumx I'm taking about a different use case:

<amp-carousel ...>
<amp-list singleitem items="."  ...>
<template>
{{#slides}}
<div>Slide 1</div>.   <= slides needs to be filtered
{{/slides}}
</template>
</amp-list>
</amp-carousel>

One solution would be to specify a path, e.g.: filter-target="slides".

sebastianbenz avatar Jan 31 '18 21:01 sebastianbenz

auto-fetch-on-scroll enables infinite scroll feature and is the name of a query param that is automatically added to the URL e.g. ?page=3 for the third fetch

something like this, combined with https://github.com/ampproject/amphtml/issues/12540, could work for us. are you envisioning the fetch triggering when the user scrolls to the end of the result set?

one small nit: instead of an incrementing page count, could the value reference a field in the previous set of results? we keep a "bookmark" for the results, which is included in a result and passed to the next result. so, a possible amp-list result could be:

{
  items: [ ... ],
  bookmark: 'placeholder'
}

where items are appended to the list of items and a bookmark field is overwritten with the latest value. then, the request for the next page would get &bookmark=placeholder appended to its query string.

i have some non-infinite scrolling prototypes that i'm working on that use this mechanism (though https://github.com/ampproject/amphtml/issues/11881 blocks us from testing in production).

cpapazian avatar Feb 01 '18 19:02 cpapazian

/cc @spacedino

ericlindley-g avatar Feb 28 '18 17:02 ericlindley-g

first idea is allowing scroll events to trigger amp-list[src] update

Using amp-list would not be feasible for a lot of content which we may want to infinite-scroll. Since amp-list renders via mustache templates, and since mustache templates restrict the markup to just basic formatting, it would prevent infinite scroll from including images, videos, and any other arbitrary rich content that would be required. Extending an amp-live-list to support infinite scroll would be viable, however, since arbitrary AMP markup is allowed. See #8314.

westonruter avatar Mar 12 '18 21:03 westonruter

@westonruter templates in amp-list support pretty much everything supported at document level including amp-image, amp-iframe, amp-video, etc.. Is there a particular component you could not use in amp-list? If so, please file an issue for us and we can look into fixing it.

aghassemi avatar Mar 13 '18 00:03 aghassemi

@aghassemi I'm referring to:

Output arbitrary HTML using {{{unescaped}}}. The output of "triple-mustache" is sanitized to only allow formatting tags such as <b>, <i>, and so on.

https://www.ampproject.org/docs/reference/components/amp-mustache#restrictions

So specifically content output via triple-mustache. For example, a use case is:

<amp-list src="https://example.com/wp-json/wp/v2/posts">
  <template type="amp-mustache">
    <article>
      <h1><a href="{{link}}">{{{title.rendered}}}</a></h1>
      {{{content.rendered}}}
    </article>
  </template>
</amp-list>

Where content.rendered includes arbitrary amphtml.

westonruter avatar Mar 13 '18 00:03 westonruter

@westonruter Oh I see, yeah that's by design since without having static template, we can't validate the end result would be valid AMP. amp-live-list won't have that issue since updates are done in the AMP page itself.

@ericlindley-g Looks like we may need a separate infinite scroll solution for amp-live-list (FR #8314) as not all cases can be handled with amp-list.

@westonruter What are some of the use-cases you have in mind, if you don't mind sharing? We are also building a separate infinite scroll component that allows loading whole new AMP documents when user reaches end of one. (see https://github.com/ampproject/amphtml/issues/12945)

aghassemi avatar Mar 13 '18 01:03 aghassemi

What are some of the use-cases you have in mind, if you don't mind sharing?

I'm not sure what else there is to elaborate on. The use case is to list the most recent posts or comments from a REST API endpoint, where the data returned can include amphtml markup which needs to be rendered in an AMP document.

westonruter avatar Mar 13 '18 02:03 westonruter

Thanks @westonruter, just wanted to make sure your use-case is different than infinite scrolling for whole AMP documents which is getting its own component. Infinite scroll for rich comments is definitely a compelling use-case.

aghassemi avatar Mar 13 '18 02:03 aghassemi