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 playlist, album and artist pages come in whole
My-Name-Is-Jeff8667f4ddc130
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 60827464..53c5b7ad 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -273,7 +273,10 @@ Redesigned:Kit/ what the redesign builds on (SGRKit.h lists it), the flags it forces (SGRedesign.h, SGRGlassDesign.x forSpotify's own glass design), its repaint hook (SGRRepaint.x), soft top edge, AMOLED black (always on,- SGRAmoled.x) and its own accent colour (SGRAccent.x, stored apart from the native look's)+ SGRAmoled.x) and its own accent colour (SGRAccent.x, stored apart from the native look's). The+ playlist, album and artist pages take their field's colour from the cover's main colour (checked on+ the Mac by harness/palette/), and come in whole: a black veil over the page until the cover has+ been read, at most SGRFieldHoldLimit (1 s), then faded away (SGRField.h)Navbar/ the glass tab bar (TabBar.x) over its own composition (Navbar.x, NavbarLayout.m) and editor, the glass search field.Spotify is made to leave the glass bar its height where its own bar is shorter (a phone with a home button,Offline or Private Session under the bar), so the now playing bar and the pages move up with it. Laid out ondiff --git a/harness/playlist/README.md b/harness/playlist/README.mdindex 497659aa..449fb359 100644--- a/harness/playlist/README.md+++ b/harness/playlist/README.md@@ -68,3 +68,7 @@ a plain UICollectionViewCell straight in the list: "plain heading a=0" once theThe owner's picture is an image view inside the creator button's facepile, filled at 1.5 s, after the header haslaid out. At 2.2 s the log line "owner picture" says where the redesign drew it: round, a line high, just beforethe name, the two centred together. "none" means the late image was missed.++"whole page" lines, in every mode: just after launch the page is under the field's veil, below the pinned ⋯, and at+3 s there is "no veil". The redesign's own line says why it lifted (`log stream`, "page shown whole"): "its artwork+was read" for a playlist and a mix, "it has no artwork" for Liked Songs, a few tens of ms after its title.diff --git a/harness/playlist/main.m b/harness/playlist/main.mindex 4bf8818d..2b683b2c 100644--- a/harness/playlist/main.m+++ b/harness/playlist/main.m@@ -531,6 +531,20 @@ static void buildLikedSongs(UIViewController *page, CGFloat W) {alpha(headingPaint), alpha(badge), alpha(card), alpha(refreshPaint), alpha(plainHeadingPaint));});+ // The page comes in whole (Kit/SGRField.h): a veil over it until the cover has been read, or, with no cover,+ // until it has its title. Just after launch it is there or already fading; by 3 s, past the field's limit, it is gone.+ for (NSNumber *when in @[@0.01, @3]) {+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(when.doubleValue * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ UIView *veil = nil;+ for (UIView *sub in page.view.subviews) {+ if ([NSStringFromClass(sub.class) isEqualToString:@"SGRFieldVeil"]) veil = sub;+ }+ NSLog(@"[harness] whole page at %.2f s: %@", when.doubleValue,+ veil ? [NSString stringWithFormat:@"veil a=%.2f, %@ the pinned more", veil.layer.presentationLayer.opacity,+ page.view.subviews.lastObject == veil ? @"over" : @"under"] : @"no veil");+ });+ }+if ([NSProcessInfo.processInfo.arguments containsObject:@"liked"]) {buildLikedSongs(page, W);[self.window makeKeyAndVisible];diff --git a/tweak/Sources/Redesigned/Album/Album.h b/tweak/Sources/Redesigned/Album/Album.hindex 45d4f341..bdb44c7a 100644--- a/tweak/Sources/Redesigned/Album/Album.h+++ b/tweak/Sources/Redesigned/Album/Album.h@@ -62,3 +62,6 @@ void SGRAlbumSetArtwork(UIView *view, UIImage *image);// The colour Spotify picked for the album, read off the wash it paints behind the header: the field shows it// until the cover's own main colour has been read, and not after.void SGRAlbumSetSpotifyColor(UIView *view, UIColor *color);+// The page comes in whole once its cover has been read (Kit/SGRField.h). Called from the album header's pass+// only, so a podcast's episode page, the same template with no cover for the field to read, is never held.+void SGRAlbumHoldPage(UIView *page);diff --git a/tweak/Sources/Redesigned/Album/AlbumField.x b/tweak/Sources/Redesigned/Album/AlbumField.xindex fb577bef..759cd323 100644--- a/tweak/Sources/Redesigned/Album/AlbumField.x+++ b/tweak/Sources/Redesigned/Album/AlbumField.x@@ -81,6 +81,10 @@ void SGRAlbumSetSpotifyColor(UIView *view, UIColor *color) {if (color) [fieldOn(view) setProvisionalColor:color];}+void SGRAlbumHoldPage(UIView *page) {+ [fieldOn(page) holdPage:page];+}+static SGRArtworkField *fieldIn(UIView *page) {SGRArtworkField *field = objc_getAssociatedObject(page, &kFieldKey);if (field) return field;diff --git a/tweak/Sources/Redesigned/Album/AlbumHeader.x b/tweak/Sources/Redesigned/Album/AlbumHeader.xindex c795eab5..523bdf8a 100644--- a/tweak/Sources/Redesigned/Album/AlbumHeader.x+++ b/tweak/Sources/Redesigned/Album/AlbumHeader.x@@ -534,6 +534,7 @@ static void applyWash(UIView *page) {static void applyHeader(UIView *header, UIView *page) {if (!SGRFindByIdentifier(header, @"CreativeWorkPlatform.Components.UI.TitleRow", &kTitleKey)) return;+ SGRAlbumHoldPage(page);applyWash(page);SGRHeaderInfo *info = applyInfo(header, page);diff --git a/tweak/Sources/Redesigned/Artist/ArtistField.x b/tweak/Sources/Redesigned/Artist/ArtistField.xindex 0faa7222..cacb2da3 100644--- a/tweak/Sources/Redesigned/Artist/ArtistField.x+++ b/tweak/Sources/Redesigned/Artist/ArtistField.x@@ -75,6 +75,8 @@ static SGRArtworkField *fieldIn(UIView *page) {if (field.superview != page) [page insertSubview:field atIndex:0];else if (page.subviews.firstObject != field) [page sendSubviewToBack:field];if (!CGRectEqualToRect(field.frame, page.bounds)) field.frame = page.bounds;+ // The page comes in whole once its photo has been read (Kit/SGRField.h).+ [field holdPage:page];}%enddiff --git a/tweak/Sources/Redesigned/Kit/SGRField.h b/tweak/Sources/Redesigned/Kit/SGRField.hindex 69ed1617..258a0cc3 100644--- a/tweak/Sources/Redesigned/Kit/SGRField.h+++ b/tweak/Sources/Redesigned/Kit/SGRField.h@@ -54,4 +54,17 @@ extern NSNotificationName const SGRFieldColorDidChangeNotification;// as the last call is a no-op, and a result that lands after a newer call is dropped. nil keeps// what the field shows.- (void)setArtwork:(UIImage *)image identity:(NSString *)identity animated:(BOOL)animated;++// A page that comes in whole rather than a piece at a time: until the field has read its first artwork, a veil+// of the neutral field lies over everything `page` holds but its pinned ⋯ (SGRPinnedMore), and then fades away+// at once, with the cover, the colour and the text that arrived under it. The back button is the navigation+// bar's, outside the page, and stays. A page whose artwork never comes is shown after SGRFieldHoldLimit, and+// one that knows it has none releases itself (-showPage). Called from the page's own pass, which keeps the+// veil on top; nothing once the page has been shown, so a page coming back is never held again.+- (void)holdPage:(UIView *)page;+- (void)showPage;@end++// How long a page waits for its artwork before it is shown anyway. The Music app shows something at once+// (HIG, Loading: "Show something as soon as possible"), so the wait is short; a page then loads as it used to.+extern const NSTimeInterval SGRFieldHoldLimit;diff --git a/tweak/Sources/Redesigned/Kit/SGRField.m b/tweak/Sources/Redesigned/Kit/SGRField.mindex bd0d1949..3d9ef846 100644--- a/tweak/Sources/Redesigned/Kit/SGRField.m+++ b/tweak/Sources/Redesigned/Kit/SGRField.m@@ -31,7 +31,39 @@ static NSDictionary *noActions(void) {return none;}+const NSTimeInterval SGRFieldHoldLimit = 1.0;++// The veil over a held page: black, the redesign's field before a colour arrives (SGRAmoled.x), painted on a+// sublayer for the reason the field is, so the repaint hook does not take it for Spotify's base surface.+@interface SGRFieldVeil : UIView+@end++@implementation SGRFieldVeil {+ CALayer *_paint;+}++- (instancetype)initWithFrame:(CGRect)frame {+ if (!(self = [super initWithFrame:frame])) return nil;+ self.userInteractionEnabled = NO;+ self.accessibilityElementsHidden = YES;+ _paint = [CALayer layer];+ _paint.actions = noActions();+ _paint.backgroundColor = UIColor.blackColor.CGColor;+ [self.layer addSublayer:_paint];+ return self;+}++- (void)layoutSubviews {+ [super layoutSubviews];+ _paint.frame = self.bounds;+}++@end+@implementation SGRArtworkField {+ SGRFieldVeil *_veil;+ CFTimeInterval _heldSince;+ BOOL _shown; // the page has been shown once, and is never held againCALayer *_solid;CAGradientLayer *_black;CALayer *_backdrop;@@ -243,8 +275,52 @@ static NSDictionary *noActions(void) {}];}+#pragma mark - holding a page++- (void)holdPage:(UIView *)page {+ if (_shown || _read || !page) return;+ if (!_veil) {+ _veil = [[SGRFieldVeil alloc] initWithFrame:page.bounds];+ _heldSince = CACurrentMediaTime();+ __weak SGRArtworkField *weakSelf = self;+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(SGRFieldHoldLimit * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ [weakSelf sgr_showPage:@"the artwork took too long"];+ });+ }+ if (!CGRectEqualToRect(_veil.frame, page.bounds)) _veil.frame = page.bounds;+ // On top of everything the page holds but its pinned ⋯, which brings itself to the front on the header's+ // passes. Moved only when out of place: a move lays the page out again. The class is looked up by name so a+ // screen that has a field and no action row (the player) does not have to link SGRActionRow.m.+ static Class pinned;+ if (!pinned) pinned = NSClassFromString(@"SGRMirrorButton");+ NSArray<UIView *> *subviews = page.subviews;+ UIView *top = subviews.lastObject;+ if (pinned && [top isKindOfClass:pinned]) {+ if (subviews.count < 2 || subviews[subviews.count - 2] != _veil) [page insertSubview:_veil belowSubview:top];+ } else if (top != _veil) {+ [page addSubview:_veil];+ }+}++- (void)showPage {+ [self sgr_showPage:@"it has no artwork"];+}++- (void)sgr_showPage:(NSString *)why {+ if (_shown) return;+ _shown = YES;+ SGRFieldVeil *veil = _veil;+ _veil = nil;+ if (!veil) return;+ static NSUInteger logged;+ if (logged++ < 4) SGLog(@"redesign kit: page shown whole after %.0f ms, %@", (CACurrentMediaTime() - _heldSince) * 1000, why);+ SGRAnimate(SGRMotionFade, ^{ veil.alpha = 0; }, ^(BOOL finished) { [veil removeFromSuperview]; });+}+- (void)applyPalette:(SGRPalette *)palette animated:(BOOL)animated {_read = YES;+ // Under the veil the colour goes in at once, and the page fades in with it.+ if (_veil) animated = NO;if (_flows && palette.flowColors) {[_flow setColors:palette.flowColors animated:animated && !_flow.hidden];_flow.hidden = NO;@@ -267,6 +343,7 @@ static NSDictionary *noActions(void) {[CATransaction commit];}[self applyColor:palette.fieldColor animated:animated];+ [self sgr_showPage:@"its artwork was read"];}@enddiff --git a/tweak/Sources/Redesigned/Playlist/Playlist.h b/tweak/Sources/Redesigned/Playlist/Playlist.hindex c17e21e5..6d31609f 100644--- a/tweak/Sources/Redesigned/Playlist/Playlist.h+++ b/tweak/Sources/Redesigned/Playlist/Playlist.h@@ -44,3 +44,5 @@ UIView *SGRPlaylistPageOf(UIView *view);UIColor *SGRPlaylistFieldColor(UIView *view);// The cover of the page `view` is on, for its field to take its colour from. The same image again is a no-op.void SGRPlaylistSetArtwork(UIView *view, UIImage *image);+// The page `view` is on has no cover to wait for (Liked Songs): shown now rather than after the field's limit.+void SGRPlaylistShowPage(UIView *view);diff --git a/tweak/Sources/Redesigned/Playlist/PlaylistField.x b/tweak/Sources/Redesigned/Playlist/PlaylistField.xindex 5eeb8b1e..e4dad488 100644--- a/tweak/Sources/Redesigned/Playlist/PlaylistField.x+++ b/tweak/Sources/Redesigned/Playlist/PlaylistField.x@@ -45,6 +45,10 @@ void SGRPlaylistSetArtwork(UIView *view, UIImage *image) {if (image) [fieldOn(view) setArtwork:image identity:nil animated:YES];}+void SGRPlaylistShowPage(UIView *view) {+ [fieldOn(view) showPage];+}+static SGRArtworkField *fieldIn(UIView *page) {SGRArtworkField *field = objc_getAssociatedObject(page, &kFieldKey);if (field) return field;@@ -66,6 +70,8 @@ static SGRArtworkField *fieldIn(UIView *page) {if (field.superview != page) [page insertSubview:field atIndex:0];else if (page.subviews.firstObject != field) [page sendSubviewToBack:field];if (!CGRectEqualToRect(field.frame, page.bounds)) field.frame = page.bounds;+ // The page comes in whole once its cover has been read (Kit/SGRField.h).+ [field holdPage:page];}// The page the repaint hook keeps clear is the one on screen; another playlist pushed over this one setsdiff --git a/tweak/Sources/Redesigned/Playlist/PlaylistHeader.x b/tweak/Sources/Redesigned/Playlist/PlaylistHeader.xindex 5ac5c80a..f0c971f7 100644--- a/tweak/Sources/Redesigned/Playlist/PlaylistHeader.x+++ b/tweak/Sources/Redesigned/Playlist/PlaylistHeader.x@@ -563,6 +563,8 @@ static void applyHeader(UIView *layout) {}CGFloat reach = rest - SGRHeaderInfoBottom - [info contentHeightForWidth:info.bounds.size.width] + SGRHeaderInfoTitleRise;if (cover) applyHero(layout, cover, plane, block, reach, stretch);+ // Liked Songs has no cover at all, so there is nothing for its page to wait for once it has its title.+ else if (info.window && modelString(viewModelOf(headerVC), @"playlistName")) SGRPlaylistShowPage(layout);}// The content layout of the page `root` belongs to, kept weakly on it: the header lays out on every step of