Page - 图1

Page React Component

Page in Framework7 has the same meaning as when you think about web pages. Page is the main component to display and operate content.

Page React component represents Framework7’s Page.

Page Components

There are following components included:

  • **Page** / **F7Page** - main page element
  • **PageContent** / **F7PageContent** - additional inner page content element

Page Properties

PropTypeDefaultDescription
<Page> properties
namestringPage name
stackedbooleanEnable for not currently active page if you use stackedPages Router parameter that keeps all pages in DOM
messagesContentbooleanEnable if you use Messages component inside to add required extra styling
pageContentbooleantrueWhen enabled it automatically adds page-content element inside. Usefule to disable when you need to use few page-content elements for tabs
tabsbooleanEnable if you use Page as Tabs wrapper
loginScreenbooleanEnable if you use Login Screen inside of the page to add required extra styling
noSwipebackbooleanDisables swipeback feature for the current page (affects iOS theme only)
withSubnavbarbooleanEnable if you have Sub Navbar inside of the page
noNavbarbooleanEnable if you use common Navbar layout and need to hide common Navbar (or use another one) for this page (affects iOS theme only)
noToolbarbooleanEnable if you use common Toolbar/Tabbar layout and need to hide Toolbar (or use another one) for this page
hideBarsOnScrollbooleanHide Navbar & Toolbar on page scroll
hideNavbarOnScrollbooleanHide Navbar on page scroll
hideToolbarOnScrollbooleanHide Toolbar on page scroll
ptrbooleanEnables Pull To Refresh
ptrDistancenumberCustom pull to refresh trigger distance. By default (if not specified) it is 44px.
ptrPreloaderbooleantrueDisable if you want to use custom pull to refresh preloader element
ptrBottombooleanfalseEnables pull to refresh from bottom
ptrMousewheelbooleanfalseEnables pull to refresh with mousewheel (for desktop apps). Works only for PTR top
infinitebooleanEnables Infinite Scroll
infiniteTopbooleanEnables infinite scroll on top of the page
infiniteDistancebooleantrueDistance from the bottom of page (in px) to trigger infinite scroll event. By default (if not specified), it is 50 (px)
infinitePreloaderbooleantrueDisable if you want to use custom infinite-scroll preloader
<PageContent> properties
tabbooleanEnable if you use page-content as Tab
tabActivebooleanEnable if the current tab is active
ptr
ptrDistance
ptrPreloader
ptrBottom
ptrMousewheel
infinite
infiniteTop
infiniteDistance
infinitePreloader
hideBarsOnScroll
hideNavbarOnScroll
hideToolbarOnScroll
messagesContent
loginScreen
Same as <Page> properties

Page Events

EventDescription
<Page> events
pageMountedEvent will be triggered when page with keepAlive route is mounted/attached to DOM
pageInitEvent will be triggered after Framework7 initialize required page’s components and navbar
pageReinitThis event will be triggered in case of navigating to the page that was already initialized.
pageBeforeInEvent will be triggered when everything initialized and page is ready to be transitioned into view (into active/current position)
pageAfterInEvent will be triggered after page transitioned into view
pageBeforeOutEvent will be triggered right before page is going to be transitioned out of view
pageAfterOutEvent will be triggered after page transitioned out of view
pageBeforeUnmountEvent will be triggered when page with keepAlive route is going to be unmounted/detached from DOM
pageBeforeRemoveEvent will be triggered right before Page will be removed from DOM. This event could be very useful if you need to detach some events / destroy some plugins to free memory. This event won’t be triggered for keepAlive routes.
ptrPullStartEvent will be triggered when you start to move pull to refresh content
ptrPullMoveEvent will be triggered during you move pull to refresh content
ptrPullEndEvent will be triggered when you release pull to refresh content
ptrRefreshEvent will be triggered when pull to refresh enters in “refreshing” state
ptrDoneEvent will be triggered after pull to refresh is done and it is back to initial state (after calling pullToRefreshDone method)
infiniteEvent will be triggered when page scroll reaches specified (in data-distance attribute) distance to the bottom.
<PageContent> events
tabShowEvent will be triggered when Tab becomes visible/active
tabHideEvent will be triggered when Tab becomes hidden/inactive
ptrPullStart
ptrPullMove
ptrPullEnd
ptrEefresh
ptrDone
infinite
Same as <Page> events

Page Slots

