Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: a Full bleed covers switch for album and playlist pages (#123)
My-Name-Is-Jeff88fd0ea3ac77
diff --git a/tweak/Sources/Redesigned/Album/AlbumField.x b/tweak/Sources/Redesigned/Album/AlbumField.xindex 58bafe8e..94c41018 100644--- a/tweak/Sources/Redesigned/Album/AlbumField.x+++ b/tweak/Sources/Redesigned/Album/AlbumField.x@@ -198,7 +198,8 @@ static void clearCards(UIView *cell) {@"ios-album-albumfeatureproperties-impl.share_in_action_row_enabled": @NO,// A row is a title and its artists. The video badge is neither.@"ios-creativeworkcommons-retrievalrow-impl.track_video_indicator_enabled": @NO,- // Spotify's cover square is concealed on both pages this covers, so there is nothing left to tilt.+ // On the album page Spotify's cover square is always concealed, the redesign drawing its own; on the playlist+ // page it is too unless Full bleed covers is off, and then it stays square and still, as in the Music app.@"ios-creativeworkcommons-cover-art-tilt-configuration-kit.album_playlist_and_podcast_pages_enabled": @NO,});if (!SGRedesignedUI()) return;diff --git a/tweak/Sources/Redesigned/Album/AlbumHeader.x b/tweak/Sources/Redesigned/Album/AlbumHeader.xindex f1e00825..94eb7416 100644--- a/tweak/Sources/Redesigned/Album/AlbumHeader.x+++ b/tweak/Sources/Redesigned/Album/AlbumHeader.x@@ -36,6 +36,9 @@ static const CGFloat kDissolve = 0.46, kTopScrim = 140, kTopScrimAlpha = 0.28;// A header whose text begins nearer the top than this is one mid load, not one to measure the hero from;// and an artwork view narrower than this is a placeholder glyph rather than the cover.static const CGFloat kMinHero = 120, kMinCover = 80;+// The square cover's corners with Full bleed covers off: Spotify's own (its ImageViewHolder, r=4), so the album's+// square is the playlist's, which is Spotify's square left in place.+static const CGFloat kSquareRadius = 4;static char kHeaderKey, kCoverKey, kTitleKey, kParentKey, kMetaKey, kAddKey, kDownloadKey, kPlayKey, kShuffleKey;static char kHeroKey, kHeroHeightKey, kHeaderHeightKey, kInfoKey, kHeaderWatchedKey, kRetryKey;@@ -118,15 +121,22 @@ 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;+// Where Spotify lays its cover square out, in the hero's coordinates. With Full bleed covers off the picture is+// drawn there instead, on the field with neither gradient, until an animated cover fills the hero over it.+@property (nonatomic) CGRect square;// The cover in Spotify's artwork view, and every cover it puts there afterward: 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;// Apple Music's animated cover over the picture, where the album has one. The same album again is a no-op.- (void)playMotionForArtist:(NSString *)artist album:(NSString *)album;+// The square's shadow, copied off whichever layer under Spotify's concealed cover casts one (its ShadowContainer),+// so the album's square has the shadow the playlist's -- Spotify's own square -- does. Once found, a no-op.+- (void)takeShadowFrom:(UIView *)cover;@end@implementation SGRAlbumHero {CAGradientLayer *_scrim, *_dissolve;+ CALayer *_shadow; // under the square, which clips and so cannot cast its own__weak UIImageView *_cover;UIView *_extension; // iOS 26's UIBackgroundExtensionView around the picture, nil before itNSString *_motionAlbum;@@ -165,6 +175,11 @@ static void *kReadyContext = &kReadyContext;_scrim.colors = @[(id)[UIColor colorWithWhite:0 alpha:kTopScrimAlpha].CGColor, (id)UIColor.clearColor.CGColor];[self.layer addSublayer:_scrim];+ // At the bottom, under the picture's layer.+ _shadow = [CALayer layer];+ _shadow.hidden = YES;+ [self.layer insertSublayer:_shadow atIndex:0];+_dissolve = [CAGradientLayer layer];_dissolve.zPosition = 2;[self.layer addSublayer:_dissolve];@@ -203,15 +218,41 @@ static void *kReadyContext = &kReadyContext;[CATransaction commit];}+- (void)setSquare:(CGRect)square {+ if (CGRectEqualToRect(_square, square)) return;+ _square = square;+ // A path, so the shadow is drawn from it rather than from an offscreen pass over the layer every frame.+ [CATransaction begin];+ [CATransaction setDisableActions:YES];+ _shadow.frame = square;+ _shadow.shadowPath = [UIBezierPath bezierPathWithRoundedRect:_shadow.bounds cornerRadius:kSquareRadius].CGPath;+ [CATransaction commit];+ [self setNeedsLayout];+}+- (void)layoutSubviews {[super layoutSubviews];CGRect bounds = self.bounds;[CATransaction begin];[CATransaction setDisableActions:YES];- if (_extension) {- _extension.frame = bounds;- CGFloat side = MIN(bounds.size.width, bounds.size.height);- _picture.frame = CGRectMake(0, 0, bounds.size.width, side);+ if (SGRFullBleedCovers()) {+ if (_extension) {+ _extension.frame = bounds;+ CGFloat side = MIN(bounds.size.width, bounds.size.height);+ _picture.frame = CGRectMake(0, 0, bounds.size.width, side);+ }+ } else {+ // Stays square under an animated cover too: the clip covers the whole hero, so nothing moves under its fade.+ UIView *holder = _extension ?: _picture;+ holder.frame = _square;+ holder.layer.cornerRadius = kSquareRadius;+ holder.layer.cornerCurve = kCACornerCurveContinuous;+ holder.clipsToBounds = YES;+ if (_extension) _picture.frame = _extension.bounds;+ BOOL bleeds = _motion.opacity == 1;+ _shadow.hidden = bleeds;+ _scrim.hidden = !bleeds;+ _dissolve.hidden = !bleeds;}_motion.frame = bounds;_scrim.frame = CGRectMake(0, 0, bounds.size.width, MIN(kTopScrim, bounds.size.height));@@ -262,6 +303,8 @@ static void *kReadyContext = &kReadyContext;[_motion removeObserver:self forKeyPath:@"readyForDisplay" context:kReadyContext];[_motion removeFromSuperlayer];_motion = nil;+ // A square cover's gradients and shadow follow whether a clip covers it.+ if (!SGRFullBleedCovers()) [self setNeedsLayout];}- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {@@ -280,13 +323,17 @@ static void *kReadyContext = &kReadyContext;[CATransaction begin];[CATransaction setDisableActions:YES];layer.opacity = 1;+ // A square cover's hero has no gradients until the clip fills it; they come in with it.+ NSArray<CALayer *> *fading = SGRFullBleedCovers() ? @[layer] : @[layer, _scrim, _dissolve];+ _scrim.hidden = NO;+ _dissolve.hidden = NO;if (self.window) {CABasicAnimation *fade = [CABasicAnimation animationWithKeyPath:@"opacity"];fade.fromValue = @0;fade.toValue = @1;fade.duration = 0.2;fade.timingFunction = [CAMediaTimingFunction functionWithControlPoints:0.23 :1 :0.32 :1];- [layer addAnimation:fade forKey:@"fade"];+ for (CALayer *each in fading) [each addAnimation:fade forKey:@"fade"];}[CATransaction commit];}@@ -312,6 +359,25 @@ static void *kReadyContext = &kReadyContext;[self sgr_updateMotion];}+- (void)takeShadowFrom:(UIView *)cover {+ if (_shadow.shadowOpacity > 0) return;+ __block CALayer *found = nil;+ SGForEachView(cover, ^(UIView *v) {+ if (!found && v.layer.shadowOpacity > 0) found = v.layer;+ });+ if (!found) return;+ [CATransaction begin];+ [CATransaction setDisableActions:YES];+ _shadow.shadowColor = found.shadowColor;+ _shadow.shadowOpacity = found.shadowOpacity;+ _shadow.shadowRadius = found.shadowRadius;+ _shadow.shadowOffset = found.shadowOffset;+ [CATransaction commit];+ SGLog(@"redesign album: square shadow from %@, opacity %.2f radius %.1f offset %@", NSStringFromClass(found.delegate.class),+ found.shadowOpacity, found.shadowRadius, NSStringFromCGSize(found.shadowOffset));+ [self setNeedsLayout];+}+- (void)followCover:(UIImageView *)source {if (!source) return;[self takeCover:source late:NO];@@ -378,7 +444,15 @@ static void applyHero(UIView *header, UIView *cover, CGFloat bottom) {if (height < kMinHero) return;setFrame(hero, CGRectMake(0, 0, header.bounds.size.width, height));hero.fieldColor = SGRAlbumFieldColor(header);-+ // Spotify's square at full size, in the header's coordinates, which are the hero's: grow-only like the height,+ // so the square stays put while the header fades and collapses. Its bottom too, since the cover can reach its+ // full size before the header's top inset is in.+ if (!SGRFullBleedCovers()) {+ CGRect square = [cover convertRect:cover.bounds toView:header];+ if (square.size.width >= kMinCover && (square.size.width > hero.square.size.width + 0.5+ || CGRectGetMaxY(square) > CGRectGetMaxY(hero.square) + 0.5)) hero.square = square;+ [hero takeShadowFrom:cover];+ }[hero followCover:coverImageIn(cover)];conceal(cover);}diff --git a/tweak/Sources/Redesigned/Kit/SGRAppearanceSettings.m b/tweak/Sources/Redesigned/Kit/SGRAppearanceSettings.mindex ef376eab..9740d343 100644--- a/tweak/Sources/Redesigned/Kit/SGRAppearanceSettings.m+++ b/tweak/Sources/Redesigned/Kit/SGRAppearanceSettings.m@@ -2,6 +2,7 @@#import "Settings/SGModPage.h"#import "Settings/SGPageStyle.h"#import "SGRAccent.h"+#import "SGRHeaderInfo.h"// The preset is read off the color stored, so the hooks keep the one key they read and a color set before// presets existed stays in effect: Apple Music's red reads as Apple Music, Spotify's own (-1) as Spotify, and@@ -40,5 +41,7 @@ NSArray<SGModRow *> *SGRAppearanceRows(void) {SGWithSymbol(menu, @"paintpalette"),SGWithSymbol(colour, @"eyedropper"),SGWithSymbol(SGOptionRow(@"Plain checkmark", @"A saved song's tick without its circle, in the accent", SGRKeyPlainCheck), @"checkmark"),+ SGWithSymbol(SGSwitchRow(@"Full bleed covers", @"Album and playlist covers across the top. Off, a square cover; "+ @"an animated cover still fills the top", SGRKeyFullBleedCovers), @"photo"),];}diff --git a/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.h b/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.hindex 667a68a2..73c0c44c 100644--- a/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.h+++ b/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.h@@ -20,6 +20,12 @@extern const CGFloat SGRHeaderInfoBottom; // 14, under the contentextern const CGFloat SGRHeaderInfoTitleRise; // 56, of the content over the picture+// Full bleed covers (issue #98): the album's and the playlist's cover across the top of the page. Off, the cover+// is the square Spotify lays out above the title, and only an album's animated cover still runs full bleed. On+// until switched off (Appearance), read once, by the first album or playlist header.+#define SGRKeyFullBleedCovers @"spotifyglass.redesign.fullBleedCovers"+BOOL SGRFullBleedCovers(void);+@interface SGRHeaderInfo : UIView// YES when anything shown changed. nil or empty hides that line.- (BOOL)showTitle:(NSString *)title creator:(NSString *)creator length:(NSString *)length about:(NSString *)about;diff --git a/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.m b/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.mindex 19727915..e4b606e3 100644--- a/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.m+++ b/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.m@@ -9,6 +9,13 @@const CGFloat SGRHeaderInfoBottom = 14;const CGFloat SGRHeaderInfoTitleRise = 56;+BOOL SGRFullBleedCovers(void) {+ static BOOL on;+ static dispatch_once_t once;+ dispatch_once(&once, ^{ on = SGEnabled(SGRKeyFullBleedCovers); });+ return on;+}+// The text kSide in from the edges; Play at least kPlayWidth wide, the Music app's; the gaps between.static const CGFloat kSide = 20, kPlayWidth = 148, kRowSpacing = 16, kRowAbove = 16, kAboutAbove = 14;diff --git a/tweak/Sources/Redesigned/Playlist/PlaylistHeader.x b/tweak/Sources/Redesigned/Playlist/PlaylistHeader.xindex aab2438b..86e1d12e 100644--- a/tweak/Sources/Redesigned/Playlist/PlaylistHeader.x+++ b/tweak/Sources/Redesigned/Playlist/PlaylistHeader.x@@ -236,6 +236,12 @@ static void applyHero(UIView *layout, UIView *cover, UIView *plane, UIView *blocif (!CGRectEqualToRect(hero.frame, frame)) hero.frame = frame;[hero followCover:coverImageIn(cover)];+ // Full bleed covers off: Spotify's own square stays above the block, shrinking as the header collapses, and the+ // hero only reads the picture for the field. A mix's picture is full bleed in Spotify's own layout, so it stays.+ if (!SGRFullBleedCovers() && [cover.accessibilityIdentifier isEqualToString:@"Components.Header.UI.ArtworkImage"]) {+ hero.hidden = YES;+ return;+ }conceal(cover);}