Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: the Tab bar page previews the bar and edits your added tabs
My-Name-Is-Jeff59b045d014c8
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 53598129..ff70ead5 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -296,7 +296,7 @@ Redesigned:bars the pages fade to half black (SGRBarFade, the stock bar's own subview). A page scrolled downminimizes the bar to two circles, the first or current tab and the last, with the now playing cardbetween them, and a scroll back up, its top, another tab or the player brings it back- (TabBarMinimize.x, MinimizeStep.h; the Navbar page's Minimize on scroll). Spotify's container is no+ (TabBarMinimize.x, MinimizeStep.h; the Player page's Apple Music style). Spotify's container is noUITabBarController, so UIKit's tabBarMinimizeBehavior and bottomAccessory cannot do it. Laid out onthe Mac against harness/tabbar/ (`mini`), the scroll's steps checked by harness/tabbar/minimize-check.cNowPlayingBar/ the glass now playing bar (NowPlayingBar.x), with Spotify's device button on it hidden on request@@ -509,7 +509,7 @@ only when their feature first needs them, so 15 s after launch the log says howit has asked for and which not yet (`flags: N overrides stored, …`), and an override asked for latergets its own line as it is asked (`flags: Spotify asked for <flag> only now, …`).-The tab editor on the Navbar page is the exception and applies as soon as the bar lays out again. It lists the tabs in the order+The tab editor on the Tab bar page is the exception and applies as soon as the bar lays out again. It lists the tabs in the orderthe bar shows them: drag to reorder, tap to hide or show, and Add a tab puts a page of Spotify's orany `spotify:` link on the bar. It is a sheet: a name, a link picked from Spotify's pages or pasted (oneSpotify's router cannot open is refused there), and an icon picked from Encore's glyphs or the SF Symbols,@@ -517,8 +517,15 @@ searchable. Split tabs sets chosen tabs apart at the right end of the bar: afteron a glass bar of their own in the redesign, like Search in the Music app. Spotify's own tabs are kept by thename under their icon, so they can be hidden but never removed, and switching the app's languagestarts 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. Hide labels, on the same page, leaves the glass bar with its-icons alone and applies straight away too.+never lights up as the tab you are on. In the redesign (Redesigned/Navbar/NavbarSettings.m) the page leads+with a preview of the glass bar, drawn by the same system UITabBar as the bar itself from the list as it+stands, the split tabs on a bar of their own, and changing with every change on the page; then Custom tab+bar (off, the bar is Spotify's own tabs in Spotify's order, the list kept); two picture cards for the labels,+Icons and names or Icons only (the glass bar's names hidden, applying straight away); the tabs, each with a+check circle that shows or hides it, its glyph (TabBar.x draws Spotify's own off their items on the bar) and+the drag handle, a tap on a tab of the mod's own opening the Add a Tab sheet as Edit Tab, with Save and Remove+Tab; Add a tab and Use Spotify's tabs; and Split tabs. Spotify's own tabs keep their names and icons. Checked+in the simulator against harness/addtab/ (`navbar`, `icons`, `off`, `hide`, `edit`, `remove`, `links`).## Adding a featurediff --git a/harness/addtab/README.md b/harness/addtab/README.mdindex 758567b7..b8beb6dd 100644--- a/harness/addtab/README.md+++ b/harness/addtab/README.md@@ -18,5 +18,18 @@ icon; `glyphs` Choose an Icon on Encore; `symbols` Choose an Icon searching SF SLiked Songs with the SF Symbol music.mic added, the tab logged. The glyphs the enumeration kept and howlong the SF Symbol list took to read are logged on every launch.-What it does not cover: Spotify's real Encore classes and router, a real finger (the steps call the+The redesign's Tab bar page (`Redesigned/Navbar/NavbarSettings.m`, with `NavbarLayout.m`) runs here too, over a+sample bar: Spotify's four tabs, Liked Songs added after Search, Create hidden and Search split apart. `stubs.m`+draws Spotify's own tabs' glyphs as SF Symbols where TabBar.x reads them off the bar. Launch words: `navbar` the+page; `icons` Icons only picked on its card; `links` the page scrolled to its end; `off` Custom tab bar switched+off; `hide` Home's circle tapped; `edit` Liked Songs tapped, which opens Edit Tab; `remove` Remove Tab on that+sheet, confirmed. Each step logs what the preview shows and what each tab row reads.++2026-10-06, iPhone 17 Pro on iOS 27.0: the preview shows Home, Liked Songs and Your Library on the main bar and+Search on a bar of its own; Icons only stores the key and drops the names; Custom tab bar off shows Spotify's four+tabs in Spotify's order; Home's circle hides it on the list and the preview; Remove Tab asks, then takes Liked+Songs off the list, the preview and the stored layout.++What it does not cover: Spotify's real Encore classes and router, the glyphs TabBar.x reads off Spotify's bar,+a drag on the list, a real finger (the steps call thetable's delegate and set the search text), the keyboard over the compact detent, and iPad.diff --git a/harness/addtab/build.sh b/harness/addtab/build.shindex 31e47b5c..d201422b 100755--- a/harness/addtab/build.sh+++ b/harness/addtab/build.sh@@ -11,6 +11,7 @@ xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-ar-I"$SRC" -I"$SRC/Shared/Navigation" -isysroot "$SDK" -Wno-deprecated-declarations \"$(dirname "$0")/main.m" "$(dirname "$0")/stubs.m" "$OUT/gen/Links.m" \"$SRC"/Shared/Navigation/AddTabSheet.m "$SRC"/Shared/Navigation/TabIcons.m \+ "$SRC"/Redesigned/Navbar/NavbarSettings.m "$SRC"/Redesigned/Navbar/NavbarLayout.m \"$SRC"/Settings/SGPage.m "$SRC"/Settings/SGPageStyle.m \"$SRC"/Core/SGLog.m "$SRC"/Core/SGPrefs.m "$SRC"/Core/SGViewTree.m "$SRC"/Core/SGGlass.m \"$SRC"/Core/SGBackdrop.m "$SRC"/Core/SGFlagForce.m "$SRC"/Core/SGUIMode.m \diff --git a/harness/addtab/main.m b/harness/addtab/main.mindex b418aa6f..991e925f 100644--- a/harness/addtab/main.m+++ b/harness/addtab/main.m@@ -5,6 +5,7 @@#import <objc/message.h>#import "Shared/Navigation/AddTabSheet.h"#import "Shared/Navigation/TabIcons.h"+#import "Redesigned/Navbar/Navbar.h"#pragma mark - Spotify's classes, by the names TabIcons.m looks for@@ -76,6 +77,82 @@ static void tap(UITableViewController *page, NSInteger section, NSInteger row) {[page.tableView.delegate tableView:page.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section]];}+// The redesign's Tab bar page (Redesigned/Navbar/NavbarSettings.m) over a sample bar: Spotify's four tabs,+// Liked Songs added after Search, Create hidden and Search split apart. `navbar` the page; `icons` Icons only+// picked on its card; `links` scrolled to its end; `off` Custom tab bar switched off; `hide` Home's circle tapped; `edit` Liked Songs+// tapped, which opens its sheet; `remove` Remove Tab on that sheet. Each step logs the preview and the list.+static void runNavbar(UIViewController *root, NSString *mode) {+ NSUserDefaults *store = NSUserDefaults.standardUserDefaults;+ [store setBool:NO forKey:SGRKeyNavbarHideLabels];+ [store removeObjectForKey:SGRKeyNavbar];+ SGRSetNavbarStock(@[@"Home", @"Search", @"Your Library", @"Create"]);+ SGRSetNavbarLayout(@[+ @{SGRNavbarID: @"Home", SGRNavbarTitle: @"Home"},+ @{SGRNavbarID: @"Search", SGRNavbarTitle: @"Search"},+ @{SGRNavbarID: @"liked", SGRNavbarTitle: @"Liked Songs", SGRNavbarURI: @"spotify:collection:tracks", SGRNavbarIcon: @"heart"},+ @{SGRNavbarID: @"Your Library", SGRNavbarTitle: @"Your Library"},+ @{SGRNavbarID: @"Create", SGRNavbarTitle: @"Create", SGRNavbarHidden: @YES},+ ]);+ SGRSetNavbarSplit(@[@"Search"]);+ UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:SGRNavbarSettingsPage()];+ nav.modalPresentationStyle = UIModalPresentationFullScreen;+ nav.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ [root presentViewController:nav animated:NO completion:nil];+ UITableViewController *page = (UITableViewController *)nav.topViewController;+ void (^log)(NSString *) = ^(NSString *step) {+ UIView *preview = page.tableView.tableHeaderView.subviews.firstObject;+ NSMutableArray<NSString *> *rows = [NSMutableArray array];+ for (NSInteger row = 0; row < [page.tableView numberOfRowsInSection:2]; row++) {+ UITableViewCell *cell = [page.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:2]];+ [rows addObject:[NSString stringWithFormat:@"%@ (%@)", [(UIListContentConfiguration *)cell.contentConfiguration text], cell.accessibilityValue]];+ }+ NSLog(@"[harness] %@: preview \"%@\", tabs %@, labels hidden %d, custom %d", step, preview.accessibilityValue,+ [rows componentsJoinedByString:@", "], [store boolForKey:SGRKeyNavbarHideLabels], [store objectForKey:SGRKeyNavbar] ? [store boolForKey:SGRKeyNavbar] : 1);+ };+ after(1.0, ^{ log(@"opened"); });+ if ([mode isEqualToString:@"icons"]) {+ after(1.5, ^{+ UIView *labels = [page.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]].contentView.subviews.firstObject;+ UIControl *iconsOnly = ((UIStackView *)labels).arrangedSubviews.lastObject;+ [iconsOnly sendActionsForControlEvents:UIControlEventTouchUpInside];+ log(@"icons only");+ });+ } else if ([mode isEqualToString:@"links"]) {+ after(1.5, ^{+ UITableView *table = page.tableView;+ [table setContentOffset:CGPointMake(0, table.contentSize.height - table.bounds.size.height + table.adjustedContentInset.bottom) animated:NO];+ });+ } else if ([mode isEqualToString:@"off"]) {+ after(1.5, ^{+ UISwitch *toggle = (UISwitch *)[page.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]].accessoryView;+ toggle.on = NO;+ [toggle sendActionsForControlEvents:UIControlEventValueChanged];+ log(@"custom off");+ });+ } else if ([mode isEqualToString:@"hide"]) {+ after(1.5, ^{+ UITableViewCell *home = [page.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:2]];+ for (UIView *v in home.contentView.subviews) if ([v isKindOfClass:UIButton.class]) [(UIButton *)v sendActionsForControlEvents:UIControlEventTouchUpInside];+ log(@"Home hidden");+ });+ } else if ([mode isEqualToString:@"edit"] || [mode isEqualToString:@"remove"]) {+ after(1.5, ^{ tap(page, 2, 2); });+ if ([mode isEqualToString:@"remove"]) {+ after(3.0, ^{ tap(topPage(page), 2, 0); });+ after(4.0, ^{+ UIAlertController *alert = (UIAlertController *)topPage(page).presentedViewController;+ UIAlertAction *remove = alert.actions.firstObject;+ NSLog(@"[harness] asked: %@ -> %@", alert.message, remove.title);+ // UIAlertAction keeps its handler under a private key; a finger on the button runs the same block.+ void (^handler)(UIAlertAction *) = [remove valueForKey:@"handler"];+ NSLog(@"[harness] the action's handler %@", handler ? @"found" : @"missing");+ [alert dismissViewControllerAnimated:NO completion:^{ if (handler) handler(remove); }];+ });+ after(5.5, ^{ log(@"Liked Songs removed"); });+ }+ }+}+@implementation SGHarnessScene// Launch words: `sheet` the sheet as it opens; `preset` Liked Songs picked from Choose a Link; `glyphs`@@ -89,6 +166,10 @@ static void tap(UITableViewController *page, NSInteger section, NSInteger row) {[self.window makeKeyAndVisible];NSArray<NSString *> *args = NSProcessInfo.processInfo.arguments;NSString *mode = args.count > 1 ? args[1] : @"sheet";+ if ([@[@"navbar", @"icons", @"off", @"hide", @"edit", @"remove", @"links"] containsObject:mode]) {+ runNavbar(root, mode);+ return;+ }NSLog(@"[harness] glyphs %@", SGEncoreGlyphNames());CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();diff --git a/harness/addtab/stubs.m b/harness/addtab/stubs.mindex 085483df..42cda7aa 100644--- a/harness/addtab/stubs.m+++ b/harness/addtab/stubs.m@@ -1,4 +1,22 @@-// What the harness does not compile: Mod Settings' opener, which SGPage.h declares.+// What the harness does not compile: Mod Settings' opener, which SGPage.h declares, and for the Tab bar page+// the glass bar's refresh, the Kit's accent and the glyphs TabBar.x reads off Spotify's bar, which are drawn+// here the way the stand-in Encore views draw them (main.m).#import <UIKit/UIKit.h>+#import "Redesigned/Navbar/Navbar.h"+#import "Shared/Navigation/TabIcons.h"void SGOpenModSettings(UIView *source) {}+void SGRRefreshTabBar(void) {}+UIColor *SGRAccent(void) { return [UIColor colorWithRed:0x1E / 255.0 green:0xD7 / 255.0 blue:0x60 / 255.0 alpha:1]; }++// Spotify's own tabs by the English label under them; a tab of the mod's own by its icon, as on the bar.+UIImage *SGRNavbarGlyph(NSDictionary *entry, BOOL active) {+ if (!entry[SGRNavbarURI]) {+ NSDictionary *stock = @{@"Home": @"house", @"Search": @"magnifyingglass", @"Your Library": @"books.vertical", @"Create": @"plus"};+ NSString *name = stock[entry[SGRNavbarID]];+ if (!name) return nil;+ return [UIImage systemImageNamed:active && ![name isEqualToString:@"plus"] ? [name stringByAppendingString:@".fill"] : name];+ }+ UIView *icon = SGTabIconView(entry[SGRNavbarIcon], [entry[SGRNavbarIconSet] isEqual:SGTabIconSetSymbols], UIColor.whiteColor);+ return [icon isKindOfClass:UIImageView.class] ? ((UIImageView *)icon).image : nil;+}diff --git a/tweak/Sources/Native/Navbar/NavbarSettings.m b/tweak/Sources/Native/Navbar/NavbarSettings.mindex 404830e2..36e084e9 100644--- a/tweak/Sources/Native/Navbar/NavbarSettings.m+++ b/tweak/Sources/Native/Navbar/NavbarSettings.m@@ -157,7 +157,7 @@ typedef NS_ENUM(NSInteger, SGNavbarSection) {- (instancetype)init {if (!(self = [super initWithStyle:UITableViewStyleInsetGrouped])) return nil;- self.title = @"Navbar";+ self.title = @"Tab bar";return self;}diff --git a/tweak/Sources/Redesigned/Navbar/Navbar.h b/tweak/Sources/Redesigned/Navbar/Navbar.hindex b1dc648d..4c5098b1 100644--- a/tweak/Sources/Redesigned/Navbar/Navbar.h+++ b/tweak/Sources/Redesigned/Navbar/Navbar.h@@ -45,5 +45,8 @@ void SGRSetTabBarMinimized(BOOL minimized, BOOL animated);// coordinates: where the now playing card goes. CGRectNull while the bar is not minimized or not on screen.CGRect SGRTabBarInlineSlot(UIView *host, CGFloat height);+// A tab's glyph as the glass bar draws it, white, filled when `active` (TabBar.x), for the Tab bar page.+UIImage *SGRNavbarGlyph(NSDictionary *entry, BOOL active);+UIViewController *SGRNavbarSettingsPage(void); // the tab editor, in Mod SettingsUIViewController *SGRNavbarEditorPage(void); // the tab editor alone, for the welcome tourdiff --git a/tweak/Sources/Redesigned/Navbar/NavbarSettings.m b/tweak/Sources/Redesigned/Navbar/NavbarSettings.mindex d8b09973..5b76a4fc 100644--- a/tweak/Sources/Redesigned/Navbar/NavbarSettings.m+++ b/tweak/Sources/Redesigned/Navbar/NavbarSettings.m@@ -3,6 +3,7 @@#import "Settings/SGPageStyle.h"#import "Navbar.h"#import "Shared/Navigation/AddTabSheet.h"+#import "Redesigned/Kit/SGRTokens.h"// 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. Playlists was spotify:collection:playlists@@ -138,33 +139,265 @@ static void appendTab(NSDictionary *tab) {@end+#pragma mark - the preview++// Spotify's own tabs in Spotify's order, as entries, all shown: what the bar has with Custom tab bar off.+static NSArray<NSDictionary *> *stockEntries(void) {+ NSMutableArray<NSDictionary *> *entries = [NSMutableArray array];+ for (NSString *ident in SGRNavbarStock()) [entries addObject:@{SGRNavbarID: ident, SGRNavbarTitle: ident}];+ return entries;+}++static UIImage *glyphFor(NSDictionary *entry, BOOL active) {+ return SGRNavbarGlyph(entry, active) ?: [UIImage systemImageNamed:@"square.dashed"];+}++static UITabBar *previewBar(void) {+ UITabBar *bar = [UITabBar new];+ // Dark whatever the system is, as TabBar.x's bars are.+ bar.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ bar.userInteractionEnabled = NO;+ bar.tintColor = SGRAccent();+ return bar;+}++// TabBar.x's split bar: UIKit draws a bar's platter 21 pt in from its sides, a split tab takes a 62 pt circle,+// and the main bar runs under the split bar's leading inset to leave 12 pt between the two platters.+static const CGFloat kPlatterInset = 21, kApartItemWidth = 62, kPlatterGap = 12;++// The glass bar as it will look, drawn by the same system UITabBar TabBar.x puts over Spotify's bar, from the+// list as it stands on the page: the shown tabs in order, the first selected, the split tabs on a bar of+// their own, names under the glyphs unless Icons only is picked. It takes no touches.+@interface SGRTabBarPreview : UIView+- (void)showEntries:(NSArray<NSDictionary *> *)entries;+@end++@implementation SGRTabBarPreview {+ UITabBar *_main, *_apart;+}++- (instancetype)initWithFrame:(CGRect)frame {+ if (!(self = [super initWithFrame:frame])) return nil;+ _main = previewBar();+ _apart = previewBar();+ [self addSubview:_main];+ [self addSubview:_apart];+ self.isAccessibilityElement = YES;+ self.accessibilityLabel = @"Tab bar preview";+ return self;+}++static NSArray<UITabBarItem *> *itemsFor(NSArray<NSDictionary *> *entries, BOOL names) {+ NSMutableArray<UITabBarItem *> *items = [NSMutableArray array];+ for (NSDictionary *entry in entries) {+ UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:names ? entry[SGRNavbarTitle] : nil image:glyphFor(entry, NO) tag:(NSInteger)items.count];+ item.selectedImage = glyphFor(entry, YES);+ [items addObject:item];+ }+ return items;+}++// What Navbar.x composes from the same list: with nothing left shown, Spotify's own tabs come back.+- (void)showEntries:(NSArray<NSDictionary *> *)entries {+ BOOL custom = SGEnabled(SGRKeyNavbar), names = !SGHidden(SGRKeyNavbarHideLabels);+ NSMutableArray<NSDictionary *> *shown = [NSMutableArray array];+ if (custom) for (NSDictionary *entry in entries) if (![entry[SGRNavbarHidden] boolValue]) [shown addObject:entry];+ if (!shown.count) [shown addObjectsFromArray:stockEntries()];+ NSSet<NSString *> *split = custom ? [NSSet setWithArray:SGRNavbarSplit()] : nil;+ NSMutableArray<NSDictionary *> *main = [NSMutableArray array], *apart = [NSMutableArray array];+ for (NSDictionary *entry in shown) [([split containsObject:entry[SGRNavbarID]] ? apart : main) addObject:entry];+ if (!main.count) {+ main = shown;+ apart = [NSMutableArray array];+ }+ [_main setItems:itemsFor(main, names) animated:NO];+ _main.selectedItem = _main.items.firstObject;+ [_apart setItems:itemsFor(apart, names) animated:NO];+ _apart.selectedItem = nil;+ _apart.hidden = !apart.count;+ self.accessibilityValue = [[shown valueForKey:SGRNavbarTitle] componentsJoinedByString:@", "];+ [self setNeedsLayout];+}++- (CGSize)sizeThatFits:(CGSize)size {+ return CGSizeMake(size.width, [_main sizeThatFits:CGSizeMake(size.width, 49)].height);+}++- (void)layoutSubviews {+ [super layoutSubviews];+ CGRect bounds = self.bounds, main = bounds, apart = CGRectZero;+ if (!_apart.hidden) {+ CGFloat width = MIN(bounds.size.width / 2, _apart.items.count * kApartItemWidth + 2 * kPlatterInset);+ CGRectDivide(bounds, &apart, &main, width, CGRectMaxXEdge);+ main.size.width += 2 * kPlatterInset - kPlatterGap;+ }+ _main.frame = main;+ _apart.frame = apart;+}++@end++#pragma mark - the labels' cards++// One of the two ways the bar can label its tabs, as a picture of the bar's first three tabs with or without+// their names, the choice's name under it and a check circle under that.+@interface SGRLabelCard : UIControl+@property (nonatomic, readonly) BOOL names;+- (instancetype)initWithTitle:(NSString *)title names:(BOOL)names;+- (void)showEntries:(NSArray<NSDictionary *> *)entries;+@end++@implementation SGRLabelCard {+ UIView *_picture;+ NSMutableArray<UIImageView *> *_glyphs;+ NSMutableArray<UIView *> *_bars; // a grey bar under each glyph stands for its name+ UILabel *_title;+ UIImageView *_check;+}++static const CGFloat kPictureHeight = 76;++- (instancetype)initWithTitle:(NSString *)title names:(BOOL)names {+ if (!(self = [super initWithFrame:CGRectZero])) return nil;+ _names = names;+ _picture = [UIView new];+ _picture.backgroundColor = SGCardBackground();+ _picture.layer.cornerRadius = 18;+ _picture.layer.cornerCurve = kCACornerCurveContinuous;+ _picture.userInteractionEnabled = NO;+ [self addSubview:_picture];+ _glyphs = [NSMutableArray array];+ _bars = [NSMutableArray array];+ for (NSUInteger i = 0; i < 3; i++) {+ UIImageView *glyph = [UIImageView new];+ glyph.contentMode = UIViewContentModeScaleAspectFit;+ glyph.tintColor = UIColor.whiteColor;+ [_picture addSubview:glyph];+ [_glyphs addObject:glyph];+ UIView *bar = [UIView new];+ bar.backgroundColor = SGGrey();+ bar.layer.cornerRadius = 2;+ bar.hidden = !names;+ [_picture addSubview:bar];+ [_bars addObject:bar];+ }+ _title = [UILabel new];+ _title.text = title;+ _title.font = SGSubtitleFont();+ _title.textColor = UIColor.whiteColor;+ _title.textAlignment = NSTextAlignmentCenter;+ _title.adjustsFontSizeToFitWidth = YES;+ _title.minimumScaleFactor = 0.8;+ [self addSubview:_title];+ _check = [UIImageView new];+ _check.contentMode = UIViewContentModeCenter;+ [self addSubview:_check];+ self.isAccessibilityElement = YES;+ self.accessibilityLabel = title;+ return self;+}++- (void)showEntries:(NSArray<NSDictionary *> *)entries {+ for (NSUInteger i = 0; i < 3; i++) {+ NSDictionary *entry = i < entries.count ? entries[i] : nil;+ _glyphs[i].image = entry ? [glyphFor(entry, NO) imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] : nil;+ _bars[i].alpha = entry ? 1 : 0;+ }+}++- (void)setSelected:(BOOL)selected {+ [super setSelected:selected];+ _picture.layer.borderWidth = selected ? 2 : 0;+ _picture.layer.borderColor = SGRAccent().CGColor;+ UIImageSymbolConfiguration *size = [UIImageSymbolConfiguration configurationWithPointSize:22 weight:UIImageSymbolWeightRegular];+ _check.image = [UIImage systemImageNamed:selected ? @"checkmark.circle.fill" : @"circle" withConfiguration:size];+ _check.tintColor = selected ? SGRAccent() : SGGrey();+ self.accessibilityTraits = UIAccessibilityTraitButton | (selected ? UIAccessibilityTraitSelected : 0);+}++- (void)setHighlighted:(BOOL)highlighted {+ [super setHighlighted:highlighted];+ _picture.alpha = highlighted ? 0.6 : 1;+}++- (void)layoutSubviews {+ [super layoutSubviews];+ CGFloat width = self.bounds.size.width;+ _picture.frame = CGRectMake(0, 0, width, kPictureHeight);+ CGFloat slot = (width - 16) / 3, glyphTop = _names ? 18 : 26;+ for (NSUInteger i = 0; i < 3; i++) {+ CGFloat x = 8 + i * slot;+ _glyphs[i].frame = CGRectMake(x + (slot - 24) / 2, glyphTop, 24, 24);+ _bars[i].frame = CGRectMake(x + (slot - 20) / 2, glyphTop + 32, 20, 4);+ }+ CGFloat titleHeight = ceil(_title.font.lineHeight);+ _title.frame = CGRectMake(0, kPictureHeight + 8, width, titleHeight);+ _check.frame = CGRectMake((width - 44) / 2, CGRectGetMaxY(_title.frame) - 6, 44, 44);+}+++ (CGFloat)height {+ return kPictureHeight + 8 + ceil(SGSubtitleFont().lineHeight) - 6 + 44;+}++@end++#pragma mark - the page+typedef NS_ENUM(NSInteger, SGRNavbarSection) {SGRNavbarSectionSwitch,+ SGRNavbarSectionLabels,SGRNavbarSectionTabs,- SGRNavbarSectionAdd,+ SGRNavbarSectionLinks, // Add a tab, Use Spotify's tabsSGRNavbarSectionSplit,- SGRNavbarSectionReset,SGRNavbarSectionCount,};-static NSString *switchKey(NSInteger row) {- return row == 2 ? SGRKeyNavbarMinimize : row == 1 ? SGRKeyNavbarHideLabels : SGRKeyNavbar;+// A tab of the list: a check circle that shows or hides it, its glyph, its name, and the table's drag handle.+@interface SGRTabCell : UITableViewCell+@property (nonatomic, strong) UIButton *check;+@end++@implementation SGRTabCell+- (void)layoutSubviews {+ [super layoutSubviews];+ CGFloat height = self.contentView.bounds.size.height;+ self.check.frame = CGRectMake(4, (height - 44) / 2, 44, 44);+}+@end++// The labels' cell: clear, so it drops the inset-grouped corner mask that clipped the cards' outer corners.+@interface SGRUnclippedCell : UITableViewCell+@end++@implementation SGRUnclippedCell++- (void)layoutSubviews {+ [super layoutSubviews];+ self.layer.cornerRadius = 0;+ self.layer.masksToBounds = NO;+ self.contentView.clipsToBounds = NO;}-// 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. Mod Settings and the welcome-// tour show the same editor.+@end++// The tab editor: a preview of the bar, how it labels its tabs, the tabs in the order the bar shows them+// (the circle shows or hides one, the handle drags it, a tap on one of the mod's own opens it in the Add a+// Tab sheet to edit or remove), then adding one, going back to Spotify's tabs and splitting tabs apart.+// Spotify's own tabs are named by their label and drawn by Spotify, so they can be hidden but not renamed,+// given another icon or removed. Mod Settings and the welcome tour show the same editor.@interface SGRNavbarPage : SGPage@end@implementation SGRNavbarPage {NSMutableArray<NSMutableDictionary *> *_entries;- UIView *_intro;+ SGRTabBarPreview *_preview;+ UIView *_header;+ SGRLabelCard *_withNames, *_iconsOnly;}- (instancetype)init {if (!(self = [super initWithStyle:UITableViewStyleInsetGrouped])) return nil;- self.title = @"Navbar";+ self.title = @"Tab bar";return self;}@@ -172,19 +405,33 @@ static NSString *switchKey(NSInteger row) {[super viewDidLoad];self.tableView.allowsSelectionDuringEditing = YES;self.tableView.editing = YES;- _intro = SGNote(@"Drag to reorder, tap to show or hide.");- self.tableView.tableHeaderView = _intro;+ _preview = [SGRTabBarPreview new];+ _header = [UIView new];+ [_header addSubview:_preview];+ self.tableView.tableHeaderView = _header;+ _withNames = [[SGRLabelCard alloc] initWithTitle:@"Icons and names" names:YES];+ _iconsOnly = [[SGRLabelCard alloc] initWithTitle:@"Icons only" names:NO];+ for (SGRLabelCard *card in @[_withNames, _iconsOnly]) [card addTarget:self action:@selector(labelsPicked:) forControlEvents:UIControlEventTouchUpInside];_entries = navbarEntries();+ [self showChoices];}-- (void)reload {- _entries = navbarEntries();- [self.tableView reloadData];+- (void)viewWillAppear:(BOOL)animated {+ [super viewWillAppear:animated];+ // Split tabs, a page pushed from here, changes what the preview shows.+ [self reload];}- (void)viewWillLayoutSubviews {[super viewWillLayoutSubviews];- SGFitNote(self.tableView, _intro, 24, 0);+ UITableView *table = self.tableView;+ CGFloat width = table.bounds.size.width;+ CGFloat height = [_preview sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)].height;+ _preview.frame = CGRectMake(0, 8, width, height);+ CGSize size = CGSizeMake(width, CGRectGetMaxY(_preview.frame) + 8);+ if (CGSizeEqualToSize(_header.bounds.size, size)) return;+ _header.frame = (CGRect){CGPointZero, size};+ table.tableHeaderView = _header;}- (void)viewDidLayoutSubviews {@@ -192,12 +439,32 @@ static NSString *switchKey(NSInteger row) {SGInsetForBars(self.tableView);}+// The preview and the cards, from the list as it stands.+- (void)showChoices {+ [_preview showEntries:_entries];+ NSMutableArray<NSDictionary *> *shown = [NSMutableArray array];+ for (NSDictionary *entry in _entries) if (![entry[SGRNavbarHidden] boolValue]) [shown addObject:entry];+ BOOL names = !SGHidden(SGRKeyNavbarHideLabels);+ for (SGRLabelCard *card in @[_withNames, _iconsOnly]) {+ [card showEntries:shown.count ? shown : (NSArray *)_entries];+ card.selected = card.names == names;+ }+ [self.view setNeedsLayout];+}++- (void)reload {+ _entries = navbarEntries();+ [self.tableView reloadData];+ [self showChoices];+}+- (void)save {SGRSetNavbarLayout(_entries);- // A split tab swiped away leaves the split list with it.+ // A split tab removed leaves the split list with it.NSArray *idents = [_entries valueForKey:SGRNavbarID];SGRSetNavbarSplit([SGRNavbarSplit() filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF IN %@", idents]]);SGRRefreshTabBar();+ [self showChoices];}- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {@@ -205,64 +472,125 @@ static NSString *switchKey(NSInteger row) {}- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {- if (section == SGRNavbarSectionSwitch) return 3;- return section == SGRNavbarSectionTabs ? (NSInteger)_entries.count : 1;+ if (section == SGRNavbarSectionTabs) return (NSInteger)_entries.count;+ return section == SGRNavbarSectionLinks ? 2 : 1;}- (NSString *)headerFor:(NSInteger)section {return section == SGRNavbarSectionTabs ? @"Tabs" : nil;}+- (NSString *)footerFor:(NSInteger)section {+ if (section == SGRNavbarSectionSwitch && !SGEnabled(SGRKeyNavbar))+ return @"Off, the bar shows Spotify's own tabs in Spotify's order. Your list is kept for when it is on again.";+ if (section == SGRNavbarSectionTabs)+ return @"Drag a tab to move it. Tap one you added to rename it or change its icon, or one of Spotify's to hide it.";+ return nil;+}+- (UIView *)tableView:(UITableView *)table viewForHeaderInSection:(NSInteger)section {NSString *title = [self headerFor:section];return title ? SGSectionHeader(table, title) : nil;}- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- if ([self headerFor:section]) return SGSectionHeaderHeight;- return [self tableView:table numberOfRowsInSection:section] ? SGSectionGap : CGFLOAT_MIN;+ return [self headerFor:section] ? SGSectionHeaderHeight : SGSectionGap;+}++- (UIView *)tableView:(UITableView *)table viewForFooterInSection:(NSInteger)section {+ NSString *text = [self footerFor:section];+ return text ? SGSectionFooter(table, text) : nil;}- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {- return CGFLOAT_MIN;+ NSString *text = [self footerFor:section];+ return text ? SGSectionFooterHeight(table, text) : CGFLOAT_MIN;+}++- (CGFloat)tableView:(UITableView *)table heightForRowAtIndexPath:(NSIndexPath *)path {+ return path.section == SGRNavbarSectionLabels ? [SGRLabelCard height] : UITableViewAutomaticDimension;+}++- (UITableViewCell *)labelsCell:(UITableView *)table {+ UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:@"labels"] ?: [[SGRUnclippedCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"labels"];+ cell.contentConfiguration = nil;+ cell.backgroundColor = UIColor.clearColor;+ cell.backgroundConfiguration = [UIBackgroundConfiguration clearConfiguration];+ cell.selectionStyle = UITableViewCellSelectionStyleNone;+ if (_withNames.superview != cell.contentView) {+ UIStackView *row = [[UIStackView alloc] initWithArrangedSubviews:@[_withNames, _iconsOnly]];+ row.distribution = UIStackViewDistributionFillEqually;+ row.spacing = 12;+ row.translatesAutoresizingMaskIntoConstraints = NO;+ [cell.contentView addSubview:row];+ [NSLayoutConstraint activateConstraints:@[+ [row.leadingAnchor constraintEqualToAnchor:cell.contentView.leadingAnchor],+ [row.trailingAnchor constraintEqualToAnchor:cell.contentView.trailingAnchor],+ [row.topAnchor constraintEqualToAnchor:cell.contentView.topAnchor],+ [row.bottomAnchor constraintEqualToAnchor:cell.contentView.bottomAnchor],+ ]];+ }+ return cell;+}++- (UITableViewCell *)tabCell:(UITableView *)table at:(NSIndexPath *)path {+ SGRTabCell *cell = [table dequeueReusableCellWithIdentifier:@"tab"] ?: [[SGRTabCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"tab"];+ NSDictionary *entry = _entries[(NSUInteger)path.row];+ BOOL hidden = [entry[SGRNavbarHidden] boolValue];+ SGFillCell(cell, entry[SGRNavbarTitle], nil, hidden ? SGGrey() : nil, nil);+ UIListContentConfiguration *content = (UIListContentConfiguration *)cell.contentConfiguration;+ content.image = glyphFor(entry, NO);+ content.imageProperties.tintColor = hidden ? SGGrey() : UIColor.whiteColor;+ content.imageProperties.maximumSize = CGSizeMake(24, 24);+ content.imageProperties.reservedLayoutSize = CGSizeMake(28, 28);+ content.imageToTextPadding = 12;+ NSDirectionalEdgeInsets margins = content.directionalLayoutMargins;+ margins.leading = 52;+ content.directionalLayoutMargins = margins;+ cell.contentConfiguration = content;+ cell.separatorInset = UIEdgeInsetsMake(0, 52, 0, 0);+ cell.selectionStyle = UITableViewCellSelectionStyleDefault;+ cell.accessibilityValue = hidden ? @"Hidden" : @"Shown";+ cell.accessibilityHint = entry[SGRNavbarURI] ? @"Opens the tab to edit it" : @"Shows or hides the tab";++ if (!cell.check) {+ cell.check = [UIButton buttonWithType:UIButtonTypeSystem];+ [cell.check addTarget:self action:@selector(checkTapped:) forControlEvents:UIControlEventTouchUpInside];+ [cell.contentView addSubview:cell.check];+ }+ UIImageSymbolConfiguration *size = [UIImageSymbolConfiguration configurationWithPointSize:22 weight:UIImageSymbolWeightRegular];+ [cell.check setImage:[UIImage systemImageNamed:hidden ? @"circle" : @"checkmark.circle.fill" withConfiguration:size] forState:UIControlStateNormal];+ cell.check.tintColor = hidden ? SGGrey() : SGRAccent();+ cell.check.accessibilityLabel = [NSString stringWithFormat:@"Show %@ on the bar", entry[SGRNavbarTitle]];+ cell.check.accessibilityValue = hidden ? @"Off" : @"On";+ return cell;}- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {+ if (path.section == SGRNavbarSectionLabels) return [self labelsCell:table];+ if (path.section == SGRNavbarSectionTabs) return [self tabCell:table at:path];UITableViewCell *cell = SGDequeueCell(table, @"navbar");switch (path.section) {case SGRNavbarSectionSwitch: {- static NSString *const titles[] = {@"Custom navbar", @"Hide labels", @"Minimize on scroll"};- static NSString *const subtitles[] = {nil, @"Icons only", @"Two tabs and the now playing bar in one row as a page scrolls down"};- SGFillCell(cell, titles[path.row], subtitles[path.row], nil, nil);+ SGFillCell(cell, @"Custom tab bar", @"Your order, hidden tabs and tabs you add", nil, nil);UISwitch *toggle = [UISwitch new];toggle.onTintColor = SGGreen();- toggle.tag = path.row;- toggle.on = path.row == 1 ? SGHidden(SGRKeyNavbarHideLabels) : SGEnabled(switchKey(path.row));- [toggle addTarget:self action:@selector(toggled:) forControlEvents:UIControlEventValueChanged];+ toggle.on = SGEnabled(SGRKeyNavbar);+ [toggle addTarget:self action:@selector(customToggled:) forControlEvents:UIControlEventValueChanged];cell.accessoryView = toggle;break;}- case SGRNavbarSectionTabs: {- NSDictionary *entry = _entries[(NSUInteger)path.row];- BOOL hidden = [entry[SGRNavbarHidden] boolValue];- NSString *uri = entry[SGRNavbarURI];- SGFillCell(cell, entry[SGRNavbarTitle], hidden ? @"Hidden" : (uri ?: @"Spotify's own tab"),- hidden ? SGGrey() : nil, hidden ? @"eye.slash" : @"eye");- break;- }- case SGRNavbarSectionAdd:- SGFillCell(cell, @"Add a tab…", nil, nil, @"plus");+ case SGRNavbarSectionLinks:+ // Links in the accent colour, as the system's own actions in a list are.+ SGFillCell(cell, path.row == 0 ? @"Add a tab" : @"Use Spotify's tabs", nil, SGRAccent(), nil);cell.selectionStyle = UITableViewCellSelectionStyleDefault;+ cell.accessibilityTraits = UIAccessibilityTraitButton;break;- case SGRNavbarSectionSplit:+ default:SGFillCell(cell, @"Split tabs", @"Place chosen tabs apart on the right", nil, @"rectangle.split.2x1");cell.accessoryView = SGSymbolView(@"chevron.right", 13, UIImageSymbolWeightSemibold, 16);cell.selectionStyle = UITableViewCellSelectionStyleDefault;break;- default:- SGFillCell(cell, @"Use Spotify's order", nil, nil, @"arrow.uturn.backward");- cell.selectionStyle = UITableViewCellSelectionStyleDefault;- break;}return cell;}@@ -275,14 +603,19 @@ static NSString *switchKey(NSInteger row) {return path.section == SGRNavbarSectionTabs;}-// Spotify's own tabs stay on the list to be switched back on; only the mod's own can go.+// The circle stands where the delete control would; a tab of the mod's own is removed from its sheet.- (UITableViewCellEditingStyle)tableView:(UITableView *)table editingStyleForRowAtIndexPath:(NSIndexPath *)path {- if (path.section != SGRNavbarSectionTabs) return UITableViewCellEditingStyleNone;- return _entries[(NSUInteger)path.row][SGRNavbarURI] ? UITableViewCellEditingStyleDelete : UITableViewCellEditingStyleNone;+ return UITableViewCellEditingStyleNone;+}++- (BOOL)tableView:(UITableView *)table shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)path {+ return NO;}- (NSIndexPath *)tableView:(UITableView *)table targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)from toProposedIndexPath:(NSIndexPath *)to {- return to.section == SGRNavbarSectionTabs ? to : from;+ if (to.section == SGRNavbarSectionTabs) return to;+ // Dragged past either end of the list, the tab stops at that end.+ return [NSIndexPath indexPathForRow:to.section < SGRNavbarSectionTabs ? 0 : (NSInteger)_entries.count - 1 inSection:SGRNavbarSectionTabs];}- (void)tableView:(UITableView *)table moveRowAtIndexPath:(NSIndexPath *)from toIndexPath:(NSIndexPath *)to {@@ -292,41 +625,96 @@ static NSString *switchKey(NSInteger row) {[self save];}-- (void)tableView:(UITableView *)table commitEditingStyle:(UITableViewCellEditingStyle)style forRowAtIndexPath:(NSIndexPath *)path {- if (style != UITableViewCellEditingStyleDelete) return;- [_entries removeObjectAtIndex:(NSUInteger)path.row];+- (void)toggleRow:(NSInteger)row {+ NSMutableDictionary *entry = _entries[(NSUInteger)row];+ entry[SGRNavbarHidden] = [entry[SGRNavbarHidden] boolValue] ? nil : @YES;[self save];- [table deleteRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationAutomatic];+ [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:row inSection:SGRNavbarSectionTabs]] withRowAnimation:UITableViewRowAnimationNone];+}++- (void)checkTapped:(UIButton *)check {+ UIView *view = check;+ while (view && ![view isKindOfClass:UITableViewCell.class]) view = view.superview;+ NSIndexPath *path = view ? [self.tableView indexPathForCell:(UITableViewCell *)view] : nil;+ if (path.section == SGRNavbarSectionTabs) [self toggleRow:path.row];}- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {[table deselectRowAtIndexPath:path animated:YES];- if (path.section == SGRNavbarSectionTabs) {- NSMutableDictionary *entry = _entries[(NSUInteger)path.row];- entry[SGRNavbarHidden] = [entry[SGRNavbarHidden] boolValue] ? nil : @YES;- [self save];- [table reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationNone];- } else if (path.section == SGRNavbarSectionAdd) {- __weak typeof(self) weakSelf = self;- SGPresentAddTabSheet(self, tabPresets(), ^(NSDictionary *tab) {- appendTab(tab);- [weakSelf reload];- });- } else if (path.section == SGRNavbarSectionSplit) {- [self.navigationController pushViewController:[SGRSplitTabsPage new] animated:YES];- } else if (path.section == SGRNavbarSectionReset) {- [self reset];+ __weak typeof(self) weakSelf = self;+ switch (path.section) {+ case SGRNavbarSectionTabs:+ if (_entries[(NSUInteger)path.row][SGRNavbarURI]) [self editRow:path.row];+ else [self toggleRow:path.row];+ break;+ case SGRNavbarSectionLinks: {+ if (path.row == 1) {+ [self reset];+ break;+ }+ SGPresentAddTabSheet(self, tabPresets(), ^(NSDictionary *tab) {+ appendTab(tab);+ [weakSelf reload];+ });+ break;+ }+ case SGRNavbarSectionSplit:+ [self.navigationController pushViewController:[SGRSplitTabsPage new] animated:YES];+ break;}}-- (void)toggled:(UISwitch *)toggle {- SGSetEnabled(switchKey(toggle.tag), toggle.on);- if (!toggle.on && toggle.tag == 2) SGRSetTabBarMinimized(NO, NO);+// The entry of the list as it is now with this identity; the list is read again whenever the page appears.+- (NSMutableDictionary *)entryWithID:(NSString *)ident {+ for (NSMutableDictionary *entry in _entries) if ([entry[SGRNavbarID] isEqualToString:ident]) return entry;+ return nil;+}++// The Add a Tab sheet over the tab as it is; Save keeps its place on the bar and its identity.+- (void)editRow:(NSInteger)row {+ NSDictionary *entry = _entries[(NSUInteger)row];+ NSString *ident = entry[SGRNavbarID];+ NSMutableDictionary *tab = [@{SGTabTitle: entry[SGRNavbarTitle] ?: @"", SGTabURI: entry[SGRNavbarURI], SGTabIcon: entry[SGRNavbarIcon] ?: @"star"} mutableCopy];+ tab[SGTabIconSet] = entry[SGRNavbarIconSet];+ __weak typeof(self) weakSelf = self;+ SGPresentEditTabSheet(self, tabPresets(), tab, ^(NSDictionary *edited) {+ NSMutableDictionary *now = [weakSelf entryWithID:ident];+ if (!now) return;+ now[SGRNavbarTitle] = edited[SGTabTitle];+ now[SGRNavbarURI] = edited[SGTabURI];+ now[SGRNavbarIcon] = edited[SGTabIcon];+ now[SGRNavbarIconSet] = edited[SGTabIconSet];+ [weakSelf save];+ [weakSelf.tableView reloadData];+ }, ^{+ typeof(self) page = weakSelf;+ NSMutableDictionary *now = [page entryWithID:ident];+ if (!now) return;+ [page->_entries removeObjectIdenticalTo:now];+ [page save];+ [page.tableView reloadData];+ });+}++- (void)labelsPicked:(SGRLabelCard *)card {+ if (card.selected) return;+ SGSetEnabled(SGRKeyNavbarHideLabels, !card.names);+ [[UISelectionFeedbackGenerator new] selectionChanged];+ SGRRefreshTabBar();+ [self showChoices];+}++- (void)customToggled:(UISwitch *)toggle {+ SGSetEnabled(SGRKeyNavbar, toggle.on);SGRRefreshTabBar();+ [self showChoices];+ [UIView performWithoutAnimation:^{+ [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:SGRNavbarSectionSwitch] withRowAnimation:UITableViewRowAnimationNone];+ }];}- (void)reset {- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Use Spotify's order"+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Use Spotify's tabs"message:@"Every tab of Spotify's comes back where Spotify put it, the tabs you added go, and no tab is split apart."preferredStyle:UIAlertControllerStyleAlert];[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];@@ -334,8 +722,7 @@ static NSString *switchKey(NSInteger row) {SGRSetNavbarLayout(@[]);SGRSetNavbarSplit(@[]);SGRRefreshTabBar();- self->_entries = navbarEntries();- [self.tableView reloadData];+ [self reload];}]];[self presentViewController:alert animated:YES completion:nil];}diff --git a/tweak/Sources/Redesigned/Navbar/TabBar.x b/tweak/Sources/Redesigned/Navbar/TabBar.xindex 70d84668..41ae48b1 100644--- a/tweak/Sources/Redesigned/Navbar/TabBar.x+++ b/tweak/Sources/Redesigned/Navbar/TabBar.x@@ -16,6 +16,7 @@#import "Redesigned/NowPlayingBar/NowPlayingBar.h"#import "Settings/SGPage.h"#import "Headers/SPTEncoreIconView.h"+#import "Shared/Navigation/TabIcons.h"#import <objc/message.h>static char kBarKey, kApartBarKey, kHostKey, kFadeKey;@@ -139,6 +140,27 @@ static UIImage *glyphOf(UIView *item, BOOL active) {return size.width >= 2 ? renderLayer(live.layer, size) : nil;}+// For the Tab bar page's list and preview: a tab of Spotify's drawn from its item on the bar, hidden or not,+// found by the label its entry is named after; a tab of the mod's own drawn from its entry, as Navbar.x+// draws it on the bar. Nil while Spotify's item has not been built.+UIImage *SGRNavbarGlyph(NSDictionary *entry, BOOL active) {+ if (entry[SGRNavbarURI]) {+ UIView *holder = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];+ UIView *icon = SGTabIconView(entry[SGRNavbarIcon], [entry[SGRNavbarIconSet] isEqual:SGTabIconSetSymbols], UIColor.whiteColor);+ icon.translatesAutoresizingMaskIntoConstraints = YES;+ icon.frame = holder.bounds;+ if ([icon isKindOfClass:UIImageView.class]) icon.contentMode = UIViewContentModeScaleAspectFit;+ [holder addSubview:icon];+ [holder layoutIfNeeded];+ return glyphOf(holder, active);+ }+ for (UIView *item in SGRowIn(sg_stockBar).arrangedSubviews) {+ if ([NSStringFromClass(item.class) isEqualToString:@"SGRTabItemView"]) continue;+ if ([labelIn(item).text isEqualToString:entry[SGRNavbarID]]) return glyphOf(item, active);+ }+ return nil;+}+#pragma mark - passing a tap on// NavigationUI_TabBarImpl's TabBarItemElementUI answers a tap recognizer (-handleTap), so the tap isdiff --git a/tweak/Sources/Redesigned/Player/PlayerSettings.m b/tweak/Sources/Redesigned/Player/PlayerSettings.mindex 183bd0bd..b39ee15e 100644--- a/tweak/Sources/Redesigned/Player/PlayerSettings.m+++ b/tweak/Sources/Redesigned/Player/PlayerSettings.m@@ -282,7 +282,8 @@ UIViewController *SGRPlayerSettingsPage(NSArray *more) {SGNotedSection(@"Mini player", SGRNowPlayingBarRows(),@"Apple Music style shrinks the tab bar to two tabs as a page scrolls down and puts the now ""playing bar between them; scrolling back up undoes it. There the bar keeps its cover, title "- "and play button, and the device button too when it is on."), nil];+ "and play button, and the device button too when it is on. Apple Music style applies at once, the device button "+ "the next time the bar shrinks."), nil];[sections addObjectsFromArray:more];SGRPlayerPage *page = [[SGRPlayerPage alloc] initWithTitle:@"Player" intro:nil sections:sections footer:SGRestartNote];page.showcase = showcase;diff --git a/tweak/Sources/Shared/Navigation/AddTabSheet.h b/tweak/Sources/Shared/Navigation/AddTabSheet.hindex 1352bbda..41c3113e 100644--- a/tweak/Sources/Shared/Navigation/AddTabSheet.h+++ b/tweak/Sources/Shared/Navigation/AddTabSheet.h@@ -12,3 +12,7 @@ extern NSString *const SGTabIconSet; // SGTabIconSetSymbols (TabIcons.h) for a// `presets` carry Encore icons; those Spotify's router has nowhere to send are left out. `add` is given// the tab when Add is tapped, then the sheet goes; Cancel hands back nothing.void SGPresentAddTabSheet(UIViewController *owner, NSArray<NSDictionary *> *presets, void (^add)(NSDictionary *tab));+// The same sheet as Edit Tab, over `tab` (the keys above): Save hands the tab back as it now is, and a Remove+// Tab row under the rest runs `remove` once an action sheet has asked.+void SGPresentEditTabSheet(UIViewController *owner, NSArray<NSDictionary *> *presets, NSDictionary *tab,+ void (^save)(NSDictionary *tab), void (^remove)(void));diff --git a/tweak/Sources/Shared/Navigation/AddTabSheet.m b/tweak/Sources/Shared/Navigation/AddTabSheet.mindex 70b91e3f..d0edb324 100644--- a/tweak/Sources/Shared/Navigation/AddTabSheet.m+++ b/tweak/Sources/Shared/Navigation/AddTabSheet.m@@ -359,7 +359,7 @@ static void showProblem(UIViewController *page, NSString *title, NSString *messatypedef NS_ENUM(NSInteger, SGAddTabSection) {SGAddTabSectionName,SGAddTabSectionCustomize,- SGAddTabSectionCount,+ SGAddTabSectionRemove, // editing only};@interface SGAddTabPage : SGPage <UITextFieldDelegate>@@ -370,9 +370,24 @@ typedef NS_ENUM(NSInteger, SGAddTabSection) {SGTabDraft *_draft;NSArray<NSDictionary *> *_presets;void (^_add)(NSDictionary *tab);+ void (^_remove)(void); // set while editing a tab, which the sheet then offers to removeUITextField *_name;}+// The same sheet over a tab already on the bar: its name, link and icon filled in, Save in place of Add.+- (instancetype)initWithTab:(NSDictionary *)tab presets:(NSArray<NSDictionary *> *)presets save:(void (^)(NSDictionary *tab))save remove:(void (^)(void))remove {+ if (!(self = [self initWithPresets:presets add:save])) return nil;+ self.title = @"Edit Tab";+ _draft.title = tab[SGTabTitle];+ _draft.uri = tab[SGTabURI];+ _draft.icon = tab[SGTabIcon] ?: @"star";+ _draft.symbols = [tab[SGTabIconSet] isEqual:SGTabIconSetSymbols];+ // A link picked from the presets now leaves the name and the icon the tab has.+ _draft.iconChosen = YES;+ _remove = [remove copy];+ return self;+}+- (instancetype)initWithPresets:(NSArray<NSDictionary *> *)presets add:(void (^)(NSDictionary *tab))add {if (!(self = [super initWithStyle:UITableViewStyleInsetGrouped])) return nil;self.title = @"Add a Tab";@@ -390,7 +405,7 @@ typedef NS_ENUM(NSInteger, SGAddTabSection) {- (void)viewDidLoad {[super viewDidLoad];self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel)];- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Add" style:UIBarButtonItemStyleDone target:self action:@selector(addTab)];+ self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:_remove ? @"Save" : @"Add" style:UIBarButtonItemStyleDone target:self action:@selector(addTab)];self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;_name = [UITextField new];@@ -438,19 +453,20 @@ typedef NS_ENUM(NSInteger, SGAddTabSection) {}- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {- return SGAddTabSectionCount;+ return _remove ? 3 : 2;}- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {- return section == SGAddTabSectionName ? 1 : 2;+ return section == SGAddTabSectionCustomize ? 2 : 1;}- (UIView *)tableView:(UITableView *)table viewForHeaderInSection:(NSInteger)section {+ if (section == SGAddTabSectionRemove) return nil;return SGSectionHeader(table, section == SGAddTabSectionName ? @"Name" : @"Customize");}- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- return SGSectionHeaderHeight;+ return section == SGAddTabSectionRemove ? SGSectionGap : SGSectionHeaderHeight;}- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {@@ -474,6 +490,13 @@ typedef NS_ENUM(NSInteger, SGAddTabSection) {}return cell;}+ if (path.section == SGAddTabSectionRemove) {+ UITableViewCell *cell = SGDequeueCell(table, @"remove");+ SGFillCell(cell, @"Remove Tab", nil, SGRed(), nil);+ cell.selectionStyle = UITableViewCellSelectionStyleDefault;+ cell.accessibilityTraits = UIAccessibilityTraitButton;+ return cell;+ }UITableViewCell *cell = SGDequeueCell(table, @"customize");if (path.row == 0) {SGFillCell(cell, @"Link", _draft.uri ?: @"Choose a page or paste a link", nil, @"link");@@ -488,6 +511,10 @@ typedef NS_ENUM(NSInteger, SGAddTabSection) {- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {[table deselectRowAtIndexPath:path animated:YES];+ if (path.section == SGAddTabSectionRemove) {+ [self confirmRemove];+ return;+ }if (path.section != SGAddTabSectionCustomize) {[_name becomeFirstResponder];return;@@ -498,17 +525,33 @@ typedef NS_ENUM(NSInteger, SGAddTabSection) {[self.navigationController pushViewController:page animated:YES];}+// The tab, its link and its icon go with it, so the sheet asks first.+- (void)confirmRemove {+ NSString *name = _draft.title.length ? _draft.title : @"this tab";+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:[NSString stringWithFormat:@"Remove %@ from the tab bar?", name]+ preferredStyle:UIAlertControllerStyleActionSheet];+ [alert addAction:[UIAlertAction actionWithTitle:@"Remove Tab" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {+ void (^remove)(void) = self->_remove;+ [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];+ if (remove) remove();+ }]];+ [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];+ alert.popoverPresentationController.sourceView = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:SGAddTabSectionRemove]];+ [self presentViewController:alert animated:YES completion:nil];+}+@end-void SGPresentAddTabSheet(UIViewController *owner, NSArray<NSDictionary *> *presets, void (^add)(NSDictionary *tab)) {- SGAddTabPage *page = [[SGAddTabPage alloc] initWithPresets:presets add:add];+static void presentSheet(UIViewController *owner, SGAddTabPage *page) {UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:page];// Outside Spotify's own stacks the sheet would take the system's appearance, light in light mode.nav.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;UISheetPresentationController *sheet = nav.sheetPresentationController;- // Tall enough for the name and the two rows under the navigation bar; the keyboard lifts it.+ // Tall enough for the name and the two rows under the navigation bar, and Remove Tab while editing; the+ // keyboard lifts it.+ CGFloat height = [page numberOfSectionsInTableView:page.tableView] > 2 ? 400 : 320;UISheetPresentationControllerDetent *compact = [UISheetPresentationControllerDetent customDetentWithIdentifier:kCompactDetent resolver:^CGFloat(id<UISheetPresentationControllerDetentResolutionContext> context) {- return MIN(320, context.maximumDetentValue);+ return MIN(height, context.maximumDetentValue);}];sheet.detents = @[compact, UISheetPresentationControllerDetent.largeDetent];sheet.selectedDetentIdentifier = kCompactDetent;@@ -516,3 +559,12 @@ void SGPresentAddTabSheet(UIViewController *owner, NSArray<NSDictionary *> *pressheet.prefersScrollingExpandsWhenScrolledToEdge = YES;[owner presentViewController:nav animated:YES completion:nil];}++void SGPresentAddTabSheet(UIViewController *owner, NSArray<NSDictionary *> *presets, void (^add)(NSDictionary *tab)) {+ presentSheet(owner, [[SGAddTabPage alloc] initWithPresets:presets add:add]);+}++void SGPresentEditTabSheet(UIViewController *owner, NSArray<NSDictionary *> *presets, NSDictionary *tab,+ void (^save)(NSDictionary *tab), void (^remove)(void)) {+ presentSheet(owner, [[SGAddTabPage alloc] initWithTab:tab presets:presets save:save remove:remove]);+}