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: an artist, album or playlist opened for the first time fills its hero when the picture lands

Vojtěch Škopek1eb52fb8f546
diff --git a/harness/artist/main.m b/harness/artist/main.m
index 77cb7f6c..c345ace5 100644
--- a/harness/artist/main.m
+++ b/harness/artist/main.m
@@ -1,6 +1,9 @@
// A mock of Spotify's artist page under its own class names and accessibility identifiers, built from
// trees/clean/artist/01.txt and 05.txt (recorded 2026-09-16), so Redesigned/Artist can be laid out and looked
-// at on the Mac. `collapsed` on the launch line shows the header scrolled into its 100pt bar.
+// at on the Mac. `collapsed` on the launch line shows the header scrolled into its 100pt bar; `late` holds
+// the Follow button's word and then the photo back, one after the other, the way a page opened for the first
+// time gets them -- each has to reach the redesign on its own (issue #52), and the artwork view carries
+// Encore's Swift class name so that it can only be watched the way the phone makes the Kit watch it.
#import <UIKit/UIKit.h>
#pragma mark - Spotify's classes, by name
@@ -45,6 +48,12 @@
@interface MockButton : UIControl @end
@implementation MockButton @end
+// Encore's image view, the one every picture Spotify loads arrives in (01.txt:48). Its name is the point of
+// the mock: a Swift one, which the Kit refuses to give an instance its own subclass of, so the harness
+// watches the photo the way the phone has to -- through an override on the class.
+@interface _TtC19LegacyUI_ECMCoreKitP33_3DFE6A8953CA91BDEBA7A38450631F5815EncoreImageView : UIImageView @end
+@implementation _TtC19LegacyUI_ECMCoreKitP33_3DFE6A8953CA91BDEBA7A38450631F5815EncoreImageView @end
+
#pragma mark - building the tree
static UIView *box(UIView *parent, Class cls, CGRect frame, NSString *identifier) {
@@ -177,6 +186,7 @@ static NSArray<NSArray *> *musicList(void) {
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
CGFloat W = self.window.bounds.size.width, H = self.window.bounds.size.height;
BOOL collapsed = [NSProcessInfo.processInfo.arguments containsObject:@"collapsed"];
+ BOOL late = [NSProcessInfo.processInfo.arguments containsObject:@"late"];
UIViewController *root = [UIViewController new];
root.view.backgroundColor = [UIColor colorWithRed:0.07 green:0.07 blue:0.07 alpha:1];
@@ -195,8 +205,9 @@ static NSArray<NSArray *> *musicList(void) {
UIView *clip = box(header, UIView.class, CGRectMake(0, 0, W, collapsed ? 0 : 424.67), nil);
clip.clipsToBounds = YES;
UIView *artwork = box(clip, UIView.class, CGRectMake(-11.33, 0, 424.67, 424.67), @"Components.Header.UI.ArtworkImage");
- UIImageView *picture = [[UIImageView alloc] initWithFrame:artwork.bounds];
- picture.image = photo();
+ UIImageView *picture = [[_TtC19LegacyUI_ECMCoreKitP33_3DFE6A8953CA91BDEBA7A38450631F5815EncoreImageView alloc]
+ initWithFrame:artwork.bounds];
+ if (!late) picture.image = photo();
picture.accessibilityIdentifier = @"Components.Header.UI.ArtworkImage.ImageView";
[artwork addSubview:picture];
UIView *wash = box(clip, MockGradientView.class, CGRectMake(-11.33, 310.67, 424.67, 257.33), nil);
@@ -216,7 +227,8 @@ static NSArray<NSArray *> *musicList(void) {
follow.layer.borderColor = UIColor.grayColor.CGColor;
follow.layer.borderWidth = 1;
follow.layer.cornerRadius = 16;
- label(follow, CGRectMake(16, 8, 40, 16), @"Follow", 11, UIColor.whiteColor, @"Encore.Label");
+ UILabel *followWord = label(follow, CGRectMake(16, 8, 40, 16), late ? @"" : @"Follow", 11, UIColor.whiteColor, @"Encore.Label");
+ if (late) follow.accessibilityLabel = nil;
[(UIControl *)follow addTarget:self action:@selector(toggleFollow:) forControlEvents:UIControlEventTouchUpInside];
glyph(box(row, MockButton.class, CGRectMake(148, 0, 48, 48), @"Components.UI.ContextMenuButton-7n2wHs1TKAczGzO7Dd2rGr"), @"ellipsis", 12);
glyph(box(row, MockButton.class, CGRectMake(278, 0, 48, 48), @"Components.UI.ShuffleButton"), @"shuffle", 12);
@@ -269,6 +281,19 @@ static NSArray<NSArray *> *musicList(void) {
[self.window makeKeyAndVisible];
+ // The photo and the follow state land after the header has laid out, and neither lays it out again.
+ if (late) {
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ followWord.text = @"Follow";
+ follow.accessibilityLabel = @"Follow";
+ NSLog(@"[harness] late: \"Follow\" is in Spotify's header now");
+ });
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ picture.image = photo();
+ NSLog(@"[harness] late: the photo is in Spotify's header now");
+ });
+ }
+
// What the Music list came to once every cell answered for itself and the dropped headings were asked
// again: each cell's kind and height, top to bottom.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
diff --git a/tweak/Sources/Redesigned/Album/AlbumHeader.x b/tweak/Sources/Redesigned/Album/AlbumHeader.x
index 4ed94ec4..16b1376b 100644
--- a/tweak/Sources/Redesigned/Album/AlbumHeader.x
+++ b/tweak/Sources/Redesigned/Album/AlbumHeader.x
@@ -36,7 +36,7 @@ static const CGFloat kDissolve = 0.46, kTopScrim = 140, kTopScrimAlpha = 0.28;
static const CGFloat kMinHero = 120, kMinCover = 80;
static char kHeaderKey, kCoverKey, kTitleKey, kParentKey, kMetaKey, kAddKey, kDownloadKey, kPlayKey, kShuffleKey;
-static char kHeroKey, kHeroHeightKey, kHeaderHeightKey, kInfoKey, kCoverWatchedKey, kHeaderWatchedKey, kRetryKey;
+static char kHeroKey, kHeroHeightKey, kHeaderHeightKey, kInfoKey, kHeaderWatchedKey, kRetryKey;
static char kExploreKey, kRowWatchedKey;
#pragma mark - moving Spotify's views
@@ -116,10 +116,14 @@ static void watch(UIView *view, const void *key, void (^laidOut)(UIView *view))
@interface SGRAlbumHero : UIView
@property (nonatomic, readonly) UIImageView *picture;
@property (nonatomic, copy) UIColor *fieldColor;
+// The cover in Spotify's artwork view, and every cover it puts there afterwards: the hero keeps itself
+// right, rather than being handed a picture on each of the header's passes and staying empty between them.
+- (void)followCover:(UIImageView *)source;
@end
@implementation SGRAlbumHero {
CAGradientLayer *_scrim, *_dissolve;
+ __weak UIImageView *_cover;
}
- (instancetype)initWithFrame:(CGRect)frame {
@@ -182,24 +186,45 @@ static void watch(UIView *view, const void *key, void (^laidOut)(UIView *view))
[CATransaction commit];
}
+- (void)followCover:(UIImageView *)source {
+ if (!source) return;
+ [self takeCover:source late:NO];
+ if (_cover == source) return;
+ _cover = source;
+ __weak SGRAlbumHero *weakSelf = self;
+ SGRObserveImage(source, ^(UIImageView *view) { [weakSelf takeCover:view late:YES]; });
+}
+
+// `late` is a cover that arrived after the header had laid out -- an album opened for the first time, whose
+// artwork is still being fetched while the page is already on screen. The log line says once that the watch,
+// and not one of the header's passes, is what filled the hero.
+- (void)takeCover:(UIImageView *)source late:(BOOL)late {
+ UIImage *image = source.image;
+ if (!image || source.bounds.size.width < kMinCover || _picture.image == image) return;
+ _picture.image = image;
+ // The page's field takes its colour from the same picture.
+ SGRAlbumSetArtwork(self, image);
+ static BOOL logged;
+ if (late && !logged) {
+ logged = YES;
+ SGLog(@"redesign album: the cover landed after the header had laid out; the hero took it");
+ }
+}
+
@end
-// The cover Spotify loaded, read from the image view of its artwork square.
+// The image view of Spotify's artwork square: the one with the cover in it, or, before the cover has been
+// fetched, the empty one it will land in, so it can be watched from the first pass.
static UIImageView *coverImageIn(UIView *cover) {
- __block UIImageView *found = nil;
+ __block UIImageView *found = nil, *empty = nil;
SGForEachView(cover, ^(UIView *v) {
if (found || ![v isKindOfClass:UIImageView.class]) return;
UIImageView *image = (UIImageView *)v;
- if (image.image && image.bounds.size.width >= kMinCover) found = image;
+ if (image.bounds.size.width < kMinCover) return;
+ if (image.image) found = image;
+ else if (!empty) empty = image;
});
- return found;
-}
-
-static void showCover(SGRAlbumHero *hero, UIImageView *view, UIView *header) {
- UIImage *image = view.image;
- if (!image || view.bounds.size.width < kMinCover) return;
- if (hero.picture.image != image) hero.picture.image = image;
- SGRAlbumSetArtwork(header, image);
+ return found ?: empty;
}
// The picture runs from the top of the header down past where its text begins, so the title and the artist
@@ -228,17 +253,7 @@ static void applyHero(UIView *header, UIView *cover, CGFloat bottom) {
setFrame(hero, CGRectMake(0, 0, header.bounds.size.width, height));
hero.fieldColor = SGRAlbumFieldColor(header);
- UIImageView *source = coverImageIn(cover);
- showCover(hero, source, header);
- // The cover loads after the header is laid out, and a new image lays nothing out again.
- if (source && !objc_getAssociatedObject(source, &kCoverWatchedKey)) {
- objc_setAssociatedObject(source, &kCoverWatchedKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- __weak SGRAlbumHero *weakHero = hero;
- __weak UIView *weakHeader = header;
- SGRObserveImage(source, ^(UIImageView *view) {
- if (weakHero && weakHeader) showCover(weakHero, view, weakHeader);
- });
- }
+ [hero followCover:coverImageIn(cover)];
conceal(cover);
}
diff --git a/tweak/Sources/Redesigned/Artist/ArtistHeader.x b/tweak/Sources/Redesigned/Artist/ArtistHeader.x
index 0afa298a..6fa6d022 100644
--- a/tweak/Sources/Redesigned/Artist/ArtistHeader.x
+++ b/tweak/Sources/Redesigned/Artist/ArtistHeader.x
@@ -39,7 +39,7 @@ static const CGFloat kMinCover = 80, kMinHero = 120;
// The collapsed ImageHeaderView, Spotify's navigation bar; the text fades out over the last kFade before it.
static const CGFloat kBar = 100, kFade = 150;
-static char kInfoKey, kHeroKey, kHeroHeightKey, kContainerHeightKey, kCoverWatchedKey, kRowWatchedKey;
+static char kInfoKey, kHeroKey, kHeroHeightKey, kContainerHeightKey, kRowWatchedKey;
static char kTitleKey, kMetaKey, kShuffleKey, kPlayKey, kFollowKey, kArtworkKey, kBarKey, kMoreKey, kMoreButtonKey;
// The back button's glass sits this far under the top of the safe area; more lines up with it.
@@ -90,10 +90,15 @@ static UIView *containerOf(UIView *header) {
@interface SGRArtistHero : UIView
@property (nonatomic, readonly) UIImageView *picture;
@property (nonatomic, copy) UIColor *fieldColor;
+// The photo in Spotify's artwork view, and every photo it puts there afterwards: the hero keeps itself
+// right, rather than being handed a picture on each of the header's passes and staying empty between them.
+// The same view again only re-reads it.
+- (void)followArtwork:(UIImageView *)source;
@end
@implementation SGRArtistHero {
CAGradientLayer *_scrim, *_dissolve;
+ __weak UIImageView *_artwork;
}
- (instancetype)initWithFrame:(CGRect)frame {
@@ -155,24 +160,46 @@ static UIView *containerOf(UIView *header) {
[CATransaction commit];
}
+- (void)followArtwork:(UIImageView *)source {
+ if (!source) return;
+ [self takeArtwork:source late:NO];
+ if (_artwork == source) return;
+ _artwork = source;
+ __weak SGRArtistHero *weakSelf = self;
+ SGRObserveImage(source, ^(UIImageView *view) { [weakSelf takeArtwork:view late:YES]; });
+}
+
+// `late` is a photo that arrived after the header had laid out -- the artist opened for the first time,
+// whose picture is still being fetched while the page is already on screen (issue #52). The log line says
+// once that the watch, and not one of the header's passes, is what filled the hero.
+- (void)takeArtwork:(UIImageView *)source late:(BOOL)late {
+ UIImage *image = source.image;
+ if (!image || _picture.image == image) return;
+ _picture.image = image;
+ // The page's field takes its colour from the same picture.
+ SGRArtistSetArtwork(self, image);
+ static BOOL logged;
+ if (late && !logged) {
+ logged = YES;
+ SGLog(@"redesign artist: the photo landed after the header had laid out; the hero took it");
+ }
+}
+
@end
-// The photo Spotify loaded, read from the image view of its artwork.
+// The image view of Spotify's artwork: the one with the photo in it, or, before the photo has been fetched,
+// the empty one it will land in, so it can be watched from the first pass. Either way one the size of the
+// picture, never a small placeholder glyph beside it.
static UIImageView *photoIn(UIView *artwork) {
- __block UIImageView *found = nil;
+ __block UIImageView *found = nil, *empty = nil;
SGForEachView(artwork, ^(UIView *v) {
if (found || ![v isKindOfClass:UIImageView.class]) return;
UIImageView *image = (UIImageView *)v;
- if (image.image && image.bounds.size.width >= kMinCover) found = image;
+ if (image.bounds.size.width < kMinCover) return;
+ if (image.image) found = image;
+ else if (!empty) empty = image;
});
- return found;
-}
-
-static void showPhoto(SGRArtistHero *hero, UIImageView *view, UIView *container) {
- UIImage *image = view.image;
- if (!image || view.bounds.size.width < kMinCover) return;
- if (hero.picture.image != image) hero.picture.image = image;
- SGRArtistSetArtwork(container, image);
+ return found ?: empty;
}
// The picture from the top of the container down to `bottom`, which comes from the container at rest and only
@@ -195,18 +222,7 @@ static void applyHero(UIView *container, UIView *artwork, CGFloat bottom) {
if (height < kMinHero) return;
setFrame(hero, CGRectMake(0, 0, container.bounds.size.width, height));
hero.fieldColor = SGRArtistFieldColor(container);
-
- UIImageView *source = photoIn(artwork);
- showPhoto(hero, source, container);
- // The photo loads after the header is laid out, and a new image lays nothing out again.
- if (source && !objc_getAssociatedObject(source, &kCoverWatchedKey)) {
- objc_setAssociatedObject(source, &kCoverWatchedKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- __weak SGRArtistHero *weakHero = hero;
- __weak UIView *weakContainer = container;
- SGRObserveImage(source, ^(UIImageView *view) {
- if (weakHero && weakContainer) showPhoto(weakHero, view, weakContainer);
- });
- }
+ [hero followArtwork:photoIn(artwork)];
}
#pragma mark - the header's pass
@@ -257,6 +273,7 @@ static void applyHeader(UIView *header) {
UIView *shuffle = SGRFindByIdentifier(header, @"Components.UI.ShuffleButton", &kShuffleKey);
UIView *play = SGRFindByIdentifier(header, @"header-play-button", &kPlayKey);
UIView *follow = SGRFindByIdentifier(header, @"Curation.FollowButtonElementKit.FollowButton", &kFollowKey);
+ NSString *word = firstText(follow);
[info showShuffle:shuffle play:play trailing:follow trailingFallback:[UIImage systemImageNamed:@"person.badge.plus"]
playColor:SGRArtistFieldColor(container)];
@@ -306,7 +323,7 @@ static void applyHeader(UIView *header) {
logged = YES;
SGLog(@"redesign artist: own block \"%@\", \"%@\"; shuffle %@, play %@, follow %@, more %@", name,
firstText(listeners) ?: @"no listeners", shuffle ? @"found" : @"missing", play ? @"found" : @"missing",
- follow ? firstText(follow) ?: @"found" : @"missing", more ? @"found" : @"missing");
+ follow ? word ?: @"found, no word yet" : @"missing", more ? @"found" : @"missing");
}
}
diff --git a/tweak/Sources/Redesigned/Kit/SGRActionRow.h b/tweak/Sources/Redesigned/Kit/SGRActionRow.h
index 4196051a..40f311d5 100644
--- a/tweak/Sources/Redesigned/Kit/SGRActionRow.h
+++ b/tweak/Sources/Redesigned/Kit/SGRActionRow.h
@@ -36,7 +36,8 @@
@property (nonatomic, strong) UIImage *fallbackGlyph;
// The word on Spotify's button instead of a glyph, in a glass capsule as wide as the word asks for: for a
// text button such as the artist's Follow, whose word is its state ("Follow", "Following") in the app's
-// language. Set before the first -feedFrom:.
+// language. Until Spotify's button has a word, the fallback glyph is drawn in the round shape instead. Set
+// before the first -feedFrom:.
@property (nonatomic) BOOL showsWord;
// The width the button wants: SGRActionHeight for a glyph, the word and its padding for a word.
- (CGFloat)sgr_width;
diff --git a/tweak/Sources/Redesigned/Kit/SGRActionRow.m b/tweak/Sources/Redesigned/Kit/SGRActionRow.m
index 71c78164..8a3b11ad 100644
--- a/tweak/Sources/Redesigned/Kit/SGRActionRow.m
+++ b/tweak/Sources/Redesigned/Kit/SGRActionRow.m
@@ -17,7 +17,7 @@ static const CGFloat kGlyphSide = 44, kCapsuleLead = 4, kCapsuleTrail = 20;
// The mirrored glyph, the size Spotify draws one inside a 48pt round button.
static const CGFloat kMirrorGlyph = 24;
-static char kCapsuleGlassKey, kMirrorGlassKey, kWordGlassKey, kGlyphWatchedKey;
+static char kCapsuleGlassKey, kMirrorGlassKey, kWordGlassKey;
// A word button's padding either side of the word.
static const CGFloat kWordPadding = 18;
@@ -66,6 +66,7 @@ static NSString *wordIn(UIView *button) {
@implementation SGRPlayCapsule {
UIImageView *_glyph;
UILabel *_title;
+ __weak UIImageView *_watchedGlyph;
}
- (instancetype)initWithFrame:(CGRect)frame {
@@ -145,9 +146,10 @@ static NSString *wordIn(UIView *button) {
NSStringFromClass(glyph.class), word);
});
}
- // Play becomes pause without the header laying out again.
- if (glyph && !objc_getAssociatedObject(glyph, &kGlyphWatchedKey)) {
- objc_setAssociatedObject(glyph, &kGlyphWatchedKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ // Play becomes pause without the header laying out again. Watched per glyph view rather than once for
+ // good, so a glyph Spotify hands to another button reports to the button it is in now.
+ if (glyph && glyph != _watchedGlyph) {
+ _watchedGlyph = glyph;
__weak SGRPlayCapsule *weakSelf = self;
__weak UIView *weakSource = source;
SGRObserveImage(glyph, ^(UIImageView *view) {
@@ -172,6 +174,15 @@ static NSString *wordIn(UIView *button) {
#pragma mark - a button standing in for Spotify's
+// The label a button shows its word in, whether it has a word in it yet or not.
+static UILabel *labelIn(UIView *button) {
+ __block UILabel *found = nil;
+ SGForEachView(button, ^(UIView *v) {
+ if (!found && [v isKindOfClass:UILabel.class]) found = (UILabel *)v;
+ });
+ return found;
+}
+
// The text a button shows: the first label under it with something in it.
static NSString *labelTextIn(UIView *button) {
__block NSString *text = nil;
@@ -186,6 +197,8 @@ static NSString *labelTextIn(UIView *button) {
@implementation SGRMirrorButton {
UIImageView *_glyph;
UILabel *_word;
+ __weak UILabel *_watchedWord;
+ __weak UIImageView *_watchedGlyph;
}
- (instancetype)initWithFrame:(CGRect)frame {
@@ -212,15 +225,22 @@ static NSString *labelTextIn(UIView *button) {
- (void)layoutSubviews {
[super layoutSubviews];
CGRect bounds = self.bounds;
+ // A word button waiting for its word draws the circle, and takes the capsule once the word is there:
+ // only one of the two shapes is asked for on a pass, so the other is put away rather than left under it.
if (self.showsWord && _word.text.length) {
SGRGlassCapsuleInside(self, &kWordGlassKey, bounds.size, NO);
+ ((UIView *)objc_getAssociatedObject(self, &kMirrorGlassKey)).hidden = YES;
[_word sizeToFit];
CGSize text = _word.bounds.size;
- _word.frame = CGRectMake(kWordPadding, round((bounds.size.height - text.height) / 2),
- MAX(0, bounds.size.width - 2 * kWordPadding), text.height);
+ // Given less width than the word asked for -- what is left of the row beside a wide Play -- the
+ // capsule spends its own padding on the word before it lets the word be cut ("Following").
+ CGFloat padding = MIN(kWordPadding, MAX(0, floor((bounds.size.width - text.width) / 2)));
+ _word.frame = CGRectMake(padding, round((bounds.size.height - text.height) / 2),
+ MAX(0, bounds.size.width - 2 * padding), text.height);
return;
}
SGRGlassInside(self, &kMirrorGlassKey, SGRGlassCircleSize);
+ ((UIView *)objc_getAssociatedObject(self, &kWordGlassKey)).hidden = YES;
_glyph.frame = CGRectMake(round((bounds.size.width - kMirrorGlyph) / 2), round((bounds.size.height - kMirrorGlyph) / 2),
kMirrorGlyph, kMirrorGlyph);
}
@@ -239,7 +259,6 @@ static NSString *labelTextIn(UIView *button) {
_word.font = SGRFont(UIFontTextStyleSubheadline, UIFontWeightSemibold, UIContentSizeCategoryExtraLarge);
_word.textColor = SGRPrimary();
[self addSubview:_word];
- _glyph.hidden = YES;
}
NSString *text = labelTextIn(source);
if (text && ![_word.text isEqualToString:text]) {
@@ -248,6 +267,30 @@ static NSString *labelTextIn(UIView *button) {
[self setNeedsLayout];
[self.superview setNeedsLayout];
}
+ // Spotify's word is its state, which it fills in a moment after the button itself is there and
+ // changes without laying out anything the page hears (the artist's Follow, issue #52). So the label
+ // it puts the word in is watched, and the button hears it land.
+ UILabel *source_word = labelIn(source);
+ if (source_word && source_word != _watchedWord) {
+ _watchedWord = source_word;
+ __weak SGRMirrorButton *weakSelf = self;
+ __weak UIView *weakSource = source;
+ SGRObserveText(source_word, ^(UILabel *label) {
+ if (weakSelf && weakSource) [weakSelf feedFrom:weakSource];
+ });
+ }
+ // Until the word is there the button is the glyph it falls back to, which says what it does, rather
+ // than an empty capsule.
+ BOOL hasWord = _word.text.length > 0;
+ if (_glyph.hidden != hasWord) {
+ _glyph.hidden = hasWord;
+ [self setNeedsLayout];
+ }
+ if (!hasWord && self.fallbackGlyph && _glyph.image != self.fallbackGlyph) {
+ _glyph.image = self.fallbackGlyph;
+ _glyph.tintColor = SGRPrimary();
+ }
+ if (!hasWord && !self.accessibilityLabel) self.accessibilityLabel = source.accessibilityLabel;
return;
}
@@ -261,8 +304,9 @@ static NSString *labelTextIn(UIView *button) {
_glyph.tintColor = SGRPrimary();
}
- if (glyph && !objc_getAssociatedObject(glyph, &kGlyphWatchedKey)) {
- objc_setAssociatedObject(glyph, &kGlyphWatchedKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ // As the capsule does: watched per glyph view, so a reused one reports where it is now.
+ if (glyph && glyph != _watchedGlyph) {
+ _watchedGlyph = glyph;
__weak SGRMirrorButton *weakSelf = self;
__weak UIView *weakSource = source;
SGRObserveImage(glyph, ^(UIImageView *view) {
@@ -281,7 +325,9 @@ static NSString *labelTextIn(UIView *button) {
- (void)sgr_tap {
fire(self.source);
- // A word is the button's state, and Spotify changes it without laying out anything the page hears.
+ // The word is watched where Spotify writes it, but a button that rebuilds its content on the state it
+ // just took writes the new word into a label the watch has never seen. So a tap, and only a tap, asks
+ // the button again a moment later, which also moves the watch onto whatever label it ended up with.
if (!self.showsWord) return;
__weak SGRMirrorButton *weakSelf = self;
for (NSNumber *delay in @[@0.3, @1.0]) {
diff --git a/tweak/Sources/Redesigned/Kit/SGRRestyle.h b/tweak/Sources/Redesigned/Kit/SGRRestyle.h
index bbe05a71..e7b11ae4 100644
--- a/tweak/Sources/Redesigned/Kit/SGRRestyle.h
+++ b/tweak/Sources/Redesigned/Kit/SGRRestyle.h
@@ -22,11 +22,20 @@ void SGRSuppress(UIView *view);
// setFont: by a runtime subclass of the instance, like SGRSuppress. Idempotent.
void SGRMonospacedDigits(UILabel *label);
-// `changed` after every setImage: on the image view, Spotify's included, for as long as the view lives, by a
-// runtime subclass of the instance like SGRSuppress. A second call replaces the block. NO when the view
-// cannot be subclassed (a KVO-observed instance): the caller then only sees what its own passes read.
+// `changed` after every setImage: on the image view, Spotify's included, for as long as the view lives: by a
+// runtime subclass of the instance like SGRSuppress, or, for one of Spotify's own classes (Encore's image
+// views, which no instance of can be subclassed), by an override on that class, which only ever reports the
+// instances that asked. A second call replaces the block. NO when neither took, which a log line says once:
+// the caller then only sees what its own passes read.
+//
+// This is how a picture that lands after a screen has been laid out reaches it: setting an image lays no
+// ancestor out, so nothing else tells the screen it is there.
BOOL SGRObserveImage(UIImageView *view, void (^changed)(UIImageView *view));
+// `changed` after every setText: and setAttributedText: on the label, the same way and with the same
+// answer: for a word of Spotify's that is a state it fills in later, such as the artist's Follow.
+BOOL SGRObserveText(UILabel *label, void (^changed)(UILabel *label));
+
// `laidOut` after every layoutSubviews of the view, Spotify's included, for as long as the view lives, by
// a runtime subclass of the instance like SGRSuppress. A second call replaces the block, and a pass started
// from inside the block is not reported again. NO when the view cannot be subclassed (one of Spotify's Swift
diff --git a/tweak/Sources/Redesigned/Kit/SGRRestyle.m b/tweak/Sources/Redesigned/Kit/SGRRestyle.m
index 197796af..09e5d66e 100644
--- a/tweak/Sources/Redesigned/Kit/SGRRestyle.m
+++ b/tweak/Sources/Redesigned/Kit/SGRRestyle.m
@@ -4,7 +4,7 @@
#import "SGRRestyle.h"
#import "SGRTokens.h"
-static char kPlateKey, kImageObserverKey, kLayoutObserverKey;
+static char kPlateKey, kImageObserverKey, kLayoutObserverKey, kTextObserverKey;
@interface SGRWeakBox : NSObject
@property (nonatomic, weak) id value;
@@ -52,6 +52,59 @@ static void addOverride(Class subclass, Class original, SEL selector, id block)
if (method) class_addMethod(subclass, selector, imp_implementationWithBlock(block), method_getTypeEncoding(method));
}
+#pragma mark - the class itself
+
+// What an instance of one of Spotify's own classes cannot have -- a subclass of its own -- the class every
+// instance of it shares can: the override goes on the class, the way each of the tweak's %hooks does. The
+// class is taken off the instance rather than named, since Encore's names carry a build hash that moves with
+// every Spotify release, and it is given the override once; an instance that never asked to be watched pays
+// one associated-object lookup for it.
+//
+// `make` is handed the implementation the override stands in front of and answers the block that replaces
+// it; that block must call the one it was given first. The implementation replaced is the class's own where
+// it has one -- so nothing above it in the hierarchy, UIKit's own classes included, is touched -- and the
+// inherited one where it does not.
+static BOOL overrideOnClass(Class cls, SEL selector, id (^make)(IMP replaced)) {
+ if (!cls || !selector) return NO;
+ // Never the class KVO made for one instance: it is swapped away again when the last observer goes, and
+ // the override with it. Everything else here is a class Spotify itself wrote.
+ if (strncmp(class_getName(cls), "NSKVONotifying_", 15) == 0) return NO;
+ // Done already? A class is an object too, and a selector is a pointer unique to its name, so the class
+ // carries its own mark per selector -- a plain lookup, since callers ask again on every pass they make.
+ if (objc_getAssociatedObject(cls, (void *)selector)) return YES;
+
+ Method inherited = class_getInstanceMethod(cls, selector);
+ if (!inherited) return NO;
+ Method own = nil;
+ unsigned int count = 0;
+ Method *methods = class_copyMethodList(cls, &count);
+ for (unsigned int i = 0; i < count; i++) {
+ if (method_getName(methods[i]) == selector) own = methods[i];
+ }
+ free(methods);
+ IMP replaced = own ? method_getImplementation(own)
+ : class_getMethodImplementation(class_getSuperclass(cls), selector);
+ if (!replaced) return NO;
+
+ IMP override = imp_implementationWithBlock(make(replaced));
+ if (own) method_setImplementation(own, override);
+ else if (!class_addMethod(cls, selector, override, method_getTypeEncoding(inherited))) return NO;
+ objc_setAssociatedObject(cls, (void *)selector, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ return YES;
+}
+
+// Said once per class: what could not be watched at all, and what had to be watched through its class.
+static void logWatch(UIView *view, SEL selector, BOOL kept, BOOL onClass) {
+ static NSMutableSet<NSString *> *logged;
+ if (!logged) logged = [NSMutableSet set];
+ NSString *name = NSStringFromClass(object_getClass(view));
+ NSString *mark = [NSString stringWithFormat:@"%@ %s", name, sel_getName(selector)];
+ if ([logged containsObject:mark]) return;
+ [logged addObject:mark];
+ if (!kept) SGLog(@"redesign kit: %@ cannot be watched for %s", name, sel_getName(selector));
+ else if (onClass) SGLog(@"redesign kit: %@ watched for %s through its class", name, sel_getName(selector));
+}
+
#pragma mark - views
void SGRSuppress(UIView *view) {
@@ -135,27 +188,69 @@ void SGRMonospacedDigits(UILabel *label) {
keepMonospaced(label, original);
}
+// Only the views that asked: everything else of the class carrying the override goes straight back out.
+static void reportImage(UIImageView *view) {
+ void (^block)(UIImageView *) = objc_getAssociatedObject(view, &kImageObserverKey);
+ if (block) block(view);
+}
+
BOOL SGRObserveImage(UIImageView *view, void (^changed)(UIImageView *view)) {
if (![view isKindOfClass:UIImageView.class]) return NO;
+ BOOL first = objc_getAssociatedObject(view, &kImageObserverKey) == nil;
objc_setAssociatedObject(view, &kImageObserverKey, changed, OBJC_ASSOCIATION_COPY_NONATOMIC);
BOOL kept = adopt(view, "SGRImageObserved_", ^(Class subclass, Class original) {
addOverride(subclass, original, @selector(setImage:), ^(UIImageView *self, UIImage *image) {
struct objc_super parent = {self, original};
((void (*)(struct objc_super *, SEL, id))objc_msgSendSuper)(&parent, @selector(setImage:), image);
- void (^block)(UIImageView *) = objc_getAssociatedObject(self, &kImageObserverKey);
- if (block) block(self);
+ reportImage(self);
});
});
+ // Encore's image views, which is what every picture Spotify loads arrives in, are Swift classes: no
+ // instance of one can be given a subclass of its own, so the class itself carries the override.
+ BOOL onClass = !kept && overrideOnClass(object_getClass(view), @selector(setImage:), ^id(IMP replaced) {
+ return ^(UIImageView *self, UIImage *image) {
+ ((void (*)(id, SEL, id))replaced)(self, @selector(setImage:), image);
+ reportImage(self);
+ };
+ });
+ if (first) logWatch(view, @selector(setImage:), kept || onClass, onClass);
+ return kept || onClass;
+}
+
+static void reportText(UILabel *label) {
+ void (^block)(UILabel *) = objc_getAssociatedObject(label, &kTextObserverKey);
+ if (block) block(label);
+}
+
+BOOL SGRObserveText(UILabel *label, void (^changed)(UILabel *label)) {
+ if (![label isKindOfClass:UILabel.class]) return NO;
+ BOOL first = objc_getAssociatedObject(label, &kTextObserverKey) == nil;
+ objc_setAssociatedObject(label, &kTextObserverKey, changed, OBJC_ASSOCIATION_COPY_NONATOMIC);
+ BOOL kept = adopt(label, "SGRTextObserved_", ^(Class subclass, Class original) {
+ for (NSString *name in @[@"setText:", @"setAttributedText:"]) {
+ SEL selector = NSSelectorFromString(name);
+ addOverride(subclass, original, selector, ^(UILabel *self, id value) {
+ struct objc_super parent = {self, original};
+ ((void (*)(struct objc_super *, SEL, id))objc_msgSendSuper)(&parent, selector, value);
+ reportText(self);
+ });
+ }
+ });
+ BOOL onClass = NO;
if (!kept) {
- static NSMutableSet<NSString *> *logged;
- if (!logged) logged = [NSMutableSet set];
- NSString *name = NSStringFromClass(object_getClass(view));
- if (![logged containsObject:name]) {
- [logged addObject:name];
- SGLog(@"redesign kit: %@ cannot be watched for its image", name);
+ Class cls = object_getClass(label);
+ for (NSString *name in @[@"setText:", @"setAttributedText:"]) {
+ SEL selector = NSSelectorFromString(name);
+ onClass |= overrideOnClass(cls, selector, ^id(IMP replaced) {
+ return ^(UILabel *self, id value) {
+ ((void (*)(id, SEL, id))replaced)(self, selector, value);
+ reportText(self);
+ };
+ });
}
}
- return kept;
+ if (first) logWatch(label, @selector(setText:), kept || onClass, onClass);
+ return kept || onClass;
}
// A pass the block itself sets off (a frame it moves) reaches layoutSubviews again before the block has
diff --git a/tweak/Sources/Redesigned/Playlist/PlaylistHeader.x b/tweak/Sources/Redesigned/Playlist/PlaylistHeader.x
index 96386db1..8ad60de8 100644
--- a/tweak/Sources/Redesigned/Playlist/PlaylistHeader.x
+++ b/tweak/Sources/Redesigned/Playlist/PlaylistHeader.x
@@ -42,7 +42,7 @@ static const CGFloat kMinHero = 120, kMinCover = 80;
static char kCoverKey, kMetaKey, kPlayKey, kLayoutKey, kToolbarKey, kScrimKey, kBarScrimKey;
static char kShuffleKey, kAddKey, kDownloadKey, kInfoKey, kBlockHeightKey, kBlockWatchedKey;
-static char kHeroKey, kHeroHeightKey, kCoverWatchedKey, kRowKey, kRowWatchedKey;
+static char kHeroKey, kHeroHeightKey, kRowKey, kRowWatchedKey;
#pragma mark - finding things
@@ -96,10 +96,14 @@ static UIView *firstOfClass(UIView *root, Class wanted) {
@property (nonatomic, readonly) UIImageView *picture;
@property (nonatomic, copy) UIColor *fieldColor;
@property (nonatomic) CGFloat coverPixels; // the widest copy of the artwork it has been shown
+// The cover in Spotify's artwork view, and every cover it puts there afterwards: the hero keeps itself
+// right, rather than being handed a picture on each of the header's passes and staying empty between them.
+- (void)followCover:(UIImageView *)source;
@end
@implementation SGRPlaylistHero {
CAGradientLayer *_scrim, *_dissolve;
+ __weak UIImageView *_cover;
}
- (instancetype)initWithFrame:(CGRect)frame {
@@ -163,30 +167,52 @@ static UIView *firstOfClass(UIView *root, Class wanted) {
[CATransaction commit];
}
-@end
-
-// The cover Spotify loaded, read from the image view of its artwork square.
-static UIImageView *coverImageIn(UIView *cover) {
- __block UIImageView *found = nil;
- SGForEachView(cover, ^(UIView *v) {
- if (found || ![v isKindOfClass:UIImageView.class]) return;
- UIImageView *image = (UIImageView *)v;
- if (image.image && image.bounds.size.width >= kMinCover) found = image;
- });
- return found;
+- (void)followCover:(UIImageView *)source {
+ if (!source) return;
+ [self takeCover:source late:NO];
+ if (_cover == source) return;
+ _cover = source;
+ __weak SGRPlaylistHero *weakSelf = self;
+ SGRObserveImage(source, ^(UIImageView *view) { [weakSelf takeCover:view late:YES]; });
}
// Spotify loads the artwork at the size the cover square is asking for, and the square shrinks as the
// header collapses: scrolled down it swapped a 105px copy in for the 254px one and the picture across the
// top of the page went soft with it (trees/continuous/2.txt, 2026-09-17). So a copy is taken only while the
// square is still at full size, which is the only time Spotify asks for one worth showing.
-static void showCover(SGRPlaylistHero *hero, UIImageView *view, UIView *layout) {
- UIImage *image = view.image;
- if (!image || view.bounds.size.width < kMinHero) return;
+//
+// `late` is a cover that arrived after the header had laid out -- a playlist opened for the first time,
+// whose artwork is still being fetched while the page is already on screen. The log line says once that the
+// watch, and not one of the header's passes, is what filled the hero.
+- (void)takeCover:(UIImageView *)source late:(BOOL)late {
+ UIImage *image = source.image;
+ if (!image || source.bounds.size.width < kMinHero || _picture.image == image) return;
+
+ self.coverPixels = image.size.width;
+ _picture.image = image;
+ // The page's field takes its colour from the same picture.
+ SGRPlaylistSetArtwork(self, image);
+ static BOOL logged;
+ if (late && !logged) {
+ logged = YES;
+ SGLog(@"redesign playlist: the cover landed after the header had laid out; the hero took it");
+ }
+}
+
+@end
- hero.coverPixels = image.size.width;
- if (hero.picture.image != image) hero.picture.image = image;
- SGRPlaylistSetArtwork(layout, image);
+// The image view of Spotify's artwork square: the one with the cover in it, or, before the cover has been
+// fetched, the empty one it will land in, so it can be watched from the first pass.
+static UIImageView *coverImageIn(UIView *cover) {
+ __block UIImageView *found = nil, *empty = nil;
+ SGForEachView(cover, ^(UIView *v) {
+ if (found || ![v isKindOfClass:UIImageView.class]) return;
+ UIImageView *image = (UIImageView *)v;
+ if (image.bounds.size.width < kMinCover) return;
+ if (image.image) found = image;
+ else if (!empty) empty = image;
+ });
+ return found ?: empty;
}
// The hero belongs in the plane Spotify's own colour wash is drawn on: that plane keeps its full height and
@@ -241,17 +267,7 @@ static void applyHero(UIView *layout, UIView *cover, UIView *plane, UIView *bloc
if (!CGRectEqualToRect(hero.frame, frame)) hero.frame = frame;
hero.fieldColor = SGRPlaylistFieldColor(layout);
- UIImageView *source = coverImageIn(cover);
- showCover(hero, source, layout);
- // The cover loads after the header is laid out, and a new image lays nothing out again.
- if (source && !objc_getAssociatedObject(source, &kCoverWatchedKey)) {
- objc_setAssociatedObject(source, &kCoverWatchedKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- __weak SGRPlaylistHero *weakHero = hero;
- __weak UIView *weakLayout = layout;
- SGRObserveImage(source, ^(UIImageView *view) {
- if (weakHero && weakLayout) showCover(weakHero, view, weakLayout);
- });
- }
+ [hero followCover:coverImageIn(cover)];
conceal(cover);
}
@@ -408,7 +424,6 @@ static SGRHeaderInfo *applyInfo(UIView *block, UIView *headerRoot, UIViewControl
return info;
}
-
#pragma mark - the header's pass
// Find on this page and Sort sit in a header view of their own above the cover, invisible until the page is
@@ -516,7 +531,6 @@ static void applyHeader(UIView *layout) {
if (cover) applyHero(layout, cover, plane, block, reach);
}
-
// The content layout of the page `root` belongs to, kept weakly on it: the header lays out on every step of
// its collapse and a walk of its tree each time would be the redesign's own cost.
static UIView *layoutIn(UIView *root) {