Skip to content

Commit 2150424

Browse files
author
Jonah Williams
authored
Reland Add platform view wide gamut test (#139101)
Reland of flutter/flutter#138837 I reverted too many config files, the app needed the pbx project file in order to find the new class I added. Instead, just put the new platform view in the app delegate so it builds.
1 parent 947488d commit 2150424

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

dev/integration_tests/wide_gamut_test/integration_test/app_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ void main() {
166166
app.run(app.Setup.drawnImage);
167167
await tester.pumpAndSettle(const Duration(seconds: 2));
168168

169+
const MethodChannel channel = MethodChannel('flutter/screenshot');
170+
final List<Object?> result =
171+
await channel.invokeMethod('test') as List<Object?>;
172+
expect(_findColor(result, <double>[0.0, 1.0, 0.0]), isTrue);
173+
});
174+
testWidgets('draw image with wide gamut works ontop of platform view with blur', (WidgetTester tester) async {
175+
app.run(app.Setup.drawnImageAndPlatformView);
176+
await tester.pumpAndSettle(const Duration(seconds: 2));
177+
169178
const MethodChannel channel = MethodChannel('flutter/screenshot');
170179
final List<Object?> result =
171180
await channel.invokeMethod('test') as List<Object?>;
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import Foundation
6+
import UIKit
7+
import Flutter
8+
9+
class FLNativeViewFactory: NSObject, FlutterPlatformViewFactory {
10+
private var messenger: FlutterBinaryMessenger
11+
12+
init(messenger: FlutterBinaryMessenger) {
13+
self.messenger = messenger
14+
super.init()
15+
}
16+
17+
func create(
18+
withFrame frame: CGRect,
19+
viewIdentifier viewId: Int64,
20+
arguments args: Any?
21+
) -> FlutterPlatformView {
22+
return FLNativeView(
23+
frame: frame,
24+
viewIdentifier: viewId,
25+
arguments: args,
26+
binaryMessenger: messenger)
27+
}
28+
29+
public func createArgsCodec() -> FlutterMessageCodec & NSObjectProtocol {
30+
return FlutterStandardMessageCodec.sharedInstance()
31+
}
32+
}
33+
34+
class SolidColorView: UIView {
35+
override init(frame: CGRect) {
36+
super.init(frame: frame)
37+
setupView()
38+
}
39+
40+
required init?(coder aDecoder: NSCoder) {
41+
super.init(coder: aDecoder)
42+
setupView()
43+
}
44+
45+
private func setupView() {
46+
backgroundColor = .blue
47+
}
48+
}
49+
50+
51+
class FLNativeView: NSObject, FlutterPlatformView {
52+
private var childView: UIView
53+
54+
init(
55+
frame: CGRect,
56+
viewIdentifier viewId: Int64,
57+
arguments args: Any?,
58+
binaryMessenger messenger: FlutterBinaryMessenger?
59+
) {
60+
childView = SolidColorView()
61+
super.init()
62+
}
63+
64+
func view() -> UIView {
65+
return childView
66+
}
67+
}
68+
69+
@UIApplicationMain
70+
@objc class AppDelegate: FlutterAppDelegate {
71+
override func application(
72+
_ application: UIApplication,
73+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
74+
) -> Bool {
75+
GeneratedPluginRegistrant.register(with: self)
76+
77+
var registrar = self.registrar(forPlugin: "plugin-name")
78+
79+
let factory = FLNativeViewFactory(messenger: registrar!.messenger())
80+
self.registrar(forPlugin: "<plugin-name>")!.register(
81+
factory,
82+
withId: "<dummy-view>")
83+
84+
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
85+
}
86+
}

dev/integration_tests/wide_gamut_test/lib/main.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ enum Setup {
145145
canvasSaveLayer,
146146
blur,
147147
drawnImage,
148+
drawnImageAndPlatformView
148149
}
149150

150151
void run(Setup setup) {
@@ -244,6 +245,19 @@ Future<ui.Image> _loadImage() async {
244245
return (await codec.getNextFrame()).image;
245246
}
246247

248+
class DummyPlatformView extends StatelessWidget {
249+
const DummyPlatformView({super.key});
250+
251+
@override
252+
Widget build(BuildContext context) {
253+
return const SizedBox(
254+
width: 400,
255+
height: 400,
256+
child: UiKitView(viewType: '<dummy-view>'),
257+
);
258+
}
259+
}
260+
247261
class MyHomePage extends StatefulWidget {
248262
const MyHomePage(this.setup, {super.key, required this.title});
249263

@@ -285,6 +299,14 @@ class _MyHomePageState extends State<MyHomePage> {
285299
imageWidget = Image.memory(base64Decode(_displayP3Logo));
286300
case Setup.drawnImage:
287301
imageWidget = CustomPaint(painter: _SaveLayerDrawer(_image));
302+
case Setup.drawnImageAndPlatformView:
303+
imageWidget = Stack(
304+
children: <Widget>[
305+
const DummyPlatformView(),
306+
Image.memory(base64Decode(_displayP3Logo)),
307+
BackdropFilter(filter: ui.ImageFilter.blur(sigmaX: 6, sigmaY: 6), child: const SizedBox(width: 400, height: 400)),
308+
],
309+
);
288310
case Setup.canvasSaveLayer:
289311
imageWidget = CustomPaint(painter: _SaveLayerDrawer(_image));
290312
case Setup.blur:

0 commit comments

Comments
 (0)