Flutter Engine
 
Loading...
Searching...
No Matches
AppDelegate.m
Go to the documentation of this file.
1// Copyright 2013 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 "AppDelegate.h"
6
10#import "TextPlatformView.h"
11
12// A UIViewController that sets YES for its preferedStatusBarHidden property.
13// StatusBar includes current time, which is non-deterministic. This ViewController
14// removes the StatusBar to make the screenshot deterministic.
15@interface NoStatusBarViewController : UIViewController
16
17@end
18
19@implementation NoStatusBarViewController
20- (BOOL)prefersStatusBarHidden {
21 return YES;
22}
23@end
24
25// The FlutterViewController version of NoStatusBarViewController
27
28@end
29
31- (BOOL)prefersStatusBarHidden {
32 return YES;
33}
34@end
35
36@implementation AppDelegate
37
38- (BOOL)application:(UIApplication*)application
39 didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
40 NSArray<NSString*>* processArguments = NSProcessInfo.processInfo.arguments;
41 if ([processArguments containsObject:@"--enable-software-rendering"]) {
42 @throw @"--enable-software-rendering is unsupported in iOS scenario tests";
43 }
44
45 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
46 if ([processArguments containsObject:@"--maskview-blocking"]) {
47 self.window.tintColor = UIColor.systemPinkColor;
48 }
49 NSDictionary<NSString*, NSString*>* launchArgsMap = @{
50 // The golden test args should match `GoldenTestManager`.
51 @"--locale-initialization" : @"locale_initialization",
52 @"--platform-view" : @"platform_view",
53 @"--platform-view-no-overlay-intersection" : @"platform_view_no_overlay_intersection",
54 @"--platform-view-two-intersecting-overlays" : @"platform_view_two_intersecting_overlays",
55 @"--platform-view-partial-intersection" : @"platform_view_partial_intersection",
56 @"--platform-view-one-overlay-two-intersecting-overlays" :
57 @"platform_view_one_overlay_two_intersecting_overlays",
58 @"--platform-view-multiple-without-overlays" : @"platform_view_multiple_without_overlays",
59 @"--platform-view-max-overlays" : @"platform_view_max_overlays",
60 @"--platform-view-surrounding-layers-fractional-coordinate" :
61 @"platform_view_surrounding_layers_fractional_coordinate",
62 @"--platform-view-partial-intersection-fractional-coordinate" :
63 @"platform_view_partial_intersection_fractional_coordinate",
64 @"--platform-view-multiple" : @"platform_view_multiple",
65 @"--platform-view-multiple-background-foreground" :
66 @"platform_view_multiple_background_foreground",
67 @"--platform-view-cliprect" : @"platform_view_cliprect",
68 @"--platform-view-cliprect-multiple-clips" : @"platform_view_cliprect_multiple_clips",
69 @"--platform-view-cliprrect" : @"platform_view_cliprrect",
70 @"--platform-view-cliprrect-multiple-clips" : @"platform_view_cliprrect_multiple_clips",
71 @"--platform-view-large-cliprrect" : @"platform_view_large_cliprrect",
72 @"--platform-view-large-cliprrect-multiple-clips" :
73 @"platform_view_large_cliprrect_multiple_clips",
74 @"--platform-view-clippath" : @"platform_view_clippath",
75 @"--platform-view-clippath-multiple-clips" : @"platform_view_clippath_multiple_clips",
76 @"--platform-view-cliprrect-with-transform" : @"platform_view_cliprrect_with_transform",
77 @"--platform-view-cliprrect-with-transform-multiple-clips" :
78 @"platform_view_cliprrect_with_transform_multiple_clips",
79 @"--platform-view-large-cliprrect-with-transform" :
80 @"platform_view_large_cliprrect_with_transform",
81 @"--platform-view-large-cliprrect-with-transform-multiple-clips" :
82 @"platform_view_large_cliprrect_with_transform_multiple_clips",
83 @"--platform-view-cliprect-with-transform" : @"platform_view_cliprect_with_transform",
84 @"--platform-view-cliprect-with-transform-multiple-clips" :
85 @"platform_view_cliprect_with_transform_multiple_clips",
86 @"--platform-view-clippath-with-transform" : @"platform_view_clippath_with_transform",
87 @"--platform-view-clippath-with-transform-multiple-clips" :
88 @"platform_view_clippath_with_transform_multiple_clips",
89 @"--platform-view-transform" : @"platform_view_transform",
90 @"--platform-view-opacity" : @"platform_view_opacity",
91 @"--platform-view-with-other-backdrop-filter" : @"platform_view_with_other_backdrop_filter",
92 @"--two-platform-views-with-other-backdrop-filter" :
93 @"two_platform_views_with_other_backdrop_filter",
94 @"--platform-view-with-negative-backdrop-filter" :
95 @"platform_view_with_negative_backdrop_filter",
96 @"--platform-view-rotate" : @"platform_view_rotate",
97 @"--non-full-screen-flutter-view-platform-view" : @"non_full_screen_flutter_view_platform_view",
98 @"--gesture-reject-after-touches-ended" : @"platform_view_gesture_reject_after_touches_ended",
99 @"--gesture-reject-eager" : @"platform_view_gesture_reject_eager",
100 @"--gesture-accept" : @"platform_view_gesture_accept",
101 @"--gesture-accept-with-overlapping-platform-views" :
102 @"platform_view_gesture_accept_with_overlapping_platform_views",
103 @"--tap-status-bar" : @"tap_status_bar",
104 @"--animated-color-square" : @"animated_color_square",
105 @"--solid-blue" : @"solid_blue",
106 @"--platform-view-with-continuous-texture" : @"platform_view_with_continuous_texture",
107 @"--bogus-font-text" : @"bogus_font_text",
108 @"--spawn-engine-works" : @"spawn_engine_works",
109 @"--pointer-events" : @"pointer_events",
110 @"--platform-view-scrolling-under-widget" : @"platform_view_scrolling_under_widget",
111 @"--platform-views-with-clips-scrolling" : @"platform_views_with_clips_scrolling",
112 @"--platform-views-with-clips-scrolling-multiple-clips" :
113 @"platform_views_with_clips_scrolling_multiple_clips",
114 @"--platform-view-cliprect-after-moved" : @"platform_view_cliprect_after_moved",
115 @"--platform-view-cliprect-after-moved-multiple-clips" :
116 @"platform_view_cliprect_after_moved_multiple_clips",
117 @"--two-platform-view-clip-rect" : @"two_platform_view_clip_rect",
118 @"--two-platform-view-clip-rect-multiple-clips" : @"two_platform_view_clip_rect_multiple_clips",
119 @"--two-platform-view-clip-rrect" : @"two_platform_view_clip_rrect",
120 @"--two-platform-view-clip-rrect-multiple-clips" :
121 @"two_platform_view_clip_rrect_multiple_clips",
122 @"--two-platform-view-clip-path" : @"two_platform_view_clip_path",
123 @"--two-platform-view-clip-path-multiple-clips" : @"two_platform_view_clip_path_multiple_clips",
124 @"--darwin-system-font" : @"darwin_system_font",
125 };
126 __block NSString* flutterViewControllerTestName = nil;
127 [launchArgsMap
128 enumerateKeysAndObjectsUsingBlock:^(NSString* argument, NSString* testName, BOOL* stop) {
129 if ([processArguments containsObject:argument]) {
130 flutterViewControllerTestName = testName;
131 *stop = YES;
132 }
133 }];
134 if (flutterViewControllerTestName) {
135 [self setupFlutterViewControllerTest:flutterViewControllerTestName];
136 } else if ([processArguments containsObject:@"--screen-before-flutter"]) {
137 self.window.rootViewController = [[ScreenBeforeFlutter alloc] initWithEngineRunCompletion:nil];
138 } else {
139 self.window.rootViewController = [[UIViewController alloc] init];
140 }
141
142 [self.window makeKeyAndVisible];
143 if ([processArguments containsObject:@"--with-continuous-texture"]) {
145 registerWithRegistrar:[self registrarForPlugin:@"com.constant.firing.texture"]];
146 }
147 return [super application:application didFinishLaunchingWithOptions:launchOptions];
148}
149
150- (FlutterEngine*)engineForTest:(NSString*)scenarioIdentifier {
151 if ([scenarioIdentifier isEqualToString:@"spawn_engine_works"]) {
152 FlutterEngine* spawner = [[FlutterEngine alloc] initWithName:@"FlutterControllerTest"
153 project:nil];
154 [spawner run];
155 return [spawner spawnWithEntrypoint:nil libraryURI:nil initialRoute:nil entrypointArgs:nil];
156 } else {
157 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"FlutterControllerTest"
158 project:nil];
159 [engine run];
160 return engine;
161 }
162}
163
164- (FlutterViewController*)flutterViewControllerForTest:(NSString*)scenarioIdentifier
165 withEngine:(FlutterEngine*)engine {
166 if ([scenarioIdentifier isEqualToString:@"tap_status_bar"]) {
167 return [[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil];
168 } else {
169 return [[NoStatusBarFlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil];
170 }
171}
172
173- (void)setupFlutterViewControllerTest:(NSString*)scenarioIdentifier {
174 FlutterEngine* engine = [self engineForTest:scenarioIdentifier];
175 FlutterViewController* flutterViewController =
176 [self flutterViewControllerForTest:scenarioIdentifier withEngine:engine];
177 flutterViewController.view.accessibilityIdentifier = @"flutter_view";
178
179 [engine.binaryMessenger
180 setMessageHandlerOnChannel:@"waiting_for_status"
181 binaryMessageHandler:^(NSData* _Nullable message, FlutterBinaryReply _Nonnull reply) {
183 methodChannelWithName:@"driver"
184 binaryMessenger:engine.binaryMessenger
185 codec:[FlutterJSONMethodCodec sharedInstance]];
186 [channel invokeMethod:@"set_scenario" arguments:@{@"name" : scenarioIdentifier}];
187 }];
188 // Can be used to synchronize timing in the test for a signal from Dart.
189 [engine.binaryMessenger
190 setMessageHandlerOnChannel:@"display_data"
191 binaryMessageHandler:^(NSData* _Nullable message, FlutterBinaryReply _Nonnull reply) {
192 NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:message
193 options:0
194 error:nil];
195 UITextField* text = [[UITextField alloc] initWithFrame:CGRectMake(0, 400, 300, 100)];
196 text.text = dict[@"data"];
197 [flutterViewController.view addSubview:text];
198 }];
199
200 TextPlatformViewFactory* textPlatformViewFactory =
201 [[TextPlatformViewFactory alloc] initWithMessenger:engine.binaryMessenger];
202 NSObject<FlutterPluginRegistrar>* registrar =
203 [engine registrarForPlugin:@"scenarios/TextPlatformViewPlugin"];
204 [registrar registerViewFactory:textPlatformViewFactory
205 withId:@"scenarios/textPlatformView"
206 gestureRecognizersBlockingPolicy:FlutterPlatformViewGestureRecognizersBlockingPolicyEager];
207 [registrar registerViewFactory:textPlatformViewFactory
208 withId:@"scenarios/textPlatformView_blockPolicyUntilTouchesEnded"
209 gestureRecognizersBlockingPolicy:
210 FlutterPlatformViewGestureRecognizersBlockingPolicyWaitUntilTouchesEnded];
211
212 UIViewController* rootViewController = flutterViewController;
213 // Make Flutter View's origin x/y not 0.
214 if ([scenarioIdentifier isEqualToString:@"non_full_screen_flutter_view_platform_view"]) {
215 rootViewController = [[NoStatusBarViewController alloc] init];
216 [rootViewController.view addSubview:flutterViewController.view];
217 flutterViewController.view.frame = CGRectMake(150, 150, 500, 500);
218 }
219
220 self.window.rootViewController = rootViewController;
221}
222
223@end
NS_ASSUME_NONNULL_BEGIN NSDictionary * launchArgsMap
FlutterEngine engine
Definition main.cc:84
FlutterEngine * spawnWithEntrypoint:libraryURI:initialRoute:entrypointArgs:(nullable NSString *entrypoint,[libraryURI] nullable NSString *libraryURI,[initialRoute] nullable NSString *initialRoute,[entrypointArgs] nullable NSArray< NSString * > *entrypointArgs)
instancetype methodChannelWithName:binaryMessenger:codec:(NSString *name,[binaryMessenger] NSObject< FlutterBinaryMessenger > *messenger,[codec] NSObject< FlutterMethodCodec > *codec)
void registerWithRegistrar:(NSObject< FlutterPluginRegistrar > *registrar)
nullable NSObject< FlutterPluginRegistrar > * registrarForPlugin:(NSString *pluginKey)
int BOOL