Page React component (<Page>) has additional slots for custom elements:

  • **default** - element will be inserted as a child of “page-content”, if page-content prop is enabled (by default)
  • **fixed** - element will be inserted as a direct child of “page” right before “page-content”
  1. <Page>
  2. <div slot="fixed">Fixed element</div>
  3. <p>Page content goes here</p>
  4. </Page>
  5. {/* Renders to: */}
  6. <div class="page">
  7. <div>Fixed element</div>
  8. <div class="page-content">
  9. <p>Page content goes here</p>
  10. </div>
  11. </div>

Examples

Infinite Scroll

  1. export default class extends React.Component {
  2. constructor(props) {
  3. super(props);
  4. this.state = {
  5. items: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
  6. allowInfinite: true,
  7. showPreloader: true,
  8. };
  9. }
  10. render() {
  11. return (
  12. <Page
  13. infinite
  14. infiniteDistance={50}
  15. infinitePreloader={this.state.showPreloader}
  16. onInfinite={this.loadMore.bind(this)}
  17. >
  18. <Navbar title="Infinite Scroll"></Navbar>
  19. <BlockTitle>Scroll bottom</BlockTitle>
  20. <List>
  21. {this.state.items.map((item, index) => (
  22. <ListItem title={`Item ${item}`} key={index}></ListItem>
  23. ))}
  24. </List>
  25. </Page>
  26. )
  27. }
  28. loadMore() {
  29. const self = this;
  30. if (!self.state.allowInfinite) return;
  31. self.setState({ allowInfinite: false });
  32. setTimeout(() => {
  33. const items = self.state.items;
  34. if (items.length >= 200) {
  35. self.setState({ showPreloader: false });
  36. return;
  37. }
  38. const itemsLength = items.length;
  39. for (let i = 1; i <= 20; i += 1) {
  40. items.push(itemsLength + i);
  41. }
  42. self.setState({
  43. items,
  44. allowInfinite: true,
  45. });
  46. }, 1000);
  47. }
  48. };

Pull To Refresh

  1. export default class extends React.Component {
  2. constructor(props) {
  3. super(props);
  4. this.state = {
  5. items: [
  6. {
  7. title: 'Yellow Submarine',
  8. author: 'Beatles',
  9. cover: 'https://cdn.framework7.io/placeholder/abstract-88x88-1.jpg',
  10. },
  11. {
  12. title: 'Don\'t Stop Me Now',
  13. author: 'Queen',
  14. cover: 'https://cdn.framework7.io/placeholder/abstract-88x88-2.jpg',
  15. },
  16. {
  17. title: 'Billie Jean',
  18. author: 'Michael Jackson',
  19. cover: 'https://cdn.framework7.io/placeholder/abstract-88x88-3.jpg',
  20. },
  21. ],
  22. songs: ['Yellow Submarine', 'Don\'t Stop Me Now', 'Billie Jean', 'Californication'],
  23. authors: ['Beatles', 'Queen', 'Michael Jackson', 'Red Hot Chili Peppers'],
  24. }
  25. }
  26. render() {
  27. return (
  28. <Page ptr onPtrRefresh={this.loadMore.bind(this)}>
  29. <Navbar title="Pull To Refresh"></Navbar>
  30. <List mediaList>
  31. {this.state.items.map((item, index) => (
  32. <ListItem
  33. key={index}
  34. title={item.title}
  35. subtitle={item.author}
  36. >
  37. <img slot="media" src={item.cover} width="44" />
  38. </ListItem>
  39. ))}
  40. <BlockFooter>
  41. <p>Just pull page down to let the magic happen.<br />Note that pull-to-refresh feature is optimised for touch and native scrolling so it may not work on desktop browser.</p>
  42. </BlockFooter>
  43. </List>
  44. </Page>
  45. );
  46. }
  47. loadMore(event, done) {
  48. const self = this;
  49. setTimeout(() => {
  50. const { items, songs, authors } = self.state;
  51. const picURL = `https://cdn.framework7.io/placeholder/abstract-88x88-${(Math.floor(Math.random() * 10) + 1)}.jpg`;
  52. const song = songs[Math.floor(Math.random() * songs.length)];
  53. const author = authors[Math.floor(Math.random() * authors.length)];
  54. items.push({
  55. title: song,
  56. author,
  57. cover: picURL,
  58. });
  59. self.setState({ items });
  60. done();
  61. }, 1000);
  62. }
  63. }