Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
3a32d9fe
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,发现更多精彩内容 >>
提交
3a32d9fe
编写于
10月 31, 2019
作者:
J
Josh
提交者:
Gary Qian
10月 31, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Force orientation change when current orientation not allowed on iOS (#13170)
上级
7fe505ca
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
219 addition
and
17 deletion
+219
-17
AUTHORS
AUTHORS
+1
-0
shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
...form/darwin/ios/framework/Source/FlutterViewController.mm
+28
-6
shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.m
...m/darwin/ios/framework/Source/FlutterViewControllerTest.m
+190
-11
未找到文件。
AUTHORS
浏览文件 @
3a32d9fe
...
...
@@ -15,3 +15,4 @@ Simon Lightfoot <simon@devangels.london>
Dwayne Slater <ds84182@gmail.com>
Tetsuhiro Ueda <najeira@gmail.com>
shoryukenn <naifu.guan@gmail.com>
SOTEC GmbH & Co. KG <sotec-contributors@sotec.eu>
\ No newline at end of file
shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
浏览文件 @
3a32d9fe
...
...
@@ -828,14 +828,36 @@ static flutter::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* touch)
if
(
update
==
nil
)
{
return
;
}
[
self
performOrientationUpdate
:
update
.
unsignedIntegerValue
];
});
}
NSUInteger
new_preferences
=
update
.
unsignedIntegerValue
;
if
(
new_preferences
!=
_orientationPreferences
)
{
_orientationPreferences
=
new_preferences
;
[
UIViewController
attemptRotationToDeviceOrientation
];
-
(
void
)
performOrientationUpdate
:(
UIInterfaceOrientationMask
)
new_preferences
{
if
(
new_preferences
!=
_orientationPreferences
)
{
_orientationPreferences
=
new_preferences
;
[
UIViewController
attemptRotationToDeviceOrientation
];
UIInterfaceOrientationMask
currentInterfaceOrientation
=
1
<<
[[
UIApplication
sharedApplication
]
statusBarOrientation
];
if
(
!
(
_orientationPreferences
&
currentInterfaceOrientation
))
{
// Force orientation switch if the current orientation is not allowed
if
(
_orientationPreferences
&
UIInterfaceOrientationMaskPortrait
)
{
// This is no official API but more like a workaround / hack (using
// key-value coding on a read-only property). This might break in
// the future, but currently it´s the only way to force an orientation change
[[
UIDevice
currentDevice
]
setValue
:
@
(
UIInterfaceOrientationPortrait
)
forKey
:
@"orientation"
];
}
else
if
(
_orientationPreferences
&
UIInterfaceOrientationMaskPortraitUpsideDown
)
{
[[
UIDevice
currentDevice
]
setValue
:
@
(
UIInterfaceOrientationPortraitUpsideDown
)
forKey:
@"orientation"
];
}
else
if
(
_orientationPreferences
&
UIInterfaceOrientationMaskLandscapeLeft
)
{
[[
UIDevice
currentDevice
]
setValue
:
@
(
UIInterfaceOrientationLandscapeLeft
)
forKey:
@"orientation"
];
}
else
if
(
_orientationPreferences
&
UIInterfaceOrientationMaskLandscapeRight
)
{
[[
UIDevice
currentDevice
]
setValue
:
@
(
UIInterfaceOrientationLandscapeRight
)
forKey:
@"orientation"
];
}
}
}
);
}
}
-
(
BOOL
)
shouldAutorotate
{
...
...
shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.m
浏览文件 @
3a32d9fe
...
...
@@ -45,6 +45,10 @@ typedef enum UIAccessibilityContrast : NSInteger {
@end
#endif
@interface
FlutterViewController
(
Tests
)
-
(
void
)
performOrientationUpdate
:(
UIInterfaceOrientationMask
)
new_preferences
;
@end
@implementation
FlutterViewControllerTest
-
(
void
)
testBinaryMessenger
{
...
...
@@ -252,6 +256,179 @@ typedef enum UIAccessibilityContrast : NSInteger {
[
mockTraitCollection
stopMocking
];
}
-
(
void
)
testPerformOrientationUpdateForcesOrientationChange
{
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskPortrait
currentOrientation:
UIInterfaceOrientationLandscapeLeft
didChangeOrientation:
YES
resultingOrientation:
UIInterfaceOrientationPortrait
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskPortrait
currentOrientation:
UIInterfaceOrientationLandscapeRight
didChangeOrientation:
YES
resultingOrientation:
UIInterfaceOrientationPortrait
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskPortrait
currentOrientation:
UIInterfaceOrientationPortraitUpsideDown
didChangeOrientation:
YES
resultingOrientation:
UIInterfaceOrientationPortrait
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskPortraitUpsideDown
currentOrientation:
UIInterfaceOrientationLandscapeLeft
didChangeOrientation:
YES
resultingOrientation:
UIInterfaceOrientationPortraitUpsideDown
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskPortraitUpsideDown
currentOrientation:
UIInterfaceOrientationLandscapeRight
didChangeOrientation:
YES
resultingOrientation:
UIInterfaceOrientationPortraitUpsideDown
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskPortraitUpsideDown
currentOrientation:
UIInterfaceOrientationPortrait
didChangeOrientation:
YES
resultingOrientation:
UIInterfaceOrientationPortraitUpsideDown
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskLandscape
currentOrientation:
UIInterfaceOrientationPortrait
didChangeOrientation:
YES
resultingOrientation:
UIInterfaceOrientationLandscapeLeft
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskLandscape
currentOrientation:
UIInterfaceOrientationPortraitUpsideDown
didChangeOrientation:
YES
resultingOrientation:
UIInterfaceOrientationLandscapeLeft
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskLandscapeLeft
currentOrientation:
UIInterfaceOrientationPortrait
didChangeOrientation:
YES
resultingOrientation:
UIInterfaceOrientationLandscapeLeft
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskLandscapeLeft
currentOrientation:
UIInterfaceOrientationLandscapeRight
didChangeOrientation:
YES
resultingOrientation:
UIInterfaceOrientationLandscapeLeft
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskLandscapeLeft
currentOrientation:
UIInterfaceOrientationPortraitUpsideDown
didChangeOrientation:
YES
resultingOrientation:
UIInterfaceOrientationLandscapeLeft
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskLandscapeRight
currentOrientation:
UIInterfaceOrientationPortrait
didChangeOrientation:
YES
resultingOrientation:
UIInterfaceOrientationLandscapeRight
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskLandscapeRight
currentOrientation:
UIInterfaceOrientationLandscapeLeft
didChangeOrientation:
YES
resultingOrientation:
UIInterfaceOrientationLandscapeRight
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskLandscapeRight
currentOrientation:
UIInterfaceOrientationPortraitUpsideDown
didChangeOrientation:
YES
resultingOrientation:
UIInterfaceOrientationLandscapeRight
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskAllButUpsideDown
currentOrientation:
UIInterfaceOrientationPortraitUpsideDown
didChangeOrientation:
YES
resultingOrientation:
UIInterfaceOrientationPortrait
];
}
-
(
void
)
testPerformOrientationUpdateDoesNotForceOrientationChange
{
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskAll
currentOrientation:
UIInterfaceOrientationPortrait
didChangeOrientation:
NO
resultingOrientation:
0
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskAll
currentOrientation:
UIInterfaceOrientationPortraitUpsideDown
didChangeOrientation:
NO
resultingOrientation:
0
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskAll
currentOrientation:
UIInterfaceOrientationLandscapeLeft
didChangeOrientation:
NO
resultingOrientation:
0
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskAll
currentOrientation:
UIInterfaceOrientationLandscapeRight
didChangeOrientation:
NO
resultingOrientation:
0
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskAllButUpsideDown
currentOrientation:
UIInterfaceOrientationPortrait
didChangeOrientation:
NO
resultingOrientation:
0
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskAllButUpsideDown
currentOrientation:
UIInterfaceOrientationLandscapeLeft
didChangeOrientation:
NO
resultingOrientation:
0
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskAllButUpsideDown
currentOrientation:
UIInterfaceOrientationLandscapeRight
didChangeOrientation:
NO
resultingOrientation:
0
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskPortrait
currentOrientation:
UIInterfaceOrientationPortrait
didChangeOrientation:
NO
resultingOrientation:
0
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskPortraitUpsideDown
currentOrientation:
UIInterfaceOrientationPortraitUpsideDown
didChangeOrientation:
NO
resultingOrientation:
0
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskLandscape
currentOrientation:
UIInterfaceOrientationLandscapeLeft
didChangeOrientation:
NO
resultingOrientation:
0
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskLandscape
currentOrientation:
UIInterfaceOrientationLandscapeRight
didChangeOrientation:
NO
resultingOrientation:
0
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskLandscapeLeft
currentOrientation:
UIInterfaceOrientationLandscapeLeft
didChangeOrientation:
NO
resultingOrientation:
0
];
[
self
orientationTestWithOrientationUpdate
:
UIInterfaceOrientationMaskLandscapeRight
currentOrientation:
UIInterfaceOrientationLandscapeRight
didChangeOrientation:
NO
resultingOrientation:
0
];
}
// Perform an orientation update test that fails when the expected outcome
// for an orientation update is not met
-
(
void
)
orientationTestWithOrientationUpdate
:(
UIInterfaceOrientationMask
)
mask
currentOrientation
:(
UIInterfaceOrientation
)
currentOrientation
didChangeOrientation
:(
BOOL
)
didChange
resultingOrientation
:(
UIInterfaceOrientation
)
resultingOrientation
{
id
engine
=
OCMClassMock
([
FlutterEngine
class
]);
id
deviceMock
=
OCMPartialMock
([
UIDevice
currentDevice
]);
if
(
!
didChange
)
{
OCMReject
([
deviceMock
setValue
:[
OCMArg
any
]
forKey
:
@"orientation"
]);
}
else
{
OCMExpect
([
deviceMock
setValue
:
@
(
resultingOrientation
)
forKey
:
@"orientation"
]);
}
FlutterViewController
*
realVC
=
[[
FlutterViewController
alloc
]
initWithEngine
:
engine
nibName:
nil
bundle:
nil
];
id
mockApplication
=
OCMClassMock
([
UIApplication
class
]);
OCMStub
([
mockApplication
sharedApplication
]).
andReturn
(
mockApplication
);
OCMStub
([
mockApplication
statusBarOrientation
]).
andReturn
(
currentOrientation
);
[
realVC
performOrientationUpdate
:
mask
];
OCMVerifyAll
(
deviceMock
);
[
engine
stopMocking
];
[
deviceMock
stopMocking
];
[
mockApplication
stopMocking
];
}
// Creates a mocked UITraitCollection with nil values for everything except accessibilityContrast,
// which is set to the given "contrast".
-
(
UITraitCollection
*
)
fakeTraitCollectionWithContrast
:(
UIAccessibilityContrast
)
contrast
{
...
...
@@ -264,17 +441,19 @@ typedef enum UIAccessibilityContrast : NSInteger {
XCTestExpectation
*
expectation
=
[[
XCTestExpectation
alloc
]
initWithDescription
:
@"notification called"
];
id
engine
=
[[
MockEngine
alloc
]
init
];
FlutterViewController
*
realVC
=
[[
FlutterViewController
alloc
]
initWithEngine
:
engine
nibName:
nil
bundle:
nil
];
id
observer
=
[[
NSNotificationCenter
defaultCenter
]
addObserverForName
:
FlutterViewControllerWillDealloc
object:
nil
queue:
[
NSOperationQueue
mainQueue
]
usingBlock:
^
(
NSNotification
*
_Nonnull
note
)
{
[
expectation
fulfill
];
}];
realVC
=
nil
;
@autoreleasepool
{
FlutterViewController
*
realVC
=
[[
FlutterViewController
alloc
]
initWithEngine
:
engine
nibName:
nil
bundle:
nil
];
id
observer
=
[[
NSNotificationCenter
defaultCenter
]
addObserverForName
:
FlutterViewControllerWillDealloc
object:
nil
queue:
[
NSOperationQueue
mainQueue
]
usingBlock:
^
(
NSNotification
*
_Nonnull
note
)
{
[
expectation
fulfill
];
}];
realVC
=
nil
;
}
[
self
waitForExpectations
:@[
expectation
]
timeout
:
1
.
0
];
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录