Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
8e1561f1
U
uni-app
项目概览
DCloud
/
uni-app
通知
699
Star
38703
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看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
8e1561f1
编写于
1月 10, 2020
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: safeAreaInsets
上级
6d37a08e
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
99 addition
and
50 deletion
+99
-50
src/platforms/app-plus/service/api/device/system.js
src/platforms/app-plus/service/api/device/system.js
+51
-35
src/platforms/app-plus/service/api/util.js
src/platforms/app-plus/service/api/util.js
+23
-5
src/platforms/app-plus/service/framework/safe-area-insets.js
src/platforms/app-plus/service/framework/safe-area-insets.js
+0
-0
src/platforms/app-plus/service/framework/tab-bar.js
src/platforms/app-plus/service/framework/tab-bar.js
+25
-10
未找到文件。
src/platforms/app-plus/service/api/device/system.js
浏览文件 @
8e1561f1
import
{
callApiSync
,
isTabBarPage
,
getLastWebview
getLastWebview
,
getStatusbarHeight
,
getScreenInfo
}
from
'
../util
'
import
{
...
...
@@ -17,47 +19,55 @@ export function getSystemInfoSync () {
export
function
getSystemInfo
()
{
const
platform
=
plus
.
os
.
name
.
toLowerCase
()
const
ios
=
platform
===
'
ios
'
// 安卓 plus 接口获取的屏幕大小值不为整数,iOS js 获取的屏幕大小横屏时颠倒
const
screenWidth
=
plus
.
screen
.
resolutionWidth
const
screenHeight
=
plus
.
screen
.
resolutionHeight
// 横屏时 iOS 获取的状态栏高度错误,进行纠正
var
landscape
=
Math
.
abs
(
plus
.
navigator
.
getOrientation
())
===
90
var
statusBarHeight
=
Math
.
round
(
plus
.
navigator
.
getStatusbarHeight
())
if
(
ios
&&
landscape
)
{
statusBarHeight
=
Math
.
min
(
20
,
statusBarHeight
)
}
var
safeAreaInsets
function
getSafeAreaInsets
()
{
return
{
left
:
0
,
right
:
0
,
top
:
titleNView
?
0
:
statusBarHeight
,
bottom
:
0
}
const
{
screenWidth
,
screenHeight
}
=
getScreenInfo
()
const
statusBarHeight
=
getStatusbarHeight
()
let
safeAreaInsets
const
titleNView
=
{
height
:
0
,
cover
:
false
}
// 判断是否存在 titleNView
var
titleNView
var
webview
=
getLastWebview
()
const
webview
=
getLastWebview
()
if
(
webview
)
{
let
style
=
webview
.
getStyle
()
if
(
style
)
{
titleNView
=
style
&&
style
.
titleNView
titleNView
=
titleNView
&&
titleNView
.
type
===
'
default
'
style
=
style
&&
style
.
titleNView
if
(
style
&&
style
.
type
&&
style
.
type
!==
'
none
'
)
{
titleNView
.
height
=
style
.
type
===
'
transparent
'
?
0
:
(
statusBarHeight
+
TITLEBAR_HEIGHT
)
titleNView
.
cover
=
style
.
type
===
'
transparent
'
||
style
.
type
===
'
float
'
}
safeAreaInsets
=
ios
?
webview
.
getSafeAreaInsets
()
:
getSafeAreaInsets
()
safeAreaInsets
=
webview
.
getSafeAreaInsets
()
}
else
{
safeAreaInsets
=
ios
?
plus
.
navigator
.
getSafeAreaInsets
()
:
getSafeAreaInsets
()
safeAreaInsets
=
plus
.
navigator
.
getSafeAreaInsets
()
}
var
windowHeight
=
Math
.
min
(
screenHeight
-
(
titleNView
?
(
statusBarHeight
+
TITLEBAR_HEIGHT
)
:
0
)
-
(
isTabBarPage
()
&&
tabBar
.
visible
?
tabBar
.
height
:
0
),
screenHeight
)
var
windowWidth
=
screenWidth
var
safeArea
=
{
const
tabBarView
=
{
height
:
0
,
cover
:
false
}
if
(
isTabBarPage
())
{
tabBarView
.
height
=
tabBar
.
visible
?
tabBar
.
height
:
0
tabBarView
.
cover
=
tabBar
.
cover
}
const
windowTop
=
titleNView
.
cover
?
titleNView
.
height
:
0
const
windowBottom
=
tabBarView
.
cover
?
tabBarView
.
height
:
0
const
windowHeight
=
screenHeight
-
titleNView
.
height
-
tabBarView
.
height
const
windowHeightReal
=
screenHeight
-
(
titleNView
.
cover
?
0
:
titleNView
.
height
)
-
(
tabBarView
.
cover
?
0
:
tabBarView
.
height
)
const
windowWidth
=
screenWidth
safeAreaInsets
=
ios
?
safeAreaInsets
:
{
left
:
0
,
right
:
0
,
top
:
titleNView
.
height
&&
!
titleNView
.
cover
?
0
:
statusBarHeight
,
bottom
:
0
}
const
safeArea
=
{
left
:
safeAreaInsets
.
left
,
right
:
windowWidth
-
safeAreaInsets
.
right
,
top
:
safeAreaInsets
.
top
,
bottom
:
windowHeight
-
safeAreaInsets
.
bottom
,
bottom
:
windowHeight
Real
-
safeAreaInsets
.
bottom
,
width
:
windowWidth
-
safeAreaInsets
.
left
-
safeAreaInsets
.
right
,
height
:
windowHeight
-
safeAreaInsets
.
top
-
safeAreaInsets
.
bottom
height
:
windowHeight
Real
-
safeAreaInsets
.
top
-
safeAreaInsets
.
bottom
}
return
{
...
...
@@ -76,8 +86,14 @@ export function getSystemInfo () {
fontSizeSetting
:
''
,
platform
,
SDKVersion
:
''
,
windowTop
:
0
,
windowBottom
:
0
,
safeArea
windowTop
,
windowBottom
,
safeArea
,
safeAreaInsets
:
{
top
:
safeAreaInsets
.
top
,
right
:
safeAreaInsets
.
right
,
bottom
:
safeAreaInsets
.
bottom
,
left
:
safeAreaInsets
.
left
}
}
}
src/platforms/app-plus/service/api/util.js
浏览文件 @
8e1561f1
export
{
isTabBarPage
}
from
'
../bridge
'
export
{
isTabBarPage
}
from
'
../bridge
'
export
function
callApiSync
(
api
,
args
,
name
,
alias
)
{
const
ret
=
api
(
args
)
if
(
ret
&&
ret
.
errMsg
)
{
...
...
@@ -148,4 +148,22 @@ const _transformlng = function (lng, lat) {
const
outOfChina
=
function
(
lng
,
lat
)
{
return
(
lng
<
72.004
||
lng
>
137.8347
)
||
((
lat
<
0.8293
||
lat
>
55.8271
)
||
false
)
}
}
export
function
getStatusbarHeight
()
{
// 横屏时 iOS 获取的状态栏高度错误,进行纠正
return
plus
.
navigator
.
isImmersedStatusbar
()
?
Math
.
round
(
plus
.
os
.
name
===
'
iOS
'
?
plus
.
navigator
.
getSafeAreaInsets
().
top
:
plus
.
navigator
.
getStatusbarHeight
())
:
0
}
export
function
getScreenInfo
()
{
const
orientation
=
plus
.
navigator
.
getOrientation
()
const
landscape
=
Math
.
abs
(
orientation
)
===
90
// 安卓 plus 接口获取的屏幕大小值不为整数
const
width
=
plus
.
screen
.
resolutionWidth
const
height
=
plus
.
screen
.
resolutionHeight
// 根据方向纠正宽高
return
{
screenWidth
:
Math
[
landscape
?
'
max
'
:
'
min
'
](
width
,
height
),
screenHeight
:
Math
[
landscape
?
'
min
'
:
'
max
'
](
width
,
height
)
}
}
src/platforms/app-plus/service/framework/safe-area.js
→
src/platforms/app-plus/service/framework/safe-area
-insets
.js
浏览文件 @
8e1561f1
文件已移动
src/platforms/app-plus/service/framework/tab-bar.js
浏览文件 @
8e1561f1
...
...
@@ -7,8 +7,10 @@ import {
requireNativePlugin
}
from
'
../bridge
'
const
TABBAR_HEIGHT
=
50
import
safeAreaInsets
from
'
./safe-area-insets
'
const
TABBAR_HEIGHT
=
50
const
isIOS
=
plus
.
os
.
name
===
'
iOS
'
let
config
/**
...
...
@@ -73,7 +75,7 @@ function setTabBarStyle (style) {
}
/**
* 隐藏 tabBar
* @param {boolean} animation 是否需要动画效果
暂未支持
* @param {boolean} animation 是否需要动画效果
*/
function
hideTabBar
(
animation
)
{
visible
=
false
...
...
@@ -83,7 +85,7 @@ function hideTabBar (animation) {
}
/**
* 显示 tabBar
* @param {boolean} animation 是否需要动画效果
暂未支持
* @param {boolean} animation 是否需要动画效果
*/
function
showTabBar
(
animation
)
{
visible
=
true
...
...
@@ -110,21 +112,28 @@ export default {
publish
(
'
onTabBarMidButtonTap
'
,
{})
})
},
switchTab
(
page
)
{
const
itemLength
=
config
.
list
.
length
indexOf
(
page
)
{
const
itemLength
=
config
&&
config
.
list
&&
config
.
list
.
length
if
(
itemLength
)
{
for
(
let
i
=
0
;
i
<
itemLength
;
i
++
)
{
if
(
config
.
list
[
i
].
pagePath
===
page
||
config
.
list
[
i
].
pagePath
===
`
${
page
}
.html`
)
{
tabBar
&&
tabBar
.
switchSelect
({
index
:
i
})
return
true
return
i
}
}
}
return
-
1
},
switchTab
(
page
)
{
const
index
=
this
.
indexOf
(
page
)
if
(
index
>=
0
)
{
tabBar
&&
tabBar
.
switchSelect
({
index
})
return
true
}
return
false
},
setTabBarBadge
,
...
...
@@ -148,7 +157,13 @@ export default {
return
visible
},
get
height
()
{
return
config
&&
config
.
height
?
parseFloat
(
config
.
height
)
:
TABBAR_HEIGHT
return
(
config
&&
config
.
height
?
parseFloat
(
config
.
height
)
:
TABBAR_HEIGHT
)
+
safeAreaInsets
.
bottom
},
// tabBar是否遮挡内容区域
get
cover
()
{
const
array
=
[
'
extralight
'
,
'
light
'
,
'
dark
'
]
// 设置背景颜色会失效
return
isIOS
&&
array
.
indexOf
(
config
.
blurEffect
)
>=
0
&&
!
config
.
backgroundColor
},
setStyle
({
mask
})
{
tabBar
.
setMask
({
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录