Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lindexi_gd
Uno
提交
b7d02799
U
Uno
项目概览
lindexi_gd
/
Uno
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
Uno
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b7d02799
编写于
4月 17, 2023
作者:
E
Elie Bariche
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
perf: Add DisplayInformation bindings
上级
d077eaf8
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
141 addition
and
12 deletion
+141
-12
src/Uno.UI/ts/Windows/Graphics/Display/DisplayInformation.ts
src/Uno.UI/ts/Windows/Graphics/Display/DisplayInformation.ts
+20
-0
src/Uno.UWP/Graphics/Display/DisplayInformation.Interop.wasm.cs
...o.UWP/Graphics/Display/DisplayInformation.Interop.wasm.cs
+41
-0
src/Uno.UWP/Graphics/Display/DisplayInformation.wasm.cs
src/Uno.UWP/Graphics/Display/DisplayInformation.wasm.cs
+80
-12
未找到文件。
src/Uno.UI/ts/Windows/Graphics/Display/DisplayInformation.ts
浏览文件 @
b7d02799
...
...
@@ -18,6 +18,26 @@
private
static
lockingSupported
:
boolean
|
null
;
public
static
getDevicePixelRatio
()
:
number
{
return
globalThis
.
devicePixelRatio
;
}
public
static
getScreenWidth
():
number
{
return
globalThis
.
screen
.
width
;
}
public
static
getScreenHeight
():
number
{
return
globalThis
.
screen
.
height
;
}
public
static
getScreenOrientationAngle
():
number
|
null
{
return
globalThis
.
screen
.
orientation
?.
angle
;
}
public
static
getScreenOrientationType
():
string
|
null
{
return
globalThis
.
screen
.
orientation
?.
type
;
}
public
static
startOrientationChanged
()
{
window
.
screen
.
orientation
.
addEventListener
(
"
change
"
,
DisplayInformation
.
onOrientationChange
);
}
...
...
src/Uno.UWP/Graphics/Display/DisplayInformation.Interop.wasm.cs
0 → 100644
浏览文件 @
b7d02799
#
if
NET7_0_OR_GREATER
using
System.Runtime.InteropServices.JavaScript
;
namespace
__Windows.Graphics.Display
{
internal
partial
class
DisplayInformation
{
internal
static
partial
class
NativeMethods
{
private
const
string
JsType
=
"globalThis.Windows.Graphics.Display.DisplayInformation"
;
[
JSImport
(
$"
{
JsType
}
.getDevicePixelRatio"
)]
internal
static
partial
float
GetDevicePixelRatio
();
[
JSImport
(
$"
{
JsType
}
.getScreenHeight"
)]
internal
static
partial
float
GetScreenHeight
();
[
JSImport
(
$"
{
JsType
}
.getScreenOrientationAngle"
)]
internal
static
partial
int
?
GetScreenOrientationAngle
();
[
JSImport
(
$"
{
JsType
}
.getScreenOrientationType"
)]
internal
static
partial
string
GetScreenOrientationType
();
[
JSImport
(
$"
{
JsType
}
.getScreenWidth"
)]
internal
static
partial
float
GetScreenWidth
();
[
JSImport
(
$"
{
JsType
}
.startDpiChanged"
)]
internal
static
partial
void
StartDpiChanged
();
[
JSImport
(
$"
{
JsType
}
.startOrientationChanged"
)]
internal
static
partial
void
StartOrientationChanged
();
[
JSImport
(
$"
{
JsType
}
.stopDpiChanged"
)]
internal
static
partial
void
StopDpiChanged
();
[
JSImport
(
$"
{
JsType
}
.stopOrientationChanged"
)]
internal
static
partial
void
StopOrientationChanged
();
}
}
}
#endif
src/Uno.UWP/Graphics/Display/DisplayInformation.wasm.cs
浏览文件 @
b7d02799
...
...
@@ -6,6 +6,10 @@ using System.Threading.Tasks;
using
Uno
;
using
Uno.Foundation
;
#if NET7_0_OR_GREATER
using
NativeMethods
=
__Windows
.
Graphics
.
Display
.
DisplayInformation
.
NativeMethods
;
#endif
namespace
Windows.Graphics.Display
{
public
sealed
partial
class
DisplayInformation
...
...
@@ -38,7 +42,7 @@ namespace Windows.Graphics.Display
{
get
{
var
jsOrientation
=
Read
JsString
(
"window.screen.orientation.type"
);
var
jsOrientation
=
Read
OrientationType
(
);
return
ParseJsOrientation
(
jsOrientation
);
}
}
...
...
@@ -52,9 +56,9 @@ namespace Windows.Graphics.Display
{
get
{
if
(
TryRead
JsInt
(
"window.screen.orientation.angle"
,
out
var
angle
))
if
(
TryRead
OrientationAngle
(
out
var
angle
))
{
var
jsOrientation
=
Read
JsString
(
"window.screen.orientation.type"
);
var
jsOrientation
=
Read
OrientationType
(
);
var
isCurrentlyPortrait
=
jsOrientation
.
StartsWith
(
"portrait"
,
StringComparison
.
Ordinal
);
var
isCurrentlyLandscape
=
jsOrientation
.
StartsWith
(
"landscape"
,
StringComparison
.
Ordinal
);
...
...
@@ -86,7 +90,7 @@ namespace Windows.Graphics.Display
{
get
{
if
(
TryRead
JsFloat
(
"window.screen.height"
,
out
var
height
))
if
(
TryRead
ScreenHeight
(
out
var
height
))
{
var
scale
=
(
double
)
LogicalDpi
/
BaseDpi
;
return
(
uint
)(
height
*
scale
);
...
...
@@ -99,7 +103,7 @@ namespace Windows.Graphics.Display
{
get
{
if
(
TryRead
JsFloat
(
"window.screen.width"
,
out
var
width
))
if
(
TryRead
ScreenWidth
(
out
var
width
))
{
var
scale
=
(
double
)
LogicalDpi
/
BaseDpi
;
return
(
uint
)(
width
*
scale
);
...
...
@@ -112,7 +116,7 @@ namespace Windows.Graphics.Display
{
get
{
if
(
TryRead
JsFloat
(
"window.devicePixelRatio"
,
out
var
devicePixelRatio
))
if
(
TryRead
DevicePixelRatio
(
out
var
devicePixelRatio
))
{
return
devicePixelRatio
*
BaseDpi
;
}
...
...
@@ -136,7 +140,7 @@ namespace Windows.Graphics.Display
{
get
{
if
(
TryRead
JsFloat
(
"window.devicePixelRatio"
,
out
var
devicePixelRatio
))
if
(
TryRead
DevicePixelRatio
(
out
var
devicePixelRatio
))
{
return
(
ResolutionScale
)(
int
)(
devicePixelRatio
*
100
);
}
...
...
@@ -150,27 +154,45 @@ namespace Windows.Graphics.Display
partial
void
StartOrientationChanged
()
{
_lastKnownOrientation
=
CurrentOrientation
;
#if NET7_0_OR_GREATER
NativeMethods
.
StartOrientationChanged
();
#else
var
command
=
$"
{
JsType
}
.startOrientationChanged()"
;
WebAssemblyRuntime
.
InvokeJS
(
command
);
#endif
}
partial
void
StopOrientationChanged
()
{
#if NET7_0_OR_GREATER
NativeMethods
.
StopOrientationChanged
();
#else
var
command
=
$"
{
JsType
}
.stopOrientationChanged()"
;
WebAssemblyRuntime
.
InvokeJS
(
command
);
#endif
}
partial
void
StartDpiChanged
()
{
_lastKnownDpi
=
LogicalDpi
;
#if NET7_0_OR_GREATER
NativeMethods
.
StartDpiChanged
();
#else
var
command
=
$"
{
JsType
}
.startDpiChanged()"
;
WebAssemblyRuntime
.
InvokeJS
(
command
);
#endif
}
partial
void
StopDpiChanged
()
{
#if NET7_0_OR_GREATER
NativeMethods
.
StopDpiChanged
();
#else
var
command
=
$"
{
JsType
}
.stopDpiChanged()"
;
WebAssemblyRuntime
.
InvokeJS
(
command
);
#endif
}
static
partial
void
SetOrientationPartial
(
DisplayOrientations
orientations
)
...
...
@@ -180,13 +202,59 @@ namespace Windows.Graphics.Display
(
ct
)
=>
SetOrientationAsync
(
orientations
,
ct
));
}
private
static
bool
TryReadJsFloat
(
string
property
,
out
float
value
)
=>
float
.
TryParse
(
WebAssemblyRuntime
.
InvokeJS
(
property
),
NumberStyles
.
Any
,
CultureInfo
.
InvariantCulture
,
out
value
);
private
static
bool
TryReadDevicePixelRatio
(
out
float
value
)
{
#if NET7_0_OR_GREATER
value
=
NativeMethods
.
GetDevicePixelRatio
();
return
true
;
#else
return
float
.
TryParse
(
WebAssemblyRuntime
.
InvokeJS
(
"window.devicePixelRatio"
),
NumberStyles
.
Any
,
CultureInfo
.
InvariantCulture
,
out
value
);
#endif
}
private
static
bool
TryReadScreenWidth
(
out
float
value
)
{
#if NET7_0_OR_GREATER
value
=
NativeMethods
.
GetScreenWidth
();
return
true
;
#else
return
float
.
TryParse
(
WebAssemblyRuntime
.
InvokeJS
(
"window.screen.width"
),
NumberStyles
.
Any
,
CultureInfo
.
InvariantCulture
,
out
value
);
#endif
}
private
static
bool
TryReadScreenHeight
(
out
float
value
)
{
#if NET7_0_OR_GREATER
value
=
NativeMethods
.
GetScreenHeight
();
return
true
;
#else
return
float
.
TryParse
(
WebAssemblyRuntime
.
InvokeJS
(
"window.screen.height"
),
NumberStyles
.
Any
,
CultureInfo
.
InvariantCulture
,
out
value
);
#endif
}
private
static
bool
TryReadOrientationAngle
(
out
int
value
)
{
#if NET7_0_OR_GREATER
var
angle
=
NativeMethods
.
GetScreenOrientationAngle
();
private
static
bool
TryReadJsInt
(
string
property
,
out
int
value
)
=>
int
.
TryParse
(
WebAssemblyRuntime
.
InvokeJS
(
property
),
NumberStyles
.
Any
,
CultureInfo
.
InvariantCulture
,
out
value
);
value
=
angle
??
default
;
private
static
string
ReadJsString
(
string
property
)
=>
WebAssemblyRuntime
.
InvokeJS
(
property
);
return
angle
.
HasValue
;
#else
return
int
.
TryParse
(
WebAssemblyRuntime
.
InvokeJS
(
"window.screen.orientation.angle"
),
NumberStyles
.
Any
,
CultureInfo
.
InvariantCulture
,
out
value
);
#endif
}
private
static
string
ReadOrientationType
()
=>
#if NET7_0_OR_GREATER
NativeMethods
.
GetScreenOrientationType
();
#else
WebAssemblyRuntime
.
InvokeJS
(
"window.screen.orientation.type"
);
#endif
private
static
DisplayOrientations
ParseJsOrientation
(
string
jsOrientation
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录