gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit6dcaeb466dcaeb46Records: resetKey planmre6dcaeb46/components/virtual-list/README.md

3.7 KB

  1. # Virtual list
  2. A list of tens of thousands of rows that scrolls smoothly on a phone. Demo: `/virtual-list`
  3. (https://components.hybriel.worldapi.org/virtual-list).
  4. Only the rows near the viewport exist in the page. Every row has the same fixed height, so the list knows
  5. where row N is without measuring: a spacer as tall as the whole list (`itemCount × rowHeight`) makes the scroll
  6. bar honest, and the few rows near the viewport (about 30 on a phone) are placed inside it. Scrolling a
  7. 13,449-row list to the end keeps the page at about 35 rows.
  8. Pure Hybriel: one file, `virtual-list.hl`, with its own `Style`; no JavaScript file. It does not fetch anything:
  9. **the host owns the data** and loads it page by page.
  10. ## Use it in an app
  11. Copy `components/virtual-list/virtual-list.hl` (and `components/icons/icons.hl`, which it imports), then:
  12. ```
  13. import VirtualList from './virtual-list.hl'
  14. Number total = 13449
  15. Hybrid chunk = [] // the rows the host has loaded
  16. Number chunkFrom = 0 // the number of the first row in `chunk`
  17. loadRange = (first, wanted) => {
  18. r = emit server myRows(first - 20 < 0 ? 0 : first - 20, 100) // an app asks its server
  19. chunk = r.rows
  20. chunkFrom = r.offset
  21. }
  22. picked = (id, index) => { ... }
  23. View {
  24. div { class = "my-box" // gets a height, the list scrolls inside it
  25. VirtualList { itemCount = total rowHeight = 56 loaded = chunk loadedFrom = chunkFrom onRange = loadRange onPick = picked selectedId = playingId }
  26. }
  27. }
  28. ```
  29. ## Attributes
  30. | Attribute | Meaning |
  31. |---|---|
  32. | `itemCount` | how many rows the whole list has |
  33. | `rowHeight` | the height of every row in pixels (default 56); the rows are exactly this tall |
  34. | `loaded` | the rows the host has loaded, `[{ id, title, sub, aside, img }]`; `img` is a thumbnail address or `''` (a plain square) and is loaded lazily |
  35. | `loadedFrom` | the number of the first row in `loaded` (0-based) |
  36. | `onRange` | a function the host hands in; called with `(first, count)` when rows near the viewport are not all in `loaded`; the host loads them and hands in new `loaded` / `loadedFrom` |
  37. | `onPick` | called with `(id, index)` when a row is tapped |
  38. | `selectedId` | the `id` of the row to mark (the accent colour on a surface) |
  39. | `thumbs` | `"false"` leaves the thumbnail out |
  40. | `overscan` | how many rows are kept above and below the viewport (default 10) |
  41. | `listLabel`, `emptyText` | the accessible name of the list; the text shown when `itemCount` is 0 |
  42. | content | anything written inside `VirtualList { … }` stands above the rows and scrolls away with them (an album's cover and title) |
  43. `emit vlTop()` scrolls back to the first row; the host calls it after it changed the order or the filter.
  44. ## Behaviour
  45. - Rows that the host has not delivered yet are blank rows of the same height, so the list never jumps; the host's
  46. `loaded` may be only a chunk of 100 rows around the viewport, a jump to the middle of the list asks for that part.
  47. - The list fills the box the host gives `virtual-list` (`height: 100%` of its parent, the scrolling happens inside).
  48. - A row is a button (keyboard Tab and Enter work), exactly `rowHeight` tall: the tap area is the row itself, no padding tricks, so the
  49. list stays dense. Thumbnail, the text block and the row share one centre line.
  50. - Colours are the semantic tokens with a black/white/grey fallback (the base look); no frames.
  51. - **Use one per page**: a composed component's members are the page's state, so the public names (`itemCount`, `loaded`, `selectedId` …)
  52. are chosen to stay clear of a host's own.
  53. ## Not yet
  54. No row measuring (all rows are one height), no sticky section headers, no horizontal lists, no keyboard arrow navigation between
  55. rows (Tab moves along the rows that exist), and a row moved out of the window loses the keyboard focus.

Branches

Latest commits

  • 6dcaeb46Records: resetKey planmre
  • c5dbf2ecRecords: R2 resultmre
  • 956069b8Records: R1 result, mission 007mre
  • 3c8a2e12Mission 007: #20 sort scrollmre
  • deb8cef5Records: mission 006 startedmre
  • 4f0ad42fMission 006: jukebox#20mre
  • 800cae06Records: #21 planmre
  • 64bc7823Records: #21 causemre
  • 76639655Records: B1 questionmre
  • d7906b36Records: mission 005 startedmre
  • d3df773cMission 005: doc linemre
  • 6a5d840aMission 005: jukebox#22mre
  • 13e5e748Records: mission 004 startedmre
  • a8098271Mission 004: jukebox#21mre
  • df8f5205Records: jukebox#19-21, #11 closedmre
  • b7a4e692Records: hybriel#298mre
  • 9bcbb017Records: day38b waits for day39 fixmre
  • f80504e1Records: day38b repro sentmre
  • 8048258bRecords: day38b jb3 regression, L1 Chromes stoppedmre
  • 68aace7fRecords: mission 003 day38bmre