amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Use Amp List for showing more content when height is not available

Open sffriend opened this issue 9 years ago • 24 comments

We want the user to be able to load a amp-list of more comments after the initial page load. We don't know the height of these comments because they can be any length. We can't use the overflow button because we already have our own overflow button whose source is updated on amp-bind.

      <script type="application/json">
      {
        "moreCommentsSrc": "/json/comments2.json"
      }
      </script>
    </amp-state>

      <amp-list class="mt1" width="auto" height="600" [height]="comments.moreCommentsSrc == '/json/comments2.json' ? 600 : 1000" layout="fixed-height"
        src="/json/comments2.json"
        [src]="comments.moreCommentsSrc"
        >
        <template type="amp-mustache">
          <div class="flex px1 pt1 depth-{{depth}}">
            <amp-img width="44" height="44" class="mr1 flex-none" alt="user" src="/img/ic_account_box_black_48dp_1x.png"></amp-img>
            <div class="ampstart-card p1 comment">
              <p><span class="user">{{user}}</span> <span class="date">{{datetime}}</span></p>
              <p>{{text}}</p>
            </div>
          </div>
        </template>
      </amp-list>
      <button class="ampstart-btn caps m1 mb3 show" [class]="comments.moreCommentsSrc == '/json/comments2.json' ? 'ampstart-btn caps m1 mb3 show' : 'ampstart-btn caps m1 mb3 hide'" on="tap:AMP.setState({comments: {moreCommentsSrc: '/json/comments3.json'}})">Show more</button>```

sffriend avatar Jul 14 '17 23:07 sffriend

/to @ericlindley-g @aghassemi

rudygalfi avatar Jul 15 '17 00:07 rudygalfi

  • @choumx

aghassemi avatar Jul 15 '17 00:07 aghassemi

Thanks @sffriend ! @choumx, I think this is somewhat similar to the request for resizing when updated through amp-bind, except it's done on the first page load. Would it be possible for amp-list to have container layout for its contents, or is that too risky for page jumps on first load?

ericlindley-g avatar Jul 15 '17 00:07 ericlindley-g

Sorry for the late response!

Would it be possible for amp-list to have container layout for its contents, or is that too risky for page jumps on first load?

Yea I'd think that's a nonstarter due to content jumping.

We can't use the overflow button because we already have our own overflow button whose source is updated on amp-bind.

Why not? I can imagine having a "view all comments" overflow button and a "next page" pagination button. Not as elegant as having a single button but avoids content jumping.

dreamofabear avatar Jul 24 '17 15:07 dreamofabear

Thanks @choumx ! Can you add detail on why content jumping is higher risk in this case than in, say, the case where it resizes based on how many items are returned from the server call?

ericlindley-g avatar Jul 24 '17 15:07 ericlindley-g

Maybe I'm missing something. The latter requires user action while the former doesn't, right?

dreamofabear avatar Jul 24 '17 15:07 dreamofabear

Ah, sorry — momentarily forgot how amp-list worked, so you can disregard my question

ericlindley-g avatar Jul 24 '17 16:07 ericlindley-g

@choumx The idea of using 2 buttons doesn't help to keep the current Reddit experience the same. Currently the mobile page shows, at the bottom: "More comments (number of comment)" and there is no pagination in place. I think having 2 buttons would be confusing.

kul3r4 avatar Jul 25 '17 15:07 kul3r4

@kul3r4 If an amp-list is at the bottom of the page, resizing should be automatic (overflow button won't be displayed).

@sffriend Can you provide more details on your exact use case? E.g. a sample page.

dreamofabear avatar Jul 25 '17 16:07 dreamofabear

I was looking at this page on mobile, it's true that the amp-list would be at the bottom of the page which makes things easier @sffriend would you like to take a second look at this?

kul3r4 avatar Jul 26 '17 10:07 kul3r4

@choumx

If an amp-list is at the bottom of the page, resizing should be automatic (overflow button won't be displayed).

I also read this in the documentation. But I can't get this to actually happen. I have a test page with just an amp-list inside the body tag. But I always get the overflow button. Is there anything specific needed to get this to work?

ghost avatar Sep 07 '17 10:09 ghost

@devanes Could you share the test page?

kul3r4 avatar Sep 07 '17 10:09 kul3r4

@kul3r4

https://bronsvuur.nl/test/test.html

ghost avatar Sep 07 '17 11:09 ghost

Note that I set the height of each item to a higher value to make the issue more visible. I can remove this and just add more content or reduce the height of the amp-list to get the same result.

ghost avatar Sep 07 '17 11:09 ghost

The problem is that your list is not below the first viewport. Take a look at this:

  • Load the page the first time and then scroll to the bottom. At the bottom there is an example of overflow button and the button doesn't appear
  • Then, without scrolling to the top, reload the page and you will see the button appearing

This is because amp-list will automatically take more space if required (and available) but at the same time it has to be below the first viewport to avoid reflow while the page is loading.

kul3r4 avatar Sep 08 '17 12:09 kul3r4

We just published a new sample showing how to implement a load more button

kul3r4 avatar Sep 19 '17 11:09 kul3r4

@kul3r4 That looks interesting. At the moment I have implemented it in a way where using amp-bind the entire contents of the amp-list is replaced with the new batch combined with a scroll to the top of the list, basically previous/next pagination without reload.

ghost avatar Sep 19 '17 12:09 ghost

@devanes I see, this was the previous approach in the sample as well, but with this new approach you only load the newer items.

kul3r4 avatar Sep 19 '17 14:09 kul3r4

Highly looking forward the <amp-list> to support the scroll event and automatically triggering the request for more items.

grahamle avatar Nov 27 '17 17:11 grahamle

@grahamle We are planning to prioritize this work. Please subscribe to https://github.com/ampproject/amphtml/issues/9423 for updates.

aghassemi avatar Nov 27 '17 21:11 aghassemi