Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix: the now playing bar's glass stays on the track in a Jam, and the Jam strip gets its own pane
My-Name-Is-Jeff33289e326ae8
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 21798ab5..b3b2c935 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -250,7 +250,8 @@ Redesigned:Offline or Private Session under the bar), so the now playing bar and the pages move up with it. Laid out onthe Mac against harness/tabbar/NowPlayingBar/ the glass now playing bar (NowPlayingBar.x), with Spotify's device button on it hidden on request- (BarConnect.x, its own key and its own Now playing page, apart from the native look's)+ (BarConnect.x, its own key and its own Now playing page, apart from the native look's). 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)Player/ the redesigned full screen player (Player.h lists its files); its more button is handed toShared/Player's Speed and pitch, which draws in the menu it opens, and a hold on either side of thecover plays at 2x until the finger lifts (PlayerArtwork.x), an octave higher while Pitch followsdiff --git a/harness/album/stubs.m b/harness/album/stubs.mindex ef2a5b60..7f27ceb9 100644--- a/harness/album/stubs.m+++ b/harness/album/stubs.m@@ -2,7 +2,7 @@#import <UIKit/UIKit.h>UIColor *SGRAccentColor(void) { return nil; }__weak UIView *sgr_nowPlayingRoot = nil;-__weak UIView *sgr_nowPlayingCard = nil;+NSHashTable<UIView *> *sgr_nowPlayingPainted = nil;__weak UIView *sgr_lyricsCardRoot = nil;__weak UIView *sgr_lyricsPageRoot = nil;__weak UIView *sgr_playlistRoot = nil;diff --git a/harness/artist/stubs.m b/harness/artist/stubs.mindex 7879b96d..6a47b5c2 100644--- a/harness/artist/stubs.m+++ b/harness/artist/stubs.m@@ -2,7 +2,7 @@#import <UIKit/UIKit.h>UIColor *SGRAccentColor(void) { return nil; }__weak UIView *sgr_nowPlayingRoot = nil;-__weak UIView *sgr_nowPlayingCard = nil;+NSHashTable<UIView *> *sgr_nowPlayingPainted = nil;__weak UIView *sgr_lyricsCardRoot = nil;__weak UIView *sgr_lyricsPageRoot = nil;__weak UIView *sgr_playlistRoot = nil;diff --git a/harness/library/stubs.m b/harness/library/stubs.mindex 7879b96d..6a47b5c2 100644--- a/harness/library/stubs.m+++ b/harness/library/stubs.m@@ -2,7 +2,7 @@#import <UIKit/UIKit.h>UIColor *SGRAccentColor(void) { return nil; }__weak UIView *sgr_nowPlayingRoot = nil;-__weak UIView *sgr_nowPlayingCard = nil;+NSHashTable<UIView *> *sgr_nowPlayingPainted = nil;__weak UIView *sgr_lyricsCardRoot = nil;__weak UIView *sgr_lyricsPageRoot = nil;__weak UIView *sgr_playlistRoot = nil;diff --git a/harness/player/stubs.m b/harness/player/stubs.mindex 95a9ecb4..6970103a 100644--- a/harness/player/stubs.m+++ b/harness/player/stubs.m@@ -11,7 +11,7 @@UIColor *SGRAccentColor(void) { return nil; }__weak UIView *sgr_nowPlayingRoot = nil;-__weak UIView *sgr_nowPlayingCard = nil;+NSHashTable<UIView *> *sgr_nowPlayingPainted = nil;__weak UIView *sgr_lyricsPageRoot = nil;__weak UIView *sgr_playlistRoot = nil;diff --git a/harness/playlist/stubs.m b/harness/playlist/stubs.mindex f6f16798..df532177 100644--- a/harness/playlist/stubs.m+++ b/harness/playlist/stubs.m@@ -2,7 +2,7 @@#import <UIKit/UIKit.h>UIColor *SGRAccentColor(void) { return nil; }__weak UIView *sgr_nowPlayingRoot = nil;-__weak UIView *sgr_nowPlayingCard = nil;+NSHashTable<UIView *> *sgr_nowPlayingPainted = nil;__weak UIView *sgr_lyricsCardRoot = nil;__weak UIView *sgr_lyricsPageRoot = nil;__weak UIView *sgr_playlistRoot = nil;diff --git a/harness/tabbar/README.md b/harness/tabbar/README.mdindex 1e31b16c..9a1c4dc6 100644--- a/harness/tabbar/README.md+++ b/harness/tabbar/README.md@@ -38,6 +38,15 @@ half way through a slide what the screen shows of the message bar, the tab bar axcrun simctl spawn <udid> log show --last 1m --style compact --predicate 'eventMessage CONTAINS "[harness]" OR eventMessage CONTAINS "tab bar:"'+`jam` plays a Jam: a strip under the class name of Spotify's (a SwiftUI hosting view of+`Jam_AttachmentsImpl.JamHatElement`, 44 pt) over the card, both in a view painted the album colour too,+the bar 44 pt taller, and the strip gone again at 3.5 s. The log then lists the bar's glass panes. The+card's glass should be the track card's (386x56), the strip's pane 36 pt above it with a 4 pt gap, and+once the Jam is over the card's glass should still be 386x56 and the strip's pane should have no effect.+Before the fix the card's glass was the painted view around both, cut to 80 pt, over the strip and+the top 36 pt of the track. How Spotify really nests the strip is not known; this is one way the spec's description+allows.+Before the fix the gap was -26 pt with nothing under the bar on an iPhone SE, and with the message barup on any phone: UIKit's glass bar is 83 pt, Spotify's bar was its 49 pt row with no inset under it,and the glass bar stood the difference above it, over the now playing bar.diff --git a/harness/tabbar/build.sh b/harness/tabbar/build.shindex ee2db19f..811fb4db 100755--- a/harness/tabbar/build.sh+++ b/harness/tabbar/build.sh@@ -18,7 +18,7 @@ xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-ar"$OUT"/gen/*.m \"$SRC"/Core/SGLog.m "$SRC"/Core/SGPrefs.m "$SRC"/Core/SGViewTree.m "$SRC"/Core/SGGlass.m \"$SRC"/Core/SGBackdrop.m "$SRC"/Core/SGFlagForce.m "$SRC"/Core/SGUIMode.m \- "$SRC"/Redesigned/Kit/SGRTokens.m \+ "$SRC"/Redesigned/Kit/SGRTokens.m "$SRC"/Redesigned/Kit/SGRGlass.m \-framework UIKit -framework QuartzCore -framework CoreGraphics -framework Foundation \-o "$OUT/TabBarHarness.app/TabBarHarness"diff --git a/harness/tabbar/main.m b/harness/tabbar/main.mindex 15c13f91..66d52f81 100644--- a/harness/tabbar/main.m+++ b/harness/tabbar/main.m@@ -35,26 +35,69 @@@implementation _TtC22NowPlaying_BarPageImplP33_CCC0D2EEA6D4725EECD8965E8C38C86D20TouchPassthroughView@end+// A Jam (`jam`): Spotify's strip, a SwiftUI hosting view of Jam_AttachmentsImpl.JamHatElement 44pt high,+// over the card, both in a view that is painted too, and the bar 44pt taller.+@interface _TtGC7SwiftUI14_UIHostingViewV19Jam_AttachmentsImpl13JamHatElement_ : UIView+@end+@implementation _TtGC7SwiftUI14_UIHostingViewV19Jam_AttachmentsImpl13JamHatElement_+@end++static BOOL sgJam;+static __weak UIView *sgJamStrip;+@interface _TtC18NowPlaying_BarImpl27NowPlayingBarViewController : UIViewController@end@implementation _TtC18NowPlaying_BarImpl27NowPlayingBarViewController- (void)loadView {self.view = [UIView new];+ UIColor *album = [UIColor colorWithRed:0x18 / 255.0 green:0x14 / 255.0 blue:0x1C / 255.0 alpha:1];+ UIView *host = self.view;+ if (sgJam) {+ host = [[UIView alloc] initWithFrame:self.view.bounds];+ host.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;+ host.backgroundColor = album;+ [self.view addSubview:host];+ }// The card, 386x56 at {8,0} with the album colour, the artwork, two lines and the progress line// (trees/clean/home/01.txt, SPTNowPlayingBar).UIView *card = [UIView new];card.accessibilityIdentifier = @"SPTNowPlayingBar";- card.backgroundColor = [UIColor colorWithRed:0x18 / 255.0 green:0x14 / 255.0 blue:0x1C / 255.0 alpha:1];+ card.backgroundColor = album;card.layer.cornerRadius = 8;card.clipsToBounds = YES;card.translatesAutoresizingMaskIntoConstraints = NO;- [self.view addSubview:card];+ [host addSubview:card];[NSLayoutConstraint activateConstraints:@[- [card.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],- [card.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],- [card.topAnchor constraintEqualToAnchor:self.view.topAnchor],- [card.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor],+ [card.leadingAnchor constraintEqualToAnchor:host.leadingAnchor],+ [card.trailingAnchor constraintEqualToAnchor:host.trailingAnchor],+ [card.bottomAnchor constraintEqualToAnchor:host.bottomAnchor],+ sgJam ? [card.heightAnchor constraintEqualToConstant:56] : [card.topAnchor constraintEqualToAnchor:host.topAnchor],]];+ if (sgJam) {+ UIView *strip = [_TtGC7SwiftUI14_UIHostingViewV19Jam_AttachmentsImpl13JamHatElement_ new];+ strip.backgroundColor = [UIColor colorWithRed:0.1 green:0.45 blue:0.3 alpha:1];+ strip.translatesAutoresizingMaskIntoConstraints = NO;+ [host addSubview:strip];+ UILabel *label = [UILabel new];+ label.text = @"Jam by Alex";+ label.font = [UIFont boldSystemFontOfSize:13];+ label.textColor = UIColor.whiteColor;+ label.frame = CGRectMake(16, 12, 200, 20);+ [strip addSubview:label];+ UIButton *more = [UIButton systemButtonWithImage:[UIImage systemImageNamed:@"ellipsis"] target:nil action:nil];+ more.tintColor = UIColor.whiteColor;+ more.translatesAutoresizingMaskIntoConstraints = NO;+ [strip addSubview:more];+ [NSLayoutConstraint activateConstraints:@[+ [strip.leadingAnchor constraintEqualToAnchor:host.leadingAnchor],+ [strip.trailingAnchor constraintEqualToAnchor:host.trailingAnchor],+ [strip.bottomAnchor constraintEqualToAnchor:card.topAnchor],+ [strip.heightAnchor constraintEqualToConstant:44],+ [more.trailingAnchor constraintEqualToAnchor:strip.trailingAnchor constant:-8],+ [more.centerYAnchor constraintEqualToAnchor:strip.centerYAnchor],+ ]];+ sgJamStrip = strip;+ }UIView *art = [[UIView alloc] initWithFrame:CGRectMake(8, 8, 40, 40)];art.layer.cornerRadius = 4;art.clipsToBounds = YES;@@ -228,6 +271,7 @@ static UIView *item(Class cls, NSString *title, NSString *symbol, BOOL active) {@property (nonatomic, strong) UIView *banner;@property (nonatomic, strong) NSLayoutConstraint *bannerHeight;@property (nonatomic, strong) UIView *npb;+@property (nonatomic, strong) NSLayoutConstraint *npbHeight;@end@implementation SGHarnessChrome@@ -284,7 +328,7 @@ static UIView *item(Class cls, NSString *title, NSString *symbol, BOOL active) {[npb.leadingAnchor constraintEqualToAnchor:view.leadingAnchor],[npb.trailingAnchor constraintEqualToAnchor:view.trailingAnchor],[npb.bottomAnchor constraintEqualToAnchor:self.tabs.compactTabBarHeightLayoutGuide.topAnchor],- [npb.heightAnchor constraintEqualToConstant:64],+ self.npbHeight = [npb.heightAnchor constraintEqualToConstant:sgJam ? 108 : 64],// CompactNowPlayingViewController: the content 8 pt above its own bottom (0x105345190).[content.view.leadingAnchor constraintEqualToAnchor:npb.leadingAnchor],[content.view.trailingAnchor constraintEqualToAnchor:npb.trailingAnchor],@@ -356,6 +400,15 @@ static void report(SGHarnessChrome *chrome, NSString *moment) {NSStringFromCGRect(banner), NSStringFromCGRect(stockFrame), NSStringFromCGRect(systemFrame), NSStringFromCGRect(platterFrame),NSStringFromCGRect(card), CGRectGetMinY(platterFrame) - CGRectGetMaxY(card), chrome.tabs.additionalSafeAreaInsets.bottom,listEnd, CGRectGetMinY(card));+ // The glass panes of the now playing bar, the card's and in a Jam the strip's, and the strip itself.+ UIView *container = chrome.npb.subviews.firstObject;+ for (UIView *sub in container.subviews) {+ if (![sub isKindOfClass:UIVisualEffectView.class]) continue;+ NSLog(@"[harness] %@ bar pane %@ %@", moment, NSStringFromCGRect([sub convertRect:sub.bounds toView:window]),+ ((UIVisualEffectView *)sub).effect ? @"shown" : @"no effect");+ }+ UIView *strip = sgJamStrip;+ if (strip.window) NSLog(@"[harness] %@ strip %@", moment, NSStringFromCGRect([strip convertRect:strip.bounds toView:window]));}#pragma mark - the app@@ -391,6 +444,15 @@ static void after(double seconds, dispatch_block_t block) {// `away` one there from the start sliding away at 1.5 s, `cycle` in at 1.5 s and out at 4.5 s.NSArray<NSString *> *args = NSProcessInfo.processInfo.arguments;NSString *mode = args.count > 1 ? args[1] : @"none";+ // `jam`: in a Jam from the start, and out of it at 3.5 s.+ if ([mode isEqualToString:@"jam"]) {+ after(3.5, ^{+ [sgJamStrip removeFromSuperview];+ chrome.npbHeight.constant = 64;+ [chrome.view layoutIfNeeded];+ });+ after(4.5, ^{ report(chrome, @"left the jam"); });+ }if ([mode isEqualToString:@"away"]) [chrome setBanner:YES animated:NO];after(0.5, ^{UITableView *list = (UITableView *)chrome.tabs.childViewControllers.firstObject.view;@@ -401,7 +463,7 @@ static void after(double seconds, dispatch_block_t block) {if ([mode isEqualToString:@"away"]) after(1.5, ^{ [chrome setBanner:NO animated:YES]; });if ([mode isEqualToString:@"cycle"]) after(4.5, ^{ [chrome setBanner:NO animated:YES]; });// Half way through the slide, what the screen shows (the presentation layers).- if (![mode isEqualToString:@"none"]) after(1.5 + 0.17, ^{+ if ([mode isEqualToString:@"shown"] || [mode isEqualToString:@"away"] || [mode isEqualToString:@"cycle"]) after(1.5 + 0.17, ^{CALayer *stock = chrome.tabs.bar.layer.presentationLayer, *npb = chrome.npb.layer.presentationLayer, *banner = chrome.banner.layer.presentationLayer;NSLog(@"[harness] mid-slide presented: banner top %.1f, tab bar top %.1f, now playing bar bottom %.1f",[banner convertPoint:CGPointZero toLayer:self.window.layer.presentationLayer].y,@@ -418,5 +480,6 @@ static void after(double seconds, dispatch_block_t block) {@endint main(int argc, char *argv[]) {+ sgJam = argc > 1 && strcmp(argv[1], "jam") == 0;@autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass(SGHarnessApp.class)); }}diff --git a/harness/tabbar/stubs.m b/harness/tabbar/stubs.mindex 03bb9d5f..9a139547 100644--- a/harness/tabbar/stubs.m+++ b/harness/tabbar/stubs.m@@ -4,7 +4,7 @@UIColor *SGRAccentColor(void) { return nil; }__weak UIView *sgr_nowPlayingRoot = nil;-__weak UIView *sgr_nowPlayingCard = nil;+NSHashTable<UIView *> *sgr_nowPlayingPainted = nil;__weak UIView *sgr_lyricsPageRoot = nil;__weak UIView *sgr_playlistRoot = nil;__weak UIView *sgr_albumRoot = nil;diff --git a/tweak/Sources/Redesigned/Kit/SGRRepaint.h b/tweak/Sources/Redesigned/Kit/SGRRepaint.hindex d3eaf3f9..a651fe07 100644--- a/tweak/Sources/Redesigned/Kit/SGRRepaint.h+++ b/tweak/Sources/Redesigned/Kit/SGRRepaint.h@@ -3,7 +3,10 @@#import <UIKit/UIKit.h>extern __weak UIView *sgr_nowPlayingRoot; // Redesigned/NowPlayingBar/NowPlayingBar.x, the bar-extern __weak UIView *sgr_nowPlayingCard; // the bar's painted card, learnt from the album-colour paint+// Every view in the bar Spotify painted as a card, learnt from the album-colour paint, which goes clear. The bar+// makes the set and picks its card from it: in a Jam Spotify also paints the Jam strip, or a view around the+// strip and the track.+extern NSHashTable<UIView *> *sgr_nowPlayingPainted;extern __weak UIView *sgr_lyricsPageRoot; // Redesigned/Lyrics/LyricsPage.x// Redesigned/Playlist/PlaylistField.x, the playlist page. Only the base surface Spotify paints the page,// its list and its rows with goes clear here: the artwork field is underneath, and the greys of adiff --git a/tweak/Sources/Redesigned/Kit/SGRRepaint.x b/tweak/Sources/Redesigned/Kit/SGRRepaint.xindex 821fef10..03e806d8 100644--- a/tweak/Sources/Redesigned/Kit/SGRRepaint.x+++ b/tweak/Sources/Redesigned/Kit/SGRRepaint.x@@ -1,10 +1,10 @@-// Keeps the areas the redesign stripped transparent when Spotify repaints them, and learns which view-// is the now playing bar's card from the album-colour paint.+// Keeps the areas the redesign stripped transparent when Spotify repaints them, and learns which views+// could be the now playing bar's card from the album-colour paint.#import "Core/SGCore.h"#import "SGRRepaint.h"__weak UIView *sgr_nowPlayingRoot = nil;-__weak UIView *sgr_nowPlayingCard = nil;+NSHashTable<UIView *> *sgr_nowPlayingPainted = nil;__weak UIView *sgr_lyricsPageRoot = nil;__weak UIView *sgr_playlistRoot = nil;__weak UIView *sgr_albumRoot = nil;@@ -16,8 +16,9 @@ __weak UIView *sgr_artistRoot = nil;UIView *view = (UIView *)self.delegate;if ([view isKindOfClass:UIView.class] && view.layer == self && !SGKeepsColor(view)) {if (SGIsInside(view, sgr_nowPlayingRoot)) {- if (SGLooksLikeCard(view, color) && sgr_nowPlayingCard != view) {- sgr_nowPlayingCard = view;+ // Its size is judged when the bar picks its card: Spotify can paint a card before it sizes it.+ if (SGIsVisibleColor(color) && ![sgr_nowPlayingPainted containsObject:view]) {+ [sgr_nowPlayingPainted addObject:view];UIView *bar = sgr_nowPlayingRoot;dispatch_async(dispatch_get_main_queue(), ^{ [bar.superview setNeedsLayout]; });}diff --git a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.xindex 64e1d05c..86a8dddf 100644--- a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x+++ b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x@@ -11,12 +11,24 @@// Tree (trees/home.txt): NowPlayingBarContainerViewController.view 402x56 > NowPlayingBarViewController.view// at {8,0} 386x56 > UIView 386x56 (the painted card) > artwork 40x40 r=4, title stack,// progress line 370x2 at the bottom. The glass pane goes on the container's view.+//+// In a Jam Spotify puts a "Jam by ..." strip on the bar, a SwiftUI _UIHostingView of+// Jam_AttachmentsImpl.JamHatElement as wide as the card and 44pt high, and grows the bar by its height+// (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.#import "Core/SGCore.h"#import "Redesigned/Kit/SGRRepaint.h"+#import "Redesigned/Kit/SGRGlass.h"+#import "Redesigned/Kit/SGRTokens.h"#import "NowPlayingBar.h"static const CGFloat kCardRadius = 24;-static char kGlassKey;+// The strip's pane is this much smaller than the strip at each end, so a gap parts it from the card's glass.+static const CGFloat kStripInset = 4;+static char kGlassKey, kStripGlassKey;+static __weak UIView *sg_card;+static CGRect sg_stripFrame;static __weak UIVisualEffectView *sg_cardGlass;static __weak UIView *sg_cardArtwork;@@ -33,14 +45,58 @@ CGRect SGRNowPlayingArtworkFrameIn(UIView *host) {return [host convertRect:artwork.bounds fromView:artwork];}-static UIView *detectColoredCard(UIView *bar) {- __block UIView *best = nil;- __block CGFloat bestArea = 0;+// The Jam strip. 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"];+}++static BOOL inStrip(UIView *view, UIView *root) {+ for (UIView *v = view; v && v != root; v = v.superview) if (isStrip(v)) return YES;+ return NO;+}++static UIView *stripIn(UIView *root) {+ __block UIView *strip = nil;+ SGForEachView(root, ^(UIView *v) { if (!strip && isStrip(v)) strip = v; });+ return strip;+}++// What holds the track on the bar: the title and artist block, else the artwork (a 36 to 48pt square that+// is not a button), never anything in the strip. Nil when neither is there.+static UIView *trackMarker(UIView *bar) {+ __block UIView *info = nil, *artwork = nil;SGForEachView(bar, ^(UIView *v) {- if ([v isKindOfClass:UIVisualEffectView.class] || SGKeepsColor(v) || !SGLooksLikeCard(v, v.layer.backgroundColor)) return;- CGFloat area = v.bounds.size.width * v.bounds.size.height;- if (area > bestArea) { bestArea = area; best = v; }+ if (info || inStrip(v, bar)) return;+ if ([NSStringFromClass(v.class) containsString:@"InformationContainer"]) info = v;+ CGSize size = v.bounds.size;+ BOOL square = size.width >= 36 && size.width <= 48 && fabs(size.width - size.height) < 1;+ if (!artwork && square && ![v isKindOfClass:UIControl.class]) artwork = v;});+ return info ?: artwork;+}++// A card holds the track and has no strip in it; one with the strip in it only when there is no other.+// Among equals the largest, which outside a Jam is the card it always was.+static BOOL isGoodCard(UIView *card, UIView *bar, UIView *marker) {+ return SGIsInside(card, bar) && !inStrip(card, bar) && (!marker || [marker isDescendantOfView:card]);+}++static UIView *chooseCard(UIView *bar, UIView *marker) {+ UIView *best = nil;+ BOOL bestHasStrip = NO;+ CGFloat bestArea = 0;+ for (UIView *v in sgr_nowPlayingPainted) {+ // Card sized: the paint itself has gone clear by now.+ if (!SGLooksLikeCard(v, UIColor.whiteColor.CGColor) || !isGoodCard(v, bar, marker)) continue;+ BOOL hasStrip = stripIn(v) != nil;+ CGFloat area = v.bounds.size.width * v.bounds.size.height;+ BOOL better = !best || (hasStrip != bestHasStrip ? !hasStrip : area > bestArea);+ if (!better) continue;+ best = v;+ bestHasStrip = hasStrip;+ bestArea = area;+ }return best;}@@ -48,7 +104,7 @@ static UIView *detectColoredCard(UIView *bar) {static CGRect contentBounds(UIView *bar, UIView *target) {__block CGRect box = CGRectNull;SGForEachView(bar, ^(UIView *v) {- if (v.hidden || v.alpha == 0) return;+ if (v.hidden || v.alpha == 0 || inStrip(v, bar)) return;CGFloat width = v.bounds.size.width;BOOL content = ([v isKindOfClass:UIImageView.class] && width >= 20 && width <= 120)|| [v isKindOfClass:UILabel.class]@@ -65,6 +121,7 @@ static void roundView(UIView *view, CGFloat radius) {static void restyleCardContent(UIView *card) {SGForEachView(card, ^(UIView *v) {+ if (inStrip(v, card)) return;CGSize size = v.bounds.size;BOOL square = size.width >= 36 && size.width <= 48 && fabs(size.width - size.height) < 1;if (!square || v.layer.cornerRadius <= 0) return;@@ -82,7 +139,7 @@ static void restyleCardContent(UIView *card) {});SGForEachView(card, ^(UIView *v) {CGRect f = v.frame;- if (f.size.height > 3 || f.size.width < 200 || v.superview.bounds.size.height < 40) return;+ if (inStrip(v, card) || f.size.height > 3 || f.size.width < 200 || v.superview.bounds.size.height < 40) return;CGRect target = CGRectMake(52, card.bounds.size.height - 6, 226, 2);if (CGRectEqualToRect(f, target)) return;v.frame = target;@@ -91,19 +148,71 @@ 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 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).+static void placeStripGlass(UIView *host, UIView *strip, CGRect card, BOOL above) {+ UIVisualEffectView *pane = objc_getAssociatedObject(host, &kStripGlassKey);+ if (!strip) {+ if (pane.effect) SGRAnimate(SGRMotionExit, ^{ SGRShowGlass(pane, NO); }, nil);+ return;+ }+ BOOL made = pane != nil;+ pane = SGGlassFor(host, &kStripGlassKey);+ if (!made) {+ pane.effect = nil;+ pane.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ }+ CGFloat height = strip.bounds.size.height;+ CGRect frame = CGRectMake(card.origin.x, above ? CGRectGetMinY(card) - height : CGRectGetMaxY(card), card.size.width, height);+ pane.frame = CGRectInset(frame, 0, kStripInset);+ SGShapeGlass(pane, MIN(kCardRadius, pane.bounds.size.height / 2), NO);+ if (!pane.effect) SGRAnimate(SGRMotionRespond, ^{ SGRShowGlass(pane, YES); }, nil);+}+static void styleNowPlayingBar(UIViewController *container) {UIViewController *barVC = container.childViewControllers.firstObject;UIView *bar = barVC.viewIfLoaded ?: container.view;+ if (!sgr_nowPlayingPainted) sgr_nowPlayingPainted = [NSHashTable weakObjectsHashTable];sgr_nowPlayingRoot = bar;- UIView *card = sgr_nowPlayingCard;- if (!card || !SGIsInside(card, bar)) card = sgr_nowPlayingCard = detectColoredCard(bar);+ // What is painted now, before it goes clear; SGRRepaint.x adds what Spotify paints later. Its size is+ // judged when the card is chosen: in a Jam the card can still be unsized here (harness/tabbar).+ SGForEachView(bar, ^(UIView *v) {+ if (![v isKindOfClass:UIVisualEffectView.class] && !SGKeepsColor(v) && SGIsVisibleColor(v.layer.backgroundColor)) [sgr_nowPlayingPainted addObject:v];+ });+ // The card stays while it still holds the track with no strip in it, whatever Spotify paints after.+ UIView *marker = trackMarker(bar);+ UIView *card = sg_card;+ if (!card || !isGoodCard(card, bar, marker) || stripIn(card)) card = sg_card = chooseCard(bar, marker);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.+ CGRect stripFrame = strip ? SGFrameIn(strip, container.view) : CGRectZero;+ if (!CGRectEqualToRect(stripFrame, sg_stripFrame)) {+ sg_stripFrame = stripFrame;+ UIView *host = container.view;+ dispatch_async(dispatch_get_main_queue(), ^{ [host setNeedsLayout]; });+ }+ if (strip.bounds.size.height < 1) strip = nil;+CGRect frame = card ? SGFrameIn(card, container.view) : contentBounds(bar, container.view);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;@@ -120,12 +229,18 @@ static void styleNowPlayingBar(UIViewController *container) {sg_cardGlass = glass;glass.frame = frame;SGShapeGlass(glass, radius, NO);+ placeStripGlass(container.view, strip, frame, stripAbove);static dispatch_once_t once;dispatch_once(&once, ^{SGLog(@"now playing card %@ at %@ (bar %@, container %@)", card.class, NSStringFromCGRect(frame),NSStringFromCGRect(bar.frame), NSStringFromCGRect(container.view.bounds));});+ static dispatch_once_t jamOnce;+ if (strip) dispatch_once(&jamOnce, ^{+ SGLog(@"now playing card in a Jam: %@ at %@, strip %@ at %@ (bar %@)", card.class, NSStringFromCGRect(frame), strip.class,+ NSStringFromCGRect(SGFrameIn(strip, container.view)), NSStringFromCGRect(bar.frame));+ });}%hook _TtC18NowPlaying_BarImpl36NowPlayingBarContainerViewController