Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lindexi_gd
Uno
提交
4ba972b6
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,发现更多精彩内容 >>
提交
4ba972b6
编写于
8月 03, 2023
作者:
Y
Youssef Victor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: Align Duration behavior with WinUI
上级
4064dd3b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
164 addition
and
30 deletion
+164
-30
src/Uno.UI.Tests/Animations/Given_Duration.cs
src/Uno.UI.Tests/Animations/Given_Duration.cs
+73
-0
src/Uno.UI/UI/Xaml/Duration.cs
src/Uno.UI/UI/Xaml/Duration.cs
+91
-30
未找到文件。
src/Uno.UI.Tests/Animations/Given_Duration.cs
浏览文件 @
4ba972b6
...
@@ -84,5 +84,78 @@ namespace Uno.UI.Tests.Animations
...
@@ -84,5 +84,78 @@ namespace Uno.UI.Tests.Animations
Assert
.
AreEqual
(
new
Duration
(
TimeSpan
.
FromSeconds
(
48
)),
duration
.
Add
(
new
Duration
(
TimeSpan
.
FromSeconds
(
24
))));
Assert
.
AreEqual
(
new
Duration
(
TimeSpan
.
FromSeconds
(
48
)),
duration
.
Add
(
new
Duration
(
TimeSpan
.
FromSeconds
(
24
))));
Assert
.
AreEqual
(
new
Duration
(
TimeSpan
.
FromSeconds
(
1
)),
duration
.
Subtract
(
new
Duration
(
TimeSpan
.
FromSeconds
(
23
))));
Assert
.
AreEqual
(
new
Duration
(
TimeSpan
.
FromSeconds
(
1
)),
duration
.
Subtract
(
new
Duration
(
TimeSpan
.
FromSeconds
(
23
))));
}
}
[
TestMethod
]
[
DataRow
(
"00:00:05"
,
"00:00:03"
,
"00:00:08"
)]
[
DataRow
(
"00:00:05"
,
"Automatic"
,
"Automatic"
)]
[
DataRow
(
"00:00:05"
,
"Forever"
,
"Forever"
)]
[
DataRow
(
"Automatic"
,
"00:00:03"
,
"Automatic"
)]
[
DataRow
(
"Automatic"
,
"Automatic"
,
"Automatic"
)]
[
DataRow
(
"Automatic"
,
"Forever"
,
"Automatic"
)]
[
DataRow
(
"Forever"
,
"00:00:03"
,
"Forever"
)]
[
DataRow
(
"Forever"
,
"Automatic"
,
"Automatic"
)]
[
DataRow
(
"Forever"
,
"Forever"
,
"Forever"
)]
public
void
When_Adding_Durations
(
string
d1
,
string
d2
,
string
expected
)
{
var
duration1
=
StringToDuration
(
d1
);
var
duration2
=
StringToDuration
(
d2
);
var
expectedDuration
=
StringToDuration
(
expected
);
Assert
.
AreEqual
(
expectedDuration
,
duration1
+
duration2
);
Assert
.
AreEqual
(
expectedDuration
,
duration1
.
Add
(
duration2
));
Assert
.
AreEqual
(
expectedDuration
,
duration2
.
Add
(
duration1
));
}
[
TestMethod
]
[
DataRow
(
"00:00:05"
,
"00:00:03"
,
"00:00:02"
)]
[
DataRow
(
"00:00:05"
,
"Automatic"
,
"Automatic"
)]
[
DataRow
(
"00:00:05"
,
"Forever"
,
"Automatic"
)]
[
DataRow
(
"Automatic"
,
"00:00:03"
,
"Automatic"
)]
[
DataRow
(
"Automatic"
,
"Automatic"
,
"Automatic"
)]
[
DataRow
(
"Automatic"
,
"Forever"
,
"Automatic"
)]
[
DataRow
(
"Forever"
,
"00:00:03"
,
"Forever"
)]
[
DataRow
(
"Forever"
,
"Automatic"
,
"Automatic"
)]
[
DataRow
(
"Forever"
,
"Forever"
,
"Automatic"
)]
public
void
When_Subtracting_Durations
(
string
d1
,
string
d2
,
string
expected
)
{
var
duration1
=
StringToDuration
(
d1
);
var
duration2
=
StringToDuration
(
d2
);
var
expectedDuration
=
StringToDuration
(
expected
);
Assert
.
AreEqual
(
expectedDuration
,
duration1
-
duration2
);
Assert
.
AreEqual
(
expectedDuration
,
duration1
.
Subtract
(
duration2
));
}
[
TestMethod
]
[
DataRow
(
"00:00:05"
,
"00:00:03"
,
1
,
true
,
true
,
false
,
false
)]
[
DataRow
(
"00:00:03"
,
"00:00:05"
,
-
1
,
false
,
false
,
true
,
true
)]
[
DataRow
(
"00:00:03"
,
"00:00:03"
,
0
,
false
,
true
,
false
,
true
)]
[
DataRow
(
"00:00:05"
,
"Automatic"
,
1
,
false
,
false
,
false
,
false
)]
[
DataRow
(
"00:00:05"
,
"Forever"
,
-
1
,
false
,
false
,
true
,
true
)]
[
DataRow
(
"Automatic"
,
"00:00:03"
,
-
1
,
false
,
false
,
false
,
false
)]
[
DataRow
(
"Automatic"
,
"Automatic"
,
0
,
false
,
true
,
false
,
true
)]
[
DataRow
(
"Automatic"
,
"Forever"
,
-
1
,
false
,
false
,
false
,
false
)]
[
DataRow
(
"Forever"
,
"00:00:03"
,
1
,
true
,
true
,
false
,
false
)]
[
DataRow
(
"Forever"
,
"Automatic"
,
1
,
false
,
false
,
false
,
false
)]
[
DataRow
(
"Forever"
,
"Forever"
,
0
,
false
,
true
,
false
,
true
)]
public
void
When_Comparing_Durations
(
string
d1
,
string
d2
,
int
expectedCompare
,
bool
isGreaterThan
,
bool
isGreaterThanOrEquals
,
bool
isLessThan
,
bool
isLessThanOrEquals
)
{
var
duration1
=
StringToDuration
(
d1
);
var
duration2
=
StringToDuration
(
d2
);
Assert
.
AreEqual
(
expectedCompare
,
duration1
.
CompareTo
(
duration2
));
Assert
.
AreEqual
(
expectedCompare
,
Duration
.
Compare
(
duration1
,
duration2
));
Assert
.
AreEqual
(
isGreaterThan
,
duration1
>
duration2
);
Assert
.
AreEqual
(
isGreaterThanOrEquals
,
duration1
>=
duration2
);
Assert
.
AreEqual
(
isLessThan
,
duration1
<
duration2
);
Assert
.
AreEqual
(
isLessThanOrEquals
,
duration1
<=
duration2
);
}
private
Duration
StringToDuration
(
string
s
)
{
return
s
switch
{
"Automatic"
=>
Duration
.
Automatic
,
"Forever"
=>
Duration
.
Forever
,
_
=>
new
Duration
(
TimeSpan
.
Parse
(
s
)),
};
}
}
}
}
}
src/Uno.UI/UI/Xaml/Duration.cs
浏览文件 @
4ba972b6
using
Uno.UI.Extensions
;
using
Uno.UI.Extensions
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Globalization
;
using
System.Globalization
;
using
System.Text
;
namespace
Windows.UI.Xaml
namespace
Windows.UI.Xaml
{
{
...
@@ -11,7 +9,6 @@ namespace Windows.UI.Xaml
...
@@ -11,7 +9,6 @@ namespace Windows.UI.Xaml
private
static
readonly
string
__automatic
=
"Automatic"
;
private
static
readonly
string
__automatic
=
"Automatic"
;
private
static
readonly
string
__forever
=
"Forever"
;
private
static
readonly
string
__forever
=
"Forever"
;
public
Duration
(
TimeSpan
timeSpan
)
public
Duration
(
TimeSpan
timeSpan
)
{
{
Type
=
DurationType
.
TimeSpan
;
Type
=
DurationType
.
TimeSpan
;
...
@@ -24,48 +21,67 @@ namespace Windows.UI.Xaml
...
@@ -24,48 +21,67 @@ namespace Windows.UI.Xaml
public
static
implicit
operator
Duration
(
string
timeSpan
)
public
static
implicit
operator
Duration
(
string
timeSpan
)
=>
timeSpan
!=
null
?
new
Duration
(
TimeSpan
.
Parse
(
timeSpan
,
CultureInfo
.
InvariantCulture
))
:
new
Duration
(
TimeSpan
.
Zero
);
=>
timeSpan
!=
null
?
new
Duration
(
TimeSpan
.
Parse
(
timeSpan
,
CultureInfo
.
InvariantCulture
))
:
new
Duration
(
TimeSpan
.
Zero
);
public
bool
HasTimeSpan
public
bool
HasTimeSpan
=>
Type
==
DurationType
.
TimeSpan
;
{
get
{
return
this
.
Type
==
DurationType
.
TimeSpan
;
}
}
public
static
Duration
Forever
public
static
Duration
Forever
=>
new
Duration
()
{
Type
=
DurationType
.
Forever
};
{
get
{
return
new
Duration
()
{
Type
=
DurationType
.
Forever
};
}
}
public
static
Duration
Automatic
public
static
Duration
Automatic
=>
new
Duration
()
{
Type
=
DurationType
.
Automatic
};
{
get
{
return
new
Duration
()
{
Type
=
DurationType
.
Automatic
};
}
}
public
Duration
Add
(
Duration
duration
)
public
Duration
Add
(
Duration
duration
)
{
{
// We have 9 cases:
// (1) TimeSpan + TimeSpan
// (2) TimeSpan + Automatic
// (3) TimeSpan + Forever
// (4) Automatic + TimeSpan
// (5) Automatic + Automatic
// (6) Automatic + Forever
// (7) Forever + TimeSpan
// (8) Forever + Automatic
// (9) Forever + Forever
// Case (1)
if
(
this
.
Type
==
DurationType
.
TimeSpan
&&
duration
.
Type
==
DurationType
.
TimeSpan
)
if
(
this
.
Type
==
DurationType
.
TimeSpan
&&
duration
.
Type
==
DurationType
.
TimeSpan
)
{
{
return
new
Duration
(
this
.
TimeSpan
.
Add
(
duration
.
TimeSpan
));
return
new
Duration
(
this
.
TimeSpan
.
Add
(
duration
.
TimeSpan
));
}
}
return
this
;
// Case (2), (4), (5), (6), (8)
if
(
this
.
Type
==
DurationType
.
Automatic
||
duration
.
Type
==
DurationType
.
Automatic
)
{
return
Automatic
;
}
// Case (3), (7), (9)
return
Forever
;
}
}
public
Duration
Subtract
(
Duration
duration
)
public
Duration
Subtract
(
Duration
duration
)
{
{
// We have 9 cases:
// (1) TimeSpan - TimeSpan ===> Subtract spans
// (2) TimeSpan - Automatic ===> Automatic
// (3) TimeSpan - Forever ===> Automatic
// (4) Automatic - TimeSpan ===> Automatic
// (5) Automatic - Automatic ===> Automatic
// (6) Automatic - Forever ===> Automatic
// (7) Forever - TimeSpan ===> Forever
// (8) Forever - Automatic ===> Automatic
// (9) Forever - Forever ===> Automatic
// Case (1)
if
(
this
.
Type
==
DurationType
.
TimeSpan
&&
duration
.
Type
==
DurationType
.
TimeSpan
)
if
(
this
.
Type
==
DurationType
.
TimeSpan
&&
duration
.
Type
==
DurationType
.
TimeSpan
)
{
{
return
new
Duration
(
this
.
TimeSpan
.
Subtract
(
duration
.
TimeSpan
));
return
new
Duration
(
this
.
TimeSpan
.
Subtract
(
duration
.
TimeSpan
));
}
}
return
this
;
// Case (7)
if
(
this
.
Type
==
DurationType
.
Forever
&&
duration
.
Type
==
DurationType
.
TimeSpan
)
{
return
Forever
;
}
return
Automatic
;
}
}
#
region
Operator
overrides
#
region
Operator
overrides
...
@@ -82,22 +98,67 @@ namespace Windows.UI.Xaml
...
@@ -82,22 +98,67 @@ namespace Windows.UI.Xaml
public
static
bool
operator
>(
Duration
t1
,
Duration
t2
)
public
static
bool
operator
>(
Duration
t1
,
Duration
t2
)
{
{
return
Compare
(
t1
,
t2
)
>
0
;
if
(
t1
.
HasTimeSpan
&&
t2
.
HasTimeSpan
)
{
return
t1
.
TimeSpan
>
t2
.
TimeSpan
;
}
if
(
t1
.
HasTimeSpan
&&
t2
.
Type
==
DurationType
.
Forever
)
{
return
false
;
}
if
(
t1
.
Type
==
DurationType
.
Forever
&&
t2
.
HasTimeSpan
)
{
return
true
;
}
return
false
;
}
}
public
static
bool
operator
>=(
Duration
t1
,
Duration
t2
)
public
static
bool
operator
>=(
Duration
t1
,
Duration
t2
)
{
{
return
Compare
(
t1
,
t2
)
>=
0
;
if
(
t1
.
Type
==
DurationType
.
Automatic
&&
t2
.
Type
==
DurationType
.
Automatic
)
{
return
true
;
}
if
(
t1
.
Type
==
DurationType
.
Automatic
||
t2
.
Type
==
DurationType
.
Automatic
)
{
return
false
;
}
return
!(
t1
<
t2
);
}
}
public
static
bool
operator
<(
Duration
t1
,
Duration
t2
)
public
static
bool
operator
<(
Duration
t1
,
Duration
t2
)
{
{
return
Compare
(
t1
,
t2
)
<
0
;
if
(
t1
.
HasTimeSpan
&&
t2
.
HasTimeSpan
)
{
return
t1
.
TimeSpan
<
t2
.
TimeSpan
;
}
if
(
t1
.
HasTimeSpan
&&
t2
.
Type
==
DurationType
.
Forever
)
{
return
true
;
}
return
false
;
}
}
public
static
bool
operator
<=(
Duration
t1
,
Duration
t2
)
public
static
bool
operator
<=(
Duration
t1
,
Duration
t2
)
{
{
return
Compare
(
t1
,
t2
)
<=
0
;
if
(
t1
.
Type
==
DurationType
.
Automatic
&&
t2
.
Type
==
DurationType
.
Automatic
)
{
return
true
;
}
if
(
t1
.
Type
==
DurationType
.
Automatic
||
t2
.
Type
==
DurationType
.
Automatic
)
{
return
false
;
}
return
!(
t1
>
t2
);
}
}
public
static
Duration
operator
+(
Duration
t1
,
Duration
t2
)
public
static
Duration
operator
+(
Duration
t1
,
Duration
t2
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录