Skip to content

Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.

C

fix: Home's shelf headings held on Spotify's own label instead of a frame

Vojtěch Škopekbbaaf501f92a
diff --git a/tweak/Sources/Redesigned/Home/HomeHeadings.x b/tweak/Sources/Redesigned/Home/HomeHeadings.x
index 5dc09e76..f1086d2a 100644
--- a/tweak/Sources/Redesigned/Home/HomeHeadings.x
+++ b/tweak/Sources/Redesigned/Home/HomeHeadings.x
@@ -5,6 +5,13 @@
// points up into the gap above the shelf. A small line over the title ("For fans of") and the artist's
// picture beside it stay Spotify's.
//
+// The label is held on Spotify's by constraints, not by a frame worked out here: a heading with a picture lays
+// its labels out in a stack of its own, which is positioned after this hook has run, so a frame taken here put
+// the title over the artist's picture at the leading edge, and a cell reused for a plain heading kept the
+// place the picture had left (trees/continuous/1.txt:2533 and :2291, 2026-09-17). Spotify's label can also have
+// no text yet when the button lays out, which left three of that tree's headings at Spotify's own size, so a
+// heading with nothing to draw on is looked at again on the next turn of the run loop, a few times at most.
+//
// Tree (trees/continuous/1.txt:2289-2312, 2026-09-17): Element_List.SupplementaryItemView 370x48 >
// ... > UIView id=Components.UI.SectionHeadingHome > AutoLayoutStackView > UIView > NoIntrinsicContentSizeButton
// (a11y "For fans of Yzomandias"), under which an ImageViewHolder 48x48 and a stack of SPTEncoreLabels:
@@ -15,7 +22,20 @@
#import "Redesigned/Kit/SGRKit.h"
#import "Home.h"
-static char kTitleKey, kShowAllKey;
+static char kTitleKey, kShowAllKey, kHeldKey, kTriesKey;
+
+// How often a heading with no title yet is looked at again.
+static const NSUInteger kTries = 3;
+
+// What the title is held on, so the constraints are made again only when it changes.
+@interface SGRHeadingHold : NSObject
+@property (nonatomic, weak) UILabel *label;
+@property (nonatomic, weak) UIView *limit;
+@property (nonatomic, copy) NSArray<NSLayoutConstraint *> *constraints;
+@end
+
+@implementation SGRHeadingHold
+@end
static UIView *headingAround(UIView *button) {
NSUInteger depth = 0;
@@ -32,13 +52,14 @@ static BOOL shown(UIView *view, UIView *root) {
return YES;
}
-// The label that is the title: the largest text showing under the button, its own label aside.
+// The label that is the title: the largest text showing under the button, its own label aside. A label the stack
+// has not sized yet counts, since the constraints take its place from the layout rather than from its bounds.
static UILabel *titleLabelIn(UIView *button, UILabel *mine) {
__block UILabel *title = nil;
SGForEachView(button, ^(UIView *v) {
if (v == mine || ![v isKindOfClass:UILabel.class]) return;
UILabel *label = (UILabel *)v;
- if (!label.text.length || label.bounds.size.height < 1 || !shown(label, button)) return;
+ if (!label.text.length || !shown(label, button)) return;
if (!title || label.font.pointSize > title.font.pointSize) title = label;
});
return title;
@@ -49,8 +70,12 @@ static void restyle(UIView *button) {
if (!heading) return;
UILabel *mine = objc_getAssociatedObject(button, &kTitleKey);
UILabel *theirs = titleLabelIn(button, mine);
+ SGRHeadingHold *held = objc_getAssociatedObject(button, &kHeldKey);
if (!theirs) {
+ // A heading between two shelves: nothing to hold the title on until its label has text again.
mine.hidden = YES;
+ if (held.constraints) [NSLayoutConstraint deactivateConstraints:held.constraints];
+ objc_setAssociatedObject(button, &kHeldKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
return;
}
if (!mine) {
@@ -58,9 +83,11 @@ static void restyle(UIView *button) {
mine.userInteractionEnabled = NO;
mine.accessibilityElementsHidden = YES;
mine.lineBreakMode = NSLineBreakByTruncatingTail;
+ mine.translatesAutoresizingMaskIntoConstraints = NO;
objc_setAssociatedObject(button, &kTitleKey, mine, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- if (mine.superview != button) [button addSubview:mine];
+ BOOL added = mine.superview != button;
+ if (added) [button addSubview:mine];
mine.hidden = NO;
UIFont *font = SGRFont(UIFontTextStyleTitle2, UIFontWeightBold, UIContentSizeCategoryLarge);
@@ -69,20 +96,42 @@ static void restyle(UIView *button) {
if (![mine.textColor isEqual:theirs.textColor]) mine.textColor = theirs.textColor;
if (theirs.alpha != 0) theirs.alpha = 0;
- // Spotify's label centres its one line in its bounds.
- CGRect frame = [theirs convertRect:theirs.bounds toView:button];
- UIFont *spotify = theirs.font;
- CGFloat baseline = CGRectGetMinY(frame) + (frame.size.height - spotify.lineHeight) / 2 + spotify.ascender;
- CGFloat x = CGRectGetMinX(frame);
- CGFloat available = heading.bounds.size.width - [button convertPoint:CGPointMake(x, 0) toView:heading].x;
+ // The leading edge and the baseline are Spotify's label's; the title ends before "Show all", or before the
+ // heading's trailing edge while there is none, and truncates rather than push anything.
+ // Whether "Show all" is offered is read off the hidden flags, not off its width: it has none to go by until
+ // the layout resolves, and a title held to the heading's own edge then ran under it.
UIView *showAll = SGRFindByIdentifier(heading, @"Components.UI.NavigationButtonHome", &kShowAllKey);
- if (showAll.bounds.size.width > 1 && shown(showAll, heading)) available -= showAll.bounds.size.width + SGRGrid;
- CGFloat width = MIN(ceil([mine sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)].width), MAX(0, available));
- CGRect target = CGRectMake(x, round(baseline - font.ascender), width, ceil(font.lineHeight));
- if (!CGRectEqualToRect(mine.frame, target)) mine.frame = target;
+ BOOL offered = showAll && shown(showAll, heading);
+ UIView *limit = offered ? showAll : heading;
+ if (added || held.label != theirs || held.limit != limit) {
+ if (held.constraints) [NSLayoutConstraint deactivateConstraints:held.constraints];
+ NSMutableArray<NSLayoutConstraint *> *constraints = [NSMutableArray arrayWithArray:@[
+ [mine.leadingAnchor constraintEqualToAnchor:theirs.leadingAnchor],
+ [mine.firstBaselineAnchor constraintEqualToAnchor:theirs.firstBaselineAnchor],
+ [mine.trailingAnchor constraintLessThanOrEqualToAnchor:heading.trailingAnchor],
+ ]];
+ if (offered) [constraints addObject:[mine.trailingAnchor constraintLessThanOrEqualToAnchor:showAll.leadingAnchor constant:-SGRGrid]];
+ [NSLayoutConstraint activateConstraints:constraints];
+ held = [SGRHeadingHold new];
+ held.label = theirs;
+ held.limit = limit;
+ held.constraints = constraints;
+ objc_setAssociatedObject(button, &kHeldKey, held, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ objc_setAssociatedObject(button, &kTriesKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ static dispatch_once_t once;
+ dispatch_once(&once, ^{ SGLog(@"redesign home: heading \"%@\" %.0fpt drawn at %.0fpt, held on Spotify's label", theirs.text, theirs.font.pointSize, font.pointSize); });
+ }
+}
- static dispatch_once_t once;
- dispatch_once(&once, ^{ SGLog(@"redesign home: heading \"%@\" %.0fpt drawn at %.0fpt, %@", theirs.text, spotify.pointSize, font.pointSize, NSStringFromCGRect(target)); });
+// Looks again once the layout has settled, while the heading has no label with text to hold the title on.
+static void restyleWhenReady(UIView *button) {
+ if (objc_getAssociatedObject(button, &kHeldKey)) return;
+ NSUInteger tries = [objc_getAssociatedObject(button, &kTriesKey) unsignedIntegerValue];
+ if (tries >= kTries) return;
+ objc_setAssociatedObject(button, &kTriesKey, @(tries + 1), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if (button.window) restyle(button);
+ });
}
%hook _TtCOOOE11Home_ECMKitO19LegacyUI_ECMCoreKit10Components18SectionHeadingHome2UI7Private28NoIntrinsicContentSizeButton
@@ -90,6 +139,7 @@ static void restyle(UIView *button) {
%orig;
CFTimeInterval began = SGRHomeProbeBegin();
restyle((UIView *)self);
+ restyleWhenReady((UIView *)self);
SGRHomeProbeEnd(SGRHomeProbeHeadings, began);
}
%end