Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
1475c2fc
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,发现更多精彩内容 >>
未验证
提交
1475c2fc
编写于
5月 20, 2020
作者:
G
Gary Qian
提交者:
GitHub
5月 20, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Send platformResolvedLocale from iOS embedder (#18519)
上级
69d0a8e7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
85 addition
and
15 deletion
+85
-15
shell/platform/darwin/ios/framework/Source/FlutterEngine.mm
shell/platform/darwin/ios/framework/Source/FlutterEngine.mm
+32
-13
testing/scenario_app/ios/Scenarios/ScenariosUITests/LocalizationInitializationTest.m
...enarios/ScenariosUITests/LocalizationInitializationTest.m
+8
-2
testing/scenario_app/lib/src/locale_initialization.dart
testing/scenario_app/lib/src/locale_initialization.dart
+45
-0
未找到文件。
shell/platform/darwin/ios/framework/Source/FlutterEngine.mm
浏览文件 @
1475c2fc
...
...
@@ -759,27 +759,46 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
#pragma mark - Locale updates
-
(
void
)
onLocaleUpdated
:(
NSNotification
*
)
notification
{
NSArray
<
NSString
*>*
preferredLocales
=
[
NSLocale
preferredLanguages
];
NSMutableArray
<
NSString
*>*
data
=
[[
NSMutableArray
new
]
autorelease
];
// [NSLocale currentLocale] provides an iOS resolved locale if the
// supported locales are exposed to the iOS embedder. Here, we get
// currentLocale and pass it to dart:ui
NSMutableArray
<
NSString
*>*
localeData
=
[[
NSMutableArray
new
]
autorelease
];
NSLocale
*
platformResolvedLocale
=
[
NSLocale
currentLocale
];
NSString
*
languageCode
=
[
platformResolvedLocale
objectForKey
:
NSLocaleLanguageCode
];
NSString
*
countryCode
=
[
platformResolvedLocale
objectForKey
:
NSLocaleCountryCode
];
NSString
*
scriptCode
=
[
platformResolvedLocale
objectForKey
:
NSLocaleScriptCode
];
NSString
*
variantCode
=
[
platformResolvedLocale
objectForKey
:
NSLocaleVariantCode
];
if
(
languageCode
)
{
[
localeData
addObject
:
languageCode
];
[
localeData
addObject
:(
countryCode
?
countryCode
:
@""
)];
[
localeData
addObject
:(
scriptCode
?
scriptCode
:
@""
)];
[
localeData
addObject
:(
variantCode
?
variantCode
:
@""
)];
}
if
(
localeData
.
count
!=
0
)
{
[
self
.
localizationChannel
invokeMethod
:
@"setPlatformResolvedLocale"
arguments
:
localeData
];
}
// Get and pass the user's preferred locale list to dart:ui
localeData
=
[[
NSMutableArray
new
]
autorelease
];
NSArray
<
NSString
*>*
preferredLocales
=
[
NSLocale
preferredLanguages
];
for
(
NSString
*
localeID
in
preferredLocales
)
{
NSLocale
*
currentL
ocale
=
[[[
NSLocale
alloc
]
initWithLocaleIdentifier
:
localeID
]
autorelease
];
NSString
*
languageCode
=
[
currentL
ocale
objectForKey
:
NSLocaleLanguageCode
];
NSString
*
countryCode
=
[
currentL
ocale
objectForKey
:
NSLocaleCountryCode
];
NSString
*
scriptCode
=
[
currentL
ocale
objectForKey
:
NSLocaleScriptCode
];
NSString
*
variantCode
=
[
currentL
ocale
objectForKey
:
NSLocaleVariantCode
];
NSLocale
*
l
ocale
=
[[[
NSLocale
alloc
]
initWithLocaleIdentifier
:
localeID
]
autorelease
];
NSString
*
languageCode
=
[
l
ocale
objectForKey
:
NSLocaleLanguageCode
];
NSString
*
countryCode
=
[
l
ocale
objectForKey
:
NSLocaleCountryCode
];
NSString
*
scriptCode
=
[
l
ocale
objectForKey
:
NSLocaleScriptCode
];
NSString
*
variantCode
=
[
l
ocale
objectForKey
:
NSLocaleVariantCode
];
if
(
!
languageCode
)
{
continue
;
}
[
d
ata
addObject
:
languageCode
];
[
d
ata
addObject
:(
countryCode
?
countryCode
:
@""
)];
[
d
ata
addObject
:(
scriptCode
?
scriptCode
:
@""
)];
[
d
ata
addObject
:(
variantCode
?
variantCode
:
@""
)];
[
localeD
ata
addObject
:
languageCode
];
[
localeD
ata
addObject
:(
countryCode
?
countryCode
:
@""
)];
[
localeD
ata
addObject
:(
scriptCode
?
scriptCode
:
@""
)];
[
localeD
ata
addObject
:(
variantCode
?
variantCode
:
@""
)];
}
if
(
d
ata
.
count
==
0
)
{
if
(
localeD
ata
.
count
==
0
)
{
return
;
}
[
self
.
localizationChannel
invokeMethod
:
@"setLocale"
arguments
:
d
ata
];
[
self
.
localizationChannel
invokeMethod
:
@"setLocale"
arguments
:
localeD
ata
];
}
@end
...
...
testing/scenario_app/ios/Scenarios/ScenariosUITests/LocalizationInitializationTest.m
浏览文件 @
1475c2fc
...
...
@@ -25,11 +25,17 @@ FLUTTER_ASSERT_ARC
-
(
void
)
testNoLocalePrepend
{
NSTimeInterval
timeout
=
10
.
0
;
// The locales received by dart:ui are exposed onBeginFrame via semantics label.
// There should only be one locale, since the default iOS app only has en_US as
// the locale. The list should consist of just the en locale.
XCUIElement
*
textInputSemanticsObject
=
[
self
.
application
.
textFields
matchingIdentifier
:
@"[en]"
].
element
;
XCTAssertTrue
([
textInputSemanticsObject
waitForExistenceWithTimeout
:
timeout
]);
[
textInputSemanticsObject
tap
];
//
The locales recieved by dart:ui are exposed onBeginFrame via semantics label
.
// There should only be one locale, as we have removed the locale prepend on iOS.
//
[NSLocale currentLocale] always includes a country code
.
textInputSemanticsObject
=
[
self
.
application
.
textFields
matchingIdentifier
:
@"en_US"
].
element
;
XCTAssertTrue
([
textInputSemanticsObject
waitForExistenceWithTimeout
:
timeout
]);
}
...
...
testing/scenario_app/lib/src/locale_initialization.dart
浏览文件 @
1475c2fc
...
...
@@ -16,6 +16,9 @@ class LocaleInitialization extends Scenario {
:
assert
(
window
!=
null
),
super
(
window
);
int
_tapCount
=
0
;
/// Start off by sending the supported locales list via semantics.
@override
void
onBeginFrame
(
Duration
duration
)
{
// Doesn't matter what we draw. Just paint white.
...
...
@@ -66,4 +69,46 @@ class LocaleInitialization extends Scenario {
)).
build
()
);
}
/// Handle taps.
///
/// Send changing information via semantics on each successive tap.
@override
void
onPointerDataPacket
(
PointerDataPacket
packet
)
{
String
label
;
switch
(
_tapCount
)
{
case
1
:
{
label
=
window
.
platformResolvedLocale
.
toString
();
break
;
}
// Expand for other test cases.
}
window
.
updateSemantics
((
SemanticsUpdateBuilder
()
..
updateNode
(
id:
0
,
// SemanticsFlag.isTextField.
flags:
16
,
// SemanticsAction.tap.
actions:
1
,
rect:
const
Rect
.
fromLTRB
(
0.0
,
0.0
,
414.0
,
48.0
),
label:
label
,
textDirection:
TextDirection
.
ltr
,
textSelectionBase:
0
,
textSelectionExtent:
0
,
platformViewId:
-
1
,
maxValueLength:
-
1
,
currentValueLength:
0
,
scrollChildren:
0
,
scrollIndex:
0
,
transform:
Matrix4
.
identity
().
storage
,
elevation:
0.0
,
thickness:
0.0
,
childrenInTraversalOrder:
Int32List
(
0
),
childrenInHitTestOrder:
Int32List
(
0
),
additionalActions:
Int32List
(
0
),
)).
build
()
);
_tapCount
++;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录