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

feat: the redesigned artist page shows logos from Apple Music

My-Name-Is-Jeff2e1e25242ba4
diff --git a/tweak/Sources/Redesigned/Artist/ArtistHeader.x b/tweak/Sources/Redesigned/Artist/ArtistHeader.x
index 4a3389e2..0351ed80 100644
--- a/tweak/Sources/Redesigned/Artist/ArtistHeader.x
+++ b/tweak/Sources/Redesigned/Artist/ArtistHeader.x
@@ -28,6 +28,7 @@
// (SGRPinnedMore) draws and fires it from the top trailing corner of the page, level with the back button.
#import "Core/SGCore.h"
#import "Redesigned/Kit/SGRKit.h"
+#import "Shared/AnimatedArtwork/AnimatedArtwork.h"
#import "Artist.h"
// How much of the photo's height the dissolve into the field covers, and the scrim over the top of it that
@@ -62,6 +63,23 @@ static NSString *trimmed(NSString *text) {
return clean.length ? clean : nil;
}
+static char kLogoNameKey;
+
+// Apple Music's logo for the artist in place of the name, where Apple Music has one. Asked once per name;
+// the catalog remembers the answer for the launch.
+static void showLogo(SGRHeaderInfo *info, NSString *name) {
+ if (!name.length || [objc_getAssociatedObject(info, &kLogoNameKey) isEqualToString:name]) return;
+ objc_setAssociatedObject(info, &kLogoNameKey, name, OBJC_ASSOCIATION_COPY_NONATOMIC);
+ __weak SGRHeaderInfo *weakInfo = info;
+ CGFloat pixels = UIScreen.mainScreen.bounds.size.width * UIScreen.mainScreen.scale;
+ SGMotionArtistLogo(name, pixels, ^(UIImage *logo) {
+ SGRHeaderInfo *shown = weakInfo;
+ if (!shown || ![objc_getAssociatedObject(shown, &kLogoNameKey) isEqualToString:name]) return;
+ [shown showTitleImage:logo];
+ if (logo) SGLog(@"redesign artist: Apple Music's logo for %@", name);
+ });
+}
+
static NSString *firstText(UIView *root) {
__block NSString *found = nil;
SGForEachView(root, ^(UIView *v) {
@@ -274,6 +292,7 @@ static void applyHeader(UIView *header) {
UIView *listeners = SGRFindByIdentifier(header, @"Components.Header.UI.Metadata", &kMetaKey);
NSString *name = firstText(title) ?: firstText(bar);
[info showTitle:name creator:nil length:firstText(listeners) about:nil];
+ showLogo(info, name);
UIView *shuffle = SGRFindByIdentifier(header, @"Components.UI.ShuffleButton", &kShuffleKey);
UIView *play = SGRFindByIdentifier(header, @"header-play-button", &kPlayKey);
diff --git a/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.h b/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.h
index 09ddcf57..050588a6 100644
--- a/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.h
+++ b/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.h
@@ -38,6 +38,9 @@ extern const CGFloat SGRHeaderInfoTitleRise; // 56, of the content over the pic
// has no image to copy. `playColor` is the colour of the capsule's glyph and word.
- (void)showShuffle:(UIView *)shuffle play:(UIView *)play trailing:(UIView *)trailing
trailingFallback:(UIImage *)trailingFallback playColor:(UIColor *)playColor;
+// A picture drawn in the title's place, such as an artist's logo; the title stays its spoken name. nil
+// draws the title again.
+- (void)showTitleImage:(UIImage *)image;
// The height the content wants at `width`, from the top of the title to the bottom of the description.
- (CGFloat)contentHeightForWidth:(CGFloat)width;
@end
diff --git a/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.m b/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.m
index fc61b822..2aa63228 100644
--- a/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.m
+++ b/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.m
@@ -31,8 +31,12 @@ static BOOL setText(UILabel *label, NSString *text) {
return YES;
}
+// The most a title picture takes: a share of the text's width, and a height near three lines of the title.
+static const CGFloat kLogoWidthShare = 0.8, kLogoMaxHeight = 64;
+
@implementation SGRHeaderInfo {
UILabel *_title, *_creator, *_length, *_about;
+ UIImageView *_logo;
SGRMirrorButton *_shuffle, *_trailing;
SGRPlayCapsule *_play;
__weak UIView *_creatorLink;
@@ -76,6 +80,31 @@ static BOOL setText(UILabel *label, NSString *text) {
return hit;
}
+- (void)showTitleImage:(UIImage *)image {
+ if (_logo.image == image) return;
+ if (!_logo) {
+ _logo = [UIImageView new];
+ _logo.contentMode = UIViewContentModeScaleAspectFit;
+ _logo.isAccessibilityElement = YES;
+ _logo.accessibilityTraits = UIAccessibilityTraitHeader;
+ [self addSubview:_logo];
+ }
+ _logo.image = image;
+ _logo.hidden = image == nil;
+ _title.alpha = image ? 0 : 1;
+ _title.accessibilityElementsHidden = image != nil;
+ [self setNeedsLayout];
+}
+
+// The title's line: the picture's fitted height where there is a picture, the label's otherwise.
+- (CGSize)sgr_sizeOf:(UILabel *)label width:(CGFloat)text {
+ if (label != _title || !_logo.image) return [label sizeThatFits:CGSizeMake(text, CGFLOAT_MAX)];
+ CGSize image = _logo.image.size;
+ if (image.width <= 0 || image.height <= 0) return CGSizeZero;
+ CGFloat scale = MIN(text * kLogoWidthShare / image.width, kLogoMaxHeight / image.height);
+ return CGSizeMake(round(image.width * scale), round(image.height * scale));
+}
+
- (BOOL)showTitle:(NSString *)title creator:(NSString *)creator length:(NSString *)length about:(NSString *)about {
BOOL changed = NO;
changed |= setText(_title, title);
@@ -151,7 +180,7 @@ static BOOL setText(UILabel *label, NSString *text) {
for (UILabel *label in @[_title, _creator, _length]) {
if (label.hidden) continue;
if (previous) height += previous == _creator ? 4 : 2;
- height += ceil([label sizeThatFits:CGSizeMake(text, CGFLOAT_MAX)].height);
+ height += ceil([self sgr_sizeOf:label width:text].height);
previous = label;
}
if (previous) height += kRowAbove;
@@ -169,8 +198,13 @@ static BOOL setText(UILabel *label, NSString *text) {
for (UILabel *label in @[_title, _creator, _length]) {
if (label.hidden) continue;
if (previous) y += previous == _creator ? 4 : 2;
- CGFloat height = ceil([label sizeThatFits:CGSizeMake(text, CGFLOAT_MAX)].height);
+ CGSize size = [self sgr_sizeOf:label width:text];
+ CGFloat height = ceil(size.height);
label.frame = CGRectMake(kSide, y, text, height);
+ if (label == _title && _logo.image) {
+ _logo.frame = CGRectMake(round((width - size.width) / 2), y, size.width, height);
+ _logo.accessibilityLabel = _title.text;
+ }
y += height;
previous = label;
}