Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
55e5ff94
U
uni-app
项目概览
DCloud
/
uni-app
6 个月 前同步成功
通知
751
Star
38709
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
8
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
8
Issue
8
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
55e5ff94
编写于
12月 16, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(types): lifecycle hooks (#3076)
上级
cdb600cf
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
169 addition
and
28 deletion
+169
-28
packages/uni-app/src/apiLifecycle.ts
packages/uni-app/src/apiLifecycle.ts
+169
-28
未找到文件。
packages/uni-app/src/apiLifecycle.ts
浏览文件 @
55e5ff94
...
...
@@ -30,6 +30,134 @@ import {
UniLifecycleHooks
,
}
from
'
@dcloudio/uni-shared
'
interface
ReferrerInfo
{
appId
:
string
extraData
?:
any
}
interface
LaunchShowOption
{
path
:
string
query
:
Record
<
string
,
string
|
undefined
>
scene
:
number
shareTicket
:
string
referrerInfo
?:
ReferrerInfo
}
type
LaunchOption
=
LaunchShowOption
type
onAppShowHook
=
(
options
:
LaunchShowOption
)
=>
void
type
onPageShowHook
=
()
=>
void
type
onLaunchHook
=
(
options
:
LaunchOption
)
=>
void
type
onLoadHook
=
(
query
:
Record
<
string
,
string
|
undefined
>
)
=>
void
type
onErrorHook
=
(
error
:
string
)
=>
void
interface
ThemeChangeOption
{
theme
:
'
dark
'
|
'
light
'
}
type
onThemeChangeHook
=
(
options
:
ThemeChangeOption
)
=>
void
interface
PageNotFoundOption
{
path
:
string
query
:
Record
<
string
,
string
|
undefined
>
isEntryPage
:
boolean
}
type
onPageNotFoundHook
=
(
options
:
PageNotFoundOption
)
=>
void
interface
UnhandledRejectionOption
{
promise
:
Promise
<
any
>
reason
:
string
}
type
onUnhandledRejectionHook
=
(
options
:
UnhandledRejectionOption
)
=>
void
interface
ResizeOption
{
size
:
{
windowWidth
:
number
windowHeight
:
number
}
}
type
onResizeHook
=
(
options
:
ResizeOption
)
=>
void
interface
BackPressOption
{
from
:
'
backbutton
'
|
'
navigateBack
'
}
type
onBackPressHook
=
(
options
:
BackPressOption
)
=>
boolean
|
void
interface
PageScrollOption
{
scrollTop
:
number
}
type
onPageScrollHook
=
(
options
:
PageScrollOption
)
=>
void
interface
TabItemTapOption
{
index
:
string
pagePath
:
string
text
:
string
}
type
onTabItemTapHook
=
(
options
:
TabItemTapOption
)
=>
void
interface
CustomShareTimeline
{
title
?:
string
query
?:
string
imageUrl
?:
string
}
type
onShareTimelineHook
=
()
=>
CustomShareTimeline
|
void
interface
AddToFavoritesOption
{
webviewUrl
?:
string
}
interface
AddToFavoritesContent
{
title
?:
string
imageUrl
?:
string
query
?:
string
}
type
onAddToFavoritesHook
=
(
options
:
AddToFavoritesOption
)
=>
AddToFavoritesContent
|
void
interface
ShareAppMessageOption
{
from
:
'
button
'
|
'
menu
'
|
string
target
:
any
webViewUrl
?:
string
}
interface
CustomShareAppMessage
{
title
?:
string
path
?:
string
imageUrl
?:
string
}
type
onShareAppMessageHook
=
(
options
:
ShareAppMessageOption
)
=>
CustomShareAppMessage
|
void
interface
NavigationBarButtonTapOption
{
index
:
number
}
type
onNavigationBarButtonTapHook
=
(
options
:
NavigationBarButtonTapOption
)
=>
void
interface
NavigationBarSearchInputChangedOption
{
text
:
string
}
type
onNavigationBarSearchInputChangedHook
=
(
options
:
NavigationBarSearchInputChangedOption
)
=>
void
type
NavigationBarSearchInputConfirmedOption
=
NavigationBarSearchInputChangedOption
type
onNavigationBarSearchInputConfirmedHook
=
(
options
:
NavigationBarSearchInputConfirmedOption
)
=>
void
interface
NavigationBarSearchInputFocusChanged
{
focus
:
boolean
}
type
onNavigationBarSearchInputFocusChangedHook
=
(
options
:
NavigationBarSearchInputFocusChanged
)
=>
void
const
createHook
=
<
T
extends
Function
=
()
=>
any
>
(
lifecycle
:
typeof
UniLifecycleHooks
[
number
]
...
...
@@ -38,45 +166,58 @@ const createHook =
// post-create lifecycle registrations are noops during SSR
!
isInSSRComponentSetup
&&
injectHook
(
lifecycle
as
any
,
hook
,
target
)
export
const
onShow
=
/*#__PURE__*/
createHook
(
ON_SHOW
)
export
const
onShow
=
/*#__PURE__*/
createHook
<
onAppShowHook
|
onPageShowHook
>
(
ON_SHOW
)
export
const
onHide
=
/*#__PURE__*/
createHook
(
ON_HIDE
)
export
const
onLaunch
=
/*#__PURE__*/
createHook
(
ON_LAUNCH
)
export
const
onError
=
/*#__PURE__*/
createHook
(
ON_ERROR
)
export
const
onThemeChange
=
/*#__PURE__*/
createHook
(
ON_THEME_CHANGE
)
export
const
onPageNotFound
=
/*#__PURE__*/
createHook
(
ON_PAGE_NOT_FOUND
)
export
const
onUnhandledRejection
=
/*#__PURE__*/
createHook
(
ON_UNHANDLE_REJECTION
)
export
const
onLaunch
=
/*#__PURE__*/
createHook
<
onLaunchHook
>
(
ON_LAUNCH
)
export
const
onError
=
/*#__PURE__*/
createHook
<
onErrorHook
>
(
ON_ERROR
)
export
const
onThemeChange
=
/*#__PURE__*/
createHook
<
onThemeChangeHook
>
(
ON_THEME_CHANGE
)
export
const
onPageNotFound
=
/*#__PURE__*/
createHook
<
onPageNotFoundHook
>
(
ON_PAGE_NOT_FOUND
)
export
const
onUnhandledRejection
=
/*#__PURE__*/
createHook
<
onUnhandledRejectionHook
>
(
ON_UNHANDLE_REJECTION
)
// 小程序如果想在 setup 的 props 传递页面参数,需要定义 props,故同时暴露 onLoad 吧
export
const
onLoad
=
/*#__PURE__*/
createHook
(
ON_LOAD
)
export
const
onLoad
=
/*#__PURE__*/
createHook
<
onLoadHook
>
(
ON_LOAD
)
export
const
onReady
=
/*#__PURE__*/
createHook
(
ON_READY
)
export
const
onUnload
=
/*#__PURE__*/
createHook
(
ON_UNLOAD
)
export
const
onResize
=
/*#__PURE__*/
createHook
(
ON_RESIZE
)
export
const
onBackPress
=
/*#__PURE__*/
createHook
(
ON_BACK_PRESS
)
export
const
onPageScroll
=
/*#__PURE__*/
createHook
(
ON_PAGE_SCROLL
)
export
const
onTabItemTap
=
/*#__PURE__*/
createHook
(
ON_TAB_ITEM_TAP
)
export
const
onResize
=
/*#__PURE__*/
createHook
<
onResizeHook
>
(
ON_RESIZE
)
export
const
onBackPress
=
/*#__PURE__*/
createHook
<
onBackPressHook
>
(
ON_BACK_PRESS
)
export
const
onPageScroll
=
/*#__PURE__*/
createHook
<
onPageScrollHook
>
(
ON_PAGE_SCROLL
)
export
const
onTabItemTap
=
/*#__PURE__*/
createHook
<
onTabItemTapHook
>
(
ON_TAB_ITEM_TAP
)
export
const
onReachBottom
=
/*#__PURE__*/
createHook
(
ON_REACH_BOTTOM
)
export
const
onPullDownRefresh
=
/*#__PURE__*/
createHook
(
ON_PULL_DOWN_REFRESH
)
export
const
onShareTimeline
=
/*#__PURE__*/
createHook
(
ON_SHARE_TIMELINE
)
export
const
onAddToFavorites
=
/*#__PURE__*/
createHook
(
ON_ADD_TO_FAVORITES
)
export
const
onShareAppMessage
=
/*#__PURE__*/
createHook
(
ON_SHARE_APP_MESSAGE
)
export
const
onShareTimeline
=
/*#__PURE__*/
createHook
<
onShareTimelineHook
>
(
ON_SHARE_TIMELINE
)
export
const
onAddToFavorites
=
/*#__PURE__*/
createHook
<
onAddToFavoritesHook
>
(
ON_ADD_TO_FAVORITES
)
export
const
onShareAppMessage
=
/*#__PURE__*/
createHook
<
onShareAppMessageHook
>
(
ON_SHARE_APP_MESSAGE
)
export
const
onNavigationBarButtonTap
=
/*#__PURE__*/
createHook
(
ON_NAVIGATION_BAR_BUTTON_TAP
)
export
const
onNavigationBarButtonTap
=
/*#__PURE__*/
createHook
<
onNavigationBarButtonTapHook
>
(
ON_NAVIGATION_BAR_BUTTON_TAP
)
export
const
onNavigationBarSearchInputChanged
=
/*#__PURE__*/
createHook
(
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED
)
export
const
onNavigationBarSearchInputChanged
=
/*#__PURE__*/
createHook
<
onNavigationBarSearchInputChangedHook
>
(
ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED
)
export
const
onNavigationBarSearchInputClicked
=
/*#__PURE__*/
createHook
(
ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED
)
export
const
onNavigationBarSearchInputConfirmed
=
/*#__PURE__*/
createHook
(
ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED
)
export
const
onNavigationBarSearchInputFocusChanged
=
/*#__PURE__*/
createHook
(
ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED
)
export
const
onNavigationBarSearchInputConfirmed
=
/*#__PURE__*/
createHook
<
onNavigationBarSearchInputConfirmedHook
>
(
ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED
)
export
const
onNavigationBarSearchInputFocusChanged
=
/*#__PURE__*/
createHook
<
onNavigationBarSearchInputFocusChangedHook
>
(
ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录