[iOS] Fixes platform view clipped when FlutterView has non-zero offset (flutter/engine#24893)

This commit is contained in:
Wu Zhong
2021-03-24 01:01:01 +08:00
committed by GitHub
parent 708d427d93
commit 0fc1ff7bc1
8 changed files with 68 additions and 9 deletions

View File

@@ -357,13 +357,12 @@ void FlutterPlatformViewsController::ApplyMutators(const MutatorsStack& mutators
CGFloat screenScale = [UIScreen mainScreen].scale;
CATransform3D finalTransform = CATransform3DMakeScale(1 / screenScale, 1 / screenScale, 1);
// Mask view needs to be full screen because we might draw platform view pixels outside of the
// `ChildClippingView`. Since the mask view's frame will be based on the `clipView`'s coordinate
// system, we need to convert the flutter_view's frame to the clipView's coordinate system. The
// mask view is not displayed on the screen.
CGRect maskViewFrame = [flutter_view_ convertRect:flutter_view_.get().frame toView:clipView];
FlutterClippingMaskView* maskView =
[[[FlutterClippingMaskView alloc] initWithFrame:maskViewFrame] autorelease];
UIView* flutter_view = flutter_view_.get();
FlutterClippingMaskView* maskView = [[[FlutterClippingMaskView alloc]
initWithFrame:CGRectMake(-clipView.frame.origin.x, -clipView.frame.origin.y,
CGRectGetWidth(flutter_view.bounds),
CGRectGetHeight(flutter_view.bounds))] autorelease];
auto iter = mutators_stack.Begin();
while (iter != mutators_stack.End()) {
switch ((*iter)->GetType()) {
@@ -392,7 +391,7 @@ void FlutterPlatformViewsController::ApplyMutators(const MutatorsStack& mutators
// So we need to revese this translate so the platform view can layout at the correct offset.
//
// Note that we don't apply this transform matrix the clippings because clippings happen on the
// mask view, whose origin is alwasy (0,0) to the flutter_view.
// mask view, whose origin is always (0,0) to the flutter_view.
CATransform3D reverseTranslate =
CATransform3DMakeTranslation(-clipView.frame.origin.x, -clipView.frame.origin.y, 0);
embedded_view.layer.transform = CATransform3DConcat(finalTransform, reverseTranslate);

View File

@@ -25,6 +25,7 @@
0DB7820222EA493B00E9B371 /* FlutterViewControllerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DB781FC22EA2C0300E9B371 /* FlutterViewControllerTest.m */; };
0DDEBC89258830B40065D0E8 /* SpawnEngineTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DDEBC88258830B40065D0E8 /* SpawnEngineTest.m */; };
0DDEBC8B258839760065D0E8 /* golden_spawn_engine_works_iPhone 8_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 0DDEBC8A258839760065D0E8 /* golden_spawn_engine_works_iPhone 8_simulator.png */; };
0EE8986D2609D05E0061D5E5 /* golden_non_full_screen_flutter_view_platform_view_iPhone 8_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 0EE8986C2609D05E0061D5E5 /* golden_non_full_screen_flutter_view_platform_view_iPhone 8_simulator.png */; };
242F37A222E636DE001E83D4 /* Flutter.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 246B4E4522E3B61000073EBF /* Flutter.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
242F37A322E636DE001E83D4 /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 246B4E4122E3B5F700073EBF /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
244EA6D0230DBE8900B2D26E /* golden_platform_view_D21AP.png in Resources */ = {isa = PBXBuildFile; fileRef = 244EA6CF230DBE8900B2D26E /* golden_platform_view_D21AP.png */; };
@@ -129,6 +130,7 @@
0DDEBC87258830B40065D0E8 /* SpawnEngineTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SpawnEngineTest.h; sourceTree = "<group>"; };
0DDEBC88258830B40065D0E8 /* SpawnEngineTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SpawnEngineTest.m; sourceTree = "<group>"; };
0DDEBC8A258839760065D0E8 /* golden_spawn_engine_works_iPhone 8_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_spawn_engine_works_iPhone 8_simulator.png"; sourceTree = "<group>"; };
0EE8986C2609D05E0061D5E5 /* golden_non_full_screen_flutter_view_platform_view_iPhone 8_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_non_full_screen_flutter_view_platform_view_iPhone 8_simulator.png"; sourceTree = "<group>"; };
244EA6CF230DBE8900B2D26E /* golden_platform_view_D21AP.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = golden_platform_view_D21AP.png; sourceTree = "<group>"; };
246A6610252E693A00EAB0F3 /* RenderingSelectionTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RenderingSelectionTest.m; sourceTree = "<group>"; };
246B4E4122E3B5F700073EBF /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = App.framework; sourceTree = "<group>"; };
@@ -266,6 +268,7 @@
3DE09E9223C010BD006C9851 /* golden_platform_view_cliprect_iPhone 8_simulator.png */,
3DE09E8C23C010BD006C9851 /* golden_platform_view_cliprrect_iPhone 8_simulator.png */,
3DE09E9023C010BD006C9851 /* golden_platform_view_iPhone 8_simulator.png */,
0EE8986C2609D05E0061D5E5 /* golden_non_full_screen_flutter_view_platform_view_iPhone 8_simulator.png */,
3DE09E8A23C010BC006C9851 /* golden_platform_view_multiple_background_foreground_iPhone 8_simulator.png */,
3DE09E8D23C010BD006C9851 /* golden_platform_view_multiple_iPhone 8_simulator.png */,
3DE09E8F23C010BD006C9851 /* golden_platform_view_opacity_iPhone 8_simulator.png */,
@@ -434,6 +437,7 @@
3DEF491523C3BE6500184216 /* golden_platform_view_iPhone 8_simulator.png in Resources */,
0D14A3FE239743190013D873 /* golden_platform_view_rotate_iPhone SE_simulator.png in Resources */,
3DEF491823C3BE6500184216 /* golden_platform_view_opacity_iPhone 8_simulator.png in Resources */,
0EE8986D2609D05E0061D5E5 /* golden_non_full_screen_flutter_view_platform_view_iPhone 8_simulator.png in Resources */,
0AC83146256E534E00DAE6BE /* golden_bogus_font_text_iPhone 8_simulator.png in Resources */,
3DEF491723C3BE6500184216 /* golden_platform_view_multiple_iPhone 8_simulator.png in Resources */,
3DEF491223C3BE6500184216 /* golden_platform_view_clippath_iPhone 8_simulator.png in Resources */,

View File

@@ -47,6 +47,7 @@
@"--platform-view-transform" : @"platform_view_transform",
@"--platform-view-opacity" : @"platform_view_opacity",
@"--platform-view-rotate" : @"platform_view_rotate",
@"--non-full-screen-flutter-view-platform-view" : @"non_full_screen_flutter_view_platform_view",
@"--gesture-reject-after-touches-ended" : @"platform_view_gesture_reject_after_touches_ended",
@"--gesture-reject-eager" : @"platform_view_gesture_reject_eager",
@"--gesture-accept" : @"platform_view_gesture_accept",
@@ -141,7 +142,16 @@
withId:@"scenarios/textPlatformView_blockPolicyUntilTouchesEnded"
gestureRecognizersBlockingPolicy:
FlutterPlatformViewGestureRecognizersBlockingPolicyWaitUntilTouchesEnded];
self.window.rootViewController = flutterViewController;
UIViewController* rootViewController = flutterViewController;
// Make Flutter View's origin x/y not 0.
if ([scenarioIdentifier isEqualToString:@"non_full_screen_flutter_view_platform_view"]) {
rootViewController = [UIViewController new];
[rootViewController.view addSubview:flutterViewController.view];
flutterViewController.view.frame = CGRectMake(150, 150, 500, 500);
}
self.window.rootViewController = rootViewController;
if ([[[NSProcessInfo processInfo] arguments] containsObject:@"--assert-ca-layer-type"]) {
if ([[[NSProcessInfo processInfo] arguments] containsObject:@"--enable-software-rendering"]) {

View File

@@ -33,6 +33,8 @@ NSDictionary* launchArgsMap;
@"--platform-view-transform" : @"platform_view_transform",
@"--platform-view-opacity" : @"platform_view_opacity",
@"--platform-view-rotate" : @"platform_view_rotate",
@"--non-full-screen-flutter-view-platform-view" :
@"non_full_screen_flutter_view_platform_view",
@"--bogus-font-text" : @"bogus_font_text",
};
});

