Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
良好的行为成为习惯
uni-app
提交
6f20c0a3
U
uni-app
项目概览
良好的行为成为习惯
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6f20c0a3
编写于
11月 19, 2019
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: v3-app focus 事件增加键盘高度信息
上级
d9c3f76b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
106 addition
and
10 deletion
+106
-10
src/core/view/components/input/index.vue
src/core/view/components/input/index.vue
+8
-5
src/core/view/components/textarea/index.vue
src/core/view/components/textarea/index.vue
+4
-2
src/core/view/mixins/index.js
src/core/view/mixins/index.js
+6
-1
src/core/view/mixins/keyboard.js
src/core/view/mixins/keyboard.js
+20
-0
src/platforms/app-plus/service/framework/plugins/keyboard.js
src/platforms/app-plus/service/framework/plugins/keyboard.js
+54
-0
src/platforms/app-plus/service/framework/plugins/vdom-sync.js
...platforms/app-plus/service/framework/plugins/vdom-sync.js
+14
-2
未找到文件。
src/core/view/components/input/index.vue
浏览文件 @
6f20c0a3
<
template
>
<
template
>
<uni-input
<uni-input
@
change.stop
@
change.stop
v-on=
"$listeners"
>
v-on=
"$listeners"
>
<div
<div
ref=
"wrapper"
ref=
"wrapper"
...
@@ -33,13 +33,14 @@
...
@@ -33,13 +33,14 @@
</
template
>
</
template
>
<
script
>
<
script
>
import
{
import
{
emitter
emitter
,
keyboard
}
from
'
uni-mixins
'
}
from
'
uni-mixins
'
const
INPUT_TYPES
=
[
'
text
'
,
'
number
'
,
'
idcard
'
,
'
digit
'
,
'
password
'
]
const
INPUT_TYPES
=
[
'
text
'
,
'
number
'
,
'
idcard
'
,
'
digit
'
,
'
password
'
]
const
NUMBER_TYPES
=
[
'
number
'
,
'
digit
'
]
const
NUMBER_TYPES
=
[
'
number
'
,
'
digit
'
]
export
default
{
export
default
{
name
:
'
Input
'
,
name
:
'
Input
'
,
mixins
:
[
emitter
],
mixins
:
[
emitter
,
keyboard
],
model
:
{
model
:
{
prop
:
'
value
'
,
prop
:
'
value
'
,
event
:
'
update:value
'
event
:
'
update:value
'
...
@@ -165,6 +166,8 @@ export default {
...
@@ -165,6 +166,8 @@ export default {
$vm
=
$vm
.
$parent
$vm
=
$vm
.
$parent
}
}
this
.
initKeyboard
(
this
.
$refs
.
input
)
this
.
focus
&&
this
.
_focusInput
()
this
.
focus
&&
this
.
_focusInput
()
},
},
beforeDestroy
()
{
beforeDestroy
()
{
...
@@ -308,7 +311,7 @@ uni-input[hidden] {
...
@@ -308,7 +311,7 @@ uni-input[hidden] {
height
:
100%
;
height
:
100%
;
background
:
none
;
background
:
none
;
color
:
inherit
;
color
:
inherit
;
opacity
:
1
;
opacity
:
1
;
-webkit-text-fill-color
:
currentcolor
;
-webkit-text-fill-color
:
currentcolor
;
font
:
inherit
;
font
:
inherit
;
line-height
:
inherit
;
line-height
:
inherit
;
...
...
src/core/view/components/textarea/index.vue
浏览文件 @
6f20c0a3
...
@@ -51,11 +51,12 @@
...
@@ -51,11 +51,12 @@
</
template
>
</
template
>
<
script
>
<
script
>
import
{
import
{
emitter
emitter
,
keyboard
}
from
'
uni-mixins
'
}
from
'
uni-mixins
'
export
default
{
export
default
{
name
:
'
Textarea
'
,
name
:
'
Textarea
'
,
mixins
:
[
emitter
],
mixins
:
[
emitter
,
keyboard
],
model
:
{
model
:
{
prop
:
'
value
'
,
prop
:
'
value
'
,
event
:
'
update:value
'
event
:
'
update:value
'
...
@@ -210,6 +211,7 @@ export default {
...
@@ -210,6 +211,7 @@ export default {
this
.
_resize
({
this
.
_resize
({
height
:
this
.
$refs
.
sensor
.
$el
.
offsetHeight
height
:
this
.
$refs
.
sensor
.
$el
.
offsetHeight
})
})
this
.
initKeyboard
(
this
.
$refs
.
textarea
)
},
},
beforeDestroy
()
{
beforeDestroy
()
{
this
.
$dispatch
(
'
Form
'
,
'
uni-form-group-update
'
,
{
this
.
$dispatch
(
'
Form
'
,
'
uni-form-group-update
'
,
{
...
...
src/core/view/mixins/index.js
浏览文件 @
6f20c0a3
...
@@ -16,4 +16,9 @@ export {
...
@@ -16,4 +16,9 @@ export {
export
{
export
{
default
as
subscriber
default
as
subscriber
}
}
from
'
./subscriber
'
from
'
./subscriber
'
export
{
default
as
keyboard
}
from
'
./keyboard
'
src/core/view/mixins/keyboard.js
0 → 100644
浏览文件 @
6f20c0a3
function
hideKeyboard
()
{
document
.
activeElement
.
blur
()
}
export
default
{
name
:
'
Keyboard
'
,
beforeDestroy
()
{
UniViewJSBridge
.
unsubscribe
(
'
hideKeyboard
'
,
hideKeyboard
)
},
methods
:
{
initKeyboard
(
el
)
{
el
.
addEventListener
(
'
focus
'
,
()
=>
{
UniViewJSBridge
.
subscribe
(
'
hideKeyboard
'
,
hideKeyboard
)
})
el
.
addEventListener
(
'
blur
'
,
()
=>
{
UniViewJSBridge
.
unsubscribe
(
'
hideKeyboard
'
,
hideKeyboard
)
})
}
}
}
src/platforms/app-plus/service/framework/plugins/keyboard.js
0 → 100644
浏览文件 @
6f20c0a3
import
{
onMethod
,
getCurrentPageId
}
from
'
../../../../../core/service/platform
'
const
isAndroid
=
plus
.
os
.
name
.
toLowerCase
()
===
'
android
'
const
FOCUS_TIMEOUT
=
isAndroid
?
300
:
700
const
HIDE_TIMEOUT
=
300
let
keyboardHeight
=
0
let
onKeyboardShow
let
focusTimer
let
hideKeyboardTimeout
export
function
hookKeyboardEvent
(
event
,
callback
)
{
onKeyboardShow
=
null
focusTimer
&&
clearTimeout
(
focusTimer
)
if
(
event
.
type
===
'
focus
'
)
{
if
(
keyboardHeight
>
0
)
{
event
.
detail
.
height
=
keyboardHeight
}
else
{
focusTimer
=
setTimeout
(
function
()
{
event
.
detail
.
height
=
keyboardHeight
callback
(
event
)
},
FOCUS_TIMEOUT
)
onKeyboardShow
=
function
()
{
clearTimeout
(
focusTimer
)
event
.
detail
.
height
=
keyboardHeight
callback
(
event
)
}
return
}
}
callback
(
event
)
}
onMethod
(
'
onKeyboardHeightChange
'
,
res
=>
{
keyboardHeight
=
res
.
height
if
(
keyboardHeight
>
0
)
{
onKeyboardShow
&&
onKeyboardShow
()
if
(
hideKeyboardTimeout
)
{
clearTimeout
(
hideKeyboardTimeout
)
hideKeyboardTimeout
=
null
}
}
else
{
// 仅安卓收起键盘时通知view层失去焦点
if
(
isAndroid
)
{
hideKeyboardTimeout
=
setTimeout
(
function
()
{
hideKeyboardTimeout
=
null
var
pageId
=
getCurrentPageId
()
UniServiceJSBridge
.
publishHandler
(
'
hideKeyboard
'
,
{},
pageId
)
},
HIDE_TIMEOUT
)
}
}
})
src/platforms/app-plus/service/framework/plugins/vdom-sync.js
浏览文件 @
6f20c0a3
...
@@ -20,6 +20,10 @@ import {
...
@@ -20,6 +20,10 @@ import {
vdSyncCallbacks
vdSyncCallbacks
}
from
'
../subscribe-handlers/on-vd-sync-callback
'
}
from
'
../subscribe-handlers/on-vd-sync-callback
'
import
{
hookKeyboardEvent
}
from
'
./keyboard
'
function
wrapperEvent
(
event
)
{
function
wrapperEvent
(
event
)
{
event
.
preventDefault
=
noop
event
.
preventDefault
=
noop
event
.
stopPropagation
=
noop
event
.
stopPropagation
=
noop
...
@@ -37,7 +41,15 @@ const handleVdData = {
...
@@ -37,7 +41,15 @@ const handleVdData = {
if
(
!
target
)
{
if
(
!
target
)
{
return
console
.
error
(
`event handler[
${
cid
}
][
${
nid
}
] not found`
)
return
console
.
error
(
`event handler[
${
cid
}
][
${
nid
}
] not found`
)
}
}
target
.
dispatchEvent
(
event
.
type
,
wrapperEvent
(
event
))
const
type
=
event
.
type
const
mpEvent
=
wrapperEvent
(
event
)
if
(
type
===
'
focus
'
||
type
===
'
blur
'
)
{
hookKeyboardEvent
(
mpEvent
,
event
=>
{
target
.
dispatchEvent
(
type
,
event
)
})
}
else
{
target
.
dispatchEvent
(
type
,
mpEvent
)
}
})
})
}
}
}
}
...
@@ -181,4 +193,4 @@ export class VDomSync {
...
@@ -181,4 +193,4 @@ export class VDomSync {
this
.
elements
.
length
=
0
this
.
elements
.
length
=
0
removeVdSync
(
this
.
pageId
)
removeVdSync
(
this
.
pageId
)
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录