Photo Browser - 图1

Photo Browser React Component

Photo Browser is an photo browser component to display collection of photos / images. Photos can be zoomed and panned (optional).

Photo Browser React component represents Framework7’s Photo Browser component.

Photo Browser React component doesn’t render any output. It can be used to create JS Photo Browser instance and control it inside of your React component.

Photo Browser Component

There are following components included:

  • PhotoBrowser / F7PhotoBrowser

Photo Browser Properties

You can pass all parameters in single params property or use separate props for each parameter to specify them via component properties:

PropTypeDefaultDescription
<PhotoBrowser> properties
initbooleantrueInitializes Photo Browser
paramsObjectObject with Photo Browser parameters
photosarray[]Array with URLs of photos or array of objects with “url” (or “html”) and “caption” properties.
urlstringphotos/Photo browser modal URL that will be set as a current route
routableModalsbooleantrueWill add opened photo browser to router history which gives ability to close photo browser by going back in router history and set current route to the photo browser modal
swiperobjectObject with Swiper parameters. By default equals to:
  1. swiper: {
  2. initialSlide: 0,
  3. spaceBetween: 20,
  4. speed: 300,
  5. loop: false,
  6. preloadImages: true,
  7. navigation: {
  8. nextEl: ‘.photo-browser-next’,
  9. prevEl: ‘.photo-browser-prev’,
  10. },
  11. zoom: {
  12. enabled: true,
  13. maxRatio: 3,
  14. minRatio: 1,
  15. },
  16. lazy: {
  17. enabled: true,
  18. },
  19. },
virtualSlidesbooleantrueWhen enabled then Swiper will use Virtual Slides
expositionbooleantrueEnable disable exposition mode when clicking on Photo Browser.
expositionHideCaptionsbooleanfalseSet to true if you also want to hide captions in exposition mode
swipeToClosebooleantrueYou can close Photo Browser with swipe up/down when this parameter is enabled
typestringstandaloneDefine how Photo Browser should be opened. Could be standalone (will be opened as an overlay with custom transition effect), popup (will be opened as popup), page (will be injected to View and loaded as a new page).
themestringlightPhoto Browser color theme, could be light or dark
captionsThemestringCaptions color theme, could be also dark or light. By default, equal to “theme” parameter
navbarbooleantrueSet to false to remove Photo Browser’s Navbar
toolbarbooleantrueSet to false to remove Photo Browser’s Toolbar
pageBackLinkTextstringBackText on back link in Photo Browser’s navbar
popupCloseLinkTextstringCloseText on close link in Photo Browser’s navbar when opened in Popup or as Standalone
navbarShowCountbooleanundefinedDefines should it display “3 of 5” text in navbar title or not. If not specified (undefined) then it will show this text if there is more than 1 item
navbarOfTextstringofText of “of” in photos counter: “3 of 5”
iconsColorstringOne of the default colors

Photo Browser Events

EventDescription
<PhotoBrowser> events
photoBrowserOpenEvent will be triggered on Photo Browser open.
photoBrowserOpenedEvent will be triggered after Photo Browser completes its opening animation
photoBrowserCloseEvent will be triggered on Photo Browser close.
photoBrowserClosedEvent will be triggered after Photo Browser completes its closing animation
photoBrowserSwipeToCloseThis event will be triggered when user close Photo Browser with swipe up/down.

Photo Browser Methods

The following Photo Browser components methods are available (e.g. by accesing it via $refs):

<PhotoBrowser> methods
.open(index);Open Photo Browser on photo with index number equal to “index” parameter. If “index” parameter is not specified, it will be opened on last closed photo.
.close();Close Photo Browser
.expositionToggle();Toggle exposition mode
.expositionEnable();Enable exposition mode
.expositionDisable();Disable exposition mode

Access To Photo Browser Instance

You can access Photo Browser initialized instance by accessing .f7PhotoBrowser component’s property.

Examples

  1. export default class extends React.Component {
  2. constructor(props) {
  3. super(props);
  4. this.state = {
  5. photos: [
  6. {
  7. url: 'img/beach.jpg',
  8. caption: 'Amazing beach in Goa, India',
  9. },
  10. 'https://placekitten.com/1024/1024',
  11. 'img/lock.jpg',
  12. {
  13. url: 'img/monkey.jpg',
  14. caption: 'I met this monkey in Chinese mountains',
  15. },
  16. {
  17. url: 'img/mountains.jpg',
  18. caption: 'Beautiful mountains in Zhangjiajie, China',
  19. },
  20. ],
  21. }
  22. }
  23. render() {
  24. return (
  25. <Page>
  26. <Navbar title="Photo Browser"></Navbar>
  27. <Block>
  28. <p>Photo Browser could be opened in a three ways - as a Standalone component (Popup modification), in Popup, and as separate Page:</p>
  29. <Row>
  30. <Col>
  31. <PhotoBrowser
  32. photos={this.state.photos}
  33. ref={(el) => {this.standalone = el}}
  34. />
  35. <Button raised onClick={() => this.standalone.open()}>Standalone</Button>
  36. </Col>
  37. <Col>
  38. <PhotoBrowser
  39. photos={this.state.photos}
  40. type="popup"
  41. ref={(el) => {this.popup = el}}
  42. />
  43. <Button raised onClick={() => this.popup.open()}>Popup</Button>
  44. </Col>
  45. <Col>
  46. <PhotoBrowser
  47. photos={this.state.photos}
  48. type="page"
  49. pageBackLinkText="Back"
  50. ref={(el) => {this.page = el}}
  51. />
  52. <Button raised onClick={() => this.page.open()}>Page</Button>
  53. </Col>
  54. </Row>
  55. </Block>
  56. <Block>
  57. <p>Photo Browser suppots 2 default themes - default Light (like in previous examples) and Dark theme. Here is a Dark theme examples:</p>
  58. <Row>
  59. <Col>
  60. <PhotoBrowser
  61. photos={this.state.photos}
  62. theme="dark"
  63. ref={(el) => {this.standaloneDark = el}}
  64. />
  65. <Button raised onClick={() => this.standaloneDark.open()}>Standalone</Button>
  66. </Col>
  67. <Col>
  68. <PhotoBrowser
  69. photos={this.state.photos}
  70. theme="dark"
  71. type="popup"
  72. ref={(el) => {this.popupDark = el}}
  73. />
  74. <Button raised onClick={() => this.popupDark.open()}>Popup</Button>
  75. </Col>
  76. <Col>
  77. <PhotoBrowser
  78. photos={this.state.photos}
  79. theme="dark"
  80. type="page"
  81. pageBackLinkText="Back"
  82. ref={(el) => {this.pageDark = el}}
  83. />
  84. <Button raised onClick={() => this.pageDark.open()}>Page</Button>
  85. </Col>
  86. </Row>
  87. </Block>
  88. </Page>
  89. );
  90. }
  91. };

← Panel / Side Panels

Popover →