View File

@@ -23,6 +23,24 @@ static const NSInteger kSecondsToWaitForPlatformView = 30;
@end
@interface NonFullScreenFlutterViewPlatformViewUITests : GoldenPlatformViewTests
@end
@implementation NonFullScreenFlutterViewPlatformViewUITests
- (instancetype)initWithInvocation:(NSInvocation*)invocation {
GoldenTestManager* manager =
[[GoldenTestManager alloc] initWithLaunchArg:@"--non-full-screen-flutter-view-platform-view"];
return [super initWithManager:manager invocation:invocation];
}
- (void)testPlatformView {
[self checkPlatformViewGolden];
}
@end
@interface MultiplePlatformViewsTest : GoldenPlatformViewTests
@end

View File

@@ -50,6 +50,31 @@ class PlatformViewScenario extends Scenario with _BasePlatformViewScenarioMixin
}
}
/// A simple platform view.
class NonFullScreenFlutterViewPlatformViewScenario extends Scenario
with _BasePlatformViewScenarioMixin {
/// Creates the PlatformView scenario.
///
/// The [dispatcher] parameter must not be null.
NonFullScreenFlutterViewPlatformViewScenario(
PlatformDispatcher dispatcher, String text,
{this.id})
: assert(dispatcher != null),
super(dispatcher) {
createPlatformView(dispatcher, text, id);
}
/// The platform view identifier.
final int id;
@override
void onBeginFrame(Duration duration) {
final SceneBuilder builder = SceneBuilder();
finishBuilderByAddingPlatformViewAndPicture(builder, id);
}
}
/// A simple platform view with overlay that doesn't intersect with the platform view.
class PlatformViewNoOverlayIntersectionScenario extends Scenario with _BasePlatformViewScenarioMixin {
/// Creates the PlatformView scenario.

View File

@@ -36,6 +36,7 @@ Map<String, ScenarioFactory> _scenarios = <String, ScenarioFactory>{
'platform_view_opacity': () => PlatformViewOpacityScenario(PlatformDispatcher.instance, 'PlatformViewOpacity', id: _viewId++),
'platform_view_multiple': () => MultiPlatformViewScenario(PlatformDispatcher.instance, firstId: 6, secondId: _viewId++),
'platform_view_multiple_background_foreground': () => MultiPlatformViewBackgroundForegroundScenario(PlatformDispatcher.instance, firstId: _viewId++, secondId: _viewId++),
'non_full_screen_flutter_view_platform_view': () => NonFullScreenFlutterViewPlatformViewScenario(PlatformDispatcher.instance, 'Hello from Scenarios (Platform View)', id: _viewId++),
'poppable_screen': () => PoppableScreenScenario(PlatformDispatcher.instance),
'platform_view_rotate': () => PlatformViewScenario(PlatformDispatcher.instance, 'Rotate Platform View', id: _viewId++),
'platform_view_gesture_reject_eager': () => PlatformViewForTouchIOSScenario(PlatformDispatcher.instance, 'platform view touch', id: _viewId++, accept: false),