UNPKG

4.52 kBTypeScriptView Raw
1import Taro from './index'
2
3type TaroGetDerivedStateFromProps<P, S> =
4/**
5 * Returns an update to a component's state based on its new props and old state.
6 *
7 * Note: its presence prevents any of the deprecated lifecycle methods from being invoked
8 */
9(nextProps: Readonly<P>, prevState: S) => Partial<S> | null;
10
11interface TaroStaticLifecycle<P, S> {
12 getDerivedStateFromProps?: TaroGetDerivedStateFromProps<P, S>;
13}
14
15interface TaroNewLifecycle<P, S, SS> {
16 /**
17 * Runs before React applies the result of `render` to the document, and
18 * returns an object to be given to componentDidUpdate. Useful for saving
19 * things such as scroll position before `render` causes changes to it.
20 *
21 * Note: the presence of getSnapshotBeforeUpdate prevents any of the deprecated
22 * lifecycle events from running.
23 */
24 getSnapshotBeforeUpdate?(prevProps: Readonly<P>, prevState: Readonly<S>): SS | null;
25 /**
26 * Called immediately after updating occurs. Not called for the initial render.
27 *
28 * The snapshot is only present if getSnapshotBeforeUpdate is present and returns non-null.
29 */
30 componentDidUpdate?(prevProps: Readonly<P>, prevState: Readonly<S>, snapshot?: SS): void;
31}
32
33declare module './index' {
34 interface PageNotFoundObject {
35 /**
36 * 不存在页面的路径
37 */
38 path: string
39
40 /**
41 * 打开不存在页面的 query
42 */
43 query: Record<string, unknown>
44
45 /**
46 * 是否本次启动的首个页面(例如从分享等入口进来,首个页面是开发者配置的分享页面)
47 */
48 isEntryPage: boolean
49 }
50
51 interface PageScrollObject {
52 /**
53 * 页面在垂直方向已滚动的距离(单位px)
54 */
55 scrollTop: number
56 }
57
58 interface PageResizeObject {
59 size: {
60 windowWidth: number
61 windowHeight: number
62 }
63 }
64
65 interface ShareAppMessageObject {
66 /**
67 * 转发事件来源
68 * `button`:页面内转发按钮
69 * `menu`:右上角转发菜单
70 *
71 * @since 1.2.4
72 */
73 from?: 'button' | 'menu' | string
74 /**
75 * 如果 `from` 值是 `button`,则 `target` 是触发这次转发事件的 `button`,否则为 `undefined`
76 *
77 * @since 1.2.4
78 */
79 target?: object
80 /**
81 * 页面中包含 `<web-view>` 组件时,返回当前 `<web-view>` 的 url
82 *
83 * @since 1.6.4
84 */
85 webViewUrl?: string
86 }
87
88 interface ShareAppMessageReturn {
89 /**
90 * 转发标题,默认为当前小程序名称
91 */
92 title?: string
93
94 /**
95 * 转发路径,必须是以 / 开头的完整路径,默认为当前页面 path
96 */
97 path?: string
98
99 /**
100 * 自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径
101 * 支持PNG及JPG
102 * 显示图片长宽比是 5:4
103 * 默认使用截图
104 *
105 * @since 1.5.0
106 */
107 imageUrl?: string
108 }
109
110 interface TabItemTapObject {
111 /**
112 * 被点击tabItem的序号,从 0 开始
113 */
114 index: string
115
116 /**
117 * 被点击tabItem的页面路径
118 */
119 pagePath: string
120
121 /**
122 * 被点击tabItem的按钮文字
123 */
124 text: string
125 }
126
127 interface AddToFavoritesObject {
128 /**
129 * 页面中包含web-view组件时,返回当前web-view的url
130 */
131 webviewUrl: string
132 }
133
134 interface AddToFavoritesReturnObject {
135 /**
136 * 自定义标题
137 */
138 title?: string
139
140 /**
141 * 自定义图片,显示图片长宽比为 1:1
142 */
143 imageUrl?: string
144
145 /**
146 * 自定义query字段
147 */
148 query?: string
149 }
150
151 interface ShareTimelineReturnObject {
152 /**
153 * 自定义标题
154 */
155 title?: string
156
157 /**
158 * 自定义页面路径中携带的参数
159 */
160 query?: string
161
162 /**
163 * 自定义图片路径,可以是本地文件或者网络图片。支持 PNG 及 JPG,显示图片长宽比是 1:1
164 */
165 imageUrl?: string
166 }
167
168 type GetDerivedStateFromProps<P, S> = TaroGetDerivedStateFromProps<P, S>
169
170 type StaticLifecycle<P, S> = TaroStaticLifecycle<P, S>
171
172 type NewLifecycle<P, S, SS> = TaroNewLifecycle<P, S, SS>
173
174 interface TaroStatic {
175 PageNotFoundObject: PageNotFoundObject
176 PageScrollObject: PageScrollObject
177 ShareAppMessageObject: ShareAppMessageObject
178 ShareAppMessageReturn: ShareAppMessageReturn
179 TabItemTapObject: TabItemTapObject
180 AddToFavoritesObject: AddToFavoritesObject
181 AddToFavoritesReturnObject: AddToFavoritesReturnObject
182 ShareTimelineReturnObject: ShareTimelineReturnObject
183 }
184}