0

[iOS] Deprecate traitCollectionDidChange in PanelContentViewController

Since traitCollectionDidChange is deprecated in iOS 17,
PanelContentViewController was updated to use the alternative system,
registerForTraitChanges.

Fixed: 391365715
Change-Id: I79e13962d7f61564826082b93d3c9bd3aae6465a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6195054
Reviewed-by: Robbie Gibson <rkgibson@google.com>
Commit-Queue: Daniel White <danieltwhite@google.com>
Cr-Commit-Position: refs/heads/main@{#1423706}
This commit is contained in:
Daniel White
2025-02-23 09:14:38 -08:00
committed by Chromium LUCI CQ
parent b4c4540c32
commit f80defd6a5

@ -18,6 +18,7 @@
#import "ios/chrome/browser/contextual_panel/utils/contextual_panel_metrics.h"
#import "ios/chrome/browser/shared/public/commands/contextual_sheet_commands.h"
#import "ios/chrome/browser/shared/ui/symbols/symbols.h"
#import "ios/chrome/browser/shared/ui/util/uikit_ui_util.h"
#import "ios/chrome/common/ui/colors/semantic_color_names.h"
#import "ios/chrome/common/ui/util/constraints_ui_util.h"
#import "ios/chrome/grit/ios_branded_strings.h"
@ -251,6 +252,12 @@ UIImage* CloseButtonImage(BOOL highlighted) {
[self.sheetDisplayController
setContentHeight:[self preferredHeightForContent]];
if (@available(iOS 17, *)) {
NSArray<UITrait>* traits = TraitCollectionSetForTraits(nil);
[self registerForTraitChanges:traits
withAction:@selector(notifyDelegateOfTraitChange)];
}
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(accessibilityReduceTransparencySettingDidChange)
@ -349,11 +356,16 @@ UIImage* CloseButtonImage(BOOL highlighted) {
[self setCollectionViewScrollIndicatorInsets];
}
#if !defined(__IPHONE_17_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_17_0
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
if (@available(iOS 17, *)) {
return;
}
[self.traitCollectionDelegate traitCollectionDidChangeForViewController:self];
[self notifyDelegateOfTraitChange];
}
#endif
// Removes the white-ish background color of one of UIVisualEffectView's
// subviews that is not desired for this feature.
@ -451,6 +463,12 @@ UIImage* CloseButtonImage(BOOL highlighted) {
_bottomToolbarHeight + kContentBottomMargin, 0);
}
// Notifies `traitCollectionDelegate` of a change in UITraits via
// `traitCollectionDidChangeForViewController`.
- (void)notifyDelegateOfTraitChange {
[self.traitCollectionDelegate traitCollectionDidChangeForViewController:self];
}
#pragma mark - View Initialization
// Creates the layout for the collection view.