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 blurred artwork player backdrop

Vojtěch Škopek1ba972be7951
diff --git a/README.md b/README.md
index 21e067fb..d6aa9d15 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, Navbar, NowPlayingView, Lyrics, SearchField, Flags, Amoled, Declutter, Repaint, Settings
+ tweak/src/ui/*.x the tweaks: NowPlayingBar, TabBar, Navbar, NowPlayingView, Lyrics, SearchField, Flags, Amoled, HomeGradient, 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
@@ -25,11 +25,11 @@ signed and installed from the Mac.
make flags # regenerate the flag table in tweak/src/SGFlagList.m from the IPA
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 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.
+field, Spotify's own glass, AMOLED), Home (a gradient background, 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 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
diff --git a/trees/screens.txt b/trees/screens.txt
index 1c406bd5..3cf4a6ba 100644
--- a/trees/screens.txt
+++ b/trees/screens.txt
@@ -4,6 +4,7 @@ home 2 more scrolled | Home tab
home 3 more scrolled | Home tab
home 4 more scrolled | Home tab
search | Search tab
+search opened | Search tab
library | Library tab
create | the + tab
now-playing | tap the now playing bar to open the full
diff --git a/tweak/control b/tweak/control
index 5810eb2b..2b39a841 100644
--- a/tweak/control
+++ b/tweak/control
@@ -1,6 +1,6 @@
Package: com.vojta.spotifyglass
Name: spotifyglass
-Version: 0.12.1
+Version: 0.13.0
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 6ab1fab8..a1f64d5b 100644
--- a/tweak/src/SGCommon.h
+++ b/tweak/src/SGCommon.h
@@ -55,6 +55,7 @@ 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
+extern __weak UIView *sg_npvBackdropRoot; // ui/NowPlayingView.x, the plane behind the player
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
@@ -68,6 +69,7 @@ void SGRememberCardColor(CGColorRef color);
extern NSString *const SGKeyNowPlayingBar;
extern NSString *const SGKeyTabBar;
extern NSString *const SGKeyPlayer;
+extern NSString *const SGKeyPlayerBackdrop; // off unless it is asked for
extern NSString *const SGKeyLyricsCard;
extern NSString *const SGKeySearchField;
extern NSString *const SGKeySpotifyGlass;
@@ -92,8 +94,11 @@ void SGSetNavbarLayout(NSArray<NSDictionary *> *layout);
NSArray<NSString *> *SGNavbarStock(void);
void SGSetNavbarStock(NSArray<NSString *> *stock);
-// ui/Navbar.x, called from the tab bar's layout pass in ui/TabBar.x.
+// ui/Navbar.x, called from the tab bar's layout passes in ui/TabBar.x.
void SGComposeTabBar(UIView *tabBar);
+void SGLogTabBarRow(UIView *tabBar);
+// Lays the bar out again after the Navbar page changes something, so it does not wait for a touch.
+void SGRefreshTabBar(void);
// Spotify's remote-config flags, generated into SGFlagList.m by scripts/extract-flags.py.
typedef NS_ENUM(NSInteger, SGFlagType) { SGFlagUnknown, SGFlagBool, SGFlagInt, SGFlagEnum };
diff --git a/tweak/src/SGCommon.m b/tweak/src/SGCommon.m
index a8d43224..9bf44068 100644
--- a/tweak/src/SGCommon.m
+++ b/tweak/src/SGCommon.m
@@ -6,6 +6,7 @@ __weak UIView *sg_nowPlayingCard = nil;
__weak UIView *sg_lyricsCardRoot = nil;
__weak UIView *sg_lyricsPageRoot = nil;
__weak UIView *sg_homeRoot = nil;
+__weak UIView *sg_npvBackdropRoot = nil;
BOOL sg_nowPlayingStock = NO;
CGColorRef sg_nowPlayingCardColor = NULL;
@@ -50,6 +51,7 @@ void SGRequireClasses(NSArray<NSString *> *names) {
NSString *const SGKeyNowPlayingBar = @"spotifyglass.nowPlayingBar";
NSString *const SGKeyTabBar = @"spotifyglass.tabBar";
NSString *const SGKeyPlayer = @"spotifyglass.player";
+NSString *const SGKeyPlayerBackdrop = @"spotifyglass.playerBackdrop";
NSString *const SGKeyLyricsCard = @"spotifyglass.lyricsCard";
NSString *const SGKeySearchField = @"spotifyglass.searchField";
NSString *const SGKeySpotifyGlass = @"spotifyglass.spotifyGlass";
@@ -215,6 +217,9 @@ static UIVisualEffect *glassEffect(void) {
static UIVisualEffectView *newPane(void) {
UIVisualEffectView *glass = [[UIVisualEffectView alloc] initWithEffect:glassEffect()];
glass.userInteractionEnabled = NO;
+ // A pane goes in at index 0, but a host that rebuilds its content puts that in at index 0 too
+ // and the pane would end up over it. Depth keeps a pane behind whatever the host draws.
+ glass.layer.zPosition = -1;
return glass;
}
diff --git a/tweak/src/ui/HomeGradient.x b/tweak/src/ui/HomeGradient.x
index e53631c8..f83e0a88 100644
--- a/tweak/src/ui/HomeGradient.x
+++ b/tweak/src/ui/HomeGradient.x
@@ -4,11 +4,12 @@
// 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.
+// Tree (trees/home.txt): FunkisViewController.view holds the page, a 402x112 wrapper around
+// LiquidGlass.GradientView (the scrim under the avatar and the pills) and HomeHeaderView. Four
+// views down, EvoLoadableResourceViewController.view holds the one
+// Home_CarouselKit.TouchCancellingCollectionView of the page, full screen and inset 112pt at the
+// top for the header, painted #121212; the shelves inside it are collection views of their own,
+// painted #121212 as well.
#import "SGCommon.h"
// Sampled off the design: #0B4110 at the top of the screen, level behind the header, gone by 390pt.
@@ -18,7 +19,7 @@ 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;
+static char kGradientKey, kStrippedKey;
// A view of its own, so the wash follows the page's layout passes instead of animating itself
// through CoreAnimation whenever the inset changes.
@@ -31,6 +32,20 @@ static char kGradientKey;
}
@end
+// The shelves and the shortcuts grid are lists of their own, each painting the base surface over
+// the wash. A cell paints itself before the page puts it in, where the hook in ui/Repaint.x cannot
+// see that it belongs to Home, so every cell is stripped once as it turns up; the repaints it
+// takes later, in the page by then, go through the hook. The page's own paint is behind the wash.
+static void stripCells(UIScrollView *list) {
+ for (UIView *cell in list.subviews) {
+ if (objc_getAssociatedObject(cell, &kStrippedKey)) continue;
+ objc_setAssociatedObject(cell, &kStrippedKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ SGForEachView(cell, ^(UIView *v) {
+ if (SGIsBaseSurface(v.layer.backgroundColor)) v.layer.backgroundColor = NULL;
+ });
+ }
+}
+
static SGHomeGradientView *gradientIn(UIScrollView *list) {
SGHomeGradientView *view = objc_getAssociatedObject(list, &kGradientKey);
if (!view) {
@@ -40,16 +55,12 @@ static SGHomeGradientView *gradientIn(UIScrollView *list) {
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];
+ // A list puts its cells in at index 0, so that its scroll indicators stay on top of them;
+ // the subview order alone would push the wash over the content. Depth settles it instead.
+ view.layer.zPosition = -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;
}
@@ -58,6 +69,8 @@ static SGHomeGradientView *gradientIn(UIScrollView *list) {
// where the top of the screen is when the list sits still.
static void layoutGradient(UIScrollView *list) {
SGHomeGradientView *view = gradientIn(list);
+ if (sg_homeRoot != list) sg_homeRoot = list;
+ stripCells(list);
CGRect frame = CGRectMake(0, -kOverscroll - list.adjustedContentInset.top,
list.bounds.size.width, kOverscroll + kFadeHeight);
if (!CGRectEqualToRect(view.frame, frame)) view.frame = frame;
@@ -88,16 +101,15 @@ static UIScrollView *pageList(UIView *view) {
}
%end
-// Everything beside the page in the host view is the header and its scrim, both of them shallow.
-%hook _TtC19Home_FunkisPageImpl29HomePageHostingViewController
+// The scrim is a gradient view one view under the page's own; the gradients of the cards sit far
+// deeper than that, so two levels cannot reach them.
+%hook _TtC19Home_FunkisPageImpl20FunkisViewController
- (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;
- });
+ for (UIView *wrapper in ((UIViewController *)self).viewIfLoaded.subviews) {
+ for (UIView *view in wrapper.subviews) {
+ if ([NSStringFromClass(view.class) containsString:@"GradientView"]) view.hidden = YES;
+ }
}
}
%end
@@ -108,6 +120,6 @@ static UIScrollView *pageList(UIView *view) {
SGRequireClasses(@[
@"_TtC16Home_EvoPageImpl33EvoLoadableResourceViewController",
@"_TtC16Home_CarouselKit29TouchCancellingCollectionView",
- @"_TtC19Home_FunkisPageImpl29HomePageHostingViewController",
+ @"_TtC19Home_FunkisPageImpl20FunkisViewController",
]);
}
diff --git a/tweak/src/ui/Navbar.x b/tweak/src/ui/Navbar.x
index 7b1dfc25..cfab01ae 100644
--- a/tweak/src/ui/Navbar.x
+++ b/tweak/src/ui/Navbar.x
@@ -1,11 +1,14 @@
// 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.
+// subviews of one stack view, but a tap on one of them is answered by counting the row off from
+// the left, not by asking the item what it is: moved in the stack, an item takes the tap of
+// whatever used to stand there. So the stack's own order is left exactly as Spotify built it.
//
-// 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.
+// The row is split into equal slots instead, and the wanted order is a translation per item:
+// hit testing goes by frame, so the touch follows the icon, while Spotify still counts its items
+// off in the order it put them in. Items of the mod's own go on the end of the stack, past that
+// count, and are translated into place with the rest. A tap on one goes through Spotify's link
+// dispatcher, the same route the app takes for a link it opens itself, so any URI works.
//
// Tree (trees/home.txt): NavigationUI_TabBarImpl.TabBarView > TabBarCompactView > UIStackView
// 402x49 of four ElementContentView<TabBarItemElement> 100x49, each an SPTEncoreIconView 24x24
@@ -29,7 +32,14 @@ static const CGFloat kLabelTop = 35;
static const CGFloat kLabelHeight = 14;
static char kCustomKey;
+// Where Spotify's own items keep their icon and label, read off one of them every pass. ui/TabBar.x
+// moves the icons when the glass bar is on, and this follows a pass later, so an item of the mod's
+// own sits on the same line as its neighbours either way.
+static CGRect sg_iconBox = {{0, kIconTop}, {kIconSize, kIconSize}};
+static CGRect sg_labelBox = {{0, kLabelTop}, {0, kLabelHeight}};
+
static __weak SGLinkDispatcher *sg_linkDispatcher;
+static __weak UIView *sg_navbarRoot;
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.
@@ -98,17 +108,22 @@ static UIView *iconView(NSString *name) {
[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.
+// Both boxes come off a neighbour, so whatever Spotify or ui/TabBar.x does to the row's line-up
+// is copied rather than guessed at; only the horizontal centring is the item's own.
- (void)layoutSubviews {
[super layoutSubviews];
- BOOL glass = SGEnabled(SGKeyTabBar);
- CGSize size = self.bounds.size;
- _title.hidden = glass;
+ CGFloat width = self.bounds.size.width;
+ _title.hidden = SGEnabled(SGKeyTabBar);
_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);
+ _title.frame = CGRectMake(0, CGRectGetMinY(sg_labelBox), width, CGRectGetHeight(sg_labelBox));
+ _icon.frame = CGRectMake((width - CGRectGetWidth(sg_iconBox)) / 2, CGRectGetMinY(sg_iconBox),
+ CGRectGetWidth(sg_iconBox), CGRectGetHeight(sg_iconBox));
+}
+
+// A row that splits its width evenly ignores this, but one that sizes itself to its content would
+// otherwise have nothing to go on for an item of ours.
+- (CGSize)intrinsicContentSize {
+ return CGSizeMake(kIconSize * 2, kLabelTop + kLabelHeight);
}
- (void)setHighlighted:(BOOL)highlighted {
@@ -140,11 +155,16 @@ static NSString *stockID(UIView *item) {
return text ?: NSStringFromClass(item.class);
}
-static void rememberFont(UIView *item) {
- if (sg_tabFont) return;
+static void measureItem(UIView *item) {
+ __block UIView *icon = nil, *label = nil;
SGForEachView(item, ^(UIView *v) {
- if (!sg_tabFont && [v isKindOfClass:UILabel.class] && ((UILabel *)v).text.length) sg_tabFont = ((UILabel *)v).font;
+ if (!icon && [NSStringFromClass(v.class) containsString:@"IconView"] && v.bounds.size.width > 1) icon = v;
+ if (!label && [v isKindOfClass:UILabel.class] && ((UILabel *)v).text.length) label = v;
});
+ if (icon) sg_iconBox = SGFrameIn(icon, item);
+ if (!label) return;
+ sg_labelBox = SGFrameIn(label, item);
+ if (!sg_tabFont) sg_tabFont = ((UILabel *)label).font;
}
static NSMutableDictionary<NSString *, SGTabItemView *> *customItems(UIStackView *stack) {
@@ -159,6 +179,7 @@ static NSMutableDictionary<NSString *, SGTabItemView *> *customItems(UIStackView
void SGComposeTabBar(UIView *tabBar) {
UIStackView *stack = SGRowIn(tabBar);
if (!stack) return;
+ sg_navbarRoot = tabBar;
NSMutableDictionary<NSString *, UIView *> *stockViews = [NSMutableDictionary dictionary];
for (UIView *item in stack.arrangedSubviews) {
@@ -166,7 +187,7 @@ void SGComposeTabBar(UIView *tabBar) {
NSString *ident = stockID(item);
if (stockViews[ident]) continue;
stockViews[ident] = item;
- rememberFont(item);
+ measureItem(item);
if (!sg_stockOrder) sg_stockOrder = [NSMutableArray array];
if (![sg_stockOrder containsObject:ident]) [sg_stockOrder addObject:ident];
}
@@ -215,13 +236,80 @@ void SGComposeTabBar(UIView *tabBar) {
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];
+ // Items of the mod's own join the stack at the end, where they are past whatever Spotify
+ // counts, and Spotify's own keep the places it gave them.
+ for (UIView *item in wanted) {
+ if ([item isKindOfClass:SGTabItemView.class] && item.superview != stack) [stack addArrangedSubview:item];
+ }
+ // Spotify sizes the row for the four items it ships; equal slots for whatever is on it now
+ // keeps a fifth from running off the right edge, and makes the order a whole slot's shift.
+ if (stack.distribution != UIStackViewDistributionFillEqually) stack.distribution = UIStackViewDistributionFillEqually;
+
+ NSMutableArray<UIView *> *slots = [NSMutableArray array];
+ for (UIView *item in stack.arrangedSubviews) if (!item.hidden) [slots addObject:item];
+ NSMutableArray<UIView *> *order = [NSMutableArray array];
+ for (UIView *item in wanted) if (!item.hidden && [slots containsObject:item]) [order addObject:item];
+ CGFloat slotWidth = slots.count ? stack.bounds.size.width / slots.count : 0;
+
+ for (UIView *item in stack.arrangedSubviews) {
+ NSUInteger from = [slots indexOfObject:item], to = [order indexOfObject:item];
+ CGAffineTransform shift = from == NSNotFound || to == NSNotFound
+ ? CGAffineTransformIdentity
+ : CGAffineTransformMakeTranslation(((CGFloat)to - (CGFloat)from) * slotWidth, 0);
+ if (!CGAffineTransformEqualToTransform(item.transform, shift)) item.transform = shift;
+ }
+}
+
+void SGRefreshTabBar(void) {
+ [sg_navbarRoot setNeedsLayout];
+}
+
+// What the row settled on, logged whenever it changes: `make log` then says whether the items fit,
+// what is holding their width, and in what order the bar ended up.
+void SGLogTabBarRow(UIView *tabBar) {
+ UIStackView *stack = SGRowIn(tabBar);
+ if (!stack) return;
+ NSMutableString *out = [NSMutableString stringWithFormat:@"row in %@ %@, icon %@ label %@, stack %@ axis %ld dist %ld align %ld spacing %.1f autolayout %d",
+ NSStringFromClass(tabBar.class), NSStringFromCGRect(tabBar.frame),
+ NSStringFromCGRect(sg_iconBox), NSStringFromCGRect(sg_labelBox), NSStringFromCGRect(stack.frame),
+ (long)stack.axis, (long)stack.distribution, (long)stack.alignment, stack.spacing,
+ !stack.translatesAutoresizingMaskIntoConstraints];
+ NSUInteger index = 0;
+ for (UIView *item in stack.arrangedSubviews) {
+ [out appendFormat:@"\n %lu %@ %@%@ shift %.1f autolayout %d", (unsigned long)index++, NSStringFromClass(item.class),
+ NSStringFromCGRect(item.frame), item.hidden ? @" hidden" : @"", item.transform.tx,
+ !item.translatesAutoresizingMaskIntoConstraints];
+ for (NSLayoutConstraint *c in item.constraints) {
+ if (c.firstAttribute == NSLayoutAttributeWidth || c.secondAttribute == NSLayoutAttributeWidth) [out appendFormat:@"\n %@", c];
+ }
+ }
+ for (NSLayoutConstraint *c in stack.constraints) [out appendFormat:@"\n own %@", c];
+ for (NSLayoutConstraint *c in stack.superview.constraints) {
+ if (c.firstItem == stack || c.secondItem == stack) [out appendFormat:@"\n held %@", c];
}
+ static NSString *last;
+ if ([out isEqualToString:last]) return;
+ last = [out copy];
+ SGLogLong(@"navbar", out);
}
+// Whether Spotify reads its own item list through this ObjC bridge decides whether the bar can be
+// composed at the model level, where the order, the taps and the widths would all follow by
+// themselves, instead of by moving views about. Silence in the log says it cannot.
+%hook _TtC28NavigationUI_TabBarItemsImpl29TabBarItemsNavigationListImpl
+- (NSArray *)items {
+ NSArray *items = %orig;
+ NSMutableString *out = [NSMutableString stringWithFormat:@"list read, %lu items", (unsigned long)items.count];
+ for (id item in items) [out appendFormat:@"\n %@ · %@", [item valueForKey:@"title"], [item valueForKey:@"viewURI"]];
+ static NSString *last;
+ if (![out isEqualToString:last]) {
+ last = [out copy];
+ SGLogLong(@"navbar", out);
+ }
+ return items;
+}
+%end
+
// The dispatcher is a singleton the app builds at startup; this is the last call of its setup.
%hook SPTLinkDispatcherImplementation
- (void)setMainUILoaded:(BOOL)loaded {
@@ -232,5 +320,10 @@ void SGComposeTabBar(UIView *tabBar) {
%ctor {
%init;
- SGRequireClasses(@[@"SPTLinkDispatcherImplementation", @"SPTEncoreIcon", @"SPTEncoreIconView"]);
+ SGRequireClasses(@[
+ @"SPTLinkDispatcherImplementation",
+ @"SPTEncoreIcon",
+ @"SPTEncoreIconView",
+ @"_TtC28NavigationUI_TabBarItemsImpl29TabBarItemsNavigationListImpl",
+ ]);
}
diff --git a/tweak/src/ui/NowPlayingView.x b/tweak/src/ui/NowPlayingView.x
index a8a65e39..808a51cd 100644
--- a/tweak/src/ui/NowPlayingView.x
+++ b/tweak/src/ui/NowPlayingView.x
@@ -1,4 +1,5 @@
-// Full screen player: glass where Liquid Glass belongs and nowhere else.
+// Full screen player: glass where Liquid Glass belongs and nowhere else, and the album colour
+// behind it traded for the cover art.
//
// 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
@@ -9,9 +10,29 @@
//
// 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.
+//
+// The background is one plane the size of the screen painted the album colour, Spotify's gradients
+// on top of it, and it is NPVBackgroundViewController's own view. Glass over a flat fill samples
+// that same flat fill back, which is why the header panes cannot be made out on it; white text and
+// Spotify's green both sit badly on saturated colour as well. SGKeyPlayerBackdrop strips the plane
+// and puts the cover behind the player instead, shrunk until none of the picture is left in it,
+// blurred, under a scrim ending near black so the cards scrolled up from below meet it. The switch
+// covers what that field changes around it too: the artwork takes corners and a shadow so it sits
+// on the field rather than being pasted onto it, the lyric under it drops behind the title in
+// contrast, and the timestamps take monospaced digits so they stop twitching every second.
#import "SGCommon.h"
static const CGFloat kButtonMin = 36, kButtonMax = 48;
+static const CGFloat kArtRadius = 12;
+// Small enough that no shape of the cover survives the scaling back up, large enough to keep the
+// colours where they were in it.
+static const CGFloat kCoverSample = 48;
+
+static BOOL backdropOn(void) {
+ return SGFlag(SGKeyPlayerBackdrop, NO);
+}
+
+#pragma mark - glass behind the header buttons
// 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
@@ -42,7 +63,189 @@ static void glassBehindRoundButtons(UIViewController *unit) {
}
%end
+#pragma mark - the cover behind the player
+
+@interface SGScrimView : UIView
+@end
+
+@implementation SGScrimView
++ (Class)layerClass {
+ return CAGradientLayer.class;
+}
+@end
+
+static char kBackdropKey;
+
+static UIImage *sg_cover; // the cover the backdrop stands on, compared by pointer
+static UIImage *sg_coverSmall;
+static __weak UIImageView *sg_coverView;
+
+static UIImage *shrunk(UIImage *cover) {
+ UIGraphicsImageRendererFormat *format = [UIGraphicsImageRendererFormat preferredFormat];
+ format.scale = 1;
+ format.opaque = YES;
+ CGRect square = CGRectMake(0, 0, kCoverSample, kCoverSample);
+ UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:square.size format:format];
+ return [renderer imageWithActions:^(UIGraphicsImageRendererContext *context) {
+ [cover drawInRect:square];
+ }];
+}
+
+static void showCover(UIImage *cover) {
+ if (!cover || cover == sg_cover) return;
+ sg_cover = cover;
+ sg_coverSmall = shrunk(cover);
+ UIImageView *view = sg_coverView;
+ if (!view) return;
+ [UIView transitionWithView:view duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
+ view.image = sg_coverSmall;
+ } completion:nil];
+}
+
+// The covers are the cells of a list scrolled sideways, one per track in the queue; the cell under
+// the middle of the list is the one playing.
+static UIImage *coverInFront(UIScrollView *list) {
+ CGFloat middle = list.contentOffset.x + list.bounds.size.width / 2;
+ __block UIImage *cover = nil;
+ // The cover is 354pt across, the glyph standing in for a missing one 64pt.
+ __block CGFloat widest = 200;
+ for (UIView *cell in list.subviews) {
+ if (middle < CGRectGetMinX(cell.frame) || middle > CGRectGetMaxX(cell.frame)) continue;
+ SGForEachView(cell, ^(UIView *view) {
+ UIImageView *image = (UIImageView *)view;
+ if (![view isKindOfClass:UIImageView.class] || !image.image || image.bounds.size.width <= widest) return;
+ widest = image.bounds.size.width;
+ cover = image.image;
+ });
+ }
+ return cover;
+}
+
+static UIView *backdropIn(UIView *plane) {
+ UIView *backdrop = objc_getAssociatedObject(plane, &kBackdropKey);
+ if (backdrop) return backdrop;
+
+ UIViewAutoresizing fill = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ backdrop = [[UIView alloc] initWithFrame:plane.bounds];
+ backdrop.userInteractionEnabled = NO;
+ backdrop.clipsToBounds = YES;
+ backdrop.autoresizingMask = fill;
+
+ UIImageView *cover = [[UIImageView alloc] initWithFrame:backdrop.bounds];
+ cover.contentMode = UIViewContentModeScaleAspectFill;
+ cover.autoresizingMask = fill;
+ cover.image = sg_coverSmall;
+ [backdrop addSubview:cover];
+ sg_coverView = cover;
+
+ // The scaled up cover comes back with the seams of its 48 pixels in it; the blur takes those
+ // out and is the same material as everything else the mod puts on this screen.
+ UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemUltraThinMaterialDark]];
+ blur.frame = backdrop.bounds;
+ blur.autoresizingMask = fill;
+ [backdrop addSubview:blur];
+
+ SGScrimView *scrim = [[SGScrimView alloc] initWithFrame:backdrop.bounds];
+ scrim.autoresizingMask = fill;
+ CAGradientLayer *fade = (CAGradientLayer *)scrim.layer;
+ fade.colors = @[
+ (id)[UIColor colorWithWhite:0 alpha:0.40].CGColor,
+ (id)[UIColor colorWithWhite:0 alpha:0.60].CGColor,
+ (id)[UIColor colorWithWhite:0 alpha:SGEnabled(SGKeyAmoled) ? 1 : 0.94].CGColor,
+ ];
+ fade.locations = @[@0, @0.5, @1];
+ [backdrop addSubview:scrim];
+
+ objc_setAssociatedObject(plane, &kBackdropKey, backdrop, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ return backdrop;
+}
+
+%hook _TtC21NowPlaying_ScrollImpl27NPVBackgroundViewController
+- (void)viewDidLayoutSubviews {
+ %orig;
+ if (!backdropOn()) return;
+ UIView *plane = ((UIViewController *)self).viewIfLoaded;
+ if (!plane || plane.bounds.size.height < 200) return;
+ sg_npvBackdropRoot = plane;
+ UIView *backdrop = backdropIn(plane);
+ for (UIView *sub in plane.subviews) {
+ if (sub != backdrop) SGStripBackgrounds(sub);
+ }
+ plane.layer.backgroundColor = NULL;
+ if (backdrop.superview != plane) [plane insertSubview:backdrop atIndex:0];
+}
+%end
+
+%hook _TtC35NowPlaying_ContentLayerPlatformImpl24AccessibleCollectionView
+- (void)layoutSubviews {
+ %orig;
+ if (backdropOn()) showCover(coverInFront((UIScrollView *)self));
+}
+%end
+
+#pragma mark - what the cover behind it changes around the player
+
+%hook _TtC35CreativeWorkCommons_CoverArtTiltKit16CoverArtTiltView
+- (void)layoutSubviews {
+ %orig;
+ if (!backdropOn()) return;
+ UIView *tilt = (UIView *)self;
+ CGSize size = tilt.bounds.size;
+ // The player's cover only; the bar downstairs carries a 40pt one of its own.
+ if (size.width < 200) return;
+ SGForEachView(tilt, ^(UIView *view) {
+ if (view == tilt || !CGSizeEqualToSize(view.bounds.size, size)) return;
+ view.layer.cornerRadius = kArtRadius;
+ view.layer.cornerCurve = kCACornerCurveContinuous;
+ view.clipsToBounds = YES;
+ });
+ tilt.layer.shadowColor = UIColor.blackColor.CGColor;
+ tilt.layer.shadowOpacity = 0.45;
+ tilt.layer.shadowRadius = 32;
+ tilt.layer.shadowOffset = CGSizeMake(0, 12);
+ tilt.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:tilt.bounds cornerRadius:kArtRadius].CGPath;
+}
+%end
+
+%hook _TtC22Lyrics_NPVContainerKit19LyricsContainerView
+- (void)layoutSubviews {
+ %orig;
+ // White at full strength, and alone in the space under the artwork, the line reads louder than
+ // the title it sits above. ui/Declutter.x hides the same view outright.
+ if (backdropOn()) ((UIView *)self).alpha = 0.72;
+}
+%end
+
+static UIFont *timeFont(void) {
+ static UIFont *font;
+ static dispatch_once_t once;
+ dispatch_once(&once, ^{
+ font = [UIFont monospacedDigitSystemFontOfSize:11 weight:UIFontWeightRegular];
+ });
+ return font;
+}
+
+%hook _TtC20NowPlaying_ModesImpl19DurationElementUnit
+- (void)viewDidLayoutSubviews {
+ %orig;
+ UIView *host = backdropOn() ? ((UIViewController *)self).viewIfLoaded : nil;
+ if (!host) return;
+ SGForEachView(host, ^(UIView *view) {
+ UILabel *label = (UILabel *)view;
+ if (![view isKindOfClass:UILabel.class] || label.font.pointSize > 11 || label.font == timeFont()) return;
+ label.font = timeFont();
+ });
+}
+%end
+
%ctor {
%init;
- SGRequireClasses(@[@"_TtC20NowPlaying_ModesImpl18HeaderElementsUnit"]);
+ SGRequireClasses(@[
+ @"_TtC20NowPlaying_ModesImpl18HeaderElementsUnit",
+ @"_TtC21NowPlaying_ScrollImpl27NPVBackgroundViewController",
+ @"_TtC35NowPlaying_ContentLayerPlatformImpl24AccessibleCollectionView",
+ @"_TtC35CreativeWorkCommons_CoverArtTiltKit16CoverArtTiltView",
+ @"_TtC22Lyrics_NPVContainerKit19LyricsContainerView",
+ @"_TtC20NowPlaying_ModesImpl19DurationElementUnit",
+ ]);
}
diff --git a/tweak/src/ui/Repaint.x b/tweak/src/ui/Repaint.x
index 944a0a14..590e6d04 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 || sg_lyricsCardRoot || sg_lyricsPageRoot || sg_homeRoot)) {
+ if (color && (sg_nowPlayingRoot || sg_tabBarRoot || sg_lyricsCardRoot || sg_lyricsPageRoot || sg_homeRoot || sg_npvBackdropRoot)) {
UIView *view = (UIView *)self.delegate;
if ([view isKindOfClass:UIView.class] && view.layer == self && !SGKeepsColor(view)) {
if (SGIsInside(view, sg_nowPlayingRoot)) {
@@ -19,6 +19,9 @@
} else if (SGIsInside(view, sg_tabBarRoot) || SGIsInside(view, sg_lyricsCardRoot)
|| SGIsInside(view, sg_lyricsPageRoot)) {
color = NULL;
+ } else if (SGIsInside(view, sg_npvBackdropRoot)) {
+ // The album colour arrives on the plane per track, outside any layout pass.
+ color = NULL;
} 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.
diff --git a/tweak/src/ui/SearchField.x b/tweak/src/ui/SearchField.x
index 49c03251..0b9cf744 100644
--- a/tweak/src/ui/SearchField.x
+++ b/tweak/src/ui/SearchField.x
@@ -1,19 +1,66 @@
// Search page: the white search field becomes a glass capsule with white text.
//
-// Tree (trees/search.txt): a 370x48 Encore tertiary button, bg white, r=6, holding an
-// SPTEncoreIconView and the placeholder label. The class is shared app-wide, so only a wide, light
-// instance is touched.
+// Tree (trees/search.txt): SearchHeaderFind.SearchBar, a 370x48 Encore tertiary button painted
+// white, r=6, holding SearchHeaderFind.SearchBarIcon and the placeholder label. The button class is
+// shared app-wide, so the identifier names the one instance the page owns, with a wide light button
+// as the fallback for a build that stops setting it.
+//
+// Two things about the colours. The glyph is an SPTEncoreIconView, which bakes its colour into what
+// it draws, so tintColor never reaches it and setForegroundColor: is the way in. And coming back
+// from the full screen search (trees/search opened.txt, a page of its own that this leaves alone)
+// Spotify configures the field for a white background again, black glyph and black text, after the
+// layout pass that styled it: both are then invisible on the glass until the next pass, a second or
+// so later. So the two setters are refused for as long as the field is a capsule.
#import "SGCommon.h"
+// Spotify's glyph view, resolved at runtime; declared on UIView so the call and the hook below
+// share one declaration.
+@interface UIView (SGEncoreIcon)
+- (void)setForegroundColor:(UIColor *)color;
+@end
+
static char kStyledKey;
+static __weak UIView *sg_searchField;
+
+static BOOL isSearchField(UIView *button) {
+ if ([button.accessibilityIdentifier isEqualToString:@"SearchHeaderFind.SearchBar"]) return YES;
+ return SGIsLightColor(button.layer.backgroundColor);
+}
+
+static void whiten(UIView *view) {
+ if ([view isKindOfClass:UILabel.class]) {
+ ((UILabel *)view).textColor = UIColor.whiteColor;
+ } else if ([NSStringFromClass(view.class) containsString:@"IconView"]) {
+ if ([view respondsToSelector:@selector(setForegroundColor:)]) [view setForegroundColor:UIColor.whiteColor];
+ else view.tintColor = UIColor.whiteColor;
+ }
+}
+
+// Debug builds only. The second the field stays invisible after the full screen search closes is
+// too short to catch in a tree, so every pass over the field says what it looked like, and the
+// silence before the first line says the field did not exist yet.
+static void traceField(UIView *button, NSString *when) {
+ if (!SGIsDebugBuild()) return;
+ UIView *pane = nil, *dim = nil;
+ for (UIView *sub in button.subviews) {
+ if ([sub isKindOfClass:UIVisualEffectView.class]) pane = sub;
+ }
+ for (UIView *v = button; v && !dim; v = v.superview) {
+ if (v.hidden || v.alpha < 0.99) dim = v;
+ }
+ SGLog(@"search field %@: window %d, %@, pane %@, hidden by %@", when, button.window != nil,
+ NSStringFromCGSize(button.bounds.size), pane ? @"attached" : @"missing",
+ dim ? NSStringFromClass(dim.class) : @"nothing");
+}
static void styleSearchField(UIView *button) {
if (!SGEnabled(SGKeySearchField)) return;
CGSize size = button.bounds.size;
if (size.width < 200 || size.height < 40 || size.height > 60) return;
BOOL styled = [objc_getAssociatedObject(button, &kStyledKey) boolValue];
- if (!styled && !SGIsLightColor(button.layer.backgroundColor)) return;
+ if (!styled && !isSearchField(button)) return;
objc_setAssociatedObject(button, &kStyledKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ if (sg_searchField != button) sg_searchField = button;
button.layer.backgroundColor = NULL;
button.layer.cornerRadius = size.height / 2;
@@ -23,10 +70,8 @@ static void styleSearchField(UIView *button) {
glass.frame = button.bounds;
SGShapeGlass(glass, size.height / 2, YES);
- SGForEachView(button, ^(UIView *v) {
- if ([v isKindOfClass:UILabel.class]) ((UILabel *)v).textColor = UIColor.whiteColor;
- else if ([NSStringFromClass(v.class) containsString:@"IconView"]) v.tintColor = UIColor.whiteColor;
- });
+ SGForEachView(button, ^(UIView *v) { whiten(v); });
+ traceField(button, @"styled");
}
%hook _TtCCE16Encore_ButtonKitO16EncoreFoundation6Encore6Button8Tertiary
@@ -34,9 +79,33 @@ static void styleSearchField(UIView *button) {
%orig;
styleSearchField((UIView *)self);
}
+// Back from the full screen search the field is styled before it draws, not a layout pass later.
+- (void)didMoveToWindow {
+ %orig;
+ if (isSearchField((UIView *)self)) traceField((UIView *)self, @"moved");
+ styleSearchField((UIView *)self);
+}
+// Spotify builds the field's content again when the page comes back, which can take the pane out
+// with it; waiting for the next layout pass to put it back would leave the capsule blank.
+- (void)didAddSubview:(UIView *)subview {
+ %orig;
+ if (![subview isKindOfClass:UIVisualEffectView.class]) styleSearchField((UIView *)self);
+}
+%end
+
+%hook UILabel
+- (void)setTextColor:(UIColor *)color {
+ %orig(SGIsInside((UIView *)self, sg_searchField) ? UIColor.whiteColor : color);
+}
+%end
+
+%hook SPTEncoreIconView
+- (void)setForegroundColor:(UIColor *)color {
+ %orig(SGIsInside((UIView *)self, sg_searchField) ? UIColor.whiteColor : color);
+}
%end
%ctor {
%init;
- SGRequireClasses(@[@"_TtCCE16Encore_ButtonKitO16EncoreFoundation6Encore6Button8Tertiary"]);
+ SGRequireClasses(@[@"_TtCCE16Encore_ButtonKitO16EncoreFoundation6Encore6Button8Tertiary", @"SPTEncoreIconView"]);
}
diff --git a/tweak/src/ui/Settings.x b/tweak/src/ui/Settings.x
index 24ca13e6..df639744 100644
--- a/tweak/src/ui/Settings.x
+++ b/tweak/src/ui/Settings.x
@@ -84,6 +84,30 @@ static UIColor *pageBackground(void) { return [UIColor colorWithWhite:0x12 / 255
#pragma mark - pages
+// Spotify's navigation controller asserts that everything on its stack is one of its own pages
+// (SPNavigationController.m:645, "[viewController conformsToProtocol:@protocol(SPTPageController)]"),
+// and the tab bar asks it for that page on every tab tap to log the interaction. A plain view
+// controller of the mod's pushed onto that stack therefore takes the app down the next time a tab
+// is pressed, from wherever it was left. The pages below answer the protocol's two questions
+// instead and are registered as conforming at load; if the protocol is gone they are presented
+// rather than pushed, so a rename in some later Spotify costs the push, not the app.
+static BOOL sg_pagesConform;
+
+@interface SGPage : UITableViewController
+@end
+
+@implementation SGPage
+
+- (NSString *)spt_pageIdentifier {
+ return @"spotifyglass";
+}
+
+- (NSURL *)spt_pageURI {
+ return [NSURL URLWithString:@"spotify:internal:spotifyglass"];
+}
+
+@end
+
// A row is a switch when it has a key and a link to another page when it has a page. A flag row
// switches one of Spotify's remote-config flags: on forces it, off leaves Spotify's value.
@interface SGModRow : NSObject
@@ -191,7 +215,7 @@ static UITableViewCell *dequeue(UITableView *table, NSString *identifier) {
?: [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
-@interface SGModPage : UITableViewController
+@interface SGModPage : SGPage
- (instancetype)initWithTitle:(NSString *)title intro:(NSString *)intro sections:(NSArray<SGModSection *> *)sections footer:(NSString *)footer;
@end
@@ -302,7 +326,7 @@ static NSString *flagState(const SGFlagDef *flag, id value) {
// Every flag in SGFlagTable, filtered by the search words; forced flags first while the search
// is empty. Bool flags get an Auto / Off / On control, the others a text field in an alert.
-@interface SGFlagsPage : UITableViewController <UISearchBarDelegate>
+@interface SGFlagsPage : SGPage <UISearchBarDelegate>
@end
@implementation SGFlagsPage {
@@ -498,9 +522,10 @@ static void appendTab(NSDictionary *tab) {
NSMutableDictionary *entry = [tab mutableCopy];
entry[SGNavbarID] = NSUUID.UUID.UUIDString;
SGSetNavbarLayout([navbarEntries() arrayByAddingObject:entry]);
+ SGRefreshTabBar();
}
-@interface SGTabPickerPage : UITableViewController
+@interface SGTabPickerPage : SGPage
@end
@implementation SGTabPickerPage {
@@ -602,7 +627,7 @@ static void appendTab(NSDictionary *tab) {
// 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
+@interface SGNavbarPage : SGPage
@end
@implementation SGNavbarPage {
@@ -654,6 +679,7 @@ static void appendTab(NSDictionary *tab) {
- (void)save {
SGSetNavbarLayout(_entries);
+ SGRefreshTabBar();
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {
@@ -756,6 +782,7 @@ static void appendTab(NSDictionary *tab) {
- (void)toggled:(UISwitch *)toggle {
SGSetEnabled(SGKeyNavbar, toggle.on);
+ SGRefreshTabBar();
}
- (void)reset {
@@ -765,6 +792,7 @@ static void appendTab(NSDictionary *tab) {
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
[alert addAction:[UIAlertAction actionWithTitle:@"Reset" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
SGSetNavbarLayout(@[]);
+ SGRefreshTabBar();
self->_entries = navbarEntries();
[self.tableView reloadData];
}]];
@@ -807,6 +835,7 @@ 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),
+ optionRow(@"Artwork background", @"The cover blurred and dimmed behind the player instead of the flat album colour", SGKeyPlayerBackdrop),
switchRow(@"Header buttons", @"Glass circles behind close and more, over the artwork", SGKeyPlayer),
switchRow(@"Lyrics", @"Glass card, and the page it expands into", SGKeyLyricsCard),
]),
@@ -912,7 +941,7 @@ static UIViewController *modSettingsPage(void) {
if ([r isKindOfClass:UIViewController.class]) owner = (UIViewController *)r;
}
UIViewController *page = modSettingsPage();
- if (owner.navigationController) [owner.navigationController pushViewController:page animated:YES];
+ if (owner.navigationController && sg_pagesConform) [owner.navigationController pushViewController:page animated:YES];
else [owner presentViewController:[[UINavigationController alloc] initWithRootViewController:page] animated:YES completion:nil];
}
@@ -975,4 +1004,8 @@ static void placeRow(UICollectionView *list, SGModSettingsRow *row) {
%ctor {
%init;
SGRequireClasses(@[@"_TtC21Settings_PlatformImpl26SettingsListViewController"]);
+ // Swift's own name for the protocol, which is what the runtime registers it under.
+ Protocol *page = objc_getProtocol("_TtP19Tome_PageAttributes17SPTPageController_") ?: objc_getProtocol("SPTPageController");
+ sg_pagesConform = page && class_addProtocol(SGPage.class, page);
+ if (!sg_pagesConform) SGLog(@"SPTPageController not found, the mod's pages are presented instead of pushed");
}
diff --git a/tweak/src/ui/TabBar.x b/tweak/src/ui/TabBar.x
index 9defe16f..d2cdb448 100644
--- a/tweak/src/ui/TabBar.x
+++ b/tweak/src/ui/TabBar.x
@@ -11,14 +11,16 @@ 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.
+// The items the bar shows, left to right. ui/Navbar.x leaves the stack in Spotify's order and
+// shifts the items across it, so the row reads by position on screen, not by arranged order.
static NSArray<UIView *> *tabItems(UIView *tabBar) {
NSMutableArray<UIView *> *items = [NSMutableArray array];
for (UIView *item in SGRowIn(tabBar).arrangedSubviews) {
if (!item.hidden && item.bounds.size.width >= 20) [items addObject:item];
}
- return items;
+ return [items sortedArrayUsingComparator:^NSComparisonResult(UIView *a, UIView *b) {
+ return [@(SGFrameIn(a, tabBar).origin.x) compare:@(SGFrameIn(b, tabBar).origin.x)];
+ }];
}
static void styleTabBar(UIView *tabBar) {
@@ -56,6 +58,12 @@ static void styleTabBar(UIView *tabBar) {
}
}
+static UIView *tabBarOf(UIView *item) {
+ Class barClass = NSClassFromString(@"_TtC23NavigationUI_TabBarImpl10TabBarView");
+ for (UIView *v = item.superview; v; v = v.superview) if ([v isKindOfClass:barClass]) return v;
+ return nil;
+}
+
// Items lay out their own icon and label, after the bar; hide the label, centre the icon, then
// restyle the bar, whose own pass ran before the items had frames.
static void styleTabItem(UIView *item) {
@@ -69,10 +77,8 @@ static void styleTabItem(UIView *item) {
v.center = CGPointMake(v.center.x, target.y);
}
});
- Class barClass = NSClassFromString(@"_TtC23NavigationUI_TabBarImpl10TabBarView");
- for (UIView *v = item.superview; v; v = v.superview) {
- if ([v isKindOfClass:barClass]) { styleTabBar(v); return; }
- }
+ UIView *bar = tabBarOf(item);
+ if (bar) styleTabBar(bar);
}
%hook _TtC23NavigationUI_TabBarImpl10TabBarView
@@ -83,20 +89,31 @@ static void styleTabItem(UIView *item) {
SGComposeTabBar((UIView *)self);
for (UIView *sub in ((UIView *)self).subviews) [sub layoutIfNeeded];
styleTabBar((UIView *)self);
+ SGLogTabBarRow((UIView *)self);
}
%end
+// The bar's own pass runs once, before Spotify has filled the row, and does not run again until
+// something touches it; the items lay out as they arrive, which is when the order is ours to set.
+static void itemDidLayOut(UIView *item) {
+ UIView *bar = tabBarOf(item);
+ if (!bar) return;
+ SGComposeTabBar(bar);
+ styleTabItem(item);
+ SGLogTabBarRow(bar);
+}
+
%hook _TtC23NavigationUI_TabBarImpl21TabBarItemElementView
- (void)layoutSubviews {
%orig;
- styleTabItem((UIView *)self);
+ itemDidLayOut((UIView *)self);
}
%end
%hook _TtC25CreateMenu_TabBarItemImpl24CreateMenuTabBarItemView
- (void)layoutSubviews {
%orig;
- styleTabItem((UIView *)self);
+ itemDidLayOut((UIView *)self);
}
%end