1111#import " flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h"
1212#import " flutter/shell/platform/darwin/ios/ios_surface.h"
1313
14+ FLUTTER_ASSERT_ARC
15+
1416@implementation UIView (FirstResponder)
1517- (BOOL )flt_hasFirstResponderInViewHierarchySubtree {
1618 if (self.isFirstResponder ) {
@@ -91,7 +93,7 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
9193 overlay_view.reset ([[FlutterOverlayView alloc ] init ]);
9294 overlay_view_wrapper.reset ([[FlutterOverlayView alloc ] init ]);
9395
94- auto ca_layer = fml::scoped_nsobject<CALayer >{[[ overlay_view.get () layer ] retain ]};
96+ auto ca_layer = fml::scoped_nsobject<CALayer >{[overlay_view.get () layer ]};
9597 std::unique_ptr<IOSSurface> ios_surface = IOSSurface::Create (ios_context, ca_layer);
9698 std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface ();
9799
@@ -105,7 +107,7 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
105107 overlay_view_wrapper.reset ([[FlutterOverlayView alloc ] initWithContentsScale: screenScale
106108 pixelFormat: pixel_format]);
107109
108- auto ca_layer = fml::scoped_nsobject<CALayer >{[[ overlay_view.get () layer ] retain ]};
110+ auto ca_layer = fml::scoped_nsobject<CALayer >{[overlay_view.get () layer ]};
109111 std::unique_ptr<IOSSurface> ios_surface = IOSSurface::Create (ios_context, ca_layer);
110112 std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface (gr_context);
111113
@@ -159,12 +161,12 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
159161}
160162
161163void FlutterPlatformViewsController::SetFlutterView (UIView* flutter_view) {
162- flutter_view_.reset ([ flutter_view retain ] );
164+ flutter_view_.reset (flutter_view);
163165}
164166
165167void FlutterPlatformViewsController::SetFlutterViewController (
166168 UIViewController<FlutterViewResponder>* flutter_view_controller) {
167- flutter_view_controller_.reset ([ flutter_view_controller retain ] );
169+ flutter_view_controller_.reset (flutter_view_controller);
168170}
169171
170172UIViewController<FlutterViewResponder>* FlutterPlatformViewsController::getFlutterViewController () {
@@ -231,21 +233,19 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
231233 // Set a unique view identifier, so the platform view can be identified in unit tests.
232234 platform_view.accessibilityIdentifier =
233235 [NSString stringWithFormat: @" platform_view[%lld ]" , viewId];
234- views_[viewId] = fml::scoped_nsobject<NSObject <FlutterPlatformView>>([ embedded_view retain ] );
236+ views_[viewId] = fml::scoped_nsobject<NSObject <FlutterPlatformView>>(embedded_view);
235237
236- FlutterTouchInterceptingView* touch_interceptor = [[[ FlutterTouchInterceptingView alloc ]
238+ FlutterTouchInterceptingView* touch_interceptor = [[FlutterTouchInterceptingView alloc ]
237239 initWithEmbeddedView: platform_view
238240 platformViewsController: GetWeakPtr ()
239- gestureRecognizersBlockingPolicy: gesture_recognizers_blocking_policies_[viewType]]
240- autorelease ];
241+ gestureRecognizersBlockingPolicy: gesture_recognizers_blocking_policies_[viewType]];
241242
242243 touch_interceptors_[viewId] =
243- fml::scoped_nsobject<FlutterTouchInterceptingView>([ touch_interceptor retain ] );
244+ fml::scoped_nsobject<FlutterTouchInterceptingView>(touch_interceptor);
244245
245- ChildClippingView* clipping_view =
246- [[[ChildClippingView alloc ] initWithFrame: CGRectZero] autorelease ];
246+ ChildClippingView* clipping_view = [[ChildClippingView alloc ] initWithFrame: CGRectZero];
247247 [clipping_view addSubview: touch_interceptor];
248- root_views_[viewId] = fml::scoped_nsobject<UIView>([ clipping_view retain ] );
248+ root_views_[viewId] = fml::scoped_nsobject<UIView>(clipping_view);
249249
250250 result (nil );
251251}
@@ -307,8 +307,7 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
307307 FlutterPlatformViewGestureRecognizersBlockingPolicy gestureRecognizerBlockingPolicy) {
308308 std::string idString ([factoryId UTF8String ]);
309309 FML_CHECK (factories_.count (idString) == 0 );
310- factories_[idString] =
311- fml::scoped_nsobject<NSObject <FlutterPlatformViewFactory>>([factory retain ]);
310+ factories_[idString] = fml::scoped_nsobject<NSObject <FlutterPlatformViewFactory>>(factory);
312311 gesture_recognizers_blocking_policies_[idString] = gestureRecognizerBlockingPolicy;
313312}
314313
@@ -417,7 +416,7 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
417416
418417long FlutterPlatformViewsController::FindFirstResponderPlatformViewId () {
419418 for (auto const & [id , root_view] : root_views_) {
420- if ((UIView*)( root_view.get ()).flt_hasFirstResponderInViewHierarchySubtree ) {
419+ if ((( UIView*)root_view.get ()).flt_hasFirstResponderInViewHierarchySubtree ) {
421420 return id ;
422421 }
423422 }
@@ -460,7 +459,7 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
460459 ChildClippingView* clipView = (ChildClippingView*)embedded_view.superview ;
461460
462461 SkMatrix transformMatrix;
463- NSMutableArray * blurFilters = [[[ NSMutableArray alloc ] init ] autorelease ];
462+ NSMutableArray * blurFilters = [[NSMutableArray alloc ] init ];
464463 FML_DCHECK (!clipView.maskView ||
465464 [clipView.maskView isKindOfClass: [FlutterClippingMaskView class ]]);
466465 if (clipView.maskView ) {
@@ -530,12 +529,11 @@ static bool ClipRRectContainsPlatformViewBoundingRect(const SkRRect& clip_rrect,
530529 // is not supported in Quartz's gaussianBlur CAFilter, so it is not used
531530 // to blur the PlatformView.
532531 CGFloat blurRadius = (*iter)->GetFilterMutation ().GetFilter ().asBlur ()->sigma_x ();
533- UIVisualEffectView* visualEffectView = [[[UIVisualEffectView alloc ]
534- initWithEffect: [UIBlurEffect effectWithStyle: UIBlurEffectStyleLight]] autorelease ];
535- PlatformViewFilter* filter =
536- [[[PlatformViewFilter alloc ] initWithFrame: frameInClipView
537- blurRadius: blurRadius
538- visualEffectView: visualEffectView] autorelease ];
532+ UIVisualEffectView* visualEffectView = [[UIVisualEffectView alloc ]
533+ initWithEffect: [UIBlurEffect effectWithStyle: UIBlurEffectStyleLight]];
534+ PlatformViewFilter* filter = [[PlatformViewFilter alloc ] initWithFrame: frameInClipView
535+ blurRadius: blurRadius
536+ visualEffectView: visualEffectView];
539537 if (!filter) {
540538 canApplyBlurBackdrop = NO ;
541539 } else {
@@ -950,11 +948,13 @@ @interface DelayingGestureRecognizer : UIGestureRecognizer <UIGestureRecognizerD
950948
951949// Indicates that if the `DelayingGestureRecognizer`'s state should be set to
952950// `UIGestureRecognizerStateEnded` during next `touchesEnded` call.
953- @property (nonatomic ) bool shouldEndInNextTouchesEnded;
951+ @property (nonatomic ) BOOL shouldEndInNextTouchesEnded;
954952
955953// Indicates that the `DelayingGestureRecognizer`'s `touchesEnded` has been invoked without
956954// setting the state to `UIGestureRecognizerStateEnded`.
957- @property (nonatomic ) bool touchedEndedWithoutBlocking;
955+ @property (nonatomic ) BOOL touchedEndedWithoutBlocking;
956+
957+ @property (nonatomic , readonly ) UIGestureRecognizer* forwardingRecognizer;
958958
959959- (instancetype )initWithTarget : (id )target
960960 action : (SEL )action
@@ -977,15 +977,18 @@ - (instancetype)initWithTarget:(id)target
977977 (fml::WeakPtr<flutter::FlutterPlatformViewsController>)platformViewsController ;
978978@end
979979
980- @implementation FlutterTouchInterceptingView {
981- fml::scoped_nsobject<DelayingGestureRecognizer> _delayingRecognizer;
982- FlutterPlatformViewGestureRecognizersBlockingPolicy _blockingPolicy;
983- UIView* _embeddedView;
984- // The used as the accessiblityContainer.
985- // The `accessiblityContainer` is used in UIKit to determine the parent of this accessibility
986- // node.
987- NSObject * _flutterAccessibilityContainer;
988- }
980+ @interface FlutterTouchInterceptingView ()
981+ @property (nonatomic , weak , readonly ) UIView* embeddedView;
982+ @property (nonatomic , readonly ) DelayingGestureRecognizer* delayingRecognizer;
983+ @property (nonatomic , readonly ) FlutterPlatformViewGestureRecognizersBlockingPolicy blockingPolicy;
984+
985+ // The used as the accessiblityContainer.
986+ // The `accessiblityContainer` is used in UIKit to determine the parent of this accessibility
987+ // node.
988+ @property (nonatomic , weak ) NSObject * flutterAccessibilityContainer;
989+ @end
990+
991+ @implementation FlutterTouchInterceptingView
989992- (instancetype )initWithEmbeddedView : (UIView*)embeddedView
990993 platformViewsController :
991994 (fml::WeakPtr<flutter::FlutterPlatformViewsController>)platformViewsController
@@ -1000,47 +1003,42 @@ - (instancetype)initWithEmbeddedView:(UIView*)embeddedView
10001003
10011004 [self addSubview: embeddedView];
10021005
1003- ForwardingGestureRecognizer* forwardingRecognizer = [[[ForwardingGestureRecognizer alloc ]
1004- initWithTarget: self
1005- platformViewsController:std: : move ( platformViewsController)] autorelease ];
1006+ ForwardingGestureRecognizer* forwardingRecognizer =
1007+ [[ForwardingGestureRecognizer alloc ] initWithTarget: self
1008+ platformViewsController: platformViewsController];
10061009
1007- _delayingRecognizer.reset ([[DelayingGestureRecognizer alloc ]
1008- initWithTarget: self
1009- action: nil
1010- forwardingRecognizer: forwardingRecognizer]);
1010+ _delayingRecognizer = [[DelayingGestureRecognizer alloc ] initWithTarget: self
1011+ action: nil
1012+ forwardingRecognizer: forwardingRecognizer];
10111013 _blockingPolicy = blockingPolicy;
10121014
1013- [self addGestureRecognizer: _delayingRecognizer. get () ];
1015+ [self addGestureRecognizer: _delayingRecognizer];
10141016 [self addGestureRecognizer: forwardingRecognizer];
10151017 }
10161018 return self;
10171019}
10181020
1019- - (UIView*)embeddedView {
1020- return [[_embeddedView retain ] autorelease ];
1021- }
1022-
10231021- (void )releaseGesture {
1024- _delayingRecognizer. get () .state = UIGestureRecognizerStateFailed;
1022+ self. delayingRecognizer .state = UIGestureRecognizerStateFailed;
10251023}
10261024
10271025- (void )blockGesture {
10281026 switch (_blockingPolicy) {
10291027 case FlutterPlatformViewGestureRecognizersBlockingPolicyEager:
10301028 // We block all other gesture recognizers immediately in this policy.
1031- _delayingRecognizer. get () .state = UIGestureRecognizerStateEnded;
1029+ self. delayingRecognizer .state = UIGestureRecognizerStateEnded;
10321030 break ;
10331031 case FlutterPlatformViewGestureRecognizersBlockingPolicyWaitUntilTouchesEnded:
1034- if (_delayingRecognizer. get () .touchedEndedWithoutBlocking ) {
1032+ if (self. delayingRecognizer .touchedEndedWithoutBlocking ) {
10351033 // If touchesEnded of the `DelayingGesureRecognizer` has been already invoked,
10361034 // we want to set the state of the `DelayingGesureRecognizer` to
10371035 // `UIGestureRecognizerStateEnded` as soon as possible.
1038- _delayingRecognizer. get () .state = UIGestureRecognizerStateEnded;
1036+ self. delayingRecognizer .state = UIGestureRecognizerStateEnded;
10391037 } else {
10401038 // If touchesEnded of the `DelayingGesureRecognizer` has not been invoked,
10411039 // We will set a flag to notify the `DelayingGesureRecognizer` to set the state to
10421040 // `UIGestureRecognizerStateEnded` when touchesEnded is called.
1043- _delayingRecognizer. get () .shouldEndInNextTouchesEnded = YES ;
1041+ self. delayingRecognizer .shouldEndInNextTouchesEnded = YES ;
10441042 }
10451043 break ;
10461044 default :
@@ -1063,19 +1061,13 @@ - (void)touchesCancelled:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
10631061- (void )touchesEnded : (NSSet *)touches withEvent : (UIEvent*)event {
10641062}
10651063
1066- - (void )setFlutterAccessibilityContainer : (NSObject *)flutterAccessibilityContainer {
1067- _flutterAccessibilityContainer = flutterAccessibilityContainer;
1068- }
1069-
10701064- (id )accessibilityContainer {
1071- return _flutterAccessibilityContainer ;
1065+ return self. flutterAccessibilityContainer ;
10721066}
10731067
10741068@end
10751069
1076- @implementation DelayingGestureRecognizer {
1077- fml::scoped_nsobject<UIGestureRecognizer> _forwardingRecognizer;
1078- }
1070+ @implementation DelayingGestureRecognizer
10791071
10801072- (instancetype )initWithTarget : (id )target
10811073 action : (SEL )action
@@ -1085,9 +1077,9 @@ - (instancetype)initWithTarget:(id)target
10851077 self.delaysTouchesBegan = YES ;
10861078 self.delaysTouchesEnded = YES ;
10871079 self.delegate = self;
1088- self. shouldEndInNextTouchesEnded = NO ;
1089- self. touchedEndedWithoutBlocking = NO ;
1090- _forwardingRecognizer. reset ([forwardingRecognizer retain ]) ;
1080+ _shouldEndInNextTouchesEnded = NO ;
1081+ _touchedEndedWithoutBlocking = NO ;
1082+ _forwardingRecognizer = forwardingRecognizer ;
10911083 }
10921084 return self;
10931085}
@@ -1096,7 +1088,7 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer
10961088 shouldBeRequiredToFailByGestureRecognizer : (UIGestureRecognizer*)otherGestureRecognizer {
10971089 // The forwarding gesture recognizer should always get all touch events, so it should not be
10981090 // required to fail by any other gesture recognizer.
1099- return otherGestureRecognizer != _forwardingRecognizer. get () && otherGestureRecognizer != self;
1091+ return otherGestureRecognizer != _forwardingRecognizer && otherGestureRecognizer != self;
11001092}
11011093
11021094- (BOOL )gestureRecognizer : (UIGestureRecognizer*)gestureRecognizer
@@ -1161,7 +1153,7 @@ - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
11611153 // At the start of each gesture sequence, we reset the `_flutterViewController`,
11621154 // so that all the touch events in the same sequence are forwarded to the same
11631155 // `_flutterViewController`.
1164- _flutterViewController.reset ([ _platformViewsController->getFlutterViewController () retain ] );
1156+ _flutterViewController.reset (_platformViewsController->getFlutterViewController ());
11651157 }
11661158 [_flutterViewController.get () touchesBegan: touches withEvent: event];
11671159 _currentTouchPointersCount += touches.count ;
0 commit comments