forked from NervJS/taro
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(weapp): support snapshot component
- Loading branch information
Showing
8 changed files
with
110 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ComponentType } from 'react' | ||
|
||
import { StandardProps } from './common' | ||
|
||
interface SnapshotProps extends StandardProps { | ||
id: string | ||
} | ||
|
||
/** | ||
* 截图组件。 支持将其子节点的渲染结果导出成图片,该组件需配合 snapshot 接口使用。 目前仅在 Skyline 渲染引擎 下支持。 | ||
* @supported weapp (基础库 3.0.1+) | ||
* @see https://developers.weixin.qq.com/miniprogram/dev/component/snapshot.html | ||
*/ | ||
declare const Snapshot: ComponentType<SnapshotProps> | ||
export { Snapshot, SnapshotProps } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -379,4 +379,5 @@ export const components = { | |
objectFit: "'contain'", | ||
bindError: _empty | ||
}, | ||
Snapshot: {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import Taro from '../../index' | ||
|
||
declare module '../../index' { | ||
/** | ||
* Snapshot 实例,可通过 SelectorQuery 获取。 | ||
* | ||
* Snapshot 通过 id 跟一个 snapshot 组件绑定,操作对应的 snapshot 组件。 | ||
* @supported weapp | ||
* @see https://developers.weixin.qq.com/miniprogram/dev/api/skyline/Snapshot.html | ||
*/ | ||
interface Snapshot { | ||
/** | ||
* 画布宽度 | ||
*/ | ||
width: number | ||
/** | ||
* 画布高度 | ||
*/ | ||
height: number | ||
/** | ||
* 对 snapshot 组件子树进行截图 | ||
* @param option | ||
* @see https://developers.weixin.qq.com/miniprogram/dev/api/skyline/Snapshot.takeSnapshot.html | ||
*/ | ||
takeSnapshot(option: Snapshot.TakeSnapshot.Option): Promise<TaroGeneral.CallbackResult> | ||
} | ||
|
||
namespace Snapshot { | ||
namespace TakeSnapshot { | ||
interface Option { | ||
/** | ||
* 截图导出类型,'file' 保存到临时文件目录或 'arraybuffer' 返回图片二进制数据,默认值为 'file' | ||
*/ | ||
type: string | ||
/** | ||
* 截图文件格式,'rgba' 或 'png',默认值为 'png' | ||
*/ | ||
format: string | ||
/** 接口调用结束的回调函数(调用成功、失败都会执行) */ | ||
complete?: (res: TaroGeneral.CallbackResult) => void | ||
/** 接口调用失败的回调函数 */ | ||
fail?: (res: TaroGeneral.CallbackResult) => void | ||
/** 接口调用成功的回调函数 */ | ||
success?: (res: SuccessCallbackResult) => void | ||
} | ||
|
||
interface SuccessCallbackResult { | ||
/** | ||
* 截图保存的临时文件路径,当 type 为 file 该字段生效 | ||
*/ | ||
tempFilePath: string | ||
/** | ||
* 截图对应的二进制数据,当 type 为 arraybuffer 该字段生效 | ||
*/ | ||
data: string | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters