Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: redesigned Search, the Browse page down to its categories on Liquid Glass tinted by their own colour
Vojtěch Škopeke18311b77152
diff --git a/AGENTS.md b/AGENTS.mdindex 70086409..e79a0ece 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -11,7 +11,8 @@ A Theos tweak (Objective-C + Logos) injected into the decrypted Spotify iOS app.Home gradient, AMOLED switch, accent colour...).- **Redesigned**: the mod's own Liquid Glass look, from a clean sheet. It includes the glass tab bar,search field and now playing bar, the redesigned player and lyrics page with Apple Music style lyrics- always on, a decluttered Home, black throughout, and its own accent colour. No native tweak runs.+ always on, a decluttered Home, Search's categories on tinted glass, black throughout, and its own accent+ colour. No native tweak runs.Anything that doesn't draw on Spotify's screens works the same under both: ads, privacy, lyricssources, gestures, blocked artists, flags.diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 65e71952..c100966e 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -114,6 +114,10 @@ Redesigned:edge, the shelves' headings at the Music app's size, each shortcut tile's cover run across it blurred(SGRPalette's extension), continuous corners on the covers, and in FLEX builds a meter of each scroll'sframes and the hooks' time (Home.h lists its files)+ Search/ the Browse page decluttered to its category cards (an allow list of the list's cells: the watch feed+ carousels and promos collapse, and the cards move up by the spacing they leave), the header the way Home+ has it without the camera, and each card as Liquid Glass tinted by its own colour, read off the Box's+ shape layer (Search.h lists its files)Haptics/ Vibrations (Haptics.h lists its files): a tap of UIKit's feedback generators for the player's and the nowplaying bar's controls, the scrubber's tenths and ends, cover swipes, gestures and the lyrics page's tap toseek (ControlHaptics.x, SGRFeedback.m); and Music Haptics, Core Haptics playing along with the song:diff --git a/tweak/Sources/Redesigned/Search/Search.h b/tweak/Sources/Redesigned/Search/Search.hnew file mode 100644index 00000000..f83933ef--- /dev/null+++ b/tweak/Sources/Redesigned/Search/Search.h@@ -0,0 +1,21 @@+// The Search redesign: Spotify's Browse page (the Search tab before anything is typed) kept, with its controllers,+// list and cards, decluttered to the categories on black and restyled from the Kit. No settings of its own. The glass+// search field is the Navbar part's (Redesigned/Navbar/SearchField.x).+//+// SearchSections.x an allow list of the page's cells: the category cards stay; the watch feed carousels+// (Playlists you can watch, Explore episodes for you), promos and any new kind collapse, and the+// cards below move up by the spacing the collapsed ones leave+// SearchPage.x the header the way Home has it: a large title, the avatar at the trailing edge, no camera, no+// scrim; and the page's layout pass, which measures that spacing+// SearchCards.x each category card as Liquid Glass tinted by its own colour, at the card radius, giving under a press+//+// Every hook installs only while Redesigned UI is on (SGRedesignedUI).+// Threading: main thread only.+#import <UIKit/UIKit.h>++// The page's list (trees/clean/search/01.txt:24).+extern NSString *const SGRSearchListIdentifier;++// SearchSections.x: measures how far the cards sit below the top of the list because of the sections collapsed above+// them, and moves every cell of the list up by that much. Cheap to call on every layout pass of the page.+void SGRSearchCloseGap(UICollectionView *list);diff --git a/tweak/Sources/Redesigned/Search/SearchCards.x b/tweak/Sources/Redesigned/Search/SearchCards.xnew file mode 100644index 00000000..fdd7992a--- /dev/null+++ b/tweak/Sources/Redesigned/Search/SearchCards.x@@ -0,0 +1,226 @@+// Search redesign: each category card as Liquid Glass tinted by its own colour. Under the glass, the card's colour runs+// diagonally from itself at the top leading corner to a darker shade of it at the bottom trailing one; the glass is the+// clear style with that colour at 35% for its tint, so its rim catches the colour and its body stays as vivid as+// Spotify's card. The cover and the title stay Spotify's, over the glass. The card takes the card radius, continuous;+// the title moves in with it; and the card gives a little under a press, which Spotify showed by darkening the colour+// the glass now covers. Picked on the iOS 27 simulator against plain tinted glass (flat on black), regular glass over+// the colour (muddy) and the cover under clear glass (smeared), 2026-09-17.+//+// Under Reduce Transparency, or before iOS 26, the card is the colour alone.+//+// Tree (trees/clean/search/01.txt:332-339): Control<Box> id=Components.UI.CategoryCardBrowse 177x108 >+// Encore.Box 177x108 clips > UIView r=4 clips (the Box's content view) > Encore.ImageView (the cover, turned 25 degrees+// at the trailing edge) and SPTEncoreLabel {8, 8} 120x18 (the title). The colour is in no view: Box's layoutSubviews sets+// the path and the fill colour of its animationLayer, a CAShapeLayer among its layer's sublayers, from the card's colour+// set on every pass (Encore_LayoutKit.Box's fields, and -[Box layoutSubviews] calling setPath: and setFillColor:,+// 2026-09-17). So the colour is read off that layer, and the layer is hidden rather than cleared, since Spotify fills it again.+#import "Core/SGCore.h"+#import "Redesigned/Kit/SGRKit.h"+#import "Search.h"++// The tint the glass takes of the card's colour, and how dark the far corner of the colour under it gets.+static const CGFloat kTintAlpha = 0.35;+static const CGFloat kFarBrightness = 0.55;+// Where the title's top leading corner moves to, clear of the larger corner.+static const CGFloat kTitleInset = 12;+static const CGFloat kPressScale = 0.96;++static char kPartsKey, kRoundedKey;++@interface UIView (SGREncoreBox)+- (BOOL)isHighlighted;+@end++@interface SGRSearchCardPlate : UIView+@end++@implementation SGRSearchCardPlate++ (Class)layerClass {+ return CAGradientLayer.class;+}+@end++@interface SGRSearchCardParts : NSObject+@property (nonatomic) SGRSearchCardPlate *plate;+@property (nonatomic) UIVisualEffectView *glass;+@property (nonatomic) UIColor *color;+@end++@implementation SGRSearchCardParts+@end++static void logOnce(NSString *what) {+ static NSMutableSet<NSString *> *logged;+ if (!logged) logged = [NSMutableSet set];+ if ([logged containsObject:what]) return;+ [logged addObject:what];+ SGLog(@"redesign search: %@", what);+}++static BOOL isCategoryCard(UIView *box) {+ return [box.superview.accessibilityIdentifier isEqualToString:@"Components.UI.CategoryCardBrowse"];+}++// The Box's animationLayer: a shape layer no view owns.+static CAShapeLayer *fillLayerOf(UIView *box) {+ for (CALayer *layer in box.layer.sublayers) {+ if ([layer isKindOfClass:CAShapeLayer.class] && ![layer.delegate isKindOfClass:UIView.class]) return (CAShapeLayer *)layer;+ }+ return nil;+}++// Any other shape layer of the Box's that paints goes too: the glass is the card's only surface.+static void hideFills(UIView *box) {+ for (CALayer *layer in box.layer.sublayers) {+ if (![layer isKindOfClass:CAShapeLayer.class] || [layer.delegate isKindOfClass:UIView.class] || layer.hidden) continue;+ if (((CAShapeLayer *)layer).fillColor) layer.hidden = YES;+ }+}++// The Box's content view: its one subview of its own size that clips.+static UIView *contentOf(UIView *box) {+ for (UIView *sub in box.subviews) {+ if (sub.clipsToBounds && CGSizeEqualToSize(sub.bounds.size, box.bounds.size)) return sub;+ }+ return nil;+}++static void roundCorners(UIView *view, CGFloat radius) {+ CALayer *layer = view.layer;+ if (layer.cornerRadius != radius) layer.cornerRadius = radius;+ if (layer.cornerCurve != kCACornerCurveContinuous) layer.cornerCurve = kCACornerCurveContinuous;+}++static UIColor *darker(UIColor *color) {+ CGFloat hue = 0, saturation = 0, brightness = 0, alpha = 1;+ if (![color getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha]) return color;+ return [UIColor colorWithHue:hue saturation:saturation brightness:brightness * kFarBrightness alpha:alpha];+}++static BOOL glassAllowed(void) {+ if (SGRReduceTransparency()) return NO;+ if (@available(iOS 26.0, *)) return YES;+ return NO;+}++static SGRSearchCardParts *partsIn(UIView *box, UIView *content) {+ SGRSearchCardParts *parts = objc_getAssociatedObject(box, &kPartsKey);+ if (!parts) {+ parts = [SGRSearchCardParts new];+ SGRSearchCardPlate *plate = [SGRSearchCardPlate new];+ plate.userInteractionEnabled = NO;+ plate.accessibilityElementsHidden = YES;+ plate.layer.zPosition = -2;+ CAGradientLayer *gradient = (CAGradientLayer *)plate.layer;+ gradient.startPoint = CGPointMake(0, 0);+ gradient.endPoint = CGPointMake(1, 1);+ parts.plate = plate;+ objc_setAssociatedObject(box, &kPartsKey, parts, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ }+ // Behind the cover and the title whatever order Spotify keeps its own views in, by depth.+ if (parts.plate.superview != content) [content insertSubview:parts.plate atIndex:0];+ if (glassAllowed() && !parts.glass) {+ UIVisualEffectView *glass = [UIVisualEffectView new];+ glass.userInteractionEnabled = NO;+ glass.accessibilityElementsHidden = YES;+ glass.layer.zPosition = -1;+ parts.glass = glass;+ parts.color = nil;+ }+ if (parts.glass && parts.glass.superview != content) [content insertSubview:parts.glass aboveSubview:parts.plate];+ if (parts.glass) parts.glass.hidden = !glassAllowed();+ return parts;+}++static void paint(SGRSearchCardParts *parts, UIColor *color) {+ if (parts.color && CGColorEqualToColor(parts.color.CGColor, color.CGColor)) return;+ parts.color = color;+ ((CAGradientLayer *)parts.plate.layer).colors = @[(id)color.CGColor, (id)darker(color).CGColor];+ if (@available(iOS 26.0, *)) {+ if (parts.glass) {+ UIGlassEffect *effect = [UIGlassEffect effectWithStyle:UIGlassEffectStyleClear];+ effect.tintColor = [color colorWithAlphaComponent:kTintAlpha];+ parts.glass.effect = effect;+ }+ }+}++// The title's own position, before the move, is where Spotify's layout put its centre.+static void moveTitleIn(UIView *content) {+ for (UIView *sub in content.subviews) {+ if (![NSStringFromClass(sub.class) containsString:@"EncoreLabel"]) continue;+ CGPoint origin = CGPointMake(sub.center.x - sub.bounds.size.width / 2, sub.center.y - sub.bounds.size.height / 2);+ CGAffineTransform moved = CGAffineTransformMakeTranslation(MAX(0, kTitleInset - origin.x), MAX(0, kTitleInset - origin.y));+ if (!CGAffineTransformEqualToTransform(sub.transform, moved)) sub.transform = moved;+ }+}++static void roundCover(UIView *content) {+ for (UIView *sub in content.subviews) {+ if (![sub.accessibilityIdentifier isEqualToString:@"Encore.ImageView"]) continue;+ for (UIView *image in sub.subviews) {+ if (![image isKindOfClass:UIImageView.class]) continue;+ roundCorners(image, SGRRadiusThumb);+ if (!image.layer.masksToBounds) image.layer.masksToBounds = YES;+ }+ }+}++static void style(UIView *box) {+ if (!isCategoryCard(box)) return;+ UIView *content = contentOf(box);+ CAShapeLayer *fill = fillLayerOf(box);+ if (!content || !fill) {+ logOnce([NSString stringWithFormat:@"a category card without its %@, left as Spotify's", content ? @"fill layer" : @"content view"]);+ return;+ }+ // A pressed card's fill is Spotify's pressed shade; the colour is taken while it is not pressed.+ CGColorRef fillColor = fill.fillColor;+ SGRSearchCardParts *parts = partsIn(box, content);+ if (fillColor && CGColorGetAlpha(fillColor) > 0 && ![box isHighlighted]) paint(parts, [UIColor colorWithCGColor:fillColor]);+ if (!parts.color) return;+ hideFills(box);++ // The card is cut at the card radius by the Box, which clips already and which Spotify gives no radius. Spotify puts+ // its own 4pt back on the content view between layout passes, and the colour and the cover then showed past the glass+ // at the corners (on the phone, 2026-09-17); the content view keeps the card radius only for as long as it lasts.+ if (content.layer.cornerRadius != SGRRadiusCard && objc_getAssociatedObject(box, &kRoundedKey)) {+ logOnce([NSString stringWithFormat:@"Spotify set a card's content radius back to %.0f; the Box's corner holds", content.layer.cornerRadius]);+ }+ objc_setAssociatedObject(box, &kRoundedKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ roundCorners(box, SGRRadiusCard);+ if (!box.layer.masksToBounds) box.layer.masksToBounds = YES;+ roundCorners(content, SGRRadiusCard);+ CGRect bounds = content.bounds;+ if (!CGRectEqualToRect(parts.plate.frame, bounds)) parts.plate.frame = bounds;+ if (parts.glass && !CGRectEqualToRect(parts.glass.frame, bounds)) {+ parts.glass.frame = bounds;+ SGShapeGlass(parts.glass, SGRRadiusCard, NO);+ }+ moveTitleIn(content);+ roundCover(content);+ logOnce(parts.glass ? @"category cards on tinted glass" : @"category cards on their colour, no glass");+}++%hook _TtCE16Encore_LayoutKitO16EncoreFoundation6Encore3Box+- (void)layoutSubviews {+ %orig;+ style((UIView *)self);+}++- (void)setHighlighted:(BOOL)highlighted {+ UIView *box = (UIView *)self;+ BOOL was = [box isHighlighted];+ %orig;+ if (was == highlighted || !isCategoryCard(box)) return;+ SGRAnimate(SGRMotionPress, ^{+ box.transform = highlighted ? CGAffineTransformMakeScale(kPressScale, kPressScale) : CGAffineTransformIdentity;+ }, nil);+}+%end++%ctor {+ if (!SGRedesignedUI()) return;+ %init;+ SGRequireClasses(@[@"_TtCE16Encore_LayoutKitO16EncoreFoundation6Encore3Box"]);+}diff --git a/tweak/Sources/Redesigned/Search/SearchPage.x b/tweak/Sources/Redesigned/Search/SearchPage.xnew file mode 100644index 00000000..d5416912--- /dev/null+++ b/tweak/Sources/Redesigned/Search/SearchPage.x@@ -0,0 +1,164 @@+// Search redesign: the Browse page's header the way Home has it (Redesigned/Home/HomeHeader.x). A large title at the+// leading edge in place of Spotify's small one; the avatar that opens the side drawer at the trailing edge; the camera+// that scans Spotify codes gone, and the scrim Spotify lays behind the header, the soft scroll edge+// (Kit/SGREdgeEffect.x) being what keeps the header clear of the cards scrolling under it. The page's layout pass also+// closes the gap the collapsed sections leave (SearchSections.x).+//+// Tree (trees/clean/search/01.txt:376-427): BrowsePageViewController's view holds the list (id=BrowsePage.ContentScrollView),+// a 402x216 UIView around Reprise_LiquidGlassKit LiquidGlass.GradientView (the scrim), and at {0, 62} the header's+// ElementView 402x124: a vertical UIStackView {16, 0} 370x108 of the toolbar row and the search field. The toolbar row+// is a UIStackView id=SearchToolBar.Header 370x48 of ListeningActivity_ElementsKit.AdaptiveFaceContainer {0, 7} 32x34+// (the avatar), SPTEncoreLabel id=SearchHeaderFind.HeaderLabel {40, 0} 278x48 ("Search", 21pt), the camera+// (id=SearchToolBar.AccessoryItem.ScannablesButton) and a hidden accessory button.+//+// Scrolled, Spotify slides the header up 56pt and fades the toolbar row out (03.txt:647-651, a=0.00), keeping the search+// field. So the title goes into that row as a subview the stack does not arrange: it slides and fades with the row, and+// its avatar moves to the trailing edge by the row's layout direction, as on Home. The title's text is Spotify's own+// label's, so it follows the app's language.+#import "Core/SGCore.h"+#import "Redesigned/Kit/SGRKit.h"+#import "Search.h"++// Layout passes without the header before that is logged.+static const NSUInteger kMissesLogged = 60;++static char kTitleKey;++static __weak UICollectionView *sg_list;+static __weak UIStackView *sg_row;+static __weak UIView *sg_scrim;++static void vanish(UIView *view) {+ if (!view) return;+ if (view.alpha != 0) view.alpha = 0;+ if (view.userInteractionEnabled) view.userInteractionEnabled = NO;+ view.accessibilityElementsHidden = YES;+}++static UIView *childNamed(UIView *host, NSString *marker) {+ for (UIView *sub in host.subviews) {+ if ([NSStringFromClass(sub.class) containsString:marker]) return sub;+ }+ return nil;+}++// A depth first search that leaves the list out: the header and the scrim sit beside it, and its cells are hundreds of views.+static UIView *findOutsideList(UIView *view, NSString *identifier) {+ for (UIView *sub in view.subviews) {+ if ([sub isKindOfClass:UICollectionView.class]) continue;+ if ([sub.accessibilityIdentifier isEqualToString:identifier]) return sub;+ UIView *found = findOutsideList(sub, identifier);+ if (found) return found;+ }+ return nil;+}++// The page's parts, found once per page: the page lays out on every step of its header sliding. A miss costs a walk of the+// header alone, so the page keeps looking while it loads.+static BOOL findParts(UIView *view) {+ if (sg_row && sg_list && [sg_row isDescendantOfView:view] && [sg_list isDescendantOfView:view]) return YES;+ for (UIView *sub in view.subviews) {+ if ([sub isKindOfClass:UICollectionView.class] && [sub.accessibilityIdentifier isEqualToString:SGRSearchListIdentifier]) {+ sg_list = (UICollectionView *)sub;+ }+ UIView *scrim = childNamed(sub, @"GradientView");+ if (scrim) sg_scrim = scrim;+ }+ UIView *row = findOutsideList(view, @"SearchToolBar.Header");+ sg_row = [row isKindOfClass:UIStackView.class] ? (UIStackView *)row : nil;+ if (sg_row && sg_list) return YES;+ static NSUInteger misses;+ if (++misses == kMissesLogged) {+ SGLog(@"redesign search: page parts not found in %lu passes (toolbar row %@, list %@), the header left as Spotify's",+ (unsigned long)misses, sg_row ? @"found" : @"missing", sg_list ? @"found" : @"missing");+ }+ return NO;+}++static NSString *titleText(UIStackView *row) {+ UIView *label = nil;+ for (UIView *part in row.arrangedSubviews) {+ if ([part.accessibilityIdentifier isEqualToString:@"SearchHeaderFind.HeaderLabel"]) label = part;+ }+ for (UIView *sub in label.subviews) {+ if ([sub isKindOfClass:UILabel.class] && ((UILabel *)sub).text.length) return ((UILabel *)sub).text;+ }+ return @"Search";+}++static UILabel *titleIn(UIStackView *row) {+ UILabel *title = objc_getAssociatedObject(row, &kTitleKey);+ if (!title) {+ title = [UILabel new];+ title.textColor = SGRPrimary();+ title.accessibilityTraits = UIAccessibilityTraitHeader;+ title.adjustsFontSizeToFitWidth = YES;+ title.minimumScaleFactor = 0.6;+ title.userInteractionEnabled = NO;+ objc_setAssociatedObject(row, &kTitleKey, title, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ }+ if (title.superview != row) [row addSubview:title];+ return title;+}++static void layoutHeader(UIStackView *row) {+ vanish(sg_scrim);++ static Class faceClass;+ if (!faceClass) faceClass = NSClassFromString(@"_TtC29ListeningActivity_ElementsKit21AdaptiveFaceContainer");+ UIView *face = nil;+ NSString *text = titleText(row);+ for (UIView *part in row.arrangedSubviews) {+ if (faceClass && [part isKindOfClass:faceClass]) face = part;+ else vanish(part);+ }+ if (row.semanticContentAttribute != UISemanticContentAttributeForceRightToLeft) {+ row.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;+ [row setNeedsLayout];+ }+ [row layoutIfNeeded];++ UILabel *title = titleIn(row);+ if (![title.text isEqualToString:text]) {+ title.text = text;+ title.accessibilityLabel = text;+ }+ UIFont *font = SGRFont(UIFontTextStyleLargeTitle, UIFontWeightBold, UIContentSizeCategoryLarge);+ if (![title.font isEqual:font]) title.font = font;++ CGFloat trailing = face ? CGRectGetMinX(face.frame) - SGRGrid : row.bounds.size.width;+ CGFloat height = ceil(font.lineHeight);+ CGRect frame = CGRectMake(0, round(CGRectGetMidY(row.bounds) - height / 2), MAX(0, trailing), height);+ if (!CGRectEqualToRect(title.frame, frame)) title.frame = frame;++ static BOOL logged;+ if (!logged && row.window && CGRectGetMinX(row.frame) >= 0 && row.bounds.size.width > 0) {+ logged = YES;+ SGLog(@"redesign search: toolbar row %@, avatar %@, title %@ \"%@\", scrim %@", NSStringFromCGRect(row.frame),+ face ? NSStringFromCGRect(face.frame) : @"not found", NSStringFromCGRect(frame), text, sg_scrim ? @"found" : @"not found");+ }+}++%hook _TtC21Browse_BrowsePageImpl24BrowsePageViewController+- (void)viewDidLayoutSubviews {+ %orig;+ UIView *view = ((UIViewController *)self).viewIfLoaded;+ if (!view || !findParts(view)) return;+ layoutHeader(sg_row);+ SGRSearchCloseGap(sg_list);+}++- (void)traitCollectionDidChange:(UITraitCollection *)previous {+ %orig;+ [((UIViewController *)self).viewIfLoaded setNeedsLayout];+}+%end++%ctor {+ if (!SGRedesignedUI()) return;+ %init;+ SGRequireClasses(@[+ @"_TtC21Browse_BrowsePageImpl24BrowsePageViewController",+ @"_TtC29ListeningActivity_ElementsKit21AdaptiveFaceContainer",+ ]);+}diff --git a/tweak/Sources/Redesigned/Search/SearchSections.x b/tweak/Sources/Redesigned/Search/SearchSections.xnew file mode 100644index 00000000..093e1096--- /dev/null+++ b/tweak/Sources/Redesigned/Search/SearchSections.x@@ -0,0 +1,212 @@+// Search redesign: of the cells the Browse page lists, only the category cards stay. Every other cell reports no+// height, so the list closes up around it: the watch feed carousels (Playlists you can watch, Explore episodes for+// you), and the promos, showcases and ad cards the page can also carry (BrowseStructure's other cases in the binary,+// swift-fields.txt 2026-09-17), and any kind the server adds later. An allow list, as for Home's sections+// (Redesigned/Home/HomeSections.x): the page is the server's, and a new kind should not turn up on a redesigned Search.+//+// Tree (trees/clean/search/01.txt): a cell of the list (id=BrowsePage.ContentScrollView) is an+// Element_List.CollectionViewCell whose content view is an ElementContentView over Browse_BrowsePageImpl.BrowseStructure,+// then an ElementView<BrowseStructure>, then the cell's own root:+// Control<Box> id=Components.UI.CategoryCardBrowse a category card 177x108 (:332)+// UIView > UIView > UIStackView > ... WatchFeedCarouselEntryPointElement a carousel 402x224 under its heading (:26-30)+//+// A collapsed cell keeps its content at the height it measured, hidden and cut off by the cell, the way Home's do: content+// squeezed to 0 with the cell breaks its constraints on every layout pass (Home.h, home perf 2026-09-17).+//+// The carousels are the page's first two sections, and the list keeps its spacing between sections whatever their+// height: collapsed, they still leave 16pt after the first and 24pt after the second (01.txt:30-31, :325), 40pt of black+// between the search field and the cards. So every cell of the list moves up by the spacing the collapsed cells above the+// first card leave, measured from the list's own layout attributes. The move is the cell's transform, set after UIKit+// applies the cell's attributes and on the cell's layout passes, so it holds through scrolling, reuse and reloads (a+// compositional list with the same shape on the iOS 27 simulator, 2026-09-17), and touches follow it. Spotify's content+// inset, which its collapsing header is worked out from, stays its own.+#import "Core/SGCore.h"+#import "Redesigned/Kit/SGRKit.h"+#import "Search.h"++NSString *const SGRSearchListIdentifier = @"BrowsePage.ContentScrollView";++typedef NS_ENUM(NSInteger, SGRSearchKind) {+ SGRSearchKindPending, // the cell's root is not in yet: left as it is+ SGRSearchKindKeep,+ SGRSearchKindDrop,+};++// The items looked at from the top of the list for the first card before the gap is taken as none.+static const NSInteger kGapItems = 24;++static char kCollapsedKey;++static CGFloat sg_gap;+// Collapses and expansions so far, so a layout pass of the page measures again after one.+static NSUInteger sg_changes;+static __weak UICollectionView *sg_list;+static BOOL sg_measureQueued;++static void logOnce(NSString *what) {+ static NSMutableSet<NSString *> *logged;+ if (!logged) logged = [NSMutableSet set];+ if ([logged containsObject:what]) return;+ [logged addObject:what];+ SGLog(@"redesign search: %@", what);+}++static BOOL isBrowseCell(UIView *content) {+ if (!content) return NO;+ static NSMutableDictionary *answers;+ if (!answers) answers = [NSMutableDictionary dictionary];+ Class cls = object_getClass(content);+ NSNumber *answer = answers[(id<NSCopying>)cls];+ if (!answer) {+ answer = @([NSStringFromClass(cls) containsString:@"Browse_BrowsePageImpl15BrowseStructure"]);+ answers[(id<NSCopying>)cls] = answer;+ }+ return answer.boolValue;+}++static SGRSearchKind kindOf(UIView *root) {+ if (!root) return SGRSearchKindPending;+ return [root.accessibilityIdentifier isEqualToString:@"Components.UI.CategoryCardBrowse"] ? SGRSearchKindKeep : SGRSearchKindDrop;+}++// What a dropped cell holds, for the log: the first identifier in it, else its root's class.+static NSString *describe(UIView *root) {+ __block NSString *identifier = nil;+ SGForEachView(root, ^(UIView *v) {+ if (!identifier && v.accessibilityIdentifier.length) identifier = v.accessibilityIdentifier;+ });+ return identifier ?: NSStringFromClass(root.class);+}++static void shift(UICollectionViewCell *cell) {+ CGAffineTransform moved = CGAffineTransformMakeTranslation(0, -sg_gap);+ if (!CGAffineTransformEqualToTransform(cell.transform, moved)) cell.transform = moved;+}++static void collapse(UICollectionViewCell *cell, CGFloat natural) {+ UIView *content = cell.contentView;+ objc_setAssociatedObject(cell, &kCollapsedKey, @(natural), OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ if (content.autoresizingMask & UIViewAutoresizingFlexibleHeight) content.autoresizingMask &= ~UIViewAutoresizingFlexibleHeight;+ CGRect frame = CGRectMake(0, 0, cell.bounds.size.width, natural);+ if (!CGRectEqualToRect(content.frame, frame)) content.frame = frame;+ if (!content.hidden) content.hidden = YES;+ if (!cell.clipsToBounds) cell.clipsToBounds = YES;+ cell.accessibilityElementsHidden = YES;+}++static void expand(UICollectionViewCell *cell) {+ UIView *content = cell.contentView;+ objc_setAssociatedObject(cell, &kCollapsedKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ content.autoresizingMask |= UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;+ content.frame = cell.bounds;+ content.hidden = NO;+ cell.clipsToBounds = NO;+ cell.accessibilityElementsHidden = NO;+}++// The top of the first item with a height, when every item above it has none; 0 when the list starts with one.+static CGFloat measure(UICollectionView *list) {+ BOOL collapsedAbove = NO;+ NSInteger seen = 0;+ NSInteger sections = list.numberOfSections;+ for (NSInteger section = 0; section < sections; section++) {+ NSInteger items = [list numberOfItemsInSection:section];+ for (NSInteger item = 0; item < items; item++) {+ if (++seen > kGapItems) return 0;+ UICollectionViewLayoutAttributes *attributes = [list layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:item inSection:section]];+ if (!attributes) return 0;+ if (attributes.frame.size.height < 1) {+ collapsedAbove = YES;+ continue;+ }+ return collapsedAbove ? MAX(0, CGRectGetMinY(attributes.frame)) : 0;+ }+ }+ return 0;+}++void SGRSearchCloseGap(UICollectionView *list) {+ if (!list) return;+ static CGSize lastSize;+ static NSUInteger lastChanges = NSUIntegerMax;+ static __weak UICollectionView *lastList;+ CGSize size = list.contentSize;+ if (list == lastList && sg_changes == lastChanges && CGSizeEqualToSize(size, lastSize)) return;+ sg_list = lastList = list;+ lastChanges = sg_changes;+ lastSize = size;++ CGFloat gap = measure(list);+ if (gap == sg_gap) return;+ sg_gap = gap;+ SGLog(@"redesign search: cards moved up %.0fpt, the spacing the collapsed sections above them leave", gap);+ for (UIView *sub in list.subviews) {+ if ([sub isKindOfClass:UICollectionViewCell.class] && isBrowseCell(((UICollectionViewCell *)sub).contentView)) {+ shift((UICollectionViewCell *)sub);+ }+ }+}++// After the pass that sized the cell: the list's attributes take the new height when that pass ends.+static void measureSoon(void) {+ if (sg_measureQueued) return;+ sg_measureQueued = YES;+ dispatch_async(dispatch_get_main_queue(), ^{+ sg_measureQueued = NO;+ SGRSearchCloseGap(sg_list);+ });+}++%hook _TtC12Element_List18CollectionViewCell+- (UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)attributes {+ UICollectionViewCell *cell = (UICollectionViewCell *)self;+ UIView *content = cell.contentView;+ if (!isBrowseCell(content)) return %orig;+ UICollectionViewLayoutAttributes *result = %orig;++ UIView *root = content.subviews.firstObject.subviews.firstObject;+ SGRSearchKind kind = kindOf(root);+ BOOL collapsed = objc_getAssociatedObject(cell, &kCollapsedKey) != nil;+ if (kind == SGRSearchKindDrop) {+ collapse(cell, MAX(1, result.size.height));+ result.size = CGSizeMake(result.size.width, 0);+ if (!collapsed) {+ sg_changes++;+ measureSoon();+ }+ logOnce([@"dropped " stringByAppendingString:describe(root)]);+ } else if (kind == SGRSearchKindKeep && collapsed) {+ // Cells are reused across kinds: one collapsed before holds a card now.+ expand(cell);+ sg_changes++;+ measureSoon();+ }+ return result;+}++- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)attributes {+ %orig;+ UICollectionViewCell *cell = (UICollectionViewCell *)self;+ if (isBrowseCell(cell.contentView)) shift(cell);+}++// The cell's own passes may size the content to the cell again, and a cell laid out before the gap was known takes it here.+- (void)layoutSubviews {+ %orig;+ UICollectionViewCell *cell = (UICollectionViewCell *)self;+ NSNumber *natural = objc_getAssociatedObject(cell, &kCollapsedKey);+ if (natural) collapse(cell, natural.doubleValue);+ if (sg_gap > 0 && isBrowseCell(cell.contentView)) shift(cell);+}++- (void)prepareForReuse {+ %orig;+ if (objc_getAssociatedObject(self, &kCollapsedKey)) expand((UICollectionViewCell *)self);+}+%end++%ctor {+ if (!SGRedesignedUI()) return;+ %init;+ SGRequireClasses(@[@"_TtC12Element_List18CollectionViewCell"]);+}