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 mini player docks in a Jam and follows the cover (#144)
My-Name-Is-Jeff5c8a87cafe98
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 6ea51ea2..c7d0298f 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -530,7 +530,10 @@ Redesigned:so it slides and fades with it; Spotify lays a page out as "title • artists" over the device line or astitle over artists, and both are read. In the minimized rowthe card drops its device and add buttons, faded out as it heads there and back in as it leaves. Only the title stays in the row. In a Jam the- glass stays on the track and Spotify's Jam strip gets a pane of its own above it (harness/tabbar/, jam)+ glass stays on the track and Spotify's Jam strip gets a pane of the same glass above it, and the fade under+ the bars reaches above the strip while the card is above the bar; in the minimized row the card docks as it does outside a Jam and the strip+ rides above it at its width (harness/tabbar/, jam). Another hat on the bar keeps the card above the tab bar.+ Follow the cover (Player/PlayerCoverAccent.x) paints the card's lit device and like buttons tooContextMenu/ the ⋯ of the player and the ⋯ pinned over the playlist, album and artist pages open the system menu,always (ContextMenu.h). The player's ⋯ is a pull-down button of the mod's over Spotify's: the menuopens on touch down with the quick row (Spotify's items 9, 19 and 11), the player's items and More,diff --git a/tweak/Sources/Redesigned/Kit/SGRTokens.h b/tweak/Sources/Redesigned/Kit/SGRTokens.hindex c989e0ab..15114df8 100644--- a/tweak/Sources/Redesigned/Kit/SGRTokens.h+++ b/tweak/Sources/Redesigned/Kit/SGRTokens.h@@ -57,7 +57,7 @@ typedef NS_ENUM(NSInteger, SGRMotion) {// An ease out over 0.15 s, for what goes once the finger has let it go (the hold's 2x badge): nothing is// watched on its way out. Kept under Reduce Motion like a fade.SGRMotionExit,- // A spring with no overshoot over 0.34 s, for the tab bar minimizing and expanding with the now playing card:+ // A spring with no overshoot over 0.26 s, for the tab bar minimizing and expanding with the now playing card:// it happens many times a session, so it is quicker than a layout spring. At once under Reduce Motion.SGRMotionBar,};diff --git a/tweak/Sources/Redesigned/Navbar/TabBar.x b/tweak/Sources/Redesigned/Navbar/TabBar.xindex 0ddbc17d..1db45300 100644--- a/tweak/Sources/Redesigned/Navbar/TabBar.x+++ b/tweak/Sources/Redesigned/Navbar/TabBar.x@@ -360,10 +360,12 @@ static void logBarOnce(UITabBar *bar) {}@end-// The now playing card (56), its gap over the bar (8) and 24 more, whether a song is playing or not.+// The now playing card (56), its gap over the bar (8) and 24 more, whether a song is playing or not; in a+// Jam the strip's height on top while the card is above the bar. In the minimized row the strip rides just+// above the card, which these 88 already reach.static const CGFloat kFadeAbove = 88;-static void placeFade(UIView *stockBar, CGRect glass) {+static void placeFade(UIView *stockBar, CGRect glass, BOOL minimized) {SGRBarFade *fade = objc_getAssociatedObject(stockBar, &kFadeKey);if (!fade) {fade = [SGRBarFade new];@@ -375,7 +377,7 @@ static void placeFade(UIView *stockBar, CGRect glass) {layer.locations = @[@0, @0.5, @1];objc_setAssociatedObject(stockBar, &kFadeKey, fade, OBJC_ASSOCIATION_RETAIN_NONATOMIC);}- CGFloat top = CGRectGetMinY(glass) - kFadeAbove;+ CGFloat top = CGRectGetMinY(glass) - kFadeAbove - (minimized ? 0 : SGRNowPlayingStripHeight());CGRect frame = CGRectMake(0, top, stockBar.bounds.size.width, CGRectGetMaxY(glass) - top);if (!CGRectEqualToRect(fade.frame, frame)) fade.frame = frame;if (fade.superview != stockBar || stockBar.subviews.firstObject != fade) [stockBar insertSubview:fade atIndex:0];@@ -565,7 +567,7 @@ static void syncBar(UIView *stockBar) {CGFloat height = MAX(bounds.size.height, glassHeight(bar, stockBar));CGRect frame = CGRectMake(0, CGRectGetMaxY(bounds) - height, width, height);if (!CGRectEqualToRect(host.frame, frame)) host.frame = frame;- placeFade(stockBar, frame);+ placeFade(stockBar, frame, minimized);CGRect mainFrame = host.bounds, apartFrame = CGRectZero;if (minimized) {CGFloat side = kApartItemWidth + 2 * kPlatterInset;@@ -820,7 +822,11 @@ static void setMinimized(BOOL minimized, BOOL animated) {settle(YES);return;}- moveFrom(host, before, ^{ SGRNowPlayingBarFollowTabBar(); }, settle);+ SGRNowPlayingBarMoving(YES);+ moveFrom(host, before, ^{ SGRNowPlayingBarFollowTabBar(); }, ^(BOOL finished) {+ SGRNowPlayingBarMoving(NO);+ settle(finished);+ });}CGRect SGRTabBarInlineSlot(UIView *host, CGFloat height) {diff --git a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.h b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.hindex 336f6f7c..d83d5ae0 100644--- a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.h+++ b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.h@@ -27,3 +27,13 @@ CGRect SGRNowPlayingArtworkFrameIn(UIView *host);// Lays the bar out again at once, into the minimized tab bar's slot or back above the bar// (Navbar.h's SGRTabBarInlineSlot); TabBar.x calls it inside its own animation.void SGRNowPlayingBarFollowTabBar(void);+// TabBar.x brackets its animated minimize and expand with YES and NO. Meanwhile the bar's own relayout after the Jam+// strip moves waits for the end, so it cannot snap the bar mid-spring.+void SGRNowPlayingBarMoving(BOOL moving);+// The height of Spotify's Jam strip on the bar, 0 outside a Jam (NowPlayingBar.x): the fade under the bars+// (TabBar.x) reaches that much higher, so the strip's text has it behind it too. The tab bar is laid out+// again when it changes.+CGFloat SGRNowPlayingStripHeight(void);+// The Jam strip in `host`'s coordinates, through any transform between them (the minimized tab bar's row moves the+// bar by one); CGRectNull outside a Jam or when the strip is not inside `host`.+CGRect SGRNowPlayingStripFrameIn(UIView *host);diff --git a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.xindex 984d6fe0..b5f7b0e4 100644--- a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x+++ b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x@@ -17,6 +17,10 @@// (386x100, the track card at y = 44). It paints the strip, or a view around the strip and the track, as// well, so the card is the painted view that holds the track and has no strip in it. The strip stays out// of the card's glass and gets a pane of its own above it, since its own paint goes clear with the rest.+// The strip's class is modelled, not recorded: no tree has a Jam in it yet. The 9.1.90 binary has the Jam's+// hat under Jam_AttachmentsImpl.HatRootViewController, so the strip is also known by its controller.+// In the minimized tab bar's row the card docks as it does outside a Jam, and the strip rides above it at+// its width, on its own pane.#import "Core/SGCore.h"#import "Redesigned/Kit/SGRRepaint.h"#import "Redesigned/Kit/SGRGlass.h"@@ -31,6 +35,9 @@ static const CGFloat kStripInset = 4;static char kGlassKey, kStripGlassKey;static __weak UIView *sg_card;static CGRect sg_stripFrame;+// The track's glass frame in the container's view as the bar was last styled, the strip cut off: the row+// takes the card's height and middle from it, never the bar's, which in a Jam has the strip on top.+static CGRect sg_trackFrame = {{INFINITY, INFINITY}, {0, 0}};static __weak UIVisualEffectView *sg_cardGlass;static __weak UIView *sg_cardArtwork;static __weak UIView *sg_progress;@@ -45,16 +52,25 @@ CGRect SGRNowPlayingCardFrameIn(UIView *host, CGFloat *radius) {return [host convertRect:glass.bounds fromView:glass];}+CGFloat SGRNowPlayingStripHeight(void) {+ return sg_stripFrame.size.height;+}+CGRect SGRNowPlayingArtworkFrameIn(UIView *host) {UIView *artwork = sg_cardArtwork;if (!artwork.window || !host) return CGRectNull;return [host convertRect:artwork.bounds fromView:artwork];}-// The Jam strip. The height keeps out a view of the same module that can hold the track card too.+// The Jam strip, by its class or by its controller's (Jam_AttachmentsImpl.HatRootViewController, whose view+// can be any hosting view). Only the Jam's: the bar's other hats (ads, sponsors) keep the card out of the row.+// The height keeps out a view of the same module that can hold the track card too.static BOOL isStrip(UIView *view) {- NSString *name = NSStringFromClass(view.class);- return view.bounds.size.height <= 60 && [name containsString:@"AttachmentsImpl"] && [name containsString:@"Hat"];+ if (view.bounds.size.height > 60) return NO;+ if (SGClassNamed(view.class, @"AttachmentsImpl") && SGClassNamed(view.class, @"Hat")) return YES;+ UIResponder *next = view.nextResponder;+ if (![next isKindOfClass:UIViewController.class]) return NO;+ return SGClassNamed(next.class, @"Jam") && SGClassNamed(next.class, @"Hat");}static BOOL inStrip(UIView *view, UIView *root) {@@ -161,7 +177,8 @@ static void restyleCardContent(UIView *card) {}}-// The strip's own pane, a strip high less the gaps, on the card's side the strip is on. It is measured from+// The strip's own pane, a strip high less the gaps, on the card's side the strip is on. It is the card's glass,+// one material with it; the strip's white text reads over a bright page by the fade under the bars (TabBar.x). It is measured from// the card's settled frame and the strip's height, not from the strip's frame: Spotify animates the strip// in, and a pane taken from it mid-way sat about 12pt off and cut its ⋯ button. The glass comes in and goes// by its effect, never by alpha (SGRGlass.h).@@ -391,13 +408,39 @@ static void placeTexts(UIView *bar) {// In the minimized tab bar's row (TabBar.x): the bar narrowed to the slot by its edges, so Spotify's content// lays itself out to the width, and moved down by a transform on the container's view, which Spotify's-// layout leaves alone. Outside a Jam only: its strip has no room in the row.+// layout leaves alone. The slot is the track card's height and the card is centred in it; in a Jam the strip,+// on the bar above the card, rides above the row. A bar taller than its card for any other reason (a hat this+// file does not know) stays above the tab bar.+static const CGFloat kHatMin = 20;++// The Jam strip the bar was last styled with, shown or not: the tab bar's move lays the bar out again without+// styling it, and a second walk of the bar on each pass for it was a cost of its own.+static __weak UIView *sg_strip;++// Class names and frames only: a hat's labels can hold the track and the names of the people in a Jam.+static void appendShape(UIView *view, NSUInteger depth, NSMutableString *out) {+ [out appendFormat:@"%*s%@ %@\n", (int)depth * 2, "", NSStringFromClass(view.class), NSStringFromCGRect(view.frame)];+ if (depth < 8) for (UIView *sub in view.subviews) appendShape(sub, depth + 1, out);+}+static void placeInline(UIViewController *container) {UIView *view = container.view;UIView *bar = container.childViewControllers.firstObject.viewIfLoaded;- UIView *strip = bar ? stripIn(bar) : nil;- BOOL jam = strip && !strip.hidden && strip.alpha >= 0.01 && strip.window && strip.bounds.size.height >= 1;- CGRect slot = !bar || bar.superview != view || jam ? CGRectNull : SGRTabBarInlineSlot(view.superview, bar.bounds.size.height);+ CGRect track = CGRectIsNull(sg_trackFrame) ? bar.frame : sg_trackFrame;+ // A hat is a row of its own (the Jam's is 44pt); a few points between card and bar are not one.+ BOOL hat = bar && bar.bounds.size.height - track.size.height >= kHatMin;+ UIView *strip = hat && [sg_strip isDescendantOfView:bar] ? sg_strip : nil;+ BOOL known = !hat || strip;+ if (!known) {+ static dispatch_once_t once;+ dispatch_once(&once, ^{+ NSMutableString *shape = [NSMutableString string];+ appendShape(bar, 0, shape);+ SGLogLong(@"now playing bar", [NSString stringWithFormat:@"a hat on the bar that is not the Jam's keeps the card out of the "+ @"tab bar's row: card %@, bar %@\n%@", NSStringFromCGRect(track), NSStringFromCGRect(bar.frame), shape]);+ });+ }+ CGRect slot = !bar || bar.superview != view || !known ? CGRectNull : SGRTabBarInlineSlot(view.superview, track.size.height);// Where the view stands untransformed, in the slot's coordinates.CGPoint origin = CGPointMake(view.center.x - view.bounds.size.width / 2, view.center.y - view.bounds.size.height / 2);if (CGRectIsNull(slot) || !setEdges(bar, CGRectGetMinX(slot) - origin.x, CGRectGetMaxX(slot) - origin.x)) {@@ -408,7 +451,7 @@ static void placeInline(UIViewController *container) {if (bar) placeTexts(bar);return;}- CGAffineTransform move = CGAffineTransformMakeTranslation(0, CGRectGetMidY(slot) - origin.y - CGRectGetMidY(bar.frame));+ CGAffineTransform move = CGAffineTransformMakeTranslation(0, CGRectGetMidY(slot) - origin.y - CGRectGetMidY(track));if (!CGAffineTransformEqualToTransform(view.transform, move)) view.transform = move;tuckExtras(bar, YES);sg_inline = view;@@ -419,6 +462,12 @@ static void placeInline(UIViewController *container) {for (UIView *v = view.superview; v; v = v.superview) if (v.clipsToBounds) [clips appendFormat:@" %@", v.class];SGLog(@"now playing bar in the tab bar's row at %@, clipped by:%@", NSStringFromCGRect(slot), clips.length ? clips : @" nothing");});+ // Whether the strip followed the bar's narrowed edges, which no recorded tree shows.+ static dispatch_once_t jamOnce;+ if (strip) dispatch_once(&jamOnce, ^{+ SGLog(@"now playing bar in the tab bar's row in a Jam: strip %@, bar %@, card %@ (in the container's view)",+ NSStringFromCGRect(SGFrameIn(strip, view)), NSStringFromCGRect(bar.frame), NSStringFromCGRect(track));+ });}void SGRNowPlayingBarFollowTabBar(void) {@@ -429,6 +478,44 @@ void SGRNowPlayingBarFollowTabBar(void) {[container.view layoutIfNeeded];}+CGRect SGRNowPlayingStripFrameIn(UIView *host) {+ UIView *strip = sg_strip;+ if (SGRNowPlayingStripHeight() <= 0 || !host || ![strip isDescendantOfView:host]) return CGRectNull;+ return [host convertRect:strip.bounds fromView:strip];+}++// The tab bar's moves under way (one can start before the last one ends), and the relayout owed to their end.+static NSInteger sg_barMoves;+static BOOL sg_owedLayout, sg_owedRefresh;++static void relayoutBar(UIView *host, BOOL taller) {+ if (sg_barMoves > 0) {+ sg_owedLayout = YES;+ sg_owedRefresh |= taller;+ return;+ }+ [host setNeedsLayout];+ if (taller) SGRRefreshTabBar();+}++void SGRNowPlayingBarMoving(BOOL moving) {+ UIView *strip = sg_strip;+ if (moving) {+ // Spotify's own strip-in animation would race the tab bar's spring: the strip goes to where it is set.+ if (sg_barMoves++ == 0 && SGRNowPlayingStripHeight() > 0 && strip.window && strip.layer.animationKeys.count) [strip.layer removeAllAnimations];+ return;+ }+ if (sg_barMoves == 0 || --sg_barMoves > 0) return;+ UIView *host = sg_container.viewIfLoaded;+ if (sg_owedLayout && host) relayoutBar(host, sg_owedRefresh);+ sg_owedLayout = sg_owedRefresh = NO;+ static dispatch_once_t once;+ if (host && SGRNowPlayingStripHeight() > 0 && [strip isDescendantOfView:host]) dispatch_once(&once, ^{+ SGLog(@"now playing bar: tab bar move ended in a Jam, strip %@, card glass %@ (in the container's view)",+ NSStringFromCGRect(SGFrameIn(strip, host)), NSStringFromCGRect(SGFrameIn(sg_cardGlass, host)));+ });+}+// The same bar class also stands at the top of Spotify's sheets (the DJ request one: Up next, device, play).// It is not the tab bar's card there: the sheet has its own blue ground and corners, and a dark 24pt pane of// the bar's full width on it reads as a frame round the track. It is left as Spotify draws it, and it must not@@ -441,6 +528,23 @@ static BOOL inSheet(UIView *view) {return NO;}+// The card's glass frame in `host`: the card, else the box round the track's content, with the strip cut+// out from its side, all of it when the card is a view around both, else as much as overlaps. CGRectNull+// when there is no card to speak of.+static CGRect trackFrame(UIView *bar, UIView *card, UIView *strip, CGRect stripFrame, UIView *host, BOOL *stripAbove) {+ CGRect frame = card ? SGFrameIn(card, host) : contentBounds(bar, host);+ if (CGRectIsNull(frame)) return frame;+ *stripAbove = NO;+ if (strip) {+ *stripAbove = CGRectGetMidY(stripFrame) < CGRectGetMidY(frame);+ CGFloat cut = card && [strip isDescendantOfView:card] ? strip.bounds.size.height : CGRectIntersection(frame, stripFrame).size.height;+ frame.size.height -= cut;+ if (*stripAbove) frame.origin.y += cut;+ }+ frame.size.height = MIN(frame.size.height, 80);+ return frame.size.height < 30 || frame.size.width < 100 ? CGRectNull : frame;+}+static void styleNowPlayingBar(UIViewController *container) {if (container.isViewLoaded && inSheet(container.view)) {UIVisualEffectView *pane = objc_getAssociatedObject(container.view, &kGlassKey);@@ -463,35 +567,44 @@ static void styleNowPlayingBar(UIViewController *container) {UIView *card = sg_card;if (!card || !isGoodCard(card, bar, marker) || stripIn(card)) card = sg_card = chooseCard(bar, marker);+ // The strip before the bar's paint goes, so the log says what it was made of.+ UIView *strip = sg_strip = stripIn(bar);+ if (strip && (strip.hidden || strip.alpha < 0.01 || !strip.window)) strip = nil;+ static dispatch_once_t stripOnce;+ if (strip) dispatch_once(&stripOnce, ^{+ NSMutableString *tree = [NSMutableString string];+ SGForEachView(strip, ^(UIView *v) {+ CGColorRef paint = v.layer.backgroundColor;+ [tree appendFormat:@"%@ %@ a=%.2f%@\n", v.class, NSStringFromCGRect(SGFrameIn(v, strip)), v.alpha,+ paint ? [NSString stringWithFormat:@" paint=%@", [UIColor colorWithCGColor:paint]] : @""];+ });+ SGLogLong(@"now playing bar", [NSString stringWithFormat:@"Jam strip %@, controller %@, in the bar: %@ (Spotify's paint inside the "+ @"bar is cleared as it is set, SGRRepaint.x)\n%@", strip.class, strip.nextResponder.class,+ [strip isDescendantOfView:bar] ? @"yes" : @"no", tree]);+ });+container.view.layer.backgroundColor = NULL;SGStripBackgrounds(bar);- UIView *strip = stripIn(bar);- if (strip && (strip.hidden || strip.alpha < 0.01 || !strip.window)) strip = nil;// Spotify lays the strip out after the bar and moves it in, so the bar is styled again a moment after- // the strip has moved, until it stays put.+ // the strip has moved, until it stays put. A strip that comes, goes or changes height moves the fade too.CGRect stripFrame = strip ? SGFrameIn(strip, container.view) : CGRectZero;if (!CGRectEqualToRect(stripFrame, sg_stripFrame)) {+ BOOL taller = stripFrame.size.height != sg_stripFrame.size.height;sg_stripFrame = stripFrame;UIView *host = container.view;- dispatch_async(dispatch_get_main_queue(), ^{ [host setNeedsLayout]; });+ // During the tab bar's move it waits for the move's end (SGRNowPlayingBarMoving).+ dispatch_async(dispatch_get_main_queue(), ^{ relayoutBar(host, taller); });}if (strip.bounds.size.height < 1) strip = nil;+ // The track's frame for the row, then again for the glass: the row narrows the bar, which the card follows.+ BOOL stripAbove = NO;+ // A card's, or in a Jam the box round the track's content; outside a Jam without a card the bar's own+ // frame stands for it, as before, since that box is padded.+ sg_trackFrame = card || strip ? trackFrame(bar, card, strip, stripFrame, container.view, &stripAbove) : CGRectNull;placeInline(container);-- CGRect frame = card ? SGFrameIn(card, container.view) : contentBounds(bar, container.view);+ CGRect frame = trackFrame(bar, card, strip, stripFrame, container.view, &stripAbove);if (CGRectIsNull(frame)) return;- // The strip comes out of the card's glass from its side: all of it when the card is a view around both,- // else as much as overlaps.- BOOL stripAbove = NO;- if (strip) {- stripAbove = CGRectGetMidY(stripFrame) < CGRectGetMidY(frame);- CGFloat cut = card && [strip isDescendantOfView:card] ? strip.bounds.size.height : CGRectIntersection(frame, stripFrame).size.height;- frame.size.height -= cut;- if (stripAbove) frame.origin.y += cut;- }- frame.size.height = MIN(frame.size.height, 80);- if (frame.size.height < 30 || frame.size.width < 100) return;CGFloat radius = MIN(kCardRadius, frame.size.height / 2);if (card) {diff --git a/tweak/Sources/Redesigned/Player/PlayerCoverAccent.x b/tweak/Sources/Redesigned/Player/PlayerCoverAccent.xindex 493fff75..8e4c0ce9 100644--- a/tweak/Sources/Redesigned/Player/PlayerCoverAccent.x+++ b/tweak/Sources/Redesigned/Player/PlayerCoverAccent.x@@ -7,14 +7,21 @@// controls and the footer): an image drawn in the accent is tinted from its own shape, a background or a shape layer// in the accent takes the color, and every original is kept to give back. It paints whenever the cover's color// changes and whenever the stack or one of its buttons lays out, which is when Spotify hands a button its new state.+//+// The mini player's lit buttons, its device glyph and its like (trees: t-home17e 1916-1945), are painted the same way,+// those two alone so the cover on the card is never judged: when the cover's color changes, which reaches here with the+// player never opened (PlayerField.x), when the bar or one of the two buttons lays out, and when the device glyph is+// handed a new image, which lays nothing out. Only the tab bar's bar (sgr_nowPlayingRoot), not the one on Spotify's sheets.#import <objc/runtime.h>#import "Core/SGCore.h"#import "Redesigned/Kit/SGRKit.h"+#import "Redesigned/Kit/SGRRepaint.h"#import "Player.h"static NSInteger sg_cover = -1; // 0xRRGGBB while a cover gives one, else -1static __weak UIView *sg_stack; // the bottom stack last painted-static char kOriginalKey, kTintedKey, kTintedCoverKey, kAccentImageKey, kInkKey, kOriginalFillKey, kOriginalStrokeKey;+static char kOriginalKey, kTintedKey, kTintedCoverKey, kAccentImageKey, kInkKey, kOriginalFillKey, kOriginalStrokeKey, kObservedKey;+static NSString *const kBarConnectId = @"Components.ConnectButtonOutputSwitcher", *const kBarLikeId = @"Components.UI.AddToButton";BOOL SGRPlayerFollowsCover(void) {static BOOL on;@@ -123,6 +130,12 @@ static void paintImageView(UIImageView *view) {UIImage *image = view.image, *tinted = objc_getAssociatedObject(view, &kTintedKey);UIImage *original = image == tinted ? objc_getAssociatedObject(view, &kOriginalKey) : image;if (!original) return;+ // A UIButton puts its own image back on every layout pass: the tint made for this cover goes back, not a new one.+ if (tinted && image != tinted && image == objc_getAssociatedObject(view, &kOriginalKey)+ && sg_cover >= 0 && [objc_getAssociatedObject(view, &kTintedCoverKey) integerValue] == sg_cover) {+ view.image = tinted;+ return;+ }if (sg_cover < 0 || !imageAccentLike(original)) {if (image == tinted && tinted) view.image = original;objc_setAssociatedObject(view, &kTintedKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);@@ -224,14 +237,12 @@ static void paintLayers(CALayer *layer) {for (CALayer *sublayer in layer.sublayers) paintLayers(sublayer);}-void SGRPlayerPaintCover(UIView *stack) {- if (!SGRPlayerFollowsCover() || !stack) return;- if (stack.superview && [stack isKindOfClass:UIStackView.class]) sg_stack = stack;+static void paintTree(UIView *root) {static Class lottie;if (!lottie) lottie = NSClassFromString(@"Lottie.LottieAnimationView");[CATransaction begin];[CATransaction setDisableActions:YES];- SGForEachView(stack, ^(UIView *view) {+ SGForEachView(root, ^(UIView *view) {if ([view.accessibilityIdentifier isEqualToString:SGRPlainCheckIdentifier]) view.tintColor = sg_cover < 0 ? SGRAccent() : coverColor();else if ([view isKindOfClass:UIImageView.class]) paintImageView((UIImageView *)view);else if (lottie && [view isKindOfClass:lottie]) paintLayers(view.layer);@@ -240,6 +251,51 @@ void SGRPlayerPaintCover(UIView *stack) {[CATransaction commit];}+void SGRPlayerPaintCover(UIView *stack) {+ if (!SGRPlayerFollowsCover() || !stack) return;+ if (stack.superview && [stack isKindOfClass:UIStackView.class]) sg_stack = stack;+ paintTree(stack);+}++static BOOL isBarButton(UIView *view) {+ NSString *name = view.accessibilityIdentifier;+ return name && ([name isEqualToString:kBarConnectId] || [name isEqualToString:kBarLikeId]);+}++// The bar's two buttons, found once per bar and cover and again only when one is gone from it: the bar lays out on+// every track change, page swipe and Jam strip move, and a walk of its hundred views on each of those was #96's kind+// of cost. A bar with one of them, or neither (an ad, an episode), is not walked again on each layout either.+static __weak UIView *sg_barConnect, *sg_barLike, *sg_barSearched;++static BOOL findBarButtons(UIView *bar) {+ UIView *connect = sg_barConnect, *like = sg_barLike;+ if (bar == sg_barSearched && (!connect || [connect isDescendantOfView:bar]) && (!like || [like isDescendantOfView:bar]))+ return connect || like;+ sg_barSearched = bar;+ __block UIView *foundConnect = nil, *foundLike = nil;+ SGForEachView(bar, ^(UIView *view) {+ NSString *name = view.accessibilityIdentifier;+ if (!foundConnect && [name isEqualToString:kBarConnectId]) foundConnect = view;+ else if (!foundLike && [name isEqualToString:kBarLikeId]) foundLike = view;+ });+ sg_barConnect = foundConnect;+ sg_barLike = foundLike;+ SGForEachView(foundConnect, ^(UIView *inner) {+ if (![inner isKindOfClass:UIImageView.class] || objc_getAssociatedObject(inner, &kObservedKey)) return;+ objc_setAssociatedObject(inner, &kObservedKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ // The tint set back reports too, and stops there: the image is the tint made for this cover.+ SGRObserveImage((UIImageView *)inner, ^(UIImageView *changed) { paintImageView(changed); });+ });+ return foundConnect || foundLike;+}++static void paintBar(UIView *bar) {+ if (!bar || !findBarButtons(bar)) return;+ UIView *connect = sg_barConnect, *like = sg_barLike;+ if (connect) paintTree(connect);+ if (like) paintTree(like);+}+void SGRPlayerSetCoverAccent(UIColor *cover) {NSInteger rgb = -1;CGFloat h, s, v, a;@@ -254,16 +310,29 @@ void SGRPlayerSetCoverAccent(UIColor *cover) {sg_cover = rgb;SGLog(@"redesign player: follow the cover %@", rgb < 0 ? @"gives the accent back (a gray cover)" : [NSString stringWithFormat:@"paints #%06lX", (long)rgb]);SGRPlayerPaintCover(sg_stack);+ sg_barSearched = nil; // a new cover looks again, for a button the last bar state did not have+ paintBar(sgr_nowPlayingRoot);}-// A button in the player's stack laid out: Spotify hands it a new state's icon or animation this way.+// A button in the player's stack, or the mini player's device or like button, laid out: Spotify hands it a new state's+// icon or animation this way.%hook UIButton- (void)layoutSubviews {%orig;- UIView *stack = sg_stack;- if (stack && (sg_cover >= 0 || objc_getAssociatedObject(self, &kTintedKey)) && [(UIView *)self isDescendantOfView:stack]) {- SGRPlayerPaintCover((UIView *)self);- }+ if (sg_cover < 0 && !objc_getAssociatedObject(self, &kTintedKey)) return;+ UIView *stack = sg_stack, *bar = sgr_nowPlayingRoot, *button = (UIView *)self;+ if (stack && [button isDescendantOfView:stack]) SGRPlayerPaintCover(button);+ else if (bar && (isBarButton(button) || isBarButton(button.superview)) && [button isDescendantOfView:bar]) paintTree(button);+}+%end++%hook _TtC18NowPlaying_BarImpl27NowPlayingBarViewController+- (void)viewDidLayoutSubviews {+ %orig;+ // A gray cover was given back to the accent when it came (SGRPlayerSetCoverAccent), which left nothing to paint.+ if (sg_cover < 0) return;+ UIView *view = ((UIViewController *)self).viewIfLoaded;+ if (view && view == sgr_nowPlayingRoot) paintBar(view);}%enddiff --git a/tweak/Sources/Redesigned/Player/PlayerMorph.x b/tweak/Sources/Redesigned/Player/PlayerMorph.xindex 7cf0fe37..98c9755b 100644--- a/tweak/Sources/Redesigned/Player/PlayerMorph.x+++ b/tweak/Sources/Redesigned/Player/PlayerMorph.x@@ -69,6 +69,8 @@ static CGFloat screenRadius(void) {@interface SGRPlayerMorph : NSObject@property (nonatomic, readonly) CGFloat restY;+@property (nonatomic, readonly) CGRect card;+@property (nonatomic, readonly) BOOL masksStrip;@end@implementation SGRPlayerMorph {@@ -76,10 +78,16 @@ static CGFloat screenRadius(void) {UIView *_sheet;UIImageView *_cover;CALayer *_mask;+ // In a Jam (follow mode only): the mask on the stand-in or its picture, its strip part fading on the way open, and+ // a close's copy of the strip's glass, which fades by alpha.+ CALayer *_stripMask, *_stripPart;+ __weak UIView *_masked, *_stripPane;+ CGFloat _stripPaneAlpha;CGRect _card, _barArtwork, _barRest, _spotifyFrame;CGFloat _cardRadius, _spotifyAlpha;CGColorRef _overlayColor;BOOL _coverHidden;+ BOOL _tornDown;BOOL _follows; // 9.1.90: Spotify animates the player's frame and alpha, which the morph then only reads}@@ -92,8 +100,66 @@ static CGFloat screenRadius(void) {// 9.1.90's CompactOverlayTransition animates the player itself, so the morph follows where it is drawn. Spotify also// crossfades its bar stand-in with the player at each end, on the render server, so the bar is in its place the moment// the card lands even when the main thread stalls; the stand-in is left to Spotify.-- (void)follow {+- (void)followFrom:(UIView *)source {_follows = YES;+ // Next turn, once every hook on the transition's start has run: a close's glass copies (BarTransition.x) exist by+ // then whichever hook runs first. At either end the strip sits in the stand-in at Spotify's own alpha, so the turn+ // without the mask shows nothing new.+ __weak SGRPlayerMorph *weak = self;+ __weak UIView *weakSource = source;+ dispatch_async(dispatch_get_main_queue(), ^{ [weak maskStripFrom:weakSource]; });+}++- (void)maskStripFrom:(UIView *)source {+ if (_tornDown || !source) return;+ // In a Jam the stand-in is the whole bar, strip and card, and the sheet grows from the card alone: the strip fades+ // in the first quarter of an open, so it never stands beside the growing player. Its place comes from Spotify's bar+ // the stand-in copies, scaled to the stand-in, not from the card: Spotify has already set the stand-in's end frame.+ UIView *bar = _bar;+ CGRect strip = SGRNowPlayingStripFrameIn(source);+ if (CGRectIsNull(strip) || !bar) return;+ CGSize from = source.bounds.size, to = bar.bounds.size;+ CGFloat sx = from.width > 0 ? to.width / from.width : 1, sy = from.height > 0 ? to.height / from.height : 1;+ strip = CGRectIntersection(CGRectMake(strip.origin.x * sx, strip.origin.y * sy, strip.size.width * sx, strip.size.height * sy), bar.bounds);+ if (CGRectIsEmpty(strip)) return;+ // A close's stand-in is a picture over copies of the bar's glass (BarTransition.x), which a mask above them would+ // break: the mask goes on the picture alone, and the strip's copy of the glass fades by alpha.+ UIView *masked = bar;+ if ([bar isKindOfClass:UIImageView.class] && !((UIImageView *)bar).image && [bar.subviews.lastObject isKindOfClass:UIImageView.class]) {+ masked = bar.subviews.lastObject;+ for (UIView *pane in bar.subviews) {+ if (pane != masked && CGRectContainsPoint(strip, CGPointMake(CGRectGetMidX(pane.frame), CGRectGetMidY(pane.frame)))) _stripPane = pane;+ }+ _stripPaneAlpha = _stripPane.alpha;+ }+ if (masked.layer.mask) {+ _stripPane = nil;+ static dispatch_once_t once;+ dispatch_once(&once, ^{ SGLog(@"player morph: the bar's stand-in has a mask of its own, the Jam strip is not faded"); });+ return;+ }+ strip = [masked convertRect:strip fromView:bar];+ // Opaque but for the strip, above or below the card, which its own part covers at the fade's opacity.+ CAShapeLayer *mask = [CAShapeLayer layer];+ mask.frame = masked.bounds;+ UIBezierPath *path = [UIBezierPath bezierPathWithRect:masked.bounds];+ [path appendPath:[UIBezierPath bezierPathWithRect:strip]];+ mask.path = path.CGPath;+ mask.fillRule = kCAFillRuleEvenOdd;+ _stripPart = [CALayer layer];+ _stripPart.backgroundColor = UIColor.blackColor.CGColor;+ _stripPart.frame = strip;+ [mask addSublayer:_stripPart];+ _stripMask = mask;+ _masked = masked;+ [CATransaction begin];+ [CATransaction setDisableActions:YES];+ masked.layer.mask = mask;+ [CATransaction commit];+}++- (BOOL)masksStrip {+ return _stripMask != nil;}- (instancetype)initWithContainer:(UIView *)container overlay:(UIView *)overlay bar:(UIView *)bar barRest:(CGRect)barRest {@@ -197,6 +263,11 @@ static CGFloat screenRadius(void) {frame.origin.y = self->_barRest.origin.y + rise;bar.frame = frame;bar.alpha = 1 - ramp(0, 0.25, t);+ } else if (self->_stripPart) {+ // Under Spotify's own crossfade of the stand-in, which stays its own.+ CGFloat strip = 1 - ramp(0, 0.25, t);+ self->_stripPart.opacity = strip;+ self->_stripPane.alpha = self->_stripPaneAlpha * strip;}if (self->_cover) {@@ -230,11 +301,18 @@ static CGFloat screenRadius(void) {}- (void)tearDown {+ _tornDown = YES;UIView *overlay = _overlay;[CATransaction begin];[CATransaction setDisableActions:YES];overlay.layer.sublayerTransform = CATransform3DIdentity;if (overlay.layer.mask == _mask) overlay.layer.mask = nil;+ UIView *masked = _masked, *pane = _stripPane;+ if (_stripMask && masked.layer.mask == _stripMask) masked.layer.mask = nil;+ pane.alpha = _stripPaneAlpha;+ _stripMask = nil;+ _stripPart = nil;+ _stripPane = nil;if (!_follows) overlay.alpha = _spotifyAlpha;if (overlay && !_follows) overlay.frame = _spotifyFrame;if (!overlay.layer.backgroundColor) overlay.layer.backgroundColor = _overlayColor;@@ -298,7 +376,8 @@ static const float kCloseSpeed = 1.5; // how much faster than Spotify's@property (nonatomic, weak) id<UIViewControllerContextTransitioning> context;@property (nonatomic, strong) CADisplayLink *link;@property (nonatomic) NSInteger still;-@property (nonatomic) CGFloat lastY;+@property (nonatomic) CGFloat lastY, lastT;+@property (nonatomic) CGRect npbFrame; // Spotify's bar frame, for the Jam close log@property (nonatomic) CFTimeInterval settledSince; // when it last moved or was driven by a finger, or began@property (nonatomic) CFTimeInterval lastTick;@property (nonatomic) BOOL sped; // the container's layer runs at kCloseSpeed until let go@@ -324,7 +403,8 @@ static void runAtSpeed(CALayer *layer, float speed) {CGFloat rest = self.morph.restY > 0 ? self.morph.restY : container.bounds.size.height;// An open's first frame has no presentation layer yet and its model already holds the end; Spotify starts it at the bar.CGFloat y = drawn ? drawn.frame.origin.y : rest;- [self.morph apply:rest > 0 ? MIN(1, MAX(0, 1 - y / rest)) : 1];+ self.lastT = rest > 0 ? MIN(1, MAX(0, 1 - y / rest)) : 1;+ [self.morph apply:self.lastT];BOOL interactive = self.context.isInteractive;// A close dragged by a finger runs faster from the moment it is let go.if (self.closing && self.wasInteractive && !interactive && !self.sped) {@@ -352,6 +432,14 @@ static void runAtSpeed(CALayer *layer, float speed) {self.link = nil;// Back to 1 from where its animations are, so a close Spotify has not finished does not jump back.if (self.sped) runAtSpeed(self.container.layer, 1);+ // Whether a close in a Jam ends at t 0: Spotify parks the player at its bar frame's top, the strip's, and restY is the card's.+ if (self.closing && self.morph.masksStrip) {+ static dispatch_once_t once;+ dispatch_once(&once, ^{+ SGLog(@"player morph: Jam close ended, npbFrame %@, card %@, restY %.1f, last t %.3f", NSStringFromCGRect(self.npbFrame),+ NSStringFromCGRect(self.morph.card), self.morph.restY, self.lastT);+ });+ }[self.morph tearDown];self.morph = nil;}@@ -364,6 +452,26 @@ static id ivarOf(id object, const char *name) {static char kFollowerKey;+// A CGRect a Swift object keeps, read at its ivar's offset; CGRectNull without that ivar, or when it cannot be a CGRect+// (an Objective-C type other than one, or too little room in the object), and the class's ivars are then logged once.+static CGRect rectIvarOf(id object, const char *name) {+ Class cls = object_getClass(object);+ Ivar ivar = class_getInstanceVariable(cls, name);+ const char *type = ivar ? ivar_getTypeEncoding(ivar) : NULL;+ BOOL fits = ivar && ivar_getOffset(ivar) >= 0 && (size_t)ivar_getOffset(ivar) + sizeof(CGRect) <= class_getInstanceSize(cls);+ if (fits && (!type || !*type || strncmp(type, "{CGRect", 7) == 0)) return *(CGRect *)((char *)(__bridge void *)object + ivar_getOffset(ivar));+ static dispatch_once_t once;+ dispatch_once(&once, ^{+ unsigned int count = 0;+ Ivar *ivars = class_copyIvarList(cls, &count);+ NSMutableString *names = [NSMutableString string];+ for (unsigned int i = 0; i < count; i++) [names appendFormat:@" %s", ivar_getName(ivars[i])];+ free(ivars);+ SGLog(@"player morph: %@ has no CGRect %s, its ivars:%@", cls, name, names);+ });+ return CGRectNull;+}+static void followTransition(id transition, id<UIViewControllerContextTransitioning> context) {if (SGRReduceMotion() || !context) return;UIView *container = context.containerView;@@ -375,7 +483,7 @@ static void followTransition(id transition, id<UIViewControllerContextTransition[old finish];SGRPlayerMorph *morph = [[SGRPlayerMorph alloc] initWithContainer:container overlay:overlay bar:ivarOf(transition, "npbSnapshotView") barRest:CGRectZero];if (!morph) return;- [morph follow];+ [morph followFrom:ivarOf(transition, "npbView")];((UIView *)ivarOf(transition, "tabBarSnapshotView")).alpha = 0;SGRMorphFollower *follower = [SGRMorphFollower new];follower.morph = morph;@@ -383,6 +491,7 @@ static void followTransition(id transition, id<UIViewControllerContextTransitionfollower.overlay = overlay;follower.context = context;follower.lastY = CGFLOAT_MAX;+ if (SGRNowPlayingStripHeight() > 0) follower.npbFrame = rectIvarOf(transition, "npbFrame");// A close plays faster: its slide, its stand-ins and so the morph that follows them. One Spotify runs on its own// from the start, one dragged by a finger from when it is let go (tick:).follower.closing = !to.isBeingPresented;diff --git a/tweak/Sources/Redesigned/Player/PlayerSettings.m b/tweak/Sources/Redesigned/Player/PlayerSettings.mindex 5a48c449..1362ce6b 100644--- a/tweak/Sources/Redesigned/Player/PlayerSettings.m+++ b/tweak/Sources/Redesigned/Player/PlayerSettings.m@@ -363,7 +363,7 @@ UIViewController *SGRPlayerSettingsPage(NSArray *more) {SGNotedSection(@"Controls", @[SGSwitchRow(@"Volume", nil, SGRKeyPlayerVolume),SGOptionRow(@"Follow the cover", nil, SGRKeyPlayerFollowsCover)],@"Volume puts a slider under the controls for this iPhone, or the speaker's while Spotify plays on another device. "- @"Follow the cover paints the like, shuffle and repeat in the color of the song playing."),+ @"Follow the cover paints the like, shuffle, repeat, device and queue buttons, and the mini player's device and like, in the color of the song playing."),SGNotedSection(@"Mini player", SGRNowPlayingBarRows(),@"Apple Music style moves the now playing bar in between two tabs as you scroll down."), nil];[sections addObjectsFromArray:more];