From 17b14885b3286f25837d67fd6b75425422f198f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E5=96=B5?= Date: Fri, 3 Mar 2023 16:40:01 +0800 Subject: [PATCH] =?UTF-8?q?chore(type):=20useShareAppMessage=20=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=AE=9A=E4=B9=89=E5=A2=9E=E5=BC=BA=20(#13303)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(type): useShareAppMessage 类型定义支持传入异步函数 * feat(type): useShareAppMessage 返回对象中支持 'promise' 属性 * fix(types): 优化分享生命周期类型 --------- Co-authored-by: Zakary --- packages/taro/types/taro.lifecycle.d.ts | 44 ++++++++++++++++++++----- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/packages/taro/types/taro.lifecycle.d.ts b/packages/taro/types/taro.lifecycle.d.ts index 95cdbc04763e..b5bd97f3ee14 100644 --- a/packages/taro/types/taro.lifecycle.d.ts +++ b/packages/taro/types/taro.lifecycle.d.ts @@ -67,25 +67,19 @@ declare module './index' { * 转发事件来源 * `button`:页面内转发按钮 * `menu`:右上角转发菜单 - * - * @since 1.2.4 */ from?: 'button' | 'menu' | string /** * 如果 `from` 值是 `button`,则 `target` 是触发这次转发事件的 `button`,否则为 `undefined` - * - * @since 1.2.4 */ target?: object /** * 页面中包含 `` 组件时,返回当前 `` 的 url - * - * @since 1.6.4 */ webViewUrl?: string } - interface ShareAppMessageReturn { + interface ShareAppMessageReturnObject { /** * 转发标题,默认为当前小程序名称 */ @@ -101,12 +95,44 @@ declare module './index' { * 支持PNG及JPG * 显示图片长宽比是 5:4 * 默认使用截图 - * - * @since 1.5.0 */ imageUrl?: string } + interface WeappShareAppMessageReturnObject extends ShareAppMessageReturnObject { + /** + * 如果该参数存在,则以 resolve 结果为准,如果三秒内不 resolve,分享会使用上面传入的默认参数 + * @supported weapp + * @see https://developers.weixin.qq.com/miniprogram/dev/reference/api/Page.html#onShareAppMessage-Object-object + * @example + * ```tsx + * import { ShareAppMessageReturnObject, useShareAppMessage } from "@tarojs/taro"; + * // ... else code + * useShareAppMessage(() => { + * const p = new Promise(resolve => { + * setTimeout(() => { + * resolve({ + * title: "", + * imageUrl: "", + * path: "" + * }) + * }, 2000) + * }) + * return { + * title: "", + * imageUrl: "", + * path: "", + * promise: p + * } + * }); + * ``` + * + */ + promise: Promise + } + + type ShareAppMessageReturn = ShareAppMessageReturnObject | Promise | WeappShareAppMessageReturnObject + interface TabItemTapObject { /** * 被点击tabItem的序号,从 0 开始