照片瀏覽器 React 元件

照片瀏覽器是一個照片瀏覽器元件,用於顯示照片 / 影像的集合。照片可以縮放和平移(選用)。

照片瀏覽器 React 元件代表 Framework7 的 照片瀏覽器 元件。

照片瀏覽器 React 元件不會呈現任何輸出。它可用於建立 JS 照片瀏覽器實例,並在 React 元件內控制它。

照片瀏覽器元件

包含下列元件

Photo Browser 屬性

您可以在單一 params 屬性中傳遞所有參數,或使用單獨的 props 為每個參數指定元件屬性

Prop類型預設值說明
<PhotoBrowser> 屬性
init布林值true初始化 Photo Browser
params物件包含 Photo Browser 參數 的物件
photos陣列[]包含照片 URL 的陣列,或包含「url」(或「html」)和「caption」屬性的物件陣列。
thumbs陣列[]陣列
包含縮圖影像 URL 的陣列。如果未指定或陣列為空,則不會呈現縮圖url字串photos/
將設定為目前路由的 Photo Browser 模式 URL布林值routableModalsfalse
將開啟的 Photo Browser 加入路由記錄,這會讓您能透過返回路由記錄並將目前路由設定為 Photo Browser 模式來關閉 Photo Browserswiper物件
swiper: {
  initialSlide: 0,
  spaceBetween: 20,
  speed: 300,
  loop: false,
  preloadImages: true,
  keyboard: {
    enabled: true,
  },
  navigation: {
    nextEl: '.photo-browser-next',
    prevEl: '.photo-browser-prev',
  },
  zoom: {
    enabled: true,
    maxRatio: 3,
    minRatio: 1,
  },
  lazy: {
    enabled: true,
  },
},
包含 Swiper 參數的物件。預設值等於布林值truevirtualSlides
啟用時,Swiper 會使用虛擬投影片布林值truecloseByBackdropClick
啟用時,背景點擊會關閉 Photo Browser 快顯視窗布林值trueexposition
點擊 Photo Browser 時,啟用或停用展示模式。布林值routableModalsexpositionHideCaptions
如果您還想在展示模式中隱藏標題,請設定為 true布林值trueswipeToClose
啟用此參數後,您可以向上/向下滑動來關閉 Photo Browserurltypestandalone
定義 Photo Browser 的開啟方式。可以是 standalone(會以自訂轉場效果開啟為疊加層)、popup(會開啟為快顯視窗)、page(會注入到檢視中並載入為新頁面)。urlthemelight
Photo Browser 顏色主題,可以是 lightdarkurlcaptionsTheme
標題顏色主題,也可以是 darklight。預設值等於「theme」參數布林值truenavbar
設定為 false 以移除 Photo Browser 的導覽列布林值truetoolbar
設定為 false 以移除 Photo Browser 的工具列url返回照片瀏覽器導航列中返回連結的文字
popupCloseLinkTexturl關閉在彈出視窗或獨立模式中開啟照片瀏覽器時,導航列中關閉連結的文字
navbarShowCount布林值未定義定義是否在導航列標題中顯示「5 中的 3」文字。如果未指定(未定義),則在有 1 個以上項目時會顯示此文字
navbarOfTexturl照片計數器中「的」文字:「5 中的 3」
iconsColorurl預設顏色之一

照片瀏覽器事件

事件說明
<PhotoBrowser> 事件
photoBrowserOpen照片瀏覽器開啟時觸發事件。
photoBrowserOpened照片瀏覽器完成開啟動畫後觸發事件
photoBrowserClose照片瀏覽器關閉時觸發事件。
photoBrowserClosed照片瀏覽器完成關閉動畫後觸發事件
photoBrowserSwipeToClose當使用者向上/向下滑動關閉照片瀏覽器時觸發此事件。

照片瀏覽器方法

以下照片瀏覽器元件方法可用(例如透過 ref 存取)

