Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix(nowplaying): match the mini player's width to the tab bar (#170) (#175)
My-Name-Is-Jeff87cf7d4a64c0
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 4f01114b..1f5dff7d 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -533,7 +533,8 @@ Redesigned:(BarConnect.x, its own key and its own row on the Player page, apart from the native look's). The card's text is the Musicapp's, the title over the artists with no device line, drawn inside Spotify's own text on each swipe pageso it slides and fades with it; Spotify lays a page out as "title • artists" over the device line or as- title over artists, and both are read. In the minimized row+ title over artists, and both are read. Above the bar the card is as wide as the glass bar's row under it+ (SGRTabBarGlassRow, 21 pt in from each side where Spotify keeps 8), as the Music app's mini player is. 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 theglass stays on the track and Spotify's Jam strip gets a pane of the same glass above it, and the fade underthe 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 stripdiff --git a/tweak/Sources/Redesigned/Navbar/Navbar.h b/tweak/Sources/Redesigned/Navbar/Navbar.hindex fd8714e8..cf9670a1 100644--- a/tweak/Sources/Redesigned/Navbar/Navbar.h+++ b/tweak/Sources/Redesigned/Navbar/Navbar.h@@ -56,6 +56,11 @@ void SGRSetTabBarMinimized(BOOL minimized, BOOL animated);// The room between the minimized bar's two tabs, `height` high and centered on them, in `host`'s// coordinates: where the now playing card goes. CGRectNull while the bar is not minimized or not on screen.CGRect SGRTabBarInlineSlot(UIView *host, CGFloat height);+// The expanded bar's glass from the leading edge of its first platter to the trailing edge of its last, in `host`'s+// coordinates (x only counts): the now playing card above the bar takes these edges, as the Music app's mini+// player stands as wide as its tab bar. CGRectNull out of a window or in a regular width, where Spotify's bar is not+// the glass row.+CGRect SGRTabBarGlassRow(UIView *host);// A tab's glyph as the glass bar draws it, white, filled when `active` (TabBar.x), for the Tab bar page.UIImage *SGRNavbarGlyph(NSDictionary *entry, BOOL active);diff --git a/tweak/Sources/Redesigned/Navbar/TabBar.x b/tweak/Sources/Redesigned/Navbar/TabBar.xindex 0657320e..bb78e97d 100644--- a/tweak/Sources/Redesigned/Navbar/TabBar.x+++ b/tweak/Sources/Redesigned/Navbar/TabBar.x@@ -25,6 +25,8 @@ static char kBarKey, kApartBarKey, kHostKey, kFadeKey;static char kGlyphNamesKey;static __weak UIView *sg_stockBar;static CGFloat sg_room, sg_glassHeight; // see "room for the glass bar"+// The glass row in the window as the now playing card was last told of it (syncBar), CGRectNull for none.+static CGRect sg_glassRow = {{INFINITY, INFINITY}, {0, 0}};// See "minimized". sg_keepApart holds the second bar on screen while the main one grows back under it.static BOOL sg_minimized, sg_keepApart;@@ -648,6 +650,16 @@ static void syncBar(UIView *stockBar) {}if (host.superview != stockBar) [stockBar addSubview:host];else if (stockBar.subviews.lastObject != host) [stockBar bringSubviewToFront:host];+ // The now playing card takes its edges from the glass row (SGRTabBarGlassRow); it is told, after this pass, when+ // the row comes, goes or its sides move.+ CGRect row = SGRTabBarGlassRow(bar.window);+ BOOL rowMoved = CGRectIsNull(row) != CGRectIsNull(sg_glassRow)+ || (!CGRectIsNull(row) && (fabs(CGRectGetMinX(row) - CGRectGetMinX(sg_glassRow)) >= 0.5+ || fabs(CGRectGetMaxX(row) - CGRectGetMaxX(sg_glassRow)) >= 0.5));+ if (rowMoved) {+ sg_glassRow = row;+ dispatch_async(dispatch_get_main_queue(), ^{ SGRNowPlayingBarFollowTabBar(); });+ }logBarOnce(bar);makeRoom(containerOf(stockBar));}@@ -879,6 +891,12 @@ static void setMinimized(BOOL minimized, BOOL animated) {});}+// The glass the expanded bar draws runs kPlatterInset in from either side of Spotify's bar, the split tabs' bar+// included: its trailing platter ends where the main one would have.+static CGRect platterEdges(UIView *stockBar, UIView *host) {+ return CGRectInset([stockBar convertRect:stockBar.bounds toView:host], kPlatterInset, 0);+}+CGRect SGRTabBarInlineSlot(UIView *host, CGFloat height) {UIView *stockBar = sg_stockBar;UIView *bar = stockBar ? objc_getAssociatedObject(stockBar, &kBarKey) : nil;@@ -893,8 +911,7 @@ CGRect SGRTabBarInlineSlot(UIView *host, CGFloat height) {CGRect trail = [apartBar.superview convertRect:apartBar.frame toView:host];right = CGRectGetMaxX(trail) - kPlatterInset - kApartItemWidth - SGRGrid;} else {- CGRect whole = [stockBar convertRect:stockBar.bounds toView:host];- right = CGRectGetMaxX(whole) - kPlatterInset;+ right = CGRectGetMaxX(platterEdges(stockBar, host));}CGFloat middle = CGRectGetMinY(lead) + kApartItemWidth / 2;CGRect slot = CGRectMake(left, middle - height / 2, right - left, height);@@ -904,6 +921,14 @@ CGRect SGRTabBarInlineSlot(UIView *host, CGFloat height) {return slot;}+// Only the x edges are meant; a bar Spotify has slid away for a page keeps them.+CGRect SGRTabBarGlassRow(UIView *host) {+ UIView *stockBar = sg_stockBar;+ UIView *bar = stockBar ? objc_getAssociatedObject(stockBar, &kBarKey) : nil;+ if (!host || !bar.window || stockBar.traitCollection.horizontalSizeClass != UIUserInterfaceSizeClassCompact) return CGRectNull;+ return platterEdges(stockBar, host);+}+#pragma mark - hooksstatic UIView *tabBarOf(UIView *item) {diff --git a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.xindex 65583d2b..cb880c1c 100644--- a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x+++ b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x@@ -216,6 +216,8 @@ static void restoreEdges(UIView *bar) {}static BOOL setEdges(UIView *bar, CGFloat left, CGFloat right) {+ // Edges already where they are asked for walk nothing: placeInline asks on every layout pass of the bar.+ if (fabs(CGRectGetMinX(bar.frame) - left) < 0.25 && fabs(CGRectGetMaxX(bar.frame) - right) < 0.25) return YES;UIView *superview = bar.superview;if (bar.translatesAutoresizingMaskIntoConstraints) {CGRect frame = CGRectMake(left, bar.frame.origin.y, right - left, bar.frame.size.height);@@ -243,7 +245,7 @@ static BOOL setEdges(UIView *bar, CGFloat left, CGFloat right) {if (held == 3) return YES;restoreEdges(bar);static dispatch_once_t once;- dispatch_once(&once, ^{ SGLog(@"now playing bar: its edges are not held by its superview's constraints, so it stays above the tab bar"); });+ dispatch_once(&once, ^{ SGLog(@"now playing bar: its edges are not held by its superview's constraints, so it keeps Spotify's"); });return NO;}@@ -423,6 +425,11 @@ static void appendShape(UIView *view, NSUInteger depth, NSMutableString *out) {if (depth < 8) for (UIView *sub in view.subviews) appendShape(sub, depth + 1, out);}+// The bar's edges set to `r`'s sides, `r` in the slot's coordinates and the view standing at `origin` in them.+static BOOL edgesTo(UIView *bar, CGRect r, CGPoint origin) {+ return !CGRectIsNull(r) && setEdges(bar, CGRectGetMinX(r) - origin.x, CGRectGetMaxX(r) - origin.x);+}+static void placeInline(UIViewController *container) {UIView *view = container.view;UIView *bar = container.childViewControllers.firstObject.viewIfLoaded;@@ -443,11 +450,13 @@ static void placeInline(UIViewController *container) {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)) {- if (sg_inline) restoreEdges(bar);+ if (!edgesTo(bar, slot, origin)) {if (sg_inline) tuckExtras(bar, NO);sg_inline = nil;if (!CGAffineTransformIsIdentity(view.transform)) view.transform = CGAffineTransformIdentity;+ // Above the bar the card takes the glass row's edges (SGRTabBarGlassRow).+ CGRect row = bar && bar.superview == view ? SGRTabBarGlassRow(view.superview) : CGRectNull;+ if (!edgesTo(bar, row, origin)) restoreEdges(bar);if (bar) placeTexts(bar);return;}