Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
69cd3d0d
U
uni-app
项目概览
DCloud
/
uni-app
4 个月 前同步成功
通知
730
Star
38707
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
69cd3d0d
编写于
3月 18, 2020
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(v3): native event
上级
e8a49402
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
139 addition
and
68 deletion
+139
-68
lib/apis.js
lib/apis.js
+3
-1
packages/uni-app-plus/dist/index.v3.js
packages/uni-app-plus/dist/index.v3.js
+93
-57
src/core/helpers/promise.js
src/core/helpers/promise.js
+1
-1
src/platforms/app-plus/service/api/index.js
src/platforms/app-plus/service/api/index.js
+2
-0
src/platforms/app-plus/service/api/plugin/on-native-event-receive.js
...ms/app-plus/service/api/plugin/on-native-event-receive.js
+16
-0
src/platforms/app-plus/service/api/plugin/send-native-event.js
...latforms/app-plus/service/api/plugin/send-native-event.js
+4
-0
src/platforms/app-plus/service/framework/app.js
src/platforms/app-plus/service/framework/app.js
+20
-9
未找到文件。
lib/apis.js
浏览文件 @
69cd3d0d
...
...
@@ -201,7 +201,9 @@ const third = [
'
restoreGlobal
'
,
'
getSubNVueById
'
,
'
getCurrentSubNVue
'
,
'
setPageMeta
'
'
setPageMeta
'
,
'
onNativeEventReceive
'
,
'
sendNativeEvent
'
]
const
ad
=
[
...
...
packages/uni-app-plus/dist/index.v3.js
浏览文件 @
69cd3d0d
...
...
@@ -212,7 +212,9 @@ var serviceContext = (function () {
'
restoreGlobal
'
,
'
getSubNVueById
'
,
'
getCurrentSubNVue
'
,
'
setPageMeta
'
'
setPageMeta
'
,
'
onNativeEventReceive
'
,
'
sendNativeEvent
'
];
const
ad
=
[
...
...
@@ -639,7 +641,7 @@ var serviceContext = (function () {
};
const
SYNC_API_RE
=
/^
\$
|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
;
/^
\$
|
sendNativeEvent|
restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
...
...
@@ -1948,6 +1950,9 @@ var serviceContext = (function () {
visible
:
{
type
:
Boolean
,
default
:
true
},
popover
:
{
type
:
Object
}
};
...
...
@@ -7332,6 +7337,23 @@ var serviceContext = (function () {
return
getSubNVueById
(
plus
.
webview
.
currentWebview
().
id
)
}
const
callbacks$3
=
[];
function
onNativeEventReceive
(
callback
)
{
isFn
(
callback
)
&&
callbacks$3
.
indexOf
(
callback
)
===
-
1
&&
callbacks$3
.
push
(
callback
);
}
function
consumeNativeEvent
(
event
,
data
)
{
callbacks$3
.
forEach
(
callback
=>
callback
(
event
,
data
));
}
function
sendNativeEvent
(
event
,
data
,
callback
)
{
// 实时获取weex module(weex可能会变化,比如首页nvue加速显示时)
return
weex
.
requireModule
(
'
plus
'
).
sendNativeEvent
(
event
,
data
,
callback
)
}
let
firstBackTime
=
0
;
function
quit
()
{
...
...
@@ -7477,6 +7499,9 @@ var serviceContext = (function () {
(
windowOptions
.
navigationStyle
===
'
custom
'
&&
!
isPlainObject
(
titleNView
)
)
||
(
windowOptions
.
transparentTitle
===
'
always
'
&&
!
isPlainObject
(
titleNView
)
)
)
{
return
false
...
...
@@ -7495,7 +7520,7 @@ var serviceContext = (function () {
titleText
:
titleImage
===
''
?
windowOptions
.
navigationBarTitleText
||
''
:
''
,
titleColor
:
windowOptions
.
navigationBarTextStyle
===
'
black
'
?
'
#000000
'
:
'
#ffffff
'
,
type
:
titleNViewTypeList
[
transparentTitle
],
backgroundColor
:
transparentTitle
!==
'
always
'
?
windowOptions
.
navigationBarBackgroundColor
||
'
#000000
'
:
'
rgba(0,0,0,0)
'
,
backgroundColor
:
windowOptions
.
navigationBarBackgroundColor
||
'
#f8f8f8
'
,
tags
:
titleImage
===
''
?
[]
:
[{
'
tag
'
:
'
img
'
,
'
src
'
:
titleImage
,
...
...
@@ -8938,11 +8963,12 @@ var serviceContext = (function () {
function
showActionSheet$1
({
itemList
=
[],
itemColor
=
'
#000000
'
,
title
=
''
title
=
''
,
popover
},
callbackId
)
{
const
options
=
{
buttons
:
itemList
.
map
(
item
=>
({
title
:
item
,
title
:
item
,
color
:
itemColor
}))
};
...
...
@@ -8954,7 +8980,7 @@ var serviceContext = (function () {
options
.
cancel
=
'
取消
'
;
}
plus
.
nativeUI
.
actionSheet
(
options
,
(
e
)
=>
{
plus
.
nativeUI
.
actionSheet
(
Object
.
assign
(
options
,
{
popover
})
,
(
e
)
=>
{
if
(
e
.
index
>
0
)
{
invoke$1
(
callbackId
,
{
errMsg
:
'
showActionSheet:ok
'
,
...
...
@@ -9103,16 +9129,16 @@ var serviceContext = (function () {
}
}
const
callbacks$
3
=
{};
const
callbacks$
4
=
{};
function
createCallbacks
(
namespace
)
{
let
scopedCallbacks
=
callbacks$
3
[
namespace
];
let
scopedCallbacks
=
callbacks$
4
[
namespace
];
if
(
!
scopedCallbacks
)
{
scopedCallbacks
=
{
id
:
1
,
callbacks
:
Object
.
create
(
null
)
};
callbacks$
3
[
namespace
]
=
scopedCallbacks
;
callbacks$
4
[
namespace
]
=
scopedCallbacks
;
}
return
{
get
(
id
)
{
...
...
@@ -9426,6 +9452,9 @@ var serviceContext = (function () {
restoreGlobal
:
restoreGlobal
,
getSubNVueById
:
getSubNVueById
,
getCurrentSubNVue
:
getCurrentSubNVue
,
onNativeEventReceive
:
onNativeEventReceive
,
consumeNativeEvent
:
consumeNativeEvent
,
sendNativeEvent
:
sendNativeEvent
,
navigateBack
:
navigateBack$1
,
navigateTo
:
navigateTo$1
,
reLaunch
:
reLaunch$1
,
...
...
@@ -9691,9 +9720,9 @@ var serviceContext = (function () {
'
error
'
,
'
waiting
'
];
const
callbacks$
4
=
{};
const
callbacks$
5
=
{};
eventNames$2
.
forEach
(
name
=>
{
callbacks$
4
[
name
]
=
[];
callbacks$
5
[
name
]
=
[];
});
const
props$1
=
[
...
...
@@ -9757,7 +9786,7 @@ var serviceContext = (function () {
errMsg
,
errCode
})
=>
{
callbacks$
4
[
state
].
forEach
(
callback
=>
{
callbacks$
5
[
state
].
forEach
(
callback
=>
{
if
(
typeof
callback
===
'
function
'
)
{
callback
(
state
===
'
error
'
?
{
errMsg
,
...
...
@@ -9809,7 +9838,7 @@ var serviceContext = (function () {
eventNames$2
.
forEach
(
item
=>
{
const
name
=
item
[
0
].
toUpperCase
()
+
item
.
substr
(
1
);
BackgroundAudioManager
.
prototype
[
`on
${
name
}
`
]
=
function
(
callback
)
{
callbacks$
4
[
item
].
push
(
callback
);
callbacks$
5
[
item
].
push
(
callback
);
};
});
...
...
@@ -10849,10 +10878,10 @@ var serviceContext = (function () {
EditorContext
:
EditorContext
});
const
callbacks$
5
=
[];
const
callbacks$
6
=
[];
onMethod
(
'
onAccelerometerChange
'
,
function
(
res
)
{
callbacks$
5
.
forEach
(
callbackId
=>
{
callbacks$
6
.
forEach
(
callbackId
=>
{
invoke$1
(
callbackId
,
res
);
});
});
...
...
@@ -10864,7 +10893,7 @@ var serviceContext = (function () {
*/
function
onAccelerometerChange
(
callbackId
)
{
// TODO 当没有 start 时,添加 on 需要主动 start?
callbacks$
5
.
push
(
callbackId
);
callbacks$
6
.
push
(
callbackId
);
if
(
!
isEnable
)
{
startAccelerometer
();
}
...
...
@@ -10921,10 +10950,10 @@ var serviceContext = (function () {
onBLECharacteristicValueChange
:
onBLECharacteristicValueChange$1
});
const
callbacks$
6
=
[];
const
callbacks$
7
=
[];
onMethod
(
'
onCompassChange
'
,
function
(
res
)
{
callbacks$
6
.
forEach
(
callbackId
=>
{
callbacks$
7
.
forEach
(
callbackId
=>
{
invoke$1
(
callbackId
,
res
);
});
});
...
...
@@ -10936,7 +10965,7 @@ var serviceContext = (function () {
*/
function
onCompassChange
(
callbackId
)
{
// TODO 当没有 start 时,添加 on 需要主动 start?
callbacks$
6
.
push
(
callbackId
);
callbacks$
7
.
push
(
callbackId
);
if
(
!
isEnable$1
)
{
startCompass
();
}
...
...
@@ -10968,16 +10997,16 @@ var serviceContext = (function () {
stopCompass
:
stopCompass
});
const
callbacks$
7
=
[];
const
callbacks$
8
=
[];
onMethod
(
'
onNetworkStatusChange
'
,
res
=>
{
callbacks$
7
.
forEach
(
callbackId
=>
{
callbacks$
8
.
forEach
(
callbackId
=>
{
invoke$1
(
callbackId
,
res
);
});
});
function
onNetworkStatusChange
(
callbackId
)
{
callbacks$
7
.
push
(
callbackId
);
callbacks$
8
.
push
(
callbackId
);
}
var
require_context_module_1_13
=
/*#__PURE__*/
Object
.
freeze
({
...
...
@@ -10985,16 +11014,16 @@ var serviceContext = (function () {
onNetworkStatusChange
:
onNetworkStatusChange
});
const
callbacks$
8
=
[];
const
callbacks$
9
=
[];
onMethod
(
'
onUIStyleChange
'
,
function
(
res
)
{
callbacks$
8
.
forEach
(
callbackId
=>
{
callbacks$
9
.
forEach
(
callbackId
=>
{
invoke$1
(
callbackId
,
res
);
});
});
function
onUIStyleChange
(
callbackId
)
{
callbacks$
8
.
push
(
callbackId
);
callbacks$
9
.
push
(
callbackId
);
}
var
require_context_module_1_14
=
/*#__PURE__*/
Object
.
freeze
({
...
...
@@ -11030,7 +11059,7 @@ var serviceContext = (function () {
previewImage
:
previewImage$1
});
const
callbacks$
9
=
{
const
callbacks$
a
=
{
pause
:
[],
resume
:
[],
start
:
[],
...
...
@@ -11044,7 +11073,7 @@ var serviceContext = (function () {
const
state
=
res
.
state
;
delete
res
.
state
;
delete
res
.
errMsg
;
callbacks$
9
[
state
].
forEach
(
callback
=>
{
callbacks$
a
[
state
].
forEach
(
callback
=>
{
if
(
typeof
callback
===
'
function
'
)
{
callback
(
res
);
}
...
...
@@ -11052,7 +11081,7 @@ var serviceContext = (function () {
});
}
onError
(
callback
)
{
callbacks$
9
.
error
.
push
(
callback
);
callbacks$
a
.
error
.
push
(
callback
);
}
onFrameRecorded
(
callback
)
{
...
...
@@ -11064,16 +11093,16 @@ var serviceContext = (function () {
}
onPause
(
callback
)
{
callbacks$
9
.
pause
.
push
(
callback
);
callbacks$
a
.
pause
.
push
(
callback
);
}
onResume
(
callback
)
{
callbacks$
9
.
resume
.
push
(
callback
);
callbacks$
a
.
resume
.
push
(
callback
);
}
onStart
(
callback
)
{
callbacks$
9
.
start
.
push
(
callback
);
callbacks$
a
.
start
.
push
(
callback
);
}
onStop
(
callback
)
{
callbacks$
9
.
stop
.
push
(
callback
);
callbacks$
a
.
stop
.
push
(
callback
);
}
pause
()
{
invokeMethod
(
'
operateRecorder
'
,
{
...
...
@@ -11387,7 +11416,7 @@ var serviceContext = (function () {
const
socketTasks$1
=
Object
.
create
(
null
);
const
socketTasksArray
=
[];
const
callbacks$
a
=
Object
.
create
(
null
);
const
callbacks$
b
=
Object
.
create
(
null
);
onMethod
(
'
onSocketTaskStateChange
'
,
({
socketTaskId
,
state
,
...
...
@@ -11401,8 +11430,8 @@ var serviceContext = (function () {
if
(
state
===
'
open
'
)
{
socketTask
.
readyState
=
socketTask
.
OPEN
;
}
if
(
socketTask
===
socketTasksArray
[
0
]
&&
callbacks$
a
[
state
])
{
invoke$1
(
callbacks$
a
[
state
],
state
===
'
message
'
?
{
if
(
socketTask
===
socketTasksArray
[
0
]
&&
callbacks$
b
[
state
])
{
invoke$1
(
callbacks$
b
[
state
],
state
===
'
message
'
?
{
data
}
:
{});
}
...
...
@@ -11468,19 +11497,19 @@ var serviceContext = (function () {
}
function
onSocketOpen
(
callbackId
)
{
callbacks$
a
.
open
=
callbackId
;
callbacks$
b
.
open
=
callbackId
;
}
function
onSocketError
(
callbackId
)
{
callbacks$
a
.
error
=
callbackId
;
callbacks$
b
.
error
=
callbackId
;
}
function
onSocketMessage
(
callbackId
)
{
callbacks$
a
.
message
=
callbackId
;
callbacks$
b
.
message
=
callbackId
;
}
function
onSocketClose
(
callbackId
)
{
callbacks$
a
.
close
=
callbackId
;
callbacks$
b
.
close
=
callbackId
;
}
var
require_context_module_1_19
=
/*#__PURE__*/
Object
.
freeze
({
...
...
@@ -11872,16 +11901,16 @@ var serviceContext = (function () {
createSelectorQuery
:
createSelectorQuery
});
const
callbacks$
b
=
[];
const
callbacks$
c
=
[];
onMethod
(
'
onKeyboardHeightChange
'
,
res
=>
{
callbacks$
b
.
forEach
(
callbackId
=>
{
callbacks$
c
.
forEach
(
callbackId
=>
{
invoke$1
(
callbackId
,
res
);
});
});
function
onKeyboardHeightChange
(
callbackId
)
{
callbacks$
b
.
push
(
callbackId
);
callbacks$
c
.
push
(
callbackId
);
}
var
require_context_module_1_24
=
/*#__PURE__*/
Object
.
freeze
({
...
...
@@ -11960,16 +11989,16 @@ var serviceContext = (function () {
const
hideTabBarRedDot$1
=
removeTabBarBadge$1
;
const
callbacks$
c
=
[];
const
callbacks$
d
=
[];
onMethod
(
'
onTabBarMidButtonTap
'
,
res
=>
{
callbacks$
c
.
forEach
(
callbackId
=>
{
callbacks$
d
.
forEach
(
callbackId
=>
{
invoke$1
(
callbackId
,
res
);
});
});
function
onTabBarMidButtonTap
(
callbackId
)
{
callbacks$
c
.
push
(
callbackId
);
callbacks$
d
.
push
(
callbackId
);
}
var
require_context_module_1_28
=
/*#__PURE__*/
Object
.
freeze
({
...
...
@@ -11980,22 +12009,22 @@ var serviceContext = (function () {
onTabBarMidButtonTap
:
onTabBarMidButtonTap
});
const
callbacks$
d
=
[];
const
callbacks$
e
=
[];
onMethod
(
'
onViewDidResize
'
,
res
=>
{
callbacks$
d
.
forEach
(
callbackId
=>
{
callbacks$
e
.
forEach
(
callbackId
=>
{
invoke$1
(
callbackId
,
res
);
});
});
function
onWindowResize
(
callbackId
)
{
callbacks$
d
.
push
(
callbackId
);
callbacks$
e
.
push
(
callbackId
);
}
function
offWindowResize
(
callbackId
)
{
// TODO 目前 on 和 off 即使传入同一个 function,获取到的 callbackId 也不会一致,导致不能 off 掉指定
// 后续修复
// 此处和微信平台一致查询不到去掉最后一个
callbacks$
d
.
splice
(
callbacks$d
.
indexOf
(
callbackId
),
1
);
callbacks$
e
.
splice
(
callbacks$e
.
indexOf
(
callbackId
),
1
);
}
var
require_context_module_1_29
=
/*#__PURE__*/
Object
.
freeze
({
...
...
@@ -12469,7 +12498,7 @@ var serviceContext = (function () {
);
}
function
initGlobalListeners
()
{
function
initGlobalListeners
()
{
const
globalEvent
=
requireNativePlugin
(
'
globalEvent
'
);
const
emit
=
UniServiceJSBridge
.
emit
;
...
...
@@ -12498,13 +12527,20 @@ var serviceContext = (function () {
publish
(
'
onKeyboardHeightChange
'
,
{
height
:
event
.
height
});
});
globalEvent
.
addEventListener
(
'
uistylechange
'
,
function
(
event
)
{
publish
(
'
onUIStyleChange
'
,
{
style
:
event
.
uistyle
});
});
});
globalEvent
.
addEventListener
(
'
uistylechange
'
,
function
(
event
)
{
publish
(
'
onUIStyleChange
'
,
{
style
:
event
.
uistyle
});
});
globalEvent
.
addEventListener
(
'
uniMPNativeEvent
'
,
function
({
event
,
data
})
{
consumeNativeEvent
(
event
,
data
);
});
plus
.
globalEvent
.
addEventListener
(
'
plusMessage
'
,
onPlusMessage$1
);
...
...
src/core/helpers/promise.js
浏览文件 @
69cd3d0d
...
...
@@ -8,7 +8,7 @@ import {
}
from
'
./interceptor
'
const
SYNC_API_RE
=
/^
\$
|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
/^
\$
|
sendNativeEvent|
restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
const
CONTEXT_API_RE
=
/^create|Manager$/
...
...
src/platforms/app-plus/service/api/index.js
浏览文件 @
69cd3d0d
...
...
@@ -50,6 +50,8 @@ export * from './plugin/require-native-plugin'
export
*
from
'
./plugin/share
'
export
*
from
'
./plugin/restore-global
'
export
*
from
'
./plugin/sub-nvue
'
export
*
from
'
./plugin/on-native-event-receive
'
export
*
from
'
./plugin/send-native-event
'
export
*
from
'
./route/navigate-back
'
export
*
from
'
./route/navigate-to
'
...
...
src/platforms/app-plus/service/api/plugin/on-native-event-receive.js
0 → 100644
浏览文件 @
69cd3d0d
import
{
isFn
}
from
'
uni-shared
'
const
callbacks
=
[]
export
function
onNativeEventReceive
(
callback
)
{
isFn
(
callback
)
&&
callbacks
.
indexOf
(
callback
)
===
-
1
&&
callbacks
.
push
(
callback
)
}
export
function
consumeNativeEvent
(
event
,
data
)
{
callbacks
.
forEach
(
callback
=>
callback
(
event
,
data
))
}
src/platforms/app-plus/service/api/plugin/send-native-event.js
0 → 100644
浏览文件 @
69cd3d0d
export
function
sendNativeEvent
(
event
,
data
,
callback
)
{
// 实时获取weex module(weex可能会变化,比如首页nvue加速显示时)
return
weex
.
requireModule
(
'
plus
'
).
sendNativeEvent
(
event
,
data
,
callback
)
}
src/platforms/app-plus/service/framework/app.js
浏览文件 @
69cd3d0d
...
...
@@ -2,7 +2,7 @@ import {
callAppHook
}
from
'
uni-core/service/plugins/util
'
import
initOn
from
'
uni-core/service/bridge/on
'
import
initOn
from
'
uni-core/service/bridge/on
'
import
{
NETWORK_TYPES
...
...
@@ -35,6 +35,10 @@ import {
backbuttonListener
}
from
'
./backbutton
'
import
{
consumeNativeEvent
}
from
'
../api/plugin/on-native-event-receive
'
let
appCtx
const
defaultApp
=
{
...
...
@@ -55,7 +59,7 @@ export function getApp ({
)
}
function
initGlobalListeners
()
{
function
initGlobalListeners
()
{
const
globalEvent
=
requireNativePlugin
(
'
globalEvent
'
)
const
emit
=
UniServiceJSBridge
.
emit
...
...
@@ -84,13 +88,20 @@ function initGlobalListeners () {
publish
(
'
onKeyboardHeightChange
'
,
{
height
:
event
.
height
})
})
globalEvent
.
addEventListener
(
'
uistylechange
'
,
function
(
event
)
{
publish
(
'
onUIStyleChange
'
,
{
style
:
event
.
uistyle
})
})
})
globalEvent
.
addEventListener
(
'
uistylechange
'
,
function
(
event
)
{
publish
(
'
onUIStyleChange
'
,
{
style
:
event
.
uistyle
})
})
globalEvent
.
addEventListener
(
'
uniMPNativeEvent
'
,
function
({
event
,
data
})
{
consumeNativeEvent
(
event
,
data
)
})
plus
.
globalEvent
.
addEventListener
(
'
plusMessage
'
,
onPlusMessage
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录