照片瀏覽器 React 元件
照片瀏覽器是一個照片瀏覽器元件,用於顯示照片 / 影像的集合。照片可以縮放和平移(選用)。
照片瀏覽器 React 元件代表 Framework7 的 照片瀏覽器 元件。
照片瀏覽器 React 元件不會呈現任何輸出。它可用於建立 JS 照片瀏覽器實例,並在 React 元件內控制它。
照片瀏覽器元件
包含下列元件
PhotoBrowser
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 | 布林值 | routableModals | false |
將開啟的 Photo Browser 加入路由記錄,這會讓您能透過返回路由記錄並將目前路由設定為 Photo Browser 模式來關閉 Photo Browser | swiper | 物件
| |
包含 Swiper 參數的物件。預設值等於 | 布林值 | true | virtualSlides |
啟用時,Swiper 會使用虛擬投影片 | 布林值 | true | closeByBackdropClick |
啟用時,背景點擊會關閉 Photo Browser 快顯視窗 | 布林值 | true | exposition |
點擊 Photo Browser 時,啟用或停用展示模式。 | 布林值 | routableModals | expositionHideCaptions |
如果您還想在展示模式中隱藏標題,請設定為 true | 布林值 | true | swipeToClose |
啟用此參數後,您可以向上/向下滑動來關閉 Photo Browser | url | type | standalone |
定義 Photo Browser 的開啟方式。可以是 standalone (會以自訂轉場效果開啟為疊加層)、popup (會開啟為快顯視窗)、page (會注入到檢視中並載入為新頁面)。 | url | theme | light |
Photo Browser 顏色主題,可以是 light 或 dark | url | captionsTheme | |
標題顏色主題,也可以是 dark 或 light 。預設值等於「theme」參數 | 布林值 | true | navbar |
設定為 false 以移除 Photo Browser 的導覽列 | 布林值 | true | toolbar |
設定為 false 以移除 Photo Browser 的工具列 | url | 返回 | 照片瀏覽器導航列中返回連結的文字 |
popupCloseLinkText | url | 關閉 | 在彈出視窗或獨立模式中開啟照片瀏覽器時,導航列中關閉連結的文字 |
navbarShowCount | 布林值 | 未定義 | 定義是否在導航列標題中顯示「5 中的 3」文字。如果未指定(未定義),則在有 1 個以上項目時會顯示此文字 |
navbarOfText | url | 的 | 照片計數器中「的」文字:「5 中的 3」 |
iconsColor | url | 預設顏色之一 |
照片瀏覽器事件
事件 | 說明 |
---|---|
<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>
);
};