<PhotoBrowser> 方法
.open(index)在索引號碼等於「index」參數的照片上開啟照片瀏覽器。如果未指定「index」參數,則會在上次關閉的照片上開啟。
.close()關閉照片瀏覽器
.expositionToggle()切換曝光模式
.expositionEnable()啟用曝光模式
.expositionDisable()停用曝光模式

範例

photo-browser.jsx
import React, { useRef } from 'react';
import { Navbar, Page, PhotoBrowser, Block, Button } from 'framework7-react';

export default () => {
  const standalone = useRef(null);
  const popup = useRef(null);
  const page = useRef(null);
  const standaloneDark = useRef(null);
  const popupDark = useRef(null);
  const pageDark = useRef(null);
  const photos = [
    {
      url: 'img/beach.jpg',
      caption: 'Amazing beach in Goa, India',
    },
    'http://placekitten.com/1024/1024',
    'img/lock.jpg',
    {
      url: 'img/monkey.jpg',
      caption: 'I met this monkey in Chinese mountains',
    },
    {
      url: 'img/mountains.jpg',
      caption: 'Beautiful mountains in Zhangjiajie, China',
    },
  ];
  const thumbs = [
    'img/beach.jpg',
    'http://placekitten.com/1024/1024',
    'img/lock.jpg',
    'img/monkey.jpg',
    'img/mountains.jpg',
  ];
  return (
    <Page>
      <Navbar title="Photo Browser"></Navbar>
      <Block strongIos outlineIos>
        <p>
          Photo Browser is a standalone and highly configurable component that allows to open window
          with photo viewer and navigation elements with the following features:
        </p>
        <ul>
          <li>Swiper between photos</li>
          <li>Multi-gestures support for zooming</li>
          <li>Toggle zoom by double tap on photo</li>
          <li>Single click on photo to toggle Exposition mode</li>
        </ul>
      </Block>
      <Block strongIos outlineIos>
        <p>
          Photo Browser could be opened in a three ways - as a Standalone component (Popup
          modification), in Popup, and as separate Page:
        </p>
        <div className="grid grid-cols-3 grid-gap">
          <div>
            <PhotoBrowser photos={photos} thumbs={thumbs} ref={standalone} />
            <Button fill onClick={() => standalone.current.open()}>
              Standalone
            </Button>
          </div>
          <div>
            <PhotoBrowser photos={photos} thumbs={thumbs} type="popup" ref={popup} />
            <Button fill onClick={() => popup.current.open()}>
              Popup
            </Button>
          </div>
          <div>
            <PhotoBrowser
              photos={photos}
              thumbs={thumbs}
              type="page"
              pageBackLinkText="Back"
              ref={page}
            />
            <Button fill onClick={() => page.current.open()}>
              Page
            </Button>
          </div>
        </div>
      </Block>
      <Block strongIos outlineIos>
        <p>
          Photo Browser supports 2 default themes - default Light (like in previous examples) and
          Dark theme. Here is a Dark theme examples:
        </p>
        <div className="grid grid-cols-3 grid-gap">
          <div>
            <PhotoBrowser photos={photos} thumbs={thumbs} theme="dark" ref={standaloneDark} />
            <Button fill onClick={() => standaloneDark.current.open()}>
              Standalone
            </Button>
          </div>
          <div>
            <PhotoBrowser
              photos={photos}
              thumbs={thumbs}
              theme="dark"
              type="popup"
              ref={popupDark}
            />
            <Button fill onClick={() => popupDark.current.open()}>
              Popup
            </Button>
          </div>
          <div>
            <PhotoBrowser
              photos={photos}
              thumbs={thumbs}
              theme="dark"
              type="page"
              pageBackLinkText="Back"
              ref={pageDark}
            />
            <Button fill onClick={() => pageDark.current.open()}>
              Page
            </Button>
          </div>
        </div>
      </Block>
    </Page>
  );
};