Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
b0b67ef9
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
b0b67ef9
编写于
4月 08, 2020
作者:
M
Mouad Debbar
提交者:
GitHub
4月 08, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[web] Fix window.defaultRouteName (#17580)
上级
3ddd1ef4
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
34 addition
and
26 deletion
+34
-26
lib/web_ui/lib/src/engine/browser_location.dart
lib/web_ui/lib/src/engine/browser_location.dart
+2
-24
lib/web_ui/lib/src/engine/test_embedding.dart
lib/web_ui/lib/src/engine/test_embedding.dart
+1
-1
lib/web_ui/lib/src/engine/window.dart
lib/web_ui/lib/src/engine/window.dart
+4
-0
lib/web_ui/test/engine/history_test.dart
lib/web_ui/test/engine/history_test.dart
+1
-1
lib/web_ui/test/window_test.dart
lib/web_ui/test/window_test.dart
+26
-0
未找到文件。
lib/web_ui/lib/src/engine/browser_location.dart
浏览文件 @
b0b67ef9
...
@@ -9,27 +9,6 @@ part of engine;
...
@@ -9,27 +9,6 @@ part of engine;
// Some parts of this file were inspired/copied from the AngularDart router.
// Some parts of this file were inspired/copied from the AngularDart router.
/// Ensures that `str` is prefixed with `leading`.
///
/// If `str` is already prefixed, it'll be returned unchanged. If it's not,
/// this function will prefix it.
///
/// The `applyWhenEmpty` flag controls whether this function should prefix `str`
/// or not when it's an empty string.
///
/// ```dart
/// ensureLeading('/path', '/'); // "/path"
/// ensureLeading('path', '/'); // "/path"
/// ensureLeading('', '/'); // "/"
/// ensureLeading('', '/', applyWhenEmpty: false); // ""
/// ```
String
ensureLeading
(
String
str
,
String
leading
,
{
bool
applyWhenEmpty
=
true
})
{
if
(
str
.
isEmpty
&&
!
applyWhenEmpty
)
{
return
str
;
}
return
str
.
startsWith
(
leading
)
?
str
:
'
$leading$str
'
;
}
/// [LocationStrategy] is responsible for representing and reading route state
/// [LocationStrategy] is responsible for representing and reading route state
/// from the browser's URL.
/// from the browser's URL.
///
///
...
@@ -93,12 +72,11 @@ class HashLocationStrategy extends LocationStrategy {
...
@@ -93,12 +72,11 @@ class HashLocationStrategy extends LocationStrategy {
// the hash value is always prefixed with a `#`
// the hash value is always prefixed with a `#`
// and if it is empty then it will stay empty
// and if it is empty then it will stay empty
String
path
=
_platformLocation
.
hash
??
''
;
String
path
=
_platformLocation
.
hash
??
''
;
assert
(
path
.
isEmpty
||
path
.
startsWith
(
'#'
));
// Dart will complain if a call to substring is
// Dart will complain if a call to substring is
// executed with a position value that exceeds the
// executed with a position value that exceeds the
// length of string.
// length of string.
path
=
path
.
isEmpty
?
path
:
path
.
substring
(
1
);
return
path
.
isEmpty
?
path
:
path
.
substring
(
1
);
// The path, by convention, should always contain a leading '/'.
return
ensureLeading
(
path
,
'/'
);
}
}
@override
@override
...
...
lib/web_ui/lib/src/engine/test_embedding.dart
浏览文件 @
b0b67ef9
...
@@ -37,7 +37,7 @@ class TestLocationStrategy extends LocationStrategy {
...
@@ -37,7 +37,7 @@ class TestLocationStrategy extends LocationStrategy {
history
=
<
TestHistoryEntry
>[
initialEntry
];
history
=
<
TestHistoryEntry
>[
initialEntry
];
@override
@override
String
get
path
=>
ensureLeading
(
currentEntry
.
url
,
'/'
)
;
String
get
path
=>
currentEntry
.
url
;
int
_currentEntryIndex
;
int
_currentEntryIndex
;
int
get
currentEntryIndex
=>
_currentEntryIndex
;
int
get
currentEntryIndex
=>
_currentEntryIndex
;
...
...
lib/web_ui/lib/src/engine/window.dart
浏览文件 @
b0b67ef9
...
@@ -441,6 +441,10 @@ class EngineWindow extends ui.Window {
...
@@ -441,6 +441,10 @@ class EngineWindow extends ui.Window {
_replyToPlatformMessage
(
callback
,
codec
.
encodeSuccessEnvelope
(
true
));
_replyToPlatformMessage
(
callback
,
codec
.
encodeSuccessEnvelope
(
true
));
break
;
break
;
}
}
// As soon as Flutter starts taking control of the app navigation, we
// should reset [_defaultRouteName] to "/" so it doesn't have any
// further effect after this point.
_defaultRouteName
=
'/'
;
return
;
return
;
}
}
...
...
lib/web_ui/test/engine/history_test.dart
浏览文件 @
b0b67ef9
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.6
// @dart = 2.6
@TestOn
(
'
vm && linux
'
)
@TestOn
(
'
!safari
'
)
// TODO(nurhan): https://github.com/flutter/flutter/issues/51169
// TODO(nurhan): https://github.com/flutter/flutter/issues/51169
import
'dart:async'
;
import
'dart:async'
;
...
...
lib/web_ui/test/window_test.dart
浏览文件 @
b0b67ef9
...
@@ -3,9 +3,15 @@
...
@@ -3,9 +3,15 @@
// found in the LICENSE file.
// found in the LICENSE file.
// @dart = 2.6
// @dart = 2.6
import
'dart:typed_data'
;
import
'package:test/test.dart'
;
import
'package:test/test.dart'
;
import
'package:ui/src/engine.dart'
;
import
'package:ui/src/engine.dart'
;
const
MethodCodec
codec
=
JSONMethodCodec
();
void
emptyCallback
(
ByteData
date
)
{}
TestLocationStrategy
_strategy
;
TestLocationStrategy
_strategy
;
TestLocationStrategy
get
strategy
=>
_strategy
;
TestLocationStrategy
get
strategy
=>
_strategy
;
set
strategy
(
TestLocationStrategy
newStrategy
)
{
set
strategy
(
TestLocationStrategy
newStrategy
)
{
...
@@ -17,7 +23,27 @@ void main() {
...
@@ -17,7 +23,27 @@ void main() {
strategy
=
TestLocationStrategy
.
fromEntry
(
TestHistoryEntry
(
'initial state'
,
null
,
'/initial'
));
strategy
=
TestLocationStrategy
.
fromEntry
(
TestHistoryEntry
(
'initial state'
,
null
,
'/initial'
));
expect
(
window
.
defaultRouteName
,
'/initial'
);
expect
(
window
.
defaultRouteName
,
'/initial'
);
// Changing the URL in the address bar later shouldn't affect [window.defaultRouteName].
strategy
.
replaceState
(
null
,
null
,
'/newpath'
);
strategy
.
replaceState
(
null
,
null
,
'/newpath'
);
expect
(
window
.
defaultRouteName
,
'/initial'
);
expect
(
window
.
defaultRouteName
,
'/initial'
);
});
});
test
(
'window.defaultRouteName should reset after navigation platform message'
,
()
{
strategy
=
TestLocationStrategy
.
fromEntry
(
TestHistoryEntry
(
'initial state'
,
null
,
'/initial'
));
// Reading it multiple times should return the same value.
expect
(
window
.
defaultRouteName
,
'/initial'
);
expect
(
window
.
defaultRouteName
,
'/initial'
);
window
.
sendPlatformMessage
(
'flutter/navigation'
,
JSONMethodCodec
().
encodeMethodCall
(
MethodCall
(
'routePushed'
,
<
String
,
dynamic
>{
'previousRouteName'
:
'/foo'
,
'routeName'
:
'/bar'
},
)),
emptyCallback
,
);
// After a navigation platform message, [window.defaultRouteName] should
// reset to "/".
expect
(
window
.
defaultRouteName
,
'/'
);
});
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录