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

Prop Type Default Description
<Page> properties
--- --- --- ---
name string Page name
stacked boolean Enable for not currently active page if you use stackedPages Router parameter that keeps all pages in DOM
messagesContent boolean Enable if you use Messages component inside to add required extra styling
pageContent boolean true When enabled it automatically adds page-content element inside. Usefule to disable when you need to use few page-content elements for tabs
tabs boolean Enable if you use Page as Tabs wrapper
loginScreen boolean Enable if you use Login Screen inside of the page to add required extra styling
noSwipeback boolean Disables swipeback feature for the current page (affects iOS theme only)
withSubnavbar boolean Enable if you have Sub Navbar inside of the page
noNavbar boolean Enable if you use common Navbar layout and need to hide common Navbar (or use another one) for this page (affects iOS theme only)
noToolbar boolean Enable if you use common Toolbar/Tabbar layout and need to hide Toolbar (or use another one) for this page
hideBarsOnScroll boolean Hide Navbar & Toolbar on page scroll
hideNavbarOnScroll boolean Hide Navbar on page scroll
hideToolbarOnScroll boolean Hide Toolbar on page scroll
ptr boolean Enables Pull To Refresh
ptrDistance number Custom pull to refresh trigger distance. By default (if not specified) it is 44px.
ptrPreloader boolean true Disable if you want to use custom pull to refresh preloader element
ptrBottom boolean false Enables pull to refresh from bottom
ptrMousewheel boolean false Enables pull to refresh with mousewheel (for desktop apps). Works only for PTR top
infinite boolean Enables Infinite Scroll
infiniteTop boolean Enables infinite scroll on top of the page
infiniteDistance boolean true Distance from the bottom of page (in px) to trigger infinite scroll event. By default (if not specified), it is 50 (px)
infinitePreloader boolean true Disable if you want to use custom infinite-scroll preloader
<PageContent> properties
tab boolean Enable if you use page-content as Tab
tabActive boolean Enable 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

Event Description
<Page> events
--- ---
pageMounted Event will be triggered when page with keepAlive route is mounted/attached to DOM
pageInit Event will be triggered after Framework7 initialize required page’s components and navbar
pageReinit This event will be triggered in case of navigating to the page that was already initialized.
pageBeforeIn Event will be triggered when everything initialized and page is ready to be transitioned into view (into active/current position)
pageAfterIn Event will be triggered after page transitioned into view
pageBeforeOut Event will be triggered right before page is going to be transitioned out of view
pageAfterOut Event will be triggered after page transitioned out of view
pageBeforeUnmount Event will be triggered when page with keepAlive route is going to be unmounted/detached from DOM
pageBeforeRemove Event 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.
ptrPullStart Event will be triggered when you start to move pull to refresh content
ptrPullMove Event will be triggered during you move pull to refresh content
ptrPullEnd Event will be triggered when you release pull to refresh content
ptrRefresh Event will be triggered when pull to refresh enters in “refreshing” state
ptrDone Event will be triggered after pull to refresh is done and it is back to initial state (after calling pullToRefreshDone method)
infinite Event will be triggered when page scroll reaches specified (in data-distance attribute) distance to the bottom.
<PageContent> events
tabShow Event will be triggered when Tab becomes visible/active
tabHide Event 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>

6. {/* Renders to: */}

8. <div class="page">
9. <div>Fixed element</div>
10. <div class="page-content">
11. <p>Page content goes here</p>
12. </div>
13. </div>

Examples

Infinite Scroll

1. export default class extends React.Component {
2. constructor(props) {
3. super(props);

5. this.state = {
6. items: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
7. allowInfinite: true,
8. showPreloader: true,
9. };
10. }
11. render() {
12. return (
13. <Page
14. infinite
15. infiniteDistance={50}
16. infinitePreloader={this.state.showPreloader}
17. onInfinite={this.loadMore.bind(this)}
18. >
19. <Navbar title="Infinite Scroll"></Navbar>
20. <BlockTitle>Scroll bottom</BlockTitle>
21. <List>
22. {this.state.items.map((item, index) => (
23. <ListItem title={`Item ${item}`} key={index}></ListItem>
24. ))}
25. </List>
26. </Page>
27. )
28. }
29. loadMore() {
30. const self = this;
31. if (!self.state.allowInfinite) return;
32. self.setState({ allowInfinite: false });

34. setTimeout(() => {
35. const items = self.state.items;
36. if (items.length >= 200) {
37. self.setState({ showPreloader: false });
38. return;
39. }

41. const itemsLength = items.length;

43. for (let i = 1; i <= 20; i += 1) {
44. items.push(itemsLength + i);
45. }

47. self.setState({
48. items,
49. allowInfinite: true,
50. });
51. }, 1000);
52. }
53. };

Pull To Refresh

1. export default class extends React.Component {
2. constructor(props) {
3. super(props);

5. this.state = {
6. items: [
7. {
8. title: 'Yellow Submarine',
9. author: 'Beatles',
10. cover: 'https://cdn.framework7.io/placeholder/abstract-88x88-1.jpg',
11. },
12. {
13. title: 'Don\'t Stop Me Now',
14. author: 'Queen',
15. cover: 'https://cdn.framework7.io/placeholder/abstract-88x88-2.jpg',
16. },
17. {
18. title: 'Billie Jean',
19. author: 'Michael Jackson',
20. cover: 'https://cdn.framework7.io/placeholder/abstract-88x88-3.jpg',
21. },
22. ],
23. songs: ['Yellow Submarine', 'Don\'t Stop Me Now', 'Billie Jean', 'Californication'],
24. authors: ['Beatles', 'Queen', 'Michael Jackson', 'Red Hot Chili Peppers'],
25. }
26. }
27. render() {
28. return (
29. <Page ptr onPtrRefresh={this.loadMore.bind(this)}>
30. <Navbar title="Pull To Refresh"></Navbar>
31. <List mediaList>
32. {this.state.items.map((item, index) => (
33. <ListItem
34. key={index}
35. title={item.title}
36. subtitle={item.author}
37. >
38. <img slot="media" src={item.cover} width="44" />
39. </ListItem>
40. ))}
41. <BlockFooter>
42. <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>
43. </BlockFooter>
44. </List>
45. </Page>
46. );
47. }
48. loadMore(event, done) {
49. const self = this;
50. setTimeout(() => {
51. const { items, songs, authors } = self.state;
52. const picURL = `https://cdn.framework7.io/placeholder/abstract-88x88-${(Math.floor(Math.random() * 10) + 1)}.jpg`;
53. const song = songs[Math.floor(Math.random() * songs.length)];
54. const author = authors[Math.floor(Math.random() * authors.length)];
55. items.push({
56. title: song,
57. author,
58. cover: picURL,
59. });
60. self.setState({ items });

62. done();
63. }, 1000);
64. }
65. }