Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix(album): stretch the header artwork on overscroll instead of leaving a gap (#169) (#176)
My-Name-Is-Jeff21d46863ce5a
diff --git a/tweak/Sources/Redesigned/Album/AlbumHeader.x b/tweak/Sources/Redesigned/Album/AlbumHeader.xindex 764f436a..b69dba2c 100644--- a/tweak/Sources/Redesigned/Album/AlbumHeader.x+++ b/tweak/Sources/Redesigned/Album/AlbumHeader.x@@ -1,7 +1,8 @@// Album redesign: the header the Music app gives an album (iOS 26.4), the same one the playlist redesign// gives a playlist. The cover runs full bleed across the top of the page and dissolves into the page's-// color; the title, the artist and the kind and date are centered on the bottom of that dissolve; and under-// them one row -- shuffle, a white Play capsule, and add.+// field, stretching when the page is pulled down (the Kit's SGRStretchHero); the title, the artist and the+// kind and date are centered on the bottom of that dissolve; and under them one row -- shuffle, a white Play+// capsule, and add.//// Tree (trees/clean/album/01.txt:39-152). The header is one element of the page's scrolling stack,// id=CreativeWorkPlatform.Components.UI.CreativeWorkHeader, a plain UIView whose height the element framework@@ -30,9 +31,7 @@#import "Shared/AnimatedArtwork/AnimatedArtwork.h"#import "Album.h"-// How much of the cover's height the dissolve into the field covers, and the scrim over the top of it that-// keeps the status bar and the back button legible on a bright picture. The playlist's numbers: one page.-static const CGFloat kDissolve = 0.46, kTopScrim = 140, kTopScrimAlpha = 0.28;+// The dissolve and the scrim are the Kit's stretching hero's (SGRStretchHero.h), the playlist's numbers.// 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;@@ -115,14 +114,19 @@ static void watch(UIView *view, const void *key, void (^laidOut)(UIView *view))#pragma mark - the cover, full bleed-// The picture across the top of the page with the field showing through the bottom of it. Two gradients-// rather than a mask or a blur: a scrim over the top for the status bar, and under it a fade from the-// picture to the very color the page's field is drawing, so the two meet with nothing to see.-@interface SGRAlbumHero : UIView+// The picture across the top of the page with the field showing through the bottom of it: the Kit's stretching+// hero (SGRStretchHero.h), whose bottom is masked away as the playlist's is, under a scrim for the status bar.+// Pulled down past the top, it grows upward by as much, so the picture stays one piece with the text and the+// list under it and zooms in, as the Music app's does, rather than sliding down and leaving the field showing+// above it (issue #169).+//+// Here the hero adds the cover square with Full bleed covers off, its shadow, and Apple Music's animated cover,+// which goes in the hero's masked content over the picture and so dissolves with it.+@interface SGRAlbumHero : SGRStretchHero@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.+// Where Spotify lays its cover square out, in the hero's coordinates at rest. With Full bleed covers off the+// picture is drawn there instead, on the field with no scrim and no mask, 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.@@ -135,8 +139,7 @@ static void watch(UIView *view, const void *key, void (^laidOut)(UIView *view))@end@implementation SGRAlbumHero {- CAGradientLayer *_scrim, *_dissolve;- CALayer *_shadow; // under the square, which clips and so cannot cast its own+ CALayer *_shadow; // under the square, which clips and so cannot cast its own; beside the masked content__weak UIImageView *_cover;UIView *_extension; // iOS 26's UIBackgroundExtensionView around the picture, nil before itNSString *_motionAlbum;@@ -145,17 +148,13 @@ static void watch(UIView *view, const void *key, void (^laidOut)(UIView *view))AVPlayerLooper *_looper;BOOL _motionOn; // what the player was last asked, so a scroll's steps ask it nothing againBOOL _motionSeen; // whether the hero was on screen when the player was last asked- __weak UIScrollView *_list; // the page's list, watched for the hero scrolling off the screen and back}static void *kReadyContext = &kReadyContext;-static void *kListContext = &kListContext;- (instancetype)initWithFrame:(CGRect)frame {if (!(self = [super initWithFrame:frame])) return nil;- self.userInteractionEnabled = NO;- self.accessibilityElementsHidden = YES;- self.clipsToBounds = YES;+ self.logName = @"album";_picture = [[UIImageView alloc] initWithFrame:self.bounds];_picture.contentMode = UIViewContentModeScaleAspectFill;@@ -168,29 +167,18 @@ static void *kListContext = &kListContext;_extension = [[extension alloc] initWithFrame:self.bounds];[_extension setValue:@NO forKey:@"automaticallyPlacesContentView"];[_extension setValue:_picture forKey:@"contentView"];- [self addSubview:_extension];+ [self.content addSubview:_extension];} else {_picture.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;- [self addSubview:_picture];+ [self.content addSubview:_picture];}- _scrim = [CAGradientLayer layer];- _scrim.zPosition = 1;- _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.+ // At the bottom, under the content's layer._shadow = [CALayer layer];_shadow.hidden = YES;[self.layer insertSublayer:_shadow atIndex:0];- _dissolve = [CAGradientLayer layer];- _dissolve.zPosition = 2;- [self.layer addSublayer:_dissolve];- self.fieldColor = SGRNeutralField();- // The color is read off the main thread, so it can land after the last layout pass of the page.NSNotificationCenter *center = NSNotificationCenter.defaultCenter;- [center addObserver:self selector:@selector(sgr_fieldColorDidChange) name:SGRFieldColorDidChangeNotification object:nil];for (NSNotificationName name in @[UIApplicationDidBecomeActiveNotification, UIApplicationWillResignActiveNotification,NSProcessInfoPowerStateDidChangeNotification, UIAccessibilityReduceMotionStatusDidChangeNotification,UIAccessibilityVideoAutoplayStatusDidChangeNotification]) {@@ -201,68 +189,53 @@ static void *kListContext = &kListContext;- (void)dealloc {[NSNotificationCenter.defaultCenter removeObserver:self];- [_list removeObserver:self forKeyPath:@"contentOffset" context:kListContext];[self sgr_dropMotion];}-- (void)sgr_fieldColorDidChange {- if (self.superview) self.fieldColor = SGRAlbumFieldColor(self);-}--- (void)setFieldColor:(UIColor *)color {- if (!color || [_fieldColor isEqual:color]) return;- _fieldColor = [color copy];- // The clear end is the same color with no alpha rather than +clearColor, so the fade keeps its hue- // instead of going through gray.- [CATransaction begin];- [CATransaction setDisableActions:YES];- _dissolve.colors = @[(id)[color colorWithAlphaComponent:0].CGColor,- (id)[color colorWithAlphaComponent:0.72].CGColor,- (id)color.CGColor];- _dissolve.locations = @[@0, @0.62, @1];- [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];+ // A path, so the shadow is drawn from it rather than from an offscreen pass over the layer every frame. In the+ // layer's own coordinates, so it holds wherever -layoutSubviews puts the layer.+ _shadow.shadowPath = [UIBezierPath bezierPathWithRoundedRect:(CGRect){CGPointZero, square.size} cornerRadius:kSquareRadius].CGPath;[self setNeedsLayout];}- (void)layoutSubviews {+ // A square cover's mask follows whether a clip covers the whole hero: the square itself reaches into the+ // dissolve, so only a clip is masked. Set before the Kit lays the content out, so both land in one pass.+ BOOL full = SGRFullBleedCovers(), bleeds = _motion.opacity == 1;+ self.dissolves = full || bleeds;[super layoutSubviews];CGRect bounds = self.bounds;+ if (bounds.size.height < 1) return;+ // Pulled down, the hero is `stretch` taller than at rest and as much higher in the header, so what sits on+ // the content -- the square, the picture's bottom -- is placed from the rest height and moved down by the+ // stretch, and the picture over it grows by the same.+ CGFloat stretch = self.stretch, rest = bounds.size.height - stretch;[CATransaction begin];[CATransaction setDisableActions:YES];- if (SGRFullBleedCovers()) {+ if (full) {if (_extension) {_extension.frame = bounds;- CGFloat side = MIN(bounds.size.width, bounds.size.height);- _picture.frame = CGRectMake(0, 0, bounds.size.width, side);+ // Scaled about its middle by as much as its bottom moves down: zoomed in, never cut off.+ CGFloat side = MIN(bounds.size.width, rest), width = bounds.size.width * (side + stretch) / side;+ _picture.frame = CGRectMake((bounds.size.width - width) / 2, 0, width, side + stretch);}} else {// Stays square under an animated cover too: the clip covers the whole hero, so nothing moves under its fade.+ CGRect square = CGRectOffset(_square, 0, stretch);UIView *holder = _extension ?: _picture;- holder.frame = _square;+ 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.frame = square;_shadow.hidden = bleeds;- _scrim.hidden = !bleeds;- _dissolve.hidden = !bleeds;+ self.scrim.hidden = !bleeds;}_motion.frame = bounds;- _scrim.frame = CGRectMake(0, 0, bounds.size.width, MIN(kTopScrim, bounds.size.height));- CGFloat fade = round(bounds.size.height * kDissolve);- _dissolve.frame = CGRectMake(0, bounds.size.height - fade, bounds.size.width, fade);[CATransaction commit];}@@ -281,9 +254,9 @@ static void *kListContext = &kListContext;});}-// Muted and looping, over the picture and under the two gradients. The picture stays under it until the-// first frame is decoded, and only then does the clip fade in: a fade started at once was spent on a layer-// with nothing in it, and the clip cut in after it.+// Muted and looping, over the picture in the hero's masked content and under the scrim. The picture stays+// under it until the first frame is decoded, and only then does the clip fade in: a fade started at once was+// spent on a layer with nothing in it, and the clip cut in after it.- (void)showMotion:(NSURL *)file {AVPlayerItem *item = [AVPlayerItem playerItemWithURL:file];_player = [AVQueuePlayer new];@@ -298,10 +271,9 @@ static void *kListContext = &kListContext;_motion.zPosition = 0.5;_motion.frame = self.bounds;_motion.opacity = 0;- [self.layer addSublayer:_motion];+ [self.content.layer addSublayer:_motion];[_motion addObserver:self forKeyPath:@"readyForDisplay" options:NSKeyValueObservingOptionInitial context:kReadyContext];_motionOn = NO;- [self sgr_watchList];[self sgr_updateMotion];SGLog(@"redesign album: animated cover %@", file.lastPathComponent);}@@ -310,18 +282,17 @@ static void *kListContext = &kListContext;[_motion removeObserver:self forKeyPath:@"readyForDisplay" context:kReadyContext];[_motion removeFromSuperlayer];_motion = nil;- // A square cover's gradients and shadow follow whether a clip covers it.+ // A square cover's scrim, mask and shadow follow whether a clip covers it.if (!SGRFullBleedCovers()) [self setNeedsLayout];}+// The Kit watches the page's list for the pull; on the same steps, with a clip, whether the hero has left the+// screen or come back to it. A hero with no clip, which most album pages have, costs the scroll nothing more.+- (void)listDidScroll {+ if (_player && [self sgr_seen] != _motionSeen) [self sgr_updateMotion];+}+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {- if (context == kListContext) {- // Only whether the hero is on screen moves while the list scrolls.- BOOL seen = [self sgr_seen];- if (seen == _motionSeen) return;- [self sgr_updateMotion];- return;- }if (context != kReadyContext) {[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];return;@@ -337,17 +308,23 @@ static void *kListContext = &kListContext;[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;+ // A square cover's hero has no scrim and no mask until the clip fills it. Its layout pass, run now, gives it+ // both, and they come in with the clip, the mask from opaque all the way down, so the square under the clip+ // is not cut into as it fades in.+ BOOL square = !SGRFullBleedCovers();+ if (square) {+ [self setNeedsLayout];+ [self layoutIfNeeded];+ }if (self.window) {+ CAMediaTimingFunction *curve = [CAMediaTimingFunction functionWithControlPoints:0.23 :1 :0.32 :1];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];- for (CALayer *each in fading) [each addAnimation:fade forKey:@"fade"];+ fade.timingFunction = curve;+ for (CALayer *each in square ? @[layer, self.scrim] : @[layer]) [each addAnimation:fade forKey:@"fade"];+ if (square) [self revealDissolveOver:fade.duration curve:curve];}[CATransaction commit];}@@ -377,23 +354,8 @@ static void *kListContext = &kListContext;else [_player pause];}-// The hero scrolls with the header, so the page's list is where its leaving the screen is heard: its offset,-// watched while the hero has a clip and is in a window, and let go when either goes. A hero with no clip, which-// every album page has, costs the scroll nothing.-- (void)sgr_watchList {- UIScrollView *list = nil;- for (UIView *v = _player && self.window ? self.superview : nil; v && !list; v = v.superview) {- if ([v isKindOfClass:UIScrollView.class]) list = (UIScrollView *)v;- }- if (list == _list) return;- [_list removeObserver:self forKeyPath:@"contentOffset" context:kListContext];- _list = list;- [list addObserver:self forKeyPath:@"contentOffset" options:0 context:kListContext];-}-- (void)didMoveToWindow {[super didMoveToWindow];- [self sgr_watchList];[self sgr_updateMotion];}@@ -458,8 +420,8 @@ static UIImageView *coverImageIn(UIView *cover) {}// The picture runs from the top of the header down past where its text begins, so the title and the artist-// sit on the bottom of its dissolve; below that the page's field is already drawing the very color the-// picture dissolves into, so there is no seam to see.+// sit on the bottom of its dissolve; the dissolve is a mask, so what shows through it is the page's field at+// that height, whatever color it is there, pulled down or not, and there is no seam to see.//// `bottom` is taken from the header at rest, never from where it is mid scroll, and only ever grows: a header// still loading is shorter than it will end up, and once the cover and the artist are in it settles and the@@ -480,8 +442,8 @@ static void applyHero(UIView *header, UIView *cover, CGFloat bottom) {SGLog(@"redesign album: hero %.0fpt across the top of the header", height);}if (height < kMinHero) return;- setFrame(hero, CGRectMake(0, 0, header.bounds.size.width, height));- hero.fieldColor = SGRAlbumFieldColor(header);+ hero.restHeight = height;+ [hero sgr_place];// 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.diff --git a/tweak/Sources/Redesigned/Artist/ArtistHeader.x b/tweak/Sources/Redesigned/Artist/ArtistHeader.xindex 9d8c7852..8d4795bc 100644--- a/tweak/Sources/Redesigned/Artist/ArtistHeader.x+++ b/tweak/Sources/Redesigned/Artist/ArtistHeader.x@@ -1,6 +1,7 @@// Artist redesign: the header the playlist and album pages have. The photo runs full bleed across the top-// of the page and dissolves into the page's color; the name and the monthly listeners are centered on the-// bottom of that dissolve; and under them one row -- shuffle, a white Play capsule, and Follow.+// of the page and dissolves into the page's field, stretching when the page is pulled down (the Kit's+// SGRStretchHero); the name and the monthly listeners are centered on the bottom of that dissolve; and under+// them one row -- shuffle, a white Play capsule, and Follow.//// Tree (trees/clean/artist/01.txt:37-170). The header is TemplateKit's HeaderContainer, 568pt, the first view// of the page's stack, holding an element view that holds the ImageHeaderView:@@ -33,9 +34,7 @@#import "Redesigned/Album/Album.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-// keeps the status bar and the back button legible on a bright picture. The playlist's and the album's.-static const CGFloat kDissolve = 0.46, kTopScrim = 140, kTopScrimAlpha = 0.28;+// The dissolve and the scrim are the Kit's stretching hero's (SGRStretchHero.h), the playlist's and the album's.// A photo view narrower than this is a placeholder glyph, and a picture shorter than this one mid load.static const CGFloat kMinCover = 80, kMinHero = 120;// The collapsed ImageHeaderView, Spotify's navigation bar; the text fades out over the last kFade before it.@@ -101,11 +100,13 @@ static UIView *containerOf(UIView *header) {#pragma mark - the photo, full bleed-// The picture across the top of the page with the field showing through the bottom of it: a scrim over the-// top for the status bar, and under it a fade to the very color the page's field is drawing.-@interface SGRArtistHero : UIView+// The picture across the top of the page with the field showing through the bottom of it: the Kit's stretching+// hero (SGRStretchHero.h), whose bottom is masked away as the playlist's and the album's are, under a scrim for+// the status bar. Pulled down past the top, it grows upward by as much, so the photo stays one piece with the+// name and the list under it and zooms in, as the Music app's does, rather than sliding down and leaving the+// field showing above it (issue #169). The photo fills the hero's content, so a pull only resizes it.+@interface SGRArtistHero : SGRStretchHero@property (nonatomic, readonly) UIImageView *picture;-@property (nonatomic, copy) UIColor *fieldColor;// The photo in Spotify's artwork view, and every photo 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.// The same view again only re-reads it.@@ -113,69 +114,20 @@ static UIView *containerOf(UIView *header) {@end@implementation SGRArtistHero {- CAGradientLayer *_scrim, *_dissolve;__weak UIImageView *_artwork;}- (instancetype)initWithFrame:(CGRect)frame {if (!(self = [super initWithFrame:frame])) return nil;- self.userInteractionEnabled = NO;- self.accessibilityElementsHidden = YES;- self.clipsToBounds = YES;-+ self.logName = @"artist";_picture = [[UIImageView alloc] initWithFrame:self.bounds];_picture.contentMode = UIViewContentModeScaleAspectFill;_picture.clipsToBounds = YES;_picture.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;- [self addSubview:_picture];-- _scrim = [CAGradientLayer layer];- _scrim.zPosition = 1;- _scrim.colors = @[(id)[UIColor colorWithWhite:0 alpha:kTopScrimAlpha].CGColor, (id)UIColor.clearColor.CGColor];- [self.layer addSublayer:_scrim];-- _dissolve = [CAGradientLayer layer];- _dissolve.zPosition = 2;- [self.layer addSublayer:_dissolve];- self.fieldColor = SGRNeutralField();- // The color is read off the main thread, so it can land after the last layout pass of the page.- [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(sgr_fieldColorDidChange)- name:SGRFieldColorDidChangeNotification object:nil];+ [self.content addSubview:_picture];return self;}-- (void)dealloc {- [NSNotificationCenter.defaultCenter removeObserver:self];-}--- (void)sgr_fieldColorDidChange {- if (self.superview) self.fieldColor = SGRArtistFieldColor(self);-}--- (void)setFieldColor:(UIColor *)color {- if (!color || [_fieldColor isEqual:color]) return;- _fieldColor = [color copy];- // The clear end is the same color with no alpha, so the fade keeps its hue instead of going through gray.- [CATransaction begin];- [CATransaction setDisableActions:YES];- _dissolve.colors = @[(id)[color colorWithAlphaComponent:0].CGColor,- (id)[color colorWithAlphaComponent:0.72].CGColor,- (id)color.CGColor];- _dissolve.locations = @[@0, @0.62, @1];- [CATransaction commit];-}--- (void)layoutSubviews {- [super layoutSubviews];- CGRect bounds = self.bounds;- [CATransaction begin];- [CATransaction setDisableActions:YES];- _scrim.frame = CGRectMake(0, 0, bounds.size.width, MIN(kTopScrim, bounds.size.height));- CGFloat fade = round(bounds.size.height * kDissolve);- _dissolve.frame = CGRectMake(0, bounds.size.height - fade, bounds.size.width, fade);- [CATransaction commit];-}-- (void)followArtwork:(UIImageView *)source {if (!source) return;[self takeArtwork:source late:NO];@@ -220,7 +172,7 @@ static UIImageView *photoIn(UIView *artwork) {// The picture from the top of the container down to `bottom`, which comes from the container at rest and only// ever grows, so it does not change size while the page loads or scrolls.-static void applyHero(UIView *container, UIView *artwork, CGFloat bottom, UIColor *fieldColor) {+static void applyHero(UIView *container, UIView *artwork, CGFloat bottom) {SGRArtistHero *hero = objc_getAssociatedObject(container, &kHeroKey);if (!hero) {hero = [[SGRArtistHero alloc] initWithFrame:CGRectZero];@@ -236,8 +188,8 @@ static void applyHero(UIView *container, UIView *artwork, CGFloat bottom, UIColoSGLog(@"redesign artist: hero %.0fpt across the top of the page", height);}if (height < kMinHero) return;- setFrame(hero, CGRectMake(0, 0, container.bounds.size.width, height));- hero.fieldColor = fieldColor;+ hero.restHeight = height;+ [hero sgr_place];[hero followArtwork:photoIn(artwork)];}@@ -318,11 +270,17 @@ static void applyHeader(UIView *header, BOOL full) {if (fabs(info.alpha - alpha) > 0.01) info.alpha = alpha;// The picture reaches to where the content's top is at rest, plus the name. The container keeps its- // height as the header collapses, and only ever grows as the page loads.- CGFloat rest = MAX([objc_getAssociatedObject(container, &kContainerHeightKey) doubleValue], container.bounds.size.height);- objc_setAssociatedObject(container, &kContainerHeightKey, @(rest), OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ // height as the header collapses, and only ever grows as the page loads. Not while the page is pulled down+ // past its top: should Spotify grow the container with the pull, that height is not the rest, and the hero+ // would stay that much too tall once the page is let go.+ CGFloat rest = [objc_getAssociatedObject(container, &kContainerHeightKey) doubleValue];+ SGRArtistHero *hero = objc_getAssociatedObject(container, &kHeroKey);+ if (container.bounds.size.height > rest && hero.pull <= 0) {+ rest = container.bounds.size.height;+ objc_setAssociatedObject(container, &kContainerHeightKey, @(rest), OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ }CGFloat bottom = rest - SGRHeaderInfoBottom - [info contentHeightForWidth:container.bounds.size.width] + SGRHeaderInfoTitleRise;- applyHero(container, artwork, bottom, fieldColor);+ applyHero(container, artwork, bottom);}// What the header shows besides its text: the logo, the buttons, More, and the watch on the buttons' row.diff --git a/tweak/Sources/Redesigned/Kit/SGRField.h b/tweak/Sources/Redesigned/Kit/SGRField.hindex fc812013..66ce90ee 100644--- a/tweak/Sources/Redesigned/Kit/SGRField.h+++ b/tweak/Sources/Redesigned/Kit/SGRField.h@@ -12,10 +12,6 @@// Threading: main thread only; the palette work it starts runs off it.#import <UIKit/UIKit.h>-// Posted on the main thread by a field whose color changed, with the field as the object and the-// new color under "color".-extern NSNotificationName const SGRFieldColorDidChangeNotification;-@interface SGRArtworkField : UIView// Where the color, the fade to black and the backdrop reach past the bounds (overscroll, a plane// that does not clip): positive values draw outside. The field never clips.diff --git a/tweak/Sources/Redesigned/Kit/SGRField.m b/tweak/Sources/Redesigned/Kit/SGRField.mindex 13bcb80a..4b4aaed7 100644--- a/tweak/Sources/Redesigned/Kit/SGRField.m+++ b/tweak/Sources/Redesigned/Kit/SGRField.m@@ -6,8 +6,6 @@#import "SGRPalette.h"#import "SGRTokens.h"-NSNotificationName const SGRFieldColorDidChangeNotification = @"spotifyglass.redesign.fieldColorDidChange";-static const CGFloat kFallbackHeight = 874; // a window-less field sizes for an iPhone 17 Pro// Where the color starts fading to black and where it is black, as shares of the window's height:@@ -251,7 +249,6 @@ const NSTimeInterval SGRFieldHoldLimit = 1.0;fade.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];[_solid addAnimation:fade forKey:@"backgroundColor"];}- [NSNotificationCenter.defaultCenter postNotificationName:SGRFieldColorDidChangeNotification object:self userInfo:@{@"color": color}];}- (void)setProvisionalColor:(UIColor *)color {diff --git a/tweak/Sources/Redesigned/Kit/SGRKit.h b/tweak/Sources/Redesigned/Kit/SGRKit.hindex 5e47b494..9c98ba53 100644--- a/tweak/Sources/Redesigned/Kit/SGRKit.h+++ b/tweak/Sources/Redesigned/Kit/SGRKit.h@@ -11,6 +11,7 @@// SGRActionRow.h the Play capsule and the stand-in button of a page's action row// SGRDownload.h Spotify's download state, read, and the glyph drawn for it// SGRHeaderInfo.h a page header's title, creator, length, row and description, the Music app's+// SGRStretchHero.h a page header's picture, dissolving into the field and stretching on a pull (album, artist)// SGRRestyle.h keeping Spotify's views restyled: suppress, digits, lookups, shadows, firing// controls, taking a list cell's paint off the field, a hard top edge (SGREdgeEffect.x)// SGRBridges.h player state, now playing artwork, the player's open and close@@ -30,6 +31,7 @@#import "SGRActionRow.h"#import "SGRDownload.h"#import "SGRHeaderInfo.h"+#import "SGRStretchHero.h"#import "SGRRestyle.h"#import "SGRBridges.h"#import "SGRRepaint.h"diff --git a/tweak/Sources/Redesigned/Kit/SGRStretchHero.h b/tweak/Sources/Redesigned/Kit/SGRStretchHero.hnew file mode 100644index 00000000..7acf8aa5--- /dev/null+++ b/tweak/Sources/Redesigned/Kit/SGRStretchHero.h@@ -0,0 +1,56 @@+// A page header's picture across the top of the page that stretches when the page is pulled down, the Music+// app's: the album's (Album/AlbumHeader.x) and the artist's (Artist/ArtistHeader.x) build on it. The playlist's+// is its own (Playlist/PlaylistHeader.x): its stretch comes from Spotify's plane growing, not from the list.+//+// What it draws: `content`, where a subclass puts the picture and anything else that should dissolve (an+// animated cover), with its bottom masked away so the field shows through whatever color it is at that height+// -- a fade to the field's flat color showed as an edge pulled down, where the still field is fading to black+// (issue #169) -- and over it a scrim for the status bar. Only `content` is masked, so the scrim and whatever a+// subclass puts beside it (a shadow) are not drawn in the mask's offscreen pass.+//+// The mask is an opaque part and under it a dissolve of a fixed height, round(restHeight * SGRStretchHeroDissolve),+// pinned to the bottom with fixed stops: 0.28 of the picture left at 0.62 of the way, the curve the color fade+// had. Pulled down, the hero grows upward by the pull and only frames move: the opaque part grows, the dissolve+// keeps its height on the bottom, where the text is.+//+// The pull: the nearest scroll view above the hero (the page's list), whose contentOffset is watched while the+// hero is in a window and let go when it leaves. A step that is not a pull and follows none costs the scroll a+// read of the offset and a comparison. The host the hero sits in is assumed to move with the list's content,+// so the pull is how far above the host's top the hero has to reach; the first stretch past 24pt says once per+// page kind whether a view between the host and the list clips, which would cut the stretch off.+//+// Threading: main thread only.+#import <UIKit/UIKit.h>++// How much of the rest height the dissolve covers; the scrim's height and its darkness at the top. The+// playlist's numbers (Playlist/PlaylistHeader.x keeps its own copy): one page.+extern const CGFloat SGRStretchHeroDissolve, SGRStretchHeroScrim, SGRStretchHeroScrimAlpha;++@interface SGRStretchHero : UIView+// Where the picture goes: the hero's bounds, masked at the bottom while `dissolves`. Laid out by the hero+// before a subclass's -layoutSubviews goes on from [super layoutSubviews].+@property (nonatomic, readonly) UIView *content;+// Over `content`, unmasked. A subclass may hide it.+@property (nonatomic, readonly) CAGradientLayer *scrim;+// Whether `content` is masked: YES unless a subclass turns it off (a square cover, whose square reaches into+// the dissolve). The one place the mask is assigned, and only when this changes.+@property (nonatomic) BOOL dissolves;+// The hero's height at rest, from the host's pass; -sgr_place adds the pull to it. Below 1, nothing is placed.+@property (nonatomic) CGFloat restHeight;+// How far the list is pulled down past its top, 0 without a list. What the hero grows upward by.+@property (nonatomic, readonly) CGFloat pull;+// How much taller than restHeight the hero is now: the pull it was last placed for, from its bounds.+@property (nonatomic, readonly) CGFloat stretch;+// The page in the one-time clip log line ("album", "artist").+@property (nonatomic, copy) NSString *logName;++// Its frame in its superview: the top of it and restHeight at rest, and pulled down, from `pull` above the top+// down to the same bottom. Writes nothing unless the frame changed. For the host's passes; the hero calls it+// itself on the list's steps.+- (void)sgr_place;+// The dissolve comes in from opaque all the way down, over `duration` on `curve`: for a mask that has just+// been turned on over a picture already showing, so nothing is cut into at once.+- (void)revealDissolveOver:(CFTimeInterval)duration curve:(CAMediaTimingFunction *)curve;+// For a subclass: called on every step of the list's offset, after the hero has been placed. Does nothing here.+- (void)listDidScroll;+@enddiff --git a/tweak/Sources/Redesigned/Kit/SGRStretchHero.m b/tweak/Sources/Redesigned/Kit/SGRStretchHero.mnew file mode 100644index 00000000..786b5013--- /dev/null+++ b/tweak/Sources/Redesigned/Kit/SGRStretchHero.m@@ -0,0 +1,159 @@+// The stretching hero of the album and artist pages (SGRStretchHero.h).+#import "Core/SGCore.h"+#import "SGRStretchHero.h"++const CGFloat SGRStretchHeroDissolve = 0.46, SGRStretchHeroScrim = 140, SGRStretchHeroScrimAlpha = 0.28;++// A pull this far is a pull and not a bounce at the end of a scroll: where the clip check runs.+static const CGFloat kClipCheckPull = 24;++static void *kListContext = &kListContext;++static void setFrame(UIView *view, CGRect frame) {+ if (view && !CGRectIsEmpty(frame) && !CGRectEqualToRect(view.frame, frame)) view.frame = frame;+}++@implementation SGRStretchHero {+ CALayer *_mask; // content's mask while it dissolves: _opaque over _fade+ CALayer *_opaque; // from the top down to the dissolve, grown by the pull+ CAGradientLayer *_fade; // the dissolve, a fixed height on the bottom with fixed stops+ __weak UIScrollView *_list; // the page's list, watched for the pull at its top while the hero is in a window+ BOOL _clipChecked; // this hero has been through the clip log's check+}++- (instancetype)initWithFrame:(CGRect)frame {+ if (!(self = [super initWithFrame:frame])) return nil;+ self.userInteractionEnabled = NO;+ self.accessibilityElementsHidden = YES;+ self.clipsToBounds = YES;++ _content = [[UIView alloc] initWithFrame:self.bounds];+ _content.userInteractionEnabled = NO;+ [self addSubview:_content];++ // Above the content whatever else is added to the view later.+ _scrim = [CAGradientLayer layer];+ _scrim.zPosition = 1;+ _scrim.colors = @[(id)[UIColor colorWithWhite:0 alpha:SGRStretchHeroScrimAlpha].CGColor, (id)UIColor.clearColor.CGColor];+ [self.layer addSublayer:_scrim];++ _mask = [CALayer layer];+ _opaque = [CALayer layer];+ _opaque.backgroundColor = UIColor.blackColor.CGColor;+ [_mask addSublayer:_opaque];+ _fade = [CAGradientLayer layer];+ _fade.colors = @[(id)UIColor.blackColor.CGColor, (id)[UIColor colorWithWhite:0 alpha:0.28].CGColor,+ (id)UIColor.clearColor.CGColor];+ _fade.locations = @[@0, @0.62, @1];+ [_mask addSublayer:_fade];+ _dissolves = YES;+ _content.layer.mask = _mask;+ _logName = @"hero";+ return self;+}++- (void)dealloc {+ [_list removeObserver:self forKeyPath:@"contentOffset" context:kListContext];+}++- (void)setDissolves:(BOOL)dissolves {+ if (_dissolves == dissolves) return;+ _dissolves = dissolves;+ _content.layer.mask = dissolves ? _mask : nil;+}++- (CGFloat)pull {+ UIScrollView *list = _list;+ return list ? MAX(0, -(list.contentOffset.y + list.adjustedContentInset.top)) : 0;+}++- (CGFloat)stretch {+ return _restHeight < 1 ? 0 : MAX(0, self.bounds.size.height - _restHeight);+}++// A pull is a change of the hero's height, so the frame write in -sgr_place is what lays this out again.+- (void)layoutSubviews {+ [super layoutSubviews];+ CGRect bounds = self.bounds;+ if (bounds.size.height < 1) return;+ // Never past the top: the bounds are restHeight and the pull.+ CGFloat fade = round(_restHeight * SGRStretchHeroDissolve);+ [CATransaction begin];+ [CATransaction setDisableActions:YES];+ _content.frame = bounds;+ _scrim.frame = CGRectMake(0, 0, bounds.size.width, MIN(SGRStretchHeroScrim, bounds.size.height));+ _mask.frame = bounds;+ _opaque.frame = CGRectMake(0, 0, bounds.size.width, bounds.size.height - fade);+ _fade.frame = CGRectMake(0, bounds.size.height - fade, bounds.size.width, fade);+ [CATransaction commit];+}++- (void)revealDissolveOver:(CFTimeInterval)duration curve:(CAMediaTimingFunction *)curve {+ id opaque = (id)UIColor.blackColor.CGColor;+ CABasicAnimation *reveal = [CABasicAnimation animationWithKeyPath:@"colors"];+ reveal.fromValue = @[opaque, opaque, opaque];+ reveal.duration = duration;+ reveal.timingFunction = curve;+ [_fade addAnimation:reveal forKey:@"reveal"];+}++- (void)sgr_place {+ [self sgr_placeForPull:self.pull];+}++- (void)sgr_placeForPull:(CGFloat)pull {+ UIView *host = self.superview;+ if (!host || _restHeight < 1 || host.bounds.size.width < 1) return;+ setFrame(self, CGRectMake(0, -pull, host.bounds.size.width, _restHeight + pull));+ if (pull > kClipCheckPull && !_clipChecked) [self sgr_checkClip:pull];+}++// Once per page kind: above the host's top is outside it, so a view on the way to the list that clips would+// cut the stretch off. The device check of the assumption that the host moves down with the pull.+- (void)sgr_checkClip:(CGFloat)pull {+ _clipChecked = YES;+ static NSMutableSet<NSString *> *logged;+ if (!logged) logged = [NSMutableSet set];+ if ([logged containsObject:_logName]) return;+ [logged addObject:_logName];+ UIView *clips = nil;+ UIScrollView *list = _list;+ for (UIView *v = self.superview; v && v != list && !clips; v = v.superview) {+ if (v.clipsToBounds) clips = v;+ }+ SGLog(@"redesign %@: hero stretched %.0fpt over the pull, %@", _logName, pull,+ clips ? [NSString stringWithFormat:@"cut off by %@", NSStringFromClass(clips.class)] : @"nothing clips it");+}++- (void)listDidScroll {+}++- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {+ if (context != kListContext) {+ [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];+ return;+ }+ // Most steps are the list scrolling, the hero neither pulled nor coming back from a pull: nothing to place.+ CGFloat pull = self.pull;+ if (pull > 0 || self.bounds.size.height > _restHeight + 0.5) [self sgr_placeForPull:pull];+ [self listDidScroll];+}++- (void)sgr_watchList {+ UIScrollView *list = nil;+ for (UIView *v = self.window ? self.superview : nil; v && !list; v = v.superview) {+ if ([v isKindOfClass:UIScrollView.class]) list = (UIScrollView *)v;+ }+ if (list == _list) return;+ [_list removeObserver:self forKeyPath:@"contentOffset" context:kListContext];+ _list = list;+ [list addObserver:self forKeyPath:@"contentOffset" options:0 context:kListContext];+ [self sgr_place];+}++- (void)didMoveToWindow {+ [super didMoveToWindow];+ [self sgr_watchList];+}++@end