From 48e786e8b5993530dd1a189f02408ee4898c0106 Mon Sep 17 00:00:00 2001 From: Didier Korthoudt Date: Mon, 21 Mar 2022 15:50:44 +0100 Subject: [PATCH] Fixed: This PR adapts views and custom views decoding to fix "not ready view" bugs (#2917) --- AppKit/CPView.j | 22 +++++++++++----------- AppKit/Cib/_CPCibCustomView.j | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/AppKit/CPView.j b/AppKit/CPView.j index b6f7d41d6..eeceea8ad 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -3781,16 +3781,21 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask", // Also decode these "early". _frame = [aCoder decodeRectForKey:CPViewFrameKey]; _bounds = [aCoder decodeRectForKey:CPViewBoundsKey]; + _scaleSize = [aCoder containsValueForKey:CPViewScaleKey] ? [aCoder decodeSizeForKey:CPViewScaleKey] : CGSizeMake(1.0, 1.0); + _hierarchyScaleSize = [aCoder containsValueForKey:CPViewSizeScaleKey] ? [aCoder decodeSizeForKey:CPViewSizeScaleKey] : CGSizeMake(1.0, 1.0); + _isScaled = [aCoder containsValueForKey:CPViewIsScaledKey] ? [aCoder decodeBoolForKey:CPViewIsScaledKey] : NO; + _subviews = @[]; + + // Trying to fix "not ready" views + _trackingAreas = [aCoder decodeObjectForKey:CPViewTrackingAreasKey] || @[]; + + [self _decodeThemeObjectsWithCoder:aCoder]; + [self setAppearance:[aCoder decodeObjectForKey:CPViewAppearanceKey]]; self = [super initWithCoder:aCoder]; if (self) { - _trackingAreas = [aCoder decodeObjectForKey:CPViewTrackingAreasKey]; - - if (!_trackingAreas) - _trackingAreas = []; - // We have to manually check because it may be 0, so we can't use || _tag = [aCoder containsValueForKey:CPViewTagKey] ? [aCoder decodeIntForKey:CPViewTagKey] : -1; _identifier = [aCoder decodeObjectForKey:CPReuseIdentifierKey]; @@ -3799,7 +3804,6 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask", _superview = [aCoder decodeObjectForKey:CPViewSuperviewKey]; // We have to manually add the subviews so that they will receive // viewWillMoveToSuperview: and viewDidMoveToSuperview: - _subviews = []; var subviews = [aCoder decodeObjectForKey:CPViewSubviewsKey] || []; @@ -3828,10 +3832,6 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask", if (_toolTip) [self _installToolTipEventHandlers]; - _scaleSize = [aCoder containsValueForKey:CPViewScaleKey] ? [aCoder decodeSizeForKey:CPViewScaleKey] : CGSizeMake(1.0, 1.0); - _hierarchyScaleSize = [aCoder containsValueForKey:CPViewSizeScaleKey] ? [aCoder decodeSizeForKey:CPViewSizeScaleKey] : CGSizeMake(1.0, 1.0); - _isScaled = [aCoder containsValueForKey:CPViewIsScaledKey] ? [aCoder decodeBoolForKey:CPViewIsScaledKey] : NO; - // DOM SETUP #if PLATFORM(DOM) _cssStylePreviousState = @[]; @@ -3862,12 +3862,12 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask", [self setBackgroundColor:[aCoder decodeObjectForKey:CPViewBackgroundColorKey]]; [self _setupViewFlags]; - [self _decodeThemeObjectsWithCoder:aCoder]; [self setAppearance:[aCoder decodeObjectForKey:CPViewAppearanceKey]]; // Set the current appearance to something that can't be the correct one so it will recalculate it at the first layout. _currentAppearance = _frame; + [self updateTrackingAreas]; [self setNeedsDisplay:YES]; [self setNeedsLayout]; } diff --git a/AppKit/Cib/_CPCibCustomView.j b/AppKit/Cib/_CPCibCustomView.j index f8acf1226..5be132d6b 100644 --- a/AppKit/Cib/_CPCibCustomView.j +++ b/AppKit/Cib/_CPCibCustomView.j @@ -118,9 +118,24 @@ var _CPCibCustomViewClassNameKey = @"_CPCibCustomViewClassNameKey"; [view setAlphaValue:[self alphaValue]]; [view setIdentifier:[self identifier]]; + // Trying to fix not ready view bug (or running condition) + view._appearance = self._appearance; + view._theme = self._theme; + + if (view._themeState == CPThemeStateNormal) + view._themeState = self._themeState; + + view._themeAttributes = self._themeAttributes; + view._themeClass = [theClass themeClass]; + + [view _loadThemeAttributes]; + [_superview replaceSubview:self with:view]; - [view setBackgroundColor:[self backgroundColor]]; + var backgroundColor = [self backgroundColor]; + + if (backgroundColor) + [view setBackgroundColor:backgroundColor]; } return view;