@@ -365,6 +365,30 @@ - (CGFloat)contentsScale {
365365 return self.superview != nil ? self.superview .layer .contentsScale : 1.0 ;
366366}
367367
368+ // / Updates the nested stack of clip views that host the platform view.
369+ - (void )updatePathClipViewsWithPaths : (NSArray *)paths {
370+ // Remove path clip views depending on the number of paths.
371+ while (_pathClipViews.count > paths.count ) {
372+ NSView * view = _pathClipViews.lastObject ;
373+ [view removeFromSuperview ];
374+ [_pathClipViews removeLastObject ];
375+ }
376+ // Otherwise, add path clip views to the end.
377+ for (size_t i = _pathClipViews.count ; i < paths.count ; ++i) {
378+ NSView * superView = _pathClipViews.count == 0 ? self : _pathClipViews.lastObject ;
379+ FlutterPathClipView* pathClipView = [[FlutterPathClipView alloc ] initWithFrame: self .bounds];
380+ [_pathClipViews addObject: pathClipView];
381+ [superView addSubview: pathClipView];
382+ }
383+ // Update bounds and apply clip paths.
384+ for (size_t i = 0 ; i < _pathClipViews.count ; ++i) {
385+ FlutterPathClipView* pathClipView = _pathClipViews[i];
386+ pathClipView.frame = self.bounds ;
387+ [pathClipView maskToPath: (__bridge CGPathRef)[paths objectAtIndex: i]
388+ withOrigin: self .frame.origin];
389+ }
390+ }
391+
368392// / Whenever possible view will be clipped using layer bounds.
369393// / If clipping to path is needed, CAShapeLayer(s) will be used as mask.
370394// / Clipping to round rect only clips to path if round corners are intersected.
@@ -397,37 +421,15 @@ - (void)applyFlutterLayer:(const FlutterLayer*)layer {
397421
398422 // / Paths in global logical coordinates that need to be clipped to.
399423 NSMutableArray * paths = RoundedRectClipsFromMutations (masterClip, mutations);
400-
401- // Add / remove path clip views depending on the number of paths.
402- while (_pathClipViews.count > paths.count ) {
403- NSView * view = _pathClipViews.lastObject ;
404- [view removeFromSuperview ];
405- [_pathClipViews removeLastObject ];
406- }
407-
408- NSView * lastView = self;
409-
410- for (size_t i = 0 ; i < paths.count ; ++i) {
411- FlutterPathClipView* pathClipView = nil ;
412- if (i < _pathClipViews.count ) {
413- pathClipView = _pathClipViews[i];
414- } else {
415- pathClipView = [[FlutterPathClipView alloc ] initWithFrame: self .bounds];
416- [_pathClipViews addObject: pathClipView];
417- [lastView addSubview: pathClipView];
418- }
419- pathClipView.frame = self.bounds ;
420- [pathClipView maskToPath: (__bridge CGPathRef)[paths objectAtIndex: i]
421- withOrigin: finalBoundingRect.origin];
422- lastView = pathClipView;
423- }
424+ [self updatePathClipViewsWithPaths: paths];
424425
425426 // Used to apply sublayer transform.
426427 if (_platformViewContainer == nil ) {
427428 _platformViewContainer = [[NSView alloc ] initWithFrame: self .bounds];
428429 _platformViewContainer.wantsLayer = YES ;
429430 }
430431
432+ NSView * lastView = _pathClipViews.count == 0 ? self : _pathClipViews.lastObject ;
431433 [lastView addSubview: _platformViewContainer];
432434 _platformViewContainer.frame = self.bounds ;
433435
0 commit comments