Skip to content

Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.

C

feat: add lyrics, navbar and home gradient

Vojtěch Škopekb01e6ea3fd4c
diff --git a/README.md b/README.md
index e932e796..21e067fb 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@ signed and installed from the Mac.
## Layout
- tweak/src/ui/*.x the tweaks: NowPlayingBar, TabBar, NowPlayingView, SearchField, Flags, Amoled, Declutter, Repaint, Settings
+ tweak/src/ui/*.x the tweaks: NowPlayingBar, TabBar, Navbar, NowPlayingView, Lyrics, SearchField, Flags, Amoled, Declutter, Repaint, Settings
tweak/src/SG* shared helpers (glass panes, view walking, logging, screen dumps); SGFlagList.m is generated
scripts/ pipeline.sh (build + inject), install.sh (sign + install), record-trees.py, dump-log.sh, extract-flags.py
trees/ recorded view trees, one per screen; the input for every new tweak
@@ -26,9 +26,17 @@ signed and installed from the Mac.
In the app, Settings → Mod Settings has three pages of switches, UI Tweaks (tab bar, search
field, Spotify's own glass, AMOLED), Home (hide sections of the Home tab) and Now Playing (glass,
-a few of Spotify's player flags, hide buttons and cards of the full screen player), plus All flags,
-Spotify's remote-config flags with a search field and an Auto / Off / On control per flag (a text
-field for the number and text ones); a change shows after Spotify restarts.
+a few of Spotify's player flags, hide buttons and cards of the full screen player), plus Navbar,
+the tab bar's own composition, and All flags, Spotify's remote-config flags with a search field
+and an Auto / Off / On control per flag (a text field for the number and text ones); a change
+shows after Spotify restarts.
+
+Navbar is the exception and applies as soon as the bar lays out again. It lists the tabs in the
+order the bar shows them: drag to reorder, tap to hide or show, and Add a tab puts a page of
+Spotify's or any `spotify:` link on the bar with one of Encore's own glyphs. Spotify's own tabs are
+kept by the name under their icon, so they can be hidden but never removed, and switching the app's
+language starts the order over. A tab of the mod's own opens its link through Spotify's link
+dispatcher, so it never lights up as the tab you are on.
Needs Theos in `~/theos` with an iPhoneOS SDK, Homebrew `make ldid dpkg zsign ideviceinstaller
libimobiledevice`, and cyan (`uv tool install "cyan @ git+https://github.com/asdfzxcvbn/pyzule-rw"`).
diff --git a/tweak/control b/tweak/control
index af83efba..5810eb2b 100644
--- a/tweak/control
+++ b/tweak/control
@@ -1,6 +1,6 @@
Package: com.vojta.spotifyglass
Name: spotifyglass
-Version: 0.10.0
+Version: 0.12.1
Architecture: iphoneos-arm
Description: Liquid Glass for the Spotify iOS app
Maintainer: vojta
diff --git a/tweak/src/SGCommon.h b/tweak/src/SGCommon.h
index 926639aa..6ab1fab8 100644
--- a/tweak/src/SGCommon.h
+++ b/tweak/src/SGCommon.h
@@ -37,6 +37,7 @@ BOOL SGKeepsColor(UIView *view);
void SGStripBackgrounds(UIView *view);
BOOL SGIsVisibleColor(CGColorRef color);
BOOL SGIsLightColor(CGColorRef color);
+BOOL SGIsBaseSurface(CGColorRef color);
BOOL SGHasClass(UIView *root, NSString *marker);
UIStackView *SGRowIn(UIView *host);
@@ -51,19 +52,49 @@ void SGShapeGlass(UIView *glass, CGFloat radius, BOOL capsule);
extern __weak UIView *sg_nowPlayingRoot;
extern __weak UIView *sg_tabBarRoot;
extern __weak UIView *sg_nowPlayingCard;
+extern __weak UIView *sg_lyricsCardRoot;
+extern __weak UIView *sg_lyricsPageRoot;
+extern __weak UIView *sg_homeRoot; // ui/HomeGradient.x, the base surface only
BOOL SGLooksLikeCard(UIView *view, CGColorRef color);
+// The full screen player morphs the now playing bar's own card into the cover art, so for the
+// length of that animation ui/NowPlayingBar.x hands the bar back to Spotify: the flag lets the
+// album colour through ui/Repaint.x again, and the last colour it took off is kept to restore.
+extern BOOL sg_nowPlayingStock;
+extern CGColorRef sg_nowPlayingCardColor;
+void SGRememberCardColor(CGColorRef color);
+
// Switches from ui/Settings.x, one per tweak; an unset switch is on.
extern NSString *const SGKeyNowPlayingBar;
extern NSString *const SGKeyTabBar;
extern NSString *const SGKeyPlayer;
+extern NSString *const SGKeyLyricsCard;
extern NSString *const SGKeySearchField;
extern NSString *const SGKeySpotifyGlass;
extern NSString *const SGKeyAmoled;
+extern NSString *const SGKeyHomeGradient; // off unless it is asked for
BOOL SGFlag(NSString *key, BOOL fallback);
BOOL SGEnabled(NSString *key);
void SGSetEnabled(NSString *key, BOOL on);
+// The tab bar's own composition, from ui/Navbar.x and the Navbar settings page: an ordered list
+// of entries, each a dictionary. An entry with a URI is a tab of the mod's own; one without names
+// one of Spotify's, by the label under its icon. No list at all is Spotify's order, all shown.
+extern NSString *const SGKeyNavbar;
+extern NSString *const SGNavbarID; // NSString, the entry's identity
+extern NSString *const SGNavbarTitle; // NSString, the name in the settings list and under the icon
+extern NSString *const SGNavbarURI; // NSString, the mod's own tabs only: what a tap opens
+extern NSString *const SGNavbarIcon; // NSString, an SPTEncoreIcon class method such as "podcasts"
+extern NSString *const SGNavbarHidden; // NSNumber
+NSArray<NSDictionary *> *SGNavbarLayout(void);
+void SGSetNavbarLayout(NSArray<NSDictionary *> *layout);
+// Spotify's own tabs in Spotify's order, as ui/Navbar.x last saw them on the bar.
+NSArray<NSString *> *SGNavbarStock(void);
+void SGSetNavbarStock(NSArray<NSString *> *stock);
+
+// ui/Navbar.x, called from the tab bar's layout pass in ui/TabBar.x.
+void SGComposeTabBar(UIView *tabBar);
+
// Spotify's remote-config flags, generated into SGFlagList.m by scripts/extract-flags.py.
typedef NS_ENUM(NSInteger, SGFlagType) { SGFlagUnknown, SGFlagBool, SGFlagInt, SGFlagEnum };
typedef struct { const char *key; SGFlagType type; long value, lower, upper; } SGFlagDef;
diff --git a/tweak/src/SGCommon.m b/tweak/src/SGCommon.m
index 5d603ccd..a8d43224 100644
--- a/tweak/src/SGCommon.m
+++ b/tweak/src/SGCommon.m
@@ -3,6 +3,22 @@
__weak UIView *sg_nowPlayingRoot = nil;
__weak UIView *sg_tabBarRoot = nil;
__weak UIView *sg_nowPlayingCard = nil;
+__weak UIView *sg_lyricsCardRoot = nil;
+__weak UIView *sg_lyricsPageRoot = nil;
+__weak UIView *sg_homeRoot = nil;
+
+BOOL sg_nowPlayingStock = NO;
+CGColorRef sg_nowPlayingCardColor = NULL;
+
+// ui/Repaint.x takes the album colour off the card on every repaint; the expand animation of the
+// full screen player needs it back, so the last one is kept. Only the main thread writes it, so
+// the read in ui/NowPlayingBar.x cannot see a released colour.
+void SGRememberCardColor(CGColorRef color) {
+ if (!NSThread.isMainThread || color == sg_nowPlayingCardColor) return;
+ CGColorRef kept = color ? CGColorRetain(color) : NULL;
+ CGColorRelease(sg_nowPlayingCardColor);
+ sg_nowPlayingCardColor = kept;
+}
#pragma mark - logging
@@ -34,9 +50,11 @@ void SGRequireClasses(NSArray<NSString *> *names) {
NSString *const SGKeyNowPlayingBar = @"spotifyglass.nowPlayingBar";
NSString *const SGKeyTabBar = @"spotifyglass.tabBar";
NSString *const SGKeyPlayer = @"spotifyglass.player";
+NSString *const SGKeyLyricsCard = @"spotifyglass.lyricsCard";
NSString *const SGKeySearchField = @"spotifyglass.searchField";
NSString *const SGKeySpotifyGlass = @"spotifyglass.spotifyGlass";
NSString *const SGKeyAmoled = @"spotifyglass.amoled";
+NSString *const SGKeyHomeGradient = @"spotifyglass.homeGradient";
BOOL SGFlag(NSString *key, BOOL fallback) {
id value = [NSUserDefaults.standardUserDefaults objectForKey:key];
@@ -55,6 +73,39 @@ void SGSetEnabled(NSString *key, BOOL on) {
[NSUserDefaults.standardUserDefaults setBool:on forKey:key];
}
+NSString *const SGKeyNavbar = @"spotifyglass.navbar";
+NSString *const SGNavbarID = @"id";
+NSString *const SGNavbarTitle = @"title";
+NSString *const SGNavbarURI = @"uri";
+NSString *const SGNavbarIcon = @"icon";
+NSString *const SGNavbarHidden = @"hidden";
+
+static NSString *const kNavbarLayout = @"spotifyglass.navbar.layout";
+static NSString *const kNavbarStock = @"spotifyglass.navbar.stock";
+
+// Only property list types go in, so a corrupt read cannot be anything but an array of dictionaries.
+static NSArray *listOfKind(NSString *key, Class kind) {
+ NSArray *list = [NSUserDefaults.standardUserDefaults arrayForKey:key];
+ for (id item in list) if (![item isKindOfClass:kind]) return @[];
+ return list ?: @[];
+}
+
+NSArray<NSDictionary *> *SGNavbarLayout(void) {
+ return listOfKind(kNavbarLayout, NSDictionary.class);
+}
+
+void SGSetNavbarLayout(NSArray<NSDictionary *> *layout) {
+ [NSUserDefaults.standardUserDefaults setObject:layout ?: @[] forKey:kNavbarLayout];
+}
+
+NSArray<NSString *> *SGNavbarStock(void) {
+ return listOfKind(kNavbarStock, NSString.class);
+}
+
+void SGSetNavbarStock(NSArray<NSString *> *stock) {
+ [NSUserDefaults.standardUserDefaults setObject:stock ?: @[] forKey:kNavbarStock];
+}
+
NSString *const SGFlagOverridePrefix = @"spotifyglass.flag.";
id SGFlagOverride(NSString *key) {
@@ -119,6 +170,17 @@ BOOL SGIsLightColor(CGColorRef color) {
return YES;
}
+// Spotify's base surface: the neutral #121212 it paints its pages with, or the black ui/Amoled.x
+// turns that into. Lighter greys (#1F1F1F placeholders, #292929 cards) and translucent paint stay.
+BOOL SGIsBaseSurface(CGColorRef color) {
+ if (!color || CFGetTypeID(color) != CGColorGetTypeID() || CGColorGetAlpha(color) < 0.95) return NO;
+ const CGFloat *c = CGColorGetComponents(color);
+ size_t n = CGColorGetNumberOfComponents(color);
+ if (n == 2) return c[0] <= 0.10;
+ if (n < 3) return NO;
+ return c[0] <= 0.10 && fabs(c[0] - c[1]) < 0.02 && fabs(c[1] - c[2]) < 0.02;
+}
+
BOOL SGHasClass(UIView *root, NSString *marker) {
__block BOOL found = NO;
SGForEachView(root, ^(UIView *v) {
@@ -127,7 +189,8 @@ BOOL SGHasClass(UIView *root, NSString *marker) {
return found;
}
-// The first wide stack view under `host` with at least two arranged children: a player row.
+// The first wide stack view under `host` with at least two arranged children: a player row, or
+// the row of items in the tab bar.
UIStackView *SGRowIn(UIView *host) {
__block UIStackView *row = nil;
SGForEachView(host, ^(UIView *v) {
diff --git a/tweak/src/ui/HomeGradient.x b/tweak/src/ui/HomeGradient.x
new file mode 100644
index 00000000..e53631c8
--- /dev/null
+++ b/tweak/src/ui/HomeGradient.x
@@ -0,0 +1,113 @@
+// Home gradient: a green wash behind the top of the Home tab, strongest under the avatar and the
+// pills and out by the second shelf, like the gradient Spotify's own Home used to have. The wash
+// is a layer inside the page's scroll view, under its content, so it scrolls away with the
+// shelves; the base grey the page and the shelves paint over it goes clear in ui/Repaint.x, and
+// Spotify's own scrim behind the header goes with it, since it would only mute the colour.
+//
+// Tree (trees/home.txt): HomePageHostingViewController.view holds the Evo page, a 402x112 wrapper
+// around LiquidGlass.GradientView (the scrim under the avatar and the pills) and HomeHeaderView.
+// The Evo page's own view holds one Home_CarouselKit.TouchCancellingCollectionView, full screen
+// and inset 112pt at the top for the header, painted #121212; the shelves inside it are
+// collection views painted #121212 of their own.
+#import "SGCommon.h"
+
+// Sampled off the design: #0B4110 at the top of the screen, level behind the header, gone by 390pt.
+static UIColor *tint(void) { return [UIColor colorWithRed:0x0B / 255.0 green:0x41 / 255.0 blue:0x10 / 255.0 alpha:1]; }
+static const CGFloat kFadeHeight = 390;
+static const CGFloat kLevelHeight = 52;
+// Colour above the content as well, for the rubber band of an overscroll to pull down into.
+static const CGFloat kOverscroll = 600;
+
+static char kGradientKey;
+
+// A view of its own, so the wash follows the page's layout passes instead of animating itself
+// through CoreAnimation whenever the inset changes.
+@interface SGHomeGradientView : UIView
+@end
+
+@implementation SGHomeGradientView
++ (Class)layerClass {
+ return CAGradientLayer.class;
+}
+@end
+
+static SGHomeGradientView *gradientIn(UIScrollView *list) {
+ SGHomeGradientView *view = objc_getAssociatedObject(list, &kGradientKey);
+ if (!view) {
+ view = [SGHomeGradientView new];
+ view.userInteractionEnabled = NO;
+ CGFloat height = kOverscroll + kFadeHeight;
+ CAGradientLayer *gradient = (CAGradientLayer *)view.layer;
+ gradient.colors = @[(id)tint().CGColor, (id)tint().CGColor, (id)[tint() colorWithAlphaComponent:0].CGColor];
+ gradient.locations = @[@0, @((kOverscroll + kLevelHeight) / height), @1];
+ objc_setAssociatedObject(list, &kGradientKey, view, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+
+ // Whatever the page painted before the wash was there; ui/Repaint.x keeps it clear from now.
+ sg_homeRoot = list;
+ SGForEachView(list, ^(UIView *v) {
+ if (SGIsBaseSurface(v.layer.backgroundColor)) v.layer.backgroundColor = NULL;
+ });
+ SGLog(@"home gradient behind %@", NSStringFromClass(list.class));
+ }
+ // Cells are added on top of it, so index 0 stays the bottom of the list.
+ if (view.superview != list) [list insertSubview:view atIndex:0];
+ return view;
+}
+
+// Content coordinates: the content starts below the header, so the wash starts at minus the inset,
+// where the top of the screen is when the list sits still.
+static void layoutGradient(UIScrollView *list) {
+ SGHomeGradientView *view = gradientIn(list);
+ CGRect frame = CGRectMake(0, -kOverscroll - list.adjustedContentInset.top,
+ list.bounds.size.width, kOverscroll + kFadeHeight);
+ if (!CGRectEqualToRect(view.frame, frame)) view.frame = frame;
+}
+
+// The one collection view of the page; the shelves are collection views nested inside it.
+static UIScrollView *pageList(UIView *view) {
+ for (UIView *sub in view.subviews) {
+ if ([sub isKindOfClass:UICollectionView.class]) return (UIScrollView *)sub;
+ }
+ return nil;
+}
+
+%hook _TtC16Home_EvoPageImpl33EvoLoadableResourceViewController
+- (void)viewDidLayoutSubviews {
+ %orig;
+ UIScrollView *list = pageList(((UIViewController *)self).viewIfLoaded);
+ if (list) layoutGradient(list);
+}
+%end
+
+// The list lays out on every scroll too, which is when the bars change its inset. Album, artist
+// and playlist pages are lists of the same class, hence the check for the one Home owns.
+%hook _TtC16Home_CarouselKit29TouchCancellingCollectionView
+- (void)layoutSubviews {
+ %orig;
+ if ((UIView *)self == sg_homeRoot) layoutGradient((UIScrollView *)self);
+}
+%end
+
+// Everything beside the page in the host view is the header and its scrim, both of them shallow.
+%hook _TtC19Home_FunkisPageImpl29HomePageHostingViewController
+- (void)viewDidLayoutSubviews {
+ %orig;
+ UIView *host = ((UIViewController *)self).viewIfLoaded;
+ for (UIView *sub in host.subviews) {
+ if (sub.bounds.size.height > host.bounds.size.height / 2) continue;
+ SGForEachView(sub, ^(UIView *v) {
+ if ([NSStringFromClass(v.class) containsString:@"GradientView"]) v.hidden = YES;
+ });
+ }
+}
+%end
+
+%ctor {
+ if (!SGFlag(SGKeyHomeGradient, NO)) return;
+ %init;
+ SGRequireClasses(@[
+ @"_TtC16Home_EvoPageImpl33EvoLoadableResourceViewController",
+ @"_TtC16Home_CarouselKit29TouchCancellingCollectionView",
+ @"_TtC19Home_FunkisPageImpl29HomePageHostingViewController",
+ ]);
+}
diff --git a/tweak/src/ui/Lyrics.x b/tweak/src/ui/Lyrics.x
new file mode 100644
index 00000000..3659ddb9
--- /dev/null
+++ b/tweak/src/ui/Lyrics.x
@@ -0,0 +1,97 @@
+// The lyrics card under the player and the page it expands into, both on glass.
+//
+// Card (trees/now-playing.txt): a Lyrics_CardElementImpl.CardView inside an
+// Element_List.CollectionViewCell 370x316. The cell is the painted surface with the 16pt corners,
+// so the pane fills it and the cell's own clipping cuts the corners.
+//
+// Page (trees/lyrics.txt): a page of its own, presented over the player by a
+// _UIOverFullscreenPresentationController, which is why the card's glass stops at the card's edge.
+// Tome_PageTemplateImpl paints the template view #121212 and FullscreenView paints itself the
+// album colour on top, both opaque; clearing them lets the player's blurred artwork through, so
+// the card reads as having grown to the screen.
+//
+// The album colour is the stubborn one: it arrives per track, after the page has laid out, and it
+// comes back through a path ui/Repaint.x never sees, so a sweep at layout time loses the race.
+// FullscreenView is asked not to keep it at all instead. The pane goes inside FullscreenView, in
+// front of whatever that view still fills itself with, rather than behind the whole page.
+#import "SGCommon.h"
+
+static const CGFloat kCardRadius = 16;
+static char kCardGlassKey, kPageGlassKey;
+
+#pragma mark - the card in the player's scroll list
+
+// The cell around the card, the view Spotify paints and rounds.
+static UIView *cellAround(UIView *view) {
+ Class cell = NSClassFromString(@"_TtC12Element_List18CollectionViewCell");
+ for (UIView *v = view; v; v = v.superview) {
+ if ([v isKindOfClass:cell]) return v;
+ }
+ return nil;
+}
+
+%hook _TtC22Lyrics_CardElementImpl8CardView
+- (void)layoutSubviews {
+ %orig;
+ if (!SGEnabled(SGKeyLyricsCard)) return;
+ UIView *cell = cellAround((UIView *)self);
+ // A card ui/Declutter.x collapsed reports no height; leave it alone.
+ if (!cell || cell.bounds.size.height < 40) return;
+ // Spotify repaints the card with the album colour when the track changes, which is no layout
+ // pass of its own; ui/Repaint.x keeps it clear in between.
+ sg_lyricsCardRoot = cell;
+ SGStripBackgrounds(cell);
+ UIVisualEffectView *glass = SGGlassFor(cell, &kCardGlassKey);
+ glass.frame = cell.bounds;
+ glass.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ SGShapeGlass(glass, kCardRadius, NO);
+}
+%end
+
+#pragma mark - the expanded page
+
+// Up to the presentation: the template views in between paint themselves opaque once, at setup.
+// Only the chain is cleared, not the subtree -- nothing else on the page is painted.
+static UIView *clearAncestors(UIView *view) {
+ UIView *top = view;
+ for (UIView *v = view; v && ![v isKindOfClass:UIWindow.class]
+ && ![NSStringFromClass(v.class) hasPrefix:@"UITransition"]; v = v.superview) {
+ v.layer.backgroundColor = NULL;
+ top = v;
+ }
+ return top;
+}
+
+%hook _TtC32Lyrics_FullscreenElementPageImpl14FullscreenView
+// A colour kept here is re-applied whenever UIKit feels like it, so it is refused outright.
+- (void)setBackgroundColor:(UIColor *)color {
+ static dispatch_once_t once;
+ dispatch_once(&once, ^{ SGLog(@"lyrics page paints itself %@ through UIView", color); });
+ %orig(SGEnabled(SGKeyLyricsCard) ? nil : color);
+}
+
+- (void)layoutSubviews {
+ %orig;
+ if (!SGEnabled(SGKeyLyricsCard)) return;
+ UIView *page = (UIView *)self;
+ if (page.bounds.size.height < 200) return;
+
+ page.layer.backgroundColor = NULL;
+ sg_lyricsPageRoot = clearAncestors(page);
+
+ UIVisualEffectView *glass = SGGlassFor(page, &kPageGlassKey);
+ glass.frame = page.bounds;
+ glass.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ // Full bleed, so the shape is spelled out: a fresh pane does not promise square corners.
+ SGShapeGlass(glass, 0, NO);
+}
+%end
+
+%ctor {
+ %init;
+ SGRequireClasses(@[
+ @"_TtC22Lyrics_CardElementImpl8CardView",
+ @"_TtC12Element_List18CollectionViewCell",
+ @"_TtC32Lyrics_FullscreenElementPageImpl14FullscreenView",
+ ]);
+}
diff --git a/tweak/src/ui/Navbar.x b/tweak/src/ui/Navbar.x
new file mode 100644
index 00000000..7b1dfc25
--- /dev/null
+++ b/tweak/src/ui/Navbar.x
@@ -0,0 +1,236 @@
+// Navbar: which tabs the bar shows, in what order, and tabs of the mod's own that open any
+// spotify: URI. Spotify keeps its four items (Home, Search, Library, Create) as the arranged
+// subviews of one stack view, each item handling its own tap, so the order is ours to change:
+// this file rewrites the stack on every layout pass, hides the items switched off and slots its
+// own item views between them. Spotify's own updates to the bar are undone on the pass after.
+//
+// A tap on an item of the mod's own goes through Spotify's link dispatcher, the same route the
+// app takes for a link it opens itself, so any URI that resolves to a page works.
+//
+// Tree (trees/home.txt): NavigationUI_TabBarImpl.TabBarView > TabBarCompactView > UIStackView
+// 402x49 of four ElementContentView<TabBarItemElement> 100x49, each an SPTEncoreIconView 24x24
+// at y 12.5 over an SPTEncoreLabel at y 35.
+#import "SGCommon.h"
+#import <objc/message.h>
+
+// Spotify's own, resolved at runtime: SpotifyShared has the icons, the app the link dispatcher.
+@interface SPTEncoreIconView : UIView
+- (instancetype)initWithIcon:(id)icon;
+- (void)setForegroundColor:(UIColor *)color;
+@end
+
+@interface SGLinkDispatcher : NSObject
+- (void)navigateToURI:(NSURL *)uri options:(long long)options interactionID:(id)interactionID;
+@end
+
+static const CGFloat kIconSize = 24;
+static const CGFloat kIconTop = 12.5;
+static const CGFloat kLabelTop = 35;
+static const CGFloat kLabelHeight = 14;
+static char kCustomKey;
+
+static __weak SGLinkDispatcher *sg_linkDispatcher;
+static UIFont *sg_tabFont;
+// Spotify's own tabs in Spotify's order, from the first layout pass of this launch, before
+// anything below has moved them.
+static NSMutableArray<NSString *> *sg_stockOrder;
+
+static UIColor *itemColor(void) { return [UIColor colorWithWhite:0xB3 / 255.0 alpha:1]; }
+
+#pragma mark - the mod's own items
+
+// One of the 538 glyphs SPTEncoreIcon exposes, one class method each ("podcasts", "heart"), so an
+// item of the mod's own is drawn the same way as Spotify's. An SF Symbol stands in if the name is
+// not one of them.
+static UIView *iconView(NSString *name) {
+ Class icon = NSClassFromString(@"SPTEncoreIcon");
+ Class view = NSClassFromString(@"SPTEncoreIconView");
+ SEL glyphSel = NSSelectorFromString(name.length ? name : @"star");
+ if (icon && view && [icon respondsToSelector:glyphSel]) {
+ id (*glyphFor)(id, SEL) = (id (*)(id, SEL))objc_msgSend;
+ id glyph = glyphFor(icon, glyphSel);
+ SPTEncoreIconView *encore = glyph ? [[view alloc] initWithIcon:glyph] : nil;
+ if (encore) {
+ [encore setForegroundColor:itemColor()];
+ return encore;
+ }
+ }
+ UIImage *image = [UIImage systemImageNamed:@"star.fill" withConfiguration:[UIImageSymbolConfiguration configurationWithPointSize:19 weight:UIImageSymbolWeightSemibold]];
+ UIImageView *fallback = [[UIImageView alloc] initWithImage:image];
+ fallback.tintColor = itemColor();
+ fallback.contentMode = UIViewContentModeCenter;
+ return fallback;
+}
+
+@interface SGTabItemView : UIControl
+@property (nonatomic, copy) NSString *uri;
+- (instancetype)initWithEntry:(NSDictionary *)entry;
+- (void)applyEntry:(NSDictionary *)entry;
+@end
+
+@implementation SGTabItemView {
+ NSString *_iconName;
+ UIView *_icon;
+ UILabel *_title;
+}
+
+- (instancetype)initWithEntry:(NSDictionary *)entry {
+ if (!(self = [super initWithFrame:CGRectZero])) return nil;
+ _title = [UILabel new];
+ _title.textAlignment = NSTextAlignmentCenter;
+ _title.textColor = itemColor();
+ [self addSubview:_title];
+ [self applyEntry:entry];
+ [self addTarget:self action:@selector(open) forControlEvents:UIControlEventTouchUpInside];
+ return self;
+}
+
+- (void)applyEntry:(NSDictionary *)entry {
+ self.uri = entry[SGNavbarURI];
+ _title.text = entry[SGNavbarTitle];
+ NSString *name = entry[SGNavbarIcon] ?: @"star";
+ if ([name isEqualToString:_iconName]) return;
+ [_icon removeFromSuperview];
+ _iconName = [name copy];
+ _icon = iconView(name);
+ // Encore's views lay themselves out from constraints; this one is placed by frame.
+ _icon.translatesAutoresizingMaskIntoConstraints = YES;
+ [self addSubview:_icon];
+}
+
+// The item keeps Spotify's own geometry, and follows ui/TabBar.x when the glass tab bar is on:
+// no label, the icon centred in the item instead.
+- (void)layoutSubviews {
+ [super layoutSubviews];
+ BOOL glass = SGEnabled(SGKeyTabBar);
+ CGSize size = self.bounds.size;
+ _title.hidden = glass;
+ _title.font = sg_tabFont ?: [UIFont systemFontOfSize:10];
+ _title.frame = CGRectMake(0, kLabelTop, size.width, kLabelHeight);
+ CGFloat top = glass ? (size.height - kIconSize) / 2 : kIconTop;
+ _icon.frame = CGRectMake((size.width - kIconSize) / 2, top, kIconSize, kIconSize);
+}
+
+- (void)setHighlighted:(BOOL)highlighted {
+ [super setHighlighted:highlighted];
+ self.alpha = highlighted ? 0.5 : 1;
+}
+
+- (void)open {
+ NSURL *url = self.uri.length ? [NSURL URLWithString:self.uri] : nil;
+ SGLinkDispatcher *dispatcher = sg_linkDispatcher;
+ if (!url || ![dispatcher respondsToSelector:@selector(navigateToURI:options:interactionID:)]) {
+ SGLog(@"navbar: cannot open %@, dispatcher %@", self.uri, dispatcher);
+ return;
+ }
+ [dispatcher navigateToURI:url options:0 interactionID:nil];
+}
+
+@end
+
+#pragma mark - composition
+
+// Spotify's items are told apart by the label under the icon: it survives the element views being
+// rebuilt, and it is the name the Navbar page lists them under.
+static NSString *stockID(UIView *item) {
+ __block NSString *text = nil;
+ SGForEachView(item, ^(UIView *v) {
+ if (!text && [v isKindOfClass:UILabel.class] && ((UILabel *)v).text.length) text = ((UILabel *)v).text;
+ });
+ return text ?: NSStringFromClass(item.class);
+}
+
+static void rememberFont(UIView *item) {
+ if (sg_tabFont) return;
+ SGForEachView(item, ^(UIView *v) {
+ if (!sg_tabFont && [v isKindOfClass:UILabel.class] && ((UILabel *)v).text.length) sg_tabFont = ((UILabel *)v).font;
+ });
+}
+
+static NSMutableDictionary<NSString *, SGTabItemView *> *customItems(UIStackView *stack) {
+ NSMutableDictionary *items = objc_getAssociatedObject(stack, &kCustomKey);
+ if (!items) {
+ items = [NSMutableDictionary dictionary];
+ objc_setAssociatedObject(stack, &kCustomKey, items, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ }
+ return items;
+}
+
+void SGComposeTabBar(UIView *tabBar) {
+ UIStackView *stack = SGRowIn(tabBar);
+ if (!stack) return;
+
+ NSMutableDictionary<NSString *, UIView *> *stockViews = [NSMutableDictionary dictionary];
+ for (UIView *item in stack.arrangedSubviews) {
+ if ([item isKindOfClass:SGTabItemView.class]) continue;
+ NSString *ident = stockID(item);
+ if (stockViews[ident]) continue;
+ stockViews[ident] = item;
+ rememberFont(item);
+ if (!sg_stockOrder) sg_stockOrder = [NSMutableArray array];
+ if (![sg_stockOrder containsObject:ident]) [sg_stockOrder addObject:ident];
+ }
+ if (sg_stockOrder && ![sg_stockOrder isEqualToArray:SGNavbarStock()]) SGSetNavbarStock(sg_stockOrder);
+
+ NSMutableDictionary<NSString *, SGTabItemView *> *custom = customItems(stack);
+ NSMutableArray<UIView *> *wanted = [NSMutableArray array];
+ NSMutableSet<NSString *> *placed = [NSMutableSet set];
+ NSMutableSet<NSString *> *keep = [NSMutableSet set];
+
+ if (SGEnabled(SGKeyNavbar)) {
+ for (NSDictionary *entry in SGNavbarLayout()) {
+ NSString *ident = entry[SGNavbarID];
+ if (![ident isKindOfClass:NSString.class] || [placed containsObject:ident]) continue;
+ [placed addObject:ident];
+ BOOL hidden = [entry[SGNavbarHidden] boolValue];
+ if (entry[SGNavbarURI]) {
+ if (hidden) continue;
+ SGTabItemView *item = custom[ident];
+ if (item) [item applyEntry:entry];
+ else custom[ident] = item = [[SGTabItemView alloc] initWithEntry:entry];
+ [keep addObject:ident];
+ [wanted addObject:item];
+ } else if (stockViews[ident]) {
+ stockViews[ident].hidden = hidden;
+ [wanted addObject:stockViews[ident]];
+ }
+ }
+ }
+ // Tabs of Spotify's the list does not name — or named before Spotify had built them — keep
+ // Spotify's own place, at the end, shown.
+ for (NSString *ident in sg_stockOrder) {
+ UIView *item = stockViews[ident];
+ if (!item || [wanted containsObject:item]) continue;
+ item.hidden = NO;
+ [wanted addObject:item];
+ }
+ for (NSString *ident in custom.allKeys) {
+ if ([keep containsObject:ident]) continue;
+ [custom[ident] removeFromSuperview];
+ [custom removeObjectForKey:ident];
+ }
+
+ // A bar with nothing on it would strand whoever emptied it, so the last word is Spotify's.
+ BOOL empty = YES;
+ for (UIView *item in wanted) if (!item.hidden) empty = NO;
+ if (empty) for (UIView *item in wanted) item.hidden = NO;
+
+ for (NSUInteger i = 0; i < wanted.count; i++) {
+ UIView *item = wanted[i];
+ if (item.superview == stack && [stack.arrangedSubviews indexOfObject:item] == i) continue;
+ [stack insertArrangedSubview:item atIndex:i];
+ }
+}
+
+// The dispatcher is a singleton the app builds at startup; this is the last call of its setup.
+%hook SPTLinkDispatcherImplementation
+- (void)setMainUILoaded:(BOOL)loaded {
+ %orig;
+ sg_linkDispatcher = (SGLinkDispatcher *)self;
+}
+%end
+
+%ctor {
+ %init;
+ SGRequireClasses(@[@"SPTLinkDispatcherImplementation", @"SPTEncoreIcon", @"SPTEncoreIconView"]);
+}
diff --git a/tweak/src/ui/NowPlayingBar.x b/tweak/src/ui/NowPlayingBar.x
index 72c9ccae..2f333148 100644
--- a/tweak/src/ui/NowPlayingBar.x
+++ b/tweak/src/ui/NowPlayingBar.x
@@ -1,12 +1,25 @@
// Now playing bar: the album-coloured card becomes a glass card with round artwork and the
// progress line under the text. Spotify's own labels, buttons and gestures stay in place.
//
-// Tree (trees/home.txt): NowPlayingBarContainerViewController.view > NowPlayingBarViewController.view
-// > UIView 386x56 (the painted card) > artwork 40x40 r=4, title stack, progress line 370x2 at the bottom.
+// The full screen player does not fade in over the bar, it morphs the bar's own card and artwork
+// into the cover art, so for the length of that animation the bar is handed back: the rounding
+// this file applied is undone, the album colour returns through ui/Repaint.x and the glass fades
+// out. Without that the card animates from a transparent circle-artwork bar into the player and
+// reads as a cut. Coming back the glass dissolves in as the artwork settles.
+//
+// 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.
#import "SGCommon.h"
static const CGFloat kCardRadius = 24;
-static char kGlassKey;
+static const NSTimeInterval kFadeOut = 0.12, kFadeIn = 0.2;
+static char kGlassKey, kRadiusKey;
+
+// The view carrying the glass pane, so the transition hooks reach it without the controllers.
+static __weak UIView *sg_barGlassHost = nil;
+// Open and close tapped in quick succession overlap; only the newest animation takes the bar back.
+static NSUInteger sg_barTransition = 0;
static UIView *detectColoredCard(UIView *bar) {
__block UIView *best = nil;
@@ -33,13 +46,30 @@ static CGRect contentBounds(UIView *bar, UIView *target) {
return CGRectIsNull(box) ? box : CGRectInset(box, -10, -8);
}
+// Spotify's own radius is kept the first time each view is rounded, so the bar can be put back
+// the way it was laid out for the player's expand animation.
+static void roundView(UIView *view, CGFloat radius) {
+ if (!objc_getAssociatedObject(view, &kRadiusKey)) {
+ objc_setAssociatedObject(view, &kRadiusKey, @(view.layer.cornerRadius), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ }
+ view.layer.cornerRadius = radius;
+ view.layer.cornerCurve = kCACornerCurveContinuous;
+}
+
+static void restoreRounding(UIView *root) {
+ SGForEachView(root, ^(UIView *v) {
+ NSNumber *saved = objc_getAssociatedObject(v, &kRadiusKey);
+ if (saved) v.layer.cornerRadius = saved.doubleValue;
+ });
+}
+
static void restyleCardContent(UIView *card) {
SGForEachView(card, ^(UIView *v) {
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 || v.layer.cornerRadius >= size.width / 2) return;
for (UIView *u = v; u && u != card && CGSizeEqualToSize(u.bounds.size, size); u = u.superview) {
- u.layer.cornerRadius = size.width / 2;
+ roundView(u, size.width / 2);
u.clipsToBounds = YES;
}
});
@@ -59,6 +89,10 @@ static void styleNowPlayingBar(UIViewController *container) {
UIViewController *barVC = container.childViewControllers.firstObject;
UIView *bar = barVC.viewIfLoaded ?: container.view;
sg_nowPlayingRoot = bar;
+ sg_barGlassHost = container.view;
+ // Mid-transition the bar is Spotify's; its layout runs untouched so the progress line, the
+ // corners and the paint are whatever the animation needs.
+ if (sg_nowPlayingStock) return;
UIView *card = sg_nowPlayingCard;
if (!card || !SGIsInside(card, bar)) card = sg_nowPlayingCard = detectColoredCard(bar);
@@ -73,8 +107,7 @@ static void styleNowPlayingBar(UIViewController *container) {
CGFloat radius = MIN(kCardRadius, frame.size.height / 2);
if (card) {
- card.layer.cornerRadius = radius;
- card.layer.cornerCurve = kCACornerCurveContinuous;
+ roundView(card, radius);
restyleCardContent(card);
}
@@ -89,6 +122,41 @@ static void styleNowPlayingBar(UIViewController *container) {
});
}
+#pragma mark - the player's expand and close animations
+
+// `stock` gives the bar back to Spotify for the length of an animation, and takes it again after.
+static void barStock(BOOL stock, NSTimeInterval fade) {
+ UIView *host = sg_barGlassHost;
+ if (!host || !SGEnabled(SGKeyNowPlayingBar) || sg_nowPlayingStock == stock) return;
+ sg_nowPlayingStock = stock;
+
+ if (stock) {
+ restoreRounding(host);
+ if (sg_nowPlayingCardColor) sg_nowPlayingCard.layer.backgroundColor = sg_nowPlayingCardColor;
+ }
+ // A layout pass with the flag already set puts the bar in the state the flag asks for: the
+ // hook above either stands aside or restyles from scratch.
+ [host setNeedsLayout];
+ [host layoutIfNeeded];
+
+ UIVisualEffectView *glass = objc_getAssociatedObject(host, &kGlassKey);
+ [UIView animateWithDuration:fade animations:^{ glass.alpha = stock ? 0 : 1; }];
+}
+
+// Both animators are UIViewControllerAnimatedTransitioning. The bar is Spotify's own from the
+// first frame and glass again once the animation has had its duration; on the way up it is behind
+// the player by then, on the way down the dissolve lands with the artwork.
+static void playerTransition(id<UIViewControllerAnimatedTransitioning> animator, id<UIViewControllerContextTransitioning> context) {
+ NSTimeInterval duration = MAX(0.1, [animator transitionDuration:context]);
+ NSUInteger generation = ++sg_barTransition;
+ barStock(YES, MIN(kFadeOut, duration / 3));
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ if (generation == sg_barTransition) barStock(NO, kFadeIn);
+ });
+ static dispatch_once_t once;
+ dispatch_once(&once, ^{ SGLog(@"player transition %@ over %.2fs", [animator class], duration); });
+}
+
%hook _TtC18NowPlaying_BarImpl36NowPlayingBarContainerViewController
- (void)viewDidLayoutSubviews {
%orig;
@@ -104,10 +172,26 @@ static void styleNowPlayingBar(UIViewController *container) {
}
%end
+%hook _TtC23NowPlaying_ViewPageImpl35ShowFullscreenAnimatedTransitioning
+- (void)animateTransition:(id<UIViewControllerContextTransitioning>)context {
+ playerTransition((id)self, context);
+ %orig;
+}
+%end
+
+%hook _TtC23NowPlaying_ViewPageImpl36CloseFullScreenAnimatedTransitioning
+- (void)animateTransition:(id<UIViewControllerContextTransitioning>)context {
+ playerTransition((id)self, context);
+ %orig;
+}
+%end
+
%ctor {
%init;
SGRequireClasses(@[
@"_TtC18NowPlaying_BarImpl36NowPlayingBarContainerViewController",
@"_TtC18NowPlaying_BarImpl27NowPlayingBarViewController",
+ @"_TtC23NowPlaying_ViewPageImpl35ShowFullscreenAnimatedTransitioning",
+ @"_TtC23NowPlaying_ViewPageImpl36CloseFullScreenAnimatedTransitioning",
]);
}
diff --git a/tweak/src/ui/NowPlayingView.x b/tweak/src/ui/NowPlayingView.x
index 1585f1fc..a8a65e39 100644
--- a/tweak/src/ui/NowPlayingView.x
+++ b/tweak/src/ui/NowPlayingView.x
@@ -1,15 +1,22 @@
-// Full screen player: glass behind the header buttons, each transport control except play, and
-// the footer buttons. Spotify's blurred artwork background stays underneath.
+// Full screen player: glass where Liquid Glass belongs and nowhere else.
//
-// Tree (trees/now-playing.txt): NowPlaying_ModesImpl units, each a child controller whose view holds
-// one UIStackView row: header (chevron, title, more), playback controls (shuffle, previous, play,
-// next, repeat), footer (connect, share, queue).
+// Glass is the navigation layer floating over content, so only the header's two round buttons get
+// a pane, the way the Music app keeps its chrome. The playlist name between them is a label, and
+// shuffle, repeat, previous, next and the footer (connect, share, queue) are bare glyphs over the
+// artwork next to Spotify's white play disc: a pane each turned both rows into a strip of glass
+// discs sampling one another, which is the one thing the material cannot do. The cards below the
+// player are surfaces rather than controls; the lyrics one is in ui/Lyrics.x.
+//
+// Tree (trees/now-playing.txt): NowPlaying_ModesImpl units, each a child controller whose view
+// holds one UIStackView row; the header row is chevron 48x48, playlist name 110x48, more 48x48.
#import "SGCommon.h"
-// A pane per direct child of the unit's row: circles for square children, capsules for wide ones.
-// `fixedSize` forces every pane to one size; children containing a `skip` class get none, nor do
-// the ones ui/Declutter.x made invisible.
-static void glassBehindRowChildren(UIViewController *unit, CGFloat minSize, CGFloat fixedSize, NSString *skip) {
+static const CGFloat kButtonMin = 36, kButtonMax = 48;
+
+// A glass circle per round button in the unit's row: children about as wide as they are tall.
+// The playlist name is 110 wide against 48 tall, so it keeps no pane, and neither do the children
+// ui/Declutter.x made invisible.
+static void glassBehindRoundButtons(UIViewController *unit) {
if (!SGEnabled(SGKeyPlayer)) return;
UIView *host = unit.viewIfLoaded;
UIStackView *row = SGRowIn(host);
@@ -19,14 +26,11 @@ static void glassBehindRowChildren(UIViewController *unit, CGFloat minSize, CGFl
for (UIView *child in row.arrangedSubviews) {
CGRect f = SGFrameIn(child, host);
if (child.hidden || child.alpha == 0 || f.size.width < 20 || f.size.height < 20) continue;
- __block BOOL skipped = NO;
- if (skip) SGForEachView(child, ^(UIView *v) { if ([NSStringFromClass(v.class) containsString:skip]) skipped = YES; });
- if (skipped) continue;
- CGFloat height = fixedSize ?: MAX(minSize, MIN(f.size.height, 48));
- CGFloat width = fixedSize ?: MAX(f.size.width, height);
+ if (f.size.width > f.size.height * 1.4) continue;
+ CGFloat side = MAX(kButtonMin, MIN(MAX(f.size.width, f.size.height), kButtonMax));
UIVisualEffectView *glass = SGGlassAt(host, index++);
- glass.frame = CGRectMake(CGRectGetMidX(f) - width / 2, CGRectGetMidY(f) - height / 2, width, height);
- SGShapeGlass(glass, height / 2, YES);
+ glass.frame = CGRectMake(CGRectGetMidX(f) - side / 2, CGRectGetMidY(f) - side / 2, side, side);
+ SGShapeGlass(glass, side / 2, YES);
}
SGHideGlassFrom(host, index);
}
@@ -34,29 +38,11 @@ static void glassBehindRowChildren(UIViewController *unit, CGFloat minSize, CGFl
%hook _TtC20NowPlaying_ModesImpl18HeaderElementsUnit
- (void)viewDidLayoutSubviews {
%orig;
- glassBehindRowChildren((UIViewController *)self, 36, 0, nil);
-}
-%end
-
-%hook _TtC20NowPlaying_ModesImpl28PlaybackControlsElementsUnit
-- (void)viewDidLayoutSubviews {
- %orig;
- glassBehindRowChildren((UIViewController *)self, 0, 52, @"PlayButton");
-}
-%end
-
-%hook _TtC20NowPlaying_ModesImpl18FooterElementsUnit
-- (void)viewDidLayoutSubviews {
- %orig;
- glassBehindRowChildren((UIViewController *)self, 36, 0, nil);
+ glassBehindRoundButtons((UIViewController *)self);
}
%end
%ctor {
%init;
- SGRequireClasses(@[
- @"_TtC20NowPlaying_ModesImpl18HeaderElementsUnit",
- @"_TtC20NowPlaying_ModesImpl28PlaybackControlsElementsUnit",
- @"_TtC20NowPlaying_ModesImpl18FooterElementsUnit",
- ]);
+ SGRequireClasses(@[@"_TtC20NowPlaying_ModesImpl18HeaderElementsUnit"]);
}
diff --git a/tweak/src/ui/Repaint.x b/tweak/src/ui/Repaint.x
index 2ff5d6c2..944a0a14 100644
--- a/tweak/src/ui/Repaint.x
+++ b/tweak/src/ui/Repaint.x
@@ -4,7 +4,7 @@
%hook CALayer
- (void)setBackgroundColor:(CGColorRef)color {
- if (color && (sg_nowPlayingRoot || sg_tabBarRoot)) {
+ if (color && (sg_nowPlayingRoot || sg_tabBarRoot || sg_lyricsCardRoot || sg_lyricsPageRoot || sg_homeRoot)) {
UIView *view = (UIView *)self.delegate;
if ([view isKindOfClass:UIView.class] && view.layer == self && !SGKeepsColor(view)) {
if (SGIsInside(view, sg_nowPlayingRoot)) {
@@ -13,8 +13,15 @@
UIView *bar = sg_nowPlayingRoot;
dispatch_async(dispatch_get_main_queue(), ^{ [bar.superview setNeedsLayout]; });
}
+ if (view == sg_nowPlayingCard) SGRememberCardColor(color);
+ // While the full screen player animates, the bar is Spotify's own again.
+ if (!sg_nowPlayingStock) color = NULL;
+ } else if (SGIsInside(view, sg_tabBarRoot) || SGIsInside(view, sg_lyricsCardRoot)
+ || SGIsInside(view, sg_lyricsPageRoot)) {
color = NULL;
- } else if (SGIsInside(view, sg_tabBarRoot)) {
+ } else if (SGIsBaseSurface(color) && SGIsInside(view, sg_homeRoot)) {
+ // Home keeps its cards and its placeholders; only the base surface the gradient
+ // of ui/HomeGradient.x sits behind goes.
color = NULL;
}
}
diff --git a/tweak/src/ui/Settings.x b/tweak/src/ui/Settings.x
index 23d6946b..24ca13e6 100644
--- a/tweak/src/ui/Settings.x
+++ b/tweak/src/ui/Settings.x
@@ -1,8 +1,9 @@
// Settings: a Mod Settings row at the end of Spotify's settings list opens the mod's own pages:
// UI Tweaks, Home and Now Playing, each sections of switches (the mod's own and a few of
-// Spotify's remote-config flags), and All flags, a searchable list of every flag with an
-// override per flag. The tweaks read the switches when they run, so a change shows after Spotify
-// restarts.
+// Spotify's remote-config flags), Navbar, the tab bar's own composition, and All flags, a
+// searchable list of every flag with an override per flag. The tweaks read the switches when they
+// run, so a change shows after Spotify restarts; the Navbar page is the exception and applies as
+// soon as the bar lays out again.
//
// Tree (trees/settings.txt): SettingsListViewController.view > SettingsListCollectionView of
// Element_List cells 402x56: 24pt icon at x 12, 13pt white title and 11pt grey subtitle at
@@ -120,6 +121,13 @@ static SGModRow *hideRow(NSString *title, NSString *subtitle, NSString *key) {
return row;
}
+// A switch for something the mod adds rather than takes away: off until it is asked for.
+static SGModRow *optionRow(NSString *title, NSString *subtitle, NSString *key) {
+ SGModRow *row = switchRow(title, subtitle, key);
+ row.defaultOn = NO;
+ return row;
+}
+
static SGModRow *flagRow(NSString *title, NSString *key) {
SGModRow *row = hideRow(title, [key substringFromIndex:[key rangeOfString:@"."].location + 1], key);
row.flag = YES;
@@ -143,6 +151,46 @@ static SGModSection *section(NSString *title, NSArray<SGModRow *> *rows) {
static const CGFloat kSectionHeaderHeight = 38;
+// Every page below draws Spotify's own list row: a 13pt white title over an 11pt grey subtitle,
+// with an optional symbol in the leading slot.
+static void fillCell(UITableViewCell *cell, NSString *title, NSString *subtitle, UIColor *color, NSString *symbolName) {
+ UIListContentConfiguration *content = [UIListContentConfiguration subtitleCellConfiguration];
+ content.text = title;
+ content.secondaryText = subtitle;
+ content.textProperties.font = titleFont();
+ content.textProperties.color = color ?: UIColor.whiteColor;
+ content.secondaryTextProperties.font = subtitleFont();
+ content.secondaryTextProperties.color = grey();
+ content.textToSecondaryTextVerticalPadding = 0;
+ content.directionalLayoutMargins = NSDirectionalEdgeInsetsMake(10, 16, 10, 16);
+ if (symbolName) {
+ content.image = [UIImage systemImageNamed:symbolName withConfiguration:[UIImageSymbolConfiguration configurationWithPointSize:15 weight:UIImageSymbolWeightRegular]];
+ content.imageProperties.tintColor = color ?: UIColor.whiteColor;
+ content.imageToTextPadding = 14;
+ }
+ cell.contentConfiguration = content;
+ cell.backgroundColor = UIColor.clearColor;
+ cell.accessoryView = nil;
+ cell.selectionStyle = UITableViewCellSelectionStyleNone;
+}
+
+static UIView *sectionHeader(UITableView *table, NSString *title) {
+ UILabel *label = [UILabel new];
+ label.text = title.uppercaseString;
+ label.font = subtitleFont();
+ label.textColor = grey();
+ label.frame = CGRectMake(16, 20, table.bounds.size.width - 32, 14);
+ label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
+ UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, table.bounds.size.width, kSectionHeaderHeight)];
+ [header addSubview:label];
+ return header;
+}
+
+static UITableViewCell *dequeue(UITableView *table, NSString *identifier) {
+ return [table dequeueReusableCellWithIdentifier:identifier]
+ ?: [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
+}
+
@interface SGModPage : UITableViewController
- (instancetype)initWithTitle:(NSString *)title intro:(NSString *)intro sections:(NSArray<SGModSection *> *)sections footer:(NSString *)footer;
@end
@@ -197,16 +245,7 @@ static const CGFloat kSectionHeaderHeight = 38;
- (UIView *)tableView:(UITableView *)table viewForHeaderInSection:(NSInteger)section {
NSString *title = _sections[(NSUInteger)section].title;
- if (!title) return nil;
- UILabel *label = [UILabel new];
- label.text = title.uppercaseString;
- label.font = subtitleFont();
- label.textColor = grey();
- label.frame = CGRectMake(16, 20, table.bounds.size.width - 32, 14);
- label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
- UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, table.bounds.size.width, kSectionHeaderHeight)];
- [header addSubview:label];
- return header;
+ return title ? sectionHeader(table, title) : nil;
}
- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {
@@ -218,23 +257,9 @@ static const CGFloat kSectionHeaderHeight = 38;
}
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {
- UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:@"row"]
- ?: [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"row"];
+ UITableViewCell *cell = dequeue(table, @"row");
SGModRow *row = [self rowAt:path];
-
- UIListContentConfiguration *content = [UIListContentConfiguration subtitleCellConfiguration];
- content.text = row.title;
- content.secondaryText = row.subtitle;
- content.textProperties.font = titleFont();
- content.textProperties.color = UIColor.whiteColor;
- content.secondaryTextProperties.font = subtitleFont();
- content.secondaryTextProperties.color = grey();
- content.textToSecondaryTextVerticalPadding = 0;
- content.directionalLayoutMargins = NSDirectionalEdgeInsetsMake(10, 16, 10, 16);
- cell.contentConfiguration = content;
- cell.backgroundColor = UIColor.clearColor;
- cell.accessoryView = nil;
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
+ fillCell(cell, row.title, row.subtitle, nil, nil);
if (row.key) {
UISwitch *toggle = [UISwitch new];
@@ -356,25 +381,15 @@ static NSString *flagState(const SGFlagDef *flag, id value) {
}
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {
- UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:@"flag"]
- ?: [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"flag"];
+ UITableViewCell *cell = dequeue(table, @"flag");
const SGFlagDef *flag = [self flagAt:path.row];
NSString *key = @(flag->key);
NSUInteger dot = [key rangeOfString:@"."].location;
id value = _overrides[key];
- UIListContentConfiguration *content = [UIListContentConfiguration subtitleCellConfiguration];
- content.text = [key substringFromIndex:dot + 1];
- content.secondaryText = [NSString stringWithFormat:@"%@ · %@", [key substringToIndex:dot], flagState(flag, value)];
- content.textProperties.font = titleFont();
- content.textProperties.color = value ? green() : UIColor.whiteColor;
- content.secondaryTextProperties.font = subtitleFont();
- content.secondaryTextProperties.color = grey();
- content.textToSecondaryTextVerticalPadding = 0;
- content.directionalLayoutMargins = NSDirectionalEdgeInsetsMake(10, 16, 10, 16);
- cell.contentConfiguration = content;
- cell.backgroundColor = UIColor.clearColor;
- cell.accessoryView = nil;
+ fillCell(cell, [key substringFromIndex:dot + 1],
+ [NSString stringWithFormat:@"%@ · %@", [key substringToIndex:dot], flagState(flag, value)],
+ value ? green() : nil, nil);
cell.selectionStyle = UITableViewCellSelectionStyleDefault;
if (flag->type == SGFlagBool) {
@@ -431,6 +446,333 @@ static NSString *flagState(const SGFlagDef *flag, id value) {
@end
+#pragma mark - navbar page
+
+// What "Add a tab" offers: URIs Spotify's own router resolves to a page of its own, each with the
+// name of the SPTEncoreIcon class method that draws its glyph.
+static NSArray<NSDictionary *> *tabPresets(void) {
+ return @[
+ @{SGNavbarTitle: @"Home", SGNavbarURI: @"spotify:home", SGNavbarIcon: @"home"},
+ @{SGNavbarTitle: @"Search", SGNavbarURI: @"spotify:search", SGNavbarIcon: @"search"},
+ @{SGNavbarTitle: @"Your Library", SGNavbarURI: @"spotify:collection", SGNavbarIcon: @"collection"},
+ @{SGNavbarTitle: @"Liked Songs", SGNavbarURI: @"spotify:collection:tracks", SGNavbarIcon: @"heart"},
+ @{SGNavbarTitle: @"Playlists", SGNavbarURI: @"spotify:collection:playlists", SGNavbarIcon: @"playlist"},
+ @{SGNavbarTitle: @"Albums", SGNavbarURI: @"spotify:collection:albums", SGNavbarIcon: @"album"},
+ @{SGNavbarTitle: @"Artists", SGNavbarURI: @"spotify:collection:artists", SGNavbarIcon: @"artist"},
+ @{SGNavbarTitle: @"Podcasts", SGNavbarURI: @"spotify:collection:podcasts", SGNavbarIcon: @"podcasts"},
+ @{SGNavbarTitle: @"Audiobooks", SGNavbarURI: @"spotify:collection:audiobooks", SGNavbarIcon: @"audiobook"},
+ @{SGNavbarTitle: @"Downloads", SGNavbarURI: @"spotify:collection:downloads", SGNavbarIcon: @"downloaded"},
+ @{SGNavbarTitle: @"Your Episodes", SGNavbarURI: @"spotify:collection:your-episodes", SGNavbarIcon: @"bookmark"},
+ @{SGNavbarTitle: @"Browse", SGNavbarURI: @"spotify:browse", SGNavbarIcon: @"browse"},
+ @{SGNavbarTitle: @"New Releases", SGNavbarURI: @"spotify:new-releases", SGNavbarIcon: @"star"},
+ @{SGNavbarTitle: @"Made For You", SGNavbarURI: @"spotify:made-for-you", SGNavbarIcon: @"user"},
+ @{SGNavbarTitle: @"Concerts", SGNavbarURI: @"spotify:concerts", SGNavbarIcon: @"events"},
+ @{SGNavbarTitle: @"Queue", SGNavbarURI: @"spotify:now-playing:queue", SGNavbarIcon: @"queue"},
+ @{SGNavbarTitle: @"Create", SGNavbarURI: @"spotify:create-menu", SGNavbarIcon: @"plus"},
+ ];
+}
+
+// The list the Navbar page edits: the saved order first, then every tab of Spotify's it does not
+// name, in Spotify's order. Entries for tabs Spotify no longer has drop out.
+static NSMutableArray<NSMutableDictionary *> *navbarEntries(void) {
+ NSArray<NSString *> *stock = SGNavbarStock();
+ NSMutableArray<NSMutableDictionary *> *entries = [NSMutableArray array];
+ NSMutableSet<NSString *> *seen = [NSMutableSet set];
+ for (NSDictionary *entry in SGNavbarLayout()) {
+ NSString *ident = entry[SGNavbarID];
+ if (![ident isKindOfClass:NSString.class] || [seen containsObject:ident]) continue;
+ if (!entry[SGNavbarURI] && ![stock containsObject:ident]) continue;
+ [seen addObject:ident];
+ [entries addObject:[entry mutableCopy]];
+ }
+ for (NSString *ident in stock) {
+ if ([seen containsObject:ident]) continue;
+ [entries addObject:[@{SGNavbarID: ident, SGNavbarTitle: ident} mutableCopy]];
+ }
+ return entries;
+}
+
+// A tab of the mod's own carries an identity of its own, so the same page can sit on the bar twice
+// and renaming one does not shuffle the order.
+static void appendTab(NSDictionary *tab) {
+ NSMutableDictionary *entry = [tab mutableCopy];
+ entry[SGNavbarID] = NSUUID.UUID.UUIDString;
+ SGSetNavbarLayout([navbarEntries() arrayByAddingObject:entry]);
+}
+
+@interface SGTabPickerPage : UITableViewController
+@end
+
+@implementation SGTabPickerPage {
+ UIView *_footer;
+}
+
+- (instancetype)init {
+ if (!(self = [super initWithStyle:UITableViewStyleGrouped])) return nil;
+ self.title = @"Add a Tab";
+ return self;
+}
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+ self.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
+ self.tableView.backgroundColor = pageBackground();
+ self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
+ self.tableView.sectionHeaderTopPadding = 0;
+ _footer = note(@"Anything Spotify can open by link works, so a playlist, an artist or a page of "
+ "your own goes on the bar the same way. Icons are Spotify's own: home, search, "
+ "collection, heart, playlist, album, artist, podcasts, audiobook, downloaded, "
+ "bookmark, browse, star, user, events, queue, plus, radio, gears, spotifyLogo.");
+ self.tableView.tableFooterView = _footer;
+}
+
+- (void)viewWillLayoutSubviews {
+ [super viewWillLayoutSubviews];
+ fitNote(self.tableView, _footer, 16, 24);
+}
+
+- (void)viewDidLayoutSubviews {
+ [super viewDidLayoutSubviews];
+ insetForBars(self.tableView);
+}
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {
+ return 2;
+}
+
+- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
+ return section == 0 ? (NSInteger)tabPresets().count : 1;
+}
+
+- (UIView *)tableView:(UITableView *)table viewForHeaderInSection:(NSInteger)section {
+ return sectionHeader(table, section == 0 ? @"Spotify's pages" : @"Anywhere else");
+}
+
+- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {
+ return kSectionHeaderHeight;
+}
+
+- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {
+ return CGFLOAT_MIN;
+}
+
+- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {
+ UITableViewCell *cell = dequeue(table, @"pick");
+ if (path.section == 0) {
+ NSDictionary *tab = tabPresets()[(NSUInteger)path.row];
+ fillCell(cell, tab[SGNavbarTitle], tab[SGNavbarURI], nil, nil);
+ } else {
+ fillCell(cell, @"Any link…", @"A name, a URI of your own and an icon", nil, @"link");
+ }
+ cell.selectionStyle = UITableViewCellSelectionStyleDefault;
+ return cell;
+}
+
+- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {
+ [table deselectRowAtIndexPath:path animated:YES];
+ if (path.section == 0) {
+ appendTab(tabPresets()[(NSUInteger)path.row]);
+ [self.navigationController popViewControllerAnimated:YES];
+ return;
+ }
+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Any link" message:@"Where the tab goes, and the glyph on it." preferredStyle:UIAlertControllerStyleAlert];
+ [alert addTextFieldWithConfigurationHandler:^(UITextField *field) { field.placeholder = @"Name"; }];
+ [alert addTextFieldWithConfigurationHandler:^(UITextField *field) {
+ field.placeholder = @"spotify:playlist:…";
+ field.autocapitalizationType = UITextAutocapitalizationTypeNone;
+ field.autocorrectionType = UITextAutocorrectionTypeNo;
+ }];
+ [alert addTextFieldWithConfigurationHandler:^(UITextField *field) {
+ field.placeholder = @"Icon";
+ field.text = @"star";
+ field.autocapitalizationType = UITextAutocapitalizationTypeNone;
+ field.autocorrectionType = UITextAutocorrectionTypeNo;
+ }];
+ [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
+ [alert addAction:[UIAlertAction actionWithTitle:@"Add" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
+ NSString *title = alert.textFields[0].text, *uri = alert.textFields[1].text, *icon = alert.textFields[2].text;
+ if (!uri.length) return;
+ appendTab(@{SGNavbarTitle: title.length ? title : uri, SGNavbarURI: uri, SGNavbarIcon: icon.length ? icon : @"star"});
+ [self.navigationController popViewControllerAnimated:YES];
+ }]];
+ [self presentViewController:alert animated:YES completion:nil];
+}
+
+@end
+
+// The tabs, in the order the bar shows them: drag to reorder, tap to show or hide, swipe a tab of
+// your own away. Spotify's own tabs can only be hidden, never removed.
+@interface SGNavbarPage : UITableViewController
+@end
+
+@implementation SGNavbarPage {
+ NSMutableArray<NSMutableDictionary *> *_entries;
+ UIView *_intro;
+ UIView *_footer;
+}
+
+- (instancetype)init {
+ if (!(self = [super initWithStyle:UITableViewStyleGrouped])) return nil;
+ self.title = @"Navbar";
+ return self;
+}
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+ self.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
+ self.tableView.backgroundColor = pageBackground();
+ self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
+ self.tableView.sectionHeaderTopPadding = 0;
+ self.tableView.allowsSelectionDuringEditing = YES;
+ self.tableView.editing = YES;
+ _intro = note(@"Drag a tab by the handle to move it, tap it to show or hide it. The bar follows straight away.");
+ _footer = note(@"Spotify's own tabs are remembered by the name under their icon, so switching the "
+ "app's language starts the order over. A tab of your own opens its link from "
+ "wherever you are, and never lights up as the tab you are on.");
+ self.tableView.tableHeaderView = _intro;
+ self.tableView.tableFooterView = _footer;
+ _entries = navbarEntries();
+}
+
+// The Add page writes straight to the layout, so the list is read again on the way back.
+- (void)viewWillAppear:(BOOL)animated {
+ [super viewWillAppear:animated];
+ _entries = navbarEntries();
+ [self.tableView reloadData];
+}
+
+- (void)viewWillLayoutSubviews {
+ [super viewWillLayoutSubviews];
+ fitNote(self.tableView, _intro, 24, 0);
+ fitNote(self.tableView, _footer, 16, 24);
+}
+
+- (void)viewDidLayoutSubviews {
+ [super viewDidLayoutSubviews];
+ insetForBars(self.tableView);
+}
+
+- (void)save {
+ SGSetNavbarLayout(_entries);
+}
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {
+ return 4;
+}
+
+- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
+ return section == 1 ? (NSInteger)_entries.count : 1;
+}
+
+- (UIView *)tableView:(UITableView *)table viewForHeaderInSection:(NSInteger)section {
+ return section == 1 ? sectionHeader(table, @"Tabs") : nil;
+}
+
+- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {
+ return section == 1 ? kSectionHeaderHeight : CGFLOAT_MIN;
+}
+
+- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {
+ return CGFLOAT_MIN;
+}
+
+- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {
+ UITableViewCell *cell = dequeue(table, @"navbar");
+ switch (path.section) {
+ case 0: {
+ fillCell(cell, @"Custom navbar", @"Off leaves the bar exactly as Spotify built it", nil, nil);
+ UISwitch *toggle = [UISwitch new];
+ toggle.onTintColor = green();
+ toggle.on = SGEnabled(SGKeyNavbar);
+ [toggle addTarget:self action:@selector(toggled:) forControlEvents:UIControlEventValueChanged];
+ cell.accessoryView = toggle;
+ break;
+ }
+ case 1: {
+ NSDictionary *entry = _entries[(NSUInteger)path.row];
+ BOOL hidden = [entry[SGNavbarHidden] boolValue];
+ NSString *uri = entry[SGNavbarURI];
+ fillCell(cell, entry[SGNavbarTitle], hidden ? @"Hidden" : (uri ?: @"Spotify's own tab"),
+ hidden ? grey() : nil, hidden ? @"eye.slash" : @"eye");
+ break;
+ }
+ case 2:
+ fillCell(cell, @"Add a tab…", @"A page of Spotify's, or any link", nil, @"plus");
+ cell.selectionStyle = UITableViewCellSelectionStyleDefault;
+ break;
+ default:
+ fillCell(cell, @"Use Spotify's order", @"Forgets the order and the tabs you added", nil, @"arrow.uturn.backward");
+ cell.selectionStyle = UITableViewCellSelectionStyleDefault;
+ break;
+ }
+ return cell;
+}
+
+- (BOOL)tableView:(UITableView *)table canMoveRowAtIndexPath:(NSIndexPath *)path {
+ return path.section == 1;
+}
+
+- (BOOL)tableView:(UITableView *)table canEditRowAtIndexPath:(NSIndexPath *)path {
+ return path.section == 1;
+}
+
+// Spotify's own tabs stay on the list to be switched back on; only the mod's own can go.
+- (UITableViewCellEditingStyle)tableView:(UITableView *)table editingStyleForRowAtIndexPath:(NSIndexPath *)path {
+ if (path.section != 1) return UITableViewCellEditingStyleNone;
+ return _entries[(NSUInteger)path.row][SGNavbarURI] ? UITableViewCellEditingStyleDelete : UITableViewCellEditingStyleNone;
+}
+
+- (NSIndexPath *)tableView:(UITableView *)table targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)from toProposedIndexPath:(NSIndexPath *)to {
+ return to.section == 1 ? to : from;
+}
+
+- (void)tableView:(UITableView *)table moveRowAtIndexPath:(NSIndexPath *)from toIndexPath:(NSIndexPath *)to {
+ NSMutableDictionary *entry = _entries[(NSUInteger)from.row];
+ [_entries removeObjectAtIndex:(NSUInteger)from.row];
+ [_entries insertObject:entry atIndex:(NSUInteger)to.row];
+ [self save];
+}
+
+- (void)tableView:(UITableView *)table commitEditingStyle:(UITableViewCellEditingStyle)style forRowAtIndexPath:(NSIndexPath *)path {
+ if (style != UITableViewCellEditingStyleDelete) return;
+ [_entries removeObjectAtIndex:(NSUInteger)path.row];
+ [self save];
+ [table deleteRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationAutomatic];
+}
+
+- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {
+ [table deselectRowAtIndexPath:path animated:YES];
+ if (path.section == 1) {
+ NSMutableDictionary *entry = _entries[(NSUInteger)path.row];
+ entry[SGNavbarHidden] = [entry[SGNavbarHidden] boolValue] ? nil : @YES;
+ [self save];
+ [table reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationNone];
+ } else if (path.section == 2) {
+ [self.navigationController pushViewController:[SGTabPickerPage new] animated:YES];
+ } else if (path.section == 3) {
+ [self reset];
+ }
+}
+
+- (void)toggled:(UISwitch *)toggle {
+ SGSetEnabled(SGKeyNavbar, toggle.on);
+}
+
+- (void)reset {
+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Use Spotify's order"
+ message:@"Every tab of Spotify's comes back where Spotify put it, and the tabs you added go."
+ preferredStyle:UIAlertControllerStyleAlert];
+ [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
+ [alert addAction:[UIAlertAction actionWithTitle:@"Reset" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
+ SGSetNavbarLayout(@[]);
+ self->_entries = navbarEntries();
+ [self.tableView reloadData];
+ }]];
+ [self presentViewController:alert animated:YES completion:nil];
+}
+
+@end
+
static NSString *const kRestart = @"Changes apply after you restart Spotify.";
static UIViewController *uiTweaksPage(void) {
@@ -448,6 +790,9 @@ static UIViewController *uiTweaksPage(void) {
static UIViewController *homePage(void) {
return [[SGModPage alloc] initWithTitle:@"Home" intro:kRestart sections:@[
+ section(@"Background", @[
+ optionRow(@"Gradient", @"A green wash behind the top of the page, fading into the background", SGKeyHomeGradient),
+ ]),
section(@"Hide", @[
hideRow(@"Filter pills", @"Music and Podcasts next to your avatar", SGHideHomePills),
hideRow(@"Shortcuts grid", @"The tiles at the top", SGHideHomeShortcuts),
@@ -462,7 +807,8 @@ static UIViewController *nowPlayingPage(void) {
return [[SGModPage alloc] initWithTitle:@"Now Playing" intro:kRestart sections:@[
section(@"Liquid Glass", @[
switchRow(@"Now playing bar", @"Glass card with round artwork", SGKeyNowPlayingBar),
- switchRow(@"Player controls", @"Glass behind the buttons of the full screen player", SGKeyPlayer),
+ switchRow(@"Header buttons", @"Glass circles behind close and more, over the artwork", SGKeyPlayer),
+ switchRow(@"Lyrics", @"Glass card, and the page it expands into", SGKeyLyricsCard),
]),
section(@"Spotify's flags", @[
flagRow(@"Sheet style player", @"ios-feature-nowplaying.sheet_style_npv"),
@@ -509,7 +855,8 @@ static UIViewController *modSettingsPage(void) {
return [[SGModPage alloc] initWithTitle:@"Mod Settings" intro:nil sections:@[
section(nil, @[
pageRow(@"UI Tweaks", @"Liquid Glass • AMOLED background", ^UIViewController *{ return uiTweaksPage(); }),
- pageRow(@"Home", @"Hide sections of the Home tab", ^UIViewController *{ return homePage(); }),
+ pageRow(@"Navbar", @"Reorder the tabs, hide them, add your own", ^UIViewController *{ return [SGNavbarPage new]; }),
+ pageRow(@"Home", @"Gradient background, hide sections of the Home tab", ^UIViewController *{ return homePage(); }),
pageRow(@"Now Playing", @"Glass, Spotify's player flags, hide buttons and cards", ^UIViewController *{ return nowPlayingPage(); }),
pageRow(@"All flags", @"Search and force any of Spotify's remote-config flags", ^UIViewController *{ return [SGFlagsPage new]; }),
]),
@@ -535,7 +882,7 @@ static UIViewController *modSettingsPage(void) {
_title.text = @"Mod Settings";
_title.textColor = UIColor.whiteColor;
_subtitle = [UILabel new];
- _subtitle.text = @"UI Tweaks • Home • Now Playing • Flags";
+ _subtitle.text = @"UI Tweaks • Navbar • Home • Now Playing • Flags";
_subtitle.textColor = grey();
_chevron = symbol(@"chevron.right", 11, UIImageSymbolWeightSemibold, 12);
for (UIView *v in @[_icon, _title, _subtitle, _chevron]) [self addSubview:v];
diff --git a/tweak/src/ui/TabBar.x b/tweak/src/ui/TabBar.x
index 308038f2..9defe16f 100644
--- a/tweak/src/ui/TabBar.x
+++ b/tweak/src/ui/TabBar.x
@@ -1,5 +1,6 @@
-// Tab bar: gradient and labels go, icons centre, a glass capsule sits behind Home, Search and
-// Library and a glass circle behind Create. Spotify maps taps by position, so the item order stays.
+// Tab bar: gradient and labels go, icons centre, a glass capsule sits behind the tabs and a glass
+// circle behind Create when Create is the last of them. ui/Navbar.x owns which items are on the
+// bar and in what order; this file only paints whatever it left there.
//
// Tree (trees/home.txt): NavigationUI_TabBarImpl.TabBarView > TabBarCompactView > TabBarGradientView
// + UIStackView 402x49 of four ElementContentView<TabBarItemElement> 100x49, each with an
@@ -10,16 +11,14 @@ static const CGFloat kPillHeight = 56;
static const CGFloat kCircleSize = 52;
static char kPillKey, kCircleKey;
+// The items the bar shows, left to right: the stack view's own arranged order, minus the ones
+// ui/Navbar.x switched off.
static NSArray<UIView *> *tabItems(UIView *tabBar) {
NSMutableArray<UIView *> *items = [NSMutableArray array];
- SGForEachView(tabBar, ^(UIView *v) {
- if (v != tabBar && v.bounds.size.width >= 20 && [NSStringFromClass(v.class) containsString:@"TabBarItemElement"]) [items addObject:v];
- });
- // Element wrappers nest; keep the outermost per item.
- return [items filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(UIView *v, id _) {
- for (UIView *u = v.superview; u && u != tabBar; u = u.superview) if ([items containsObject:u]) return NO;
- return YES;
- }]];
+ for (UIView *item in SGRowIn(tabBar).arrangedSubviews) {
+ if (!item.hidden && item.bounds.size.width >= 20) [items addObject:item];
+ }
+ return items;
}
static void styleTabBar(UIView *tabBar) {
@@ -33,22 +32,28 @@ static void styleTabBar(UIView *tabBar) {
dispatch_once(&once, ^{ SGLog(@"tab bar %@ with %lu items", tabBar.class, (unsigned long)items.count); });
if (items.count < 2) return;
- NSArray<UIView *> *sorted = [items sortedArrayUsingComparator:^NSComparisonResult(UIView *a, UIView *b) {
- return [@(SGFrameIn(a, tabBar).origin.x) compare:@(SGFrameIn(b, tabBar).origin.x)];
- }];
- CGRect first = SGFrameIn(sorted.firstObject, tabBar);
- CGRect lastMain = SGFrameIn(sorted[sorted.count - 2], tabBar);
- CGRect last = SGFrameIn(sorted.lastObject, tabBar);
+ // Create is a round button of its own, but only where Spotify puts it: last. Moved in among
+ // the others by ui/Navbar.x it joins them under the capsule instead.
+ BOOL circled = SGHasClass(items.lastObject, @"CreateMenu");
+ NSArray<UIView *> *capsuled = circled ? [items subarrayWithRange:NSMakeRange(0, items.count - 1)] : items;
+ CGRect first = SGFrameIn(items.firstObject, tabBar);
CGFloat midY = CGRectGetMidY(first);
UIVisualEffectView *pill = SGGlassFor(tabBar, &kPillKey);
- CGFloat left = MAX(12, first.origin.x + 12);
- pill.frame = CGRectMake(left, midY - kPillHeight / 2, CGRectGetMaxX(lastMain) + 4 - left, kPillHeight);
- SGShapeGlass(pill, kPillHeight / 2, YES);
+ pill.hidden = capsuled.count == 0;
+ if (capsuled.count) {
+ CGFloat left = MAX(12, first.origin.x + 12);
+ pill.frame = CGRectMake(left, midY - kPillHeight / 2, CGRectGetMaxX(SGFrameIn(capsuled.lastObject, tabBar)) + 4 - left, kPillHeight);
+ SGShapeGlass(pill, kPillHeight / 2, YES);
+ }
UIVisualEffectView *circle = SGGlassFor(tabBar, &kCircleKey);
- circle.frame = CGRectMake(CGRectGetMidX(last) - kCircleSize / 2, midY - kCircleSize / 2, kCircleSize, kCircleSize);
- SGShapeGlass(circle, kCircleSize / 2, YES);
+ circle.hidden = !circled;
+ if (circled) {
+ CGRect last = SGFrameIn(items.lastObject, tabBar);
+ circle.frame = CGRectMake(CGRectGetMidX(last) - kCircleSize / 2, midY - kCircleSize / 2, kCircleSize, kCircleSize);
+ SGShapeGlass(circle, kCircleSize / 2, YES);
+ }
}
// Items lay out their own icon and label, after the bar; hide the label, centre the icon, then
@@ -73,6 +78,9 @@ static void styleTabItem(UIView *item) {
%hook _TtC23NavigationUI_TabBarImpl10TabBarView
- (void)layoutSubviews {
%orig;
+ // After Spotify's own pass, so whatever it did to the row of items is undone before the glass
+ // is measured against it; the layoutIfNeeded below gives the moved items their frames.
+ SGComposeTabBar((UIView *)self);
for (UIView *sub in ((UIView *)self).subviews) [sub layoutIfNeeded];
styleTabBar((UIView *)self);
}