Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: navbar hide labels
Vojtěch Škopekd4ebbd026879
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex c100966e..889e0f2a 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -197,7 +197,8 @@ the bar shows them: drag to reorder, tap to hide or show, and Add a tab puts a pany `spotify:` link on the bar with one of Encore's own glyphs. 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.+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.## Adding a featurediff --git a/tweak/Sources/Redesigned/Navbar/Navbar.h b/tweak/Sources/Redesigned/Navbar/Navbar.hindex 4e3f60d2..26e6df28 100644--- a/tweak/Sources/Redesigned/Navbar/Navbar.h+++ b/tweak/Sources/Redesigned/Navbar/Navbar.h@@ -5,6 +5,8 @@#import <UIKit/UIKit.h>#define SGRKeyNavbar @"spotifyglass.redesign.navbar"+// Icons only on the glass bar. Off unless set; applies as soon as the bar lays out again.+#define SGRKeyNavbarHideLabels @"spotifyglass.redesign.navbar.hideLabels"extern NSString *const SGRNavbarID; // NSString, the entry's identityextern NSString *const SGRNavbarTitle; // NSString, the name in the settings list and under the icondiff --git a/tweak/Sources/Redesigned/Navbar/NavbarSettings.m b/tweak/Sources/Redesigned/Navbar/NavbarSettings.mindex ff75ef98..d58bae3c 100644--- a/tweak/Sources/Redesigned/Navbar/NavbarSettings.m+++ b/tweak/Sources/Redesigned/Navbar/NavbarSettings.m@@ -213,6 +213,7 @@ typedef NS_ENUM(NSInteger, SGRNavbarSection) {}- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {+ if (section == SGRNavbarSectionSwitch) return 2;return section == SGRNavbarSectionTabs ? (NSInteger)_entries.count : 1;}@@ -238,10 +239,12 @@ typedef NS_ENUM(NSInteger, SGRNavbarSection) {UITableViewCell *cell = SGDequeueCell(table, @"navbar");switch (path.section) {case SGRNavbarSectionSwitch: {- SGFillCell(cell, @"Custom navbar", nil, nil, nil);+ BOOL labels = path.row == 1;+ SGFillCell(cell, labels ? @"Hide labels" : @"Custom navbar", labels ? @"Icons only" : nil, nil, nil);UISwitch *toggle = [UISwitch new];toggle.onTintColor = SGGreen();- toggle.on = SGEnabled(SGRKeyNavbar);+ toggle.tag = path.row;+ toggle.on = labels ? SGHidden(SGRKeyNavbarHideLabels) : SGEnabled(SGRKeyNavbar);[toggle addTarget:self action:@selector(toggled:) forControlEvents:UIControlEventValueChanged];cell.accessoryView = toggle;break;@@ -313,7 +316,7 @@ typedef NS_ENUM(NSInteger, SGRNavbarSection) {}- (void)toggled:(UISwitch *)toggle {- SGSetEnabled(SGRKeyNavbar, toggle.on);+ SGSetEnabled(toggle.tag == 1 ? SGRKeyNavbarHideLabels : SGRKeyNavbar, toggle.on);SGRRefreshTabBar();}diff --git a/tweak/Sources/Redesigned/Navbar/TabBar.x b/tweak/Sources/Redesigned/Navbar/TabBar.xindex bc08eb83..165d95c4 100644--- a/tweak/Sources/Redesigned/Navbar/TabBar.x+++ b/tweak/Sources/Redesigned/Navbar/TabBar.x@@ -191,16 +191,19 @@ static void forwardTap(UIView *item) {});}-// UIKit's item views are private, so the item under a touch is the one whose title label is nearest.+// UIKit's item views are private, so the item under a touch is the one whose title label or glyph is+// nearest. With the labels hidden only the glyph is left; UIKit shows the item's own image instance.- (UITabBarItem *)itemAt:(CGPoint)point {__block UITabBarItem *nearest = nil;__block CGFloat best = CGFLOAT_MAX;SGForEachView(self, ^(UIView *v) {- if (![v isKindOfClass:UILabel.class] || v.bounds.size.width < 1) return;+ BOOL label = [v isKindOfClass:UILabel.class], glyph = [v isKindOfClass:UIImageView.class];+ if ((!label && !glyph) || v.bounds.size.width < 1) return;CGFloat distance = fabs([v convertPoint:CGPointMake(CGRectGetMidX(v.bounds), 0) toView:self].x - point.x);if (distance >= best) return;for (UITabBarItem *item in self.items) {- if (![((UILabel *)v).text isEqualToString:item.title]) continue;+ UIImage *image = glyph ? ((UIImageView *)v).image : nil;+ if (label ? ![((UILabel *)v).text isEqualToString:item.title] : !image || (image != item.image && image != item.selectedImage)) continue;best = distance;nearest = item;break;@@ -288,10 +291,12 @@ static void syncBar(UIView *stockBar) {NSArray<UIView *> *sources = tabItems(stockBar);if (!sources.count) return;+ // An item with no title is drawn by UIKit as its glyph alone, centred, on a bar of the same height.+ BOOL hideLabels = SGHidden(SGRKeyNavbarHideLabels);if (![sources isEqualToArray:bar.sources]) {NSMutableArray<UITabBarItem *> *items = [NSMutableArray array];- for (UIView *source in sources) [items addObject:[[UITabBarItem alloc] initWithTitle:labelIn(source).text image:nil tag:items.count]];+ for (UIView *source in sources) [items addObject:[[UITabBarItem alloc] initWithTitle:hideLabels ? nil : labelIn(source).text image:nil tag:items.count]];bar.sources = sources;[bar setItems:items animated:NO];NSMutableString *out = [NSMutableString stringWithString:@"tab bar icons"];@@ -313,8 +318,8 @@ static void syncBar(UIView *stockBar) {if (!item.image) item.image = glyphOf(sources[i], NO);if (!item.selectedImage || item.selectedImage == item.image) item.selectedImage = glyphOf(sources[i], YES);missing |= !item.image || !item.selectedImage;- NSString *title = labelIn(sources[i]).text;- if (title.length && ![title isEqualToString:item.title]) item.title = title;+ NSString *title = hideLabels ? nil : labelIn(sources[i]).text;+ if (hideLabels ? item.title != nil : title.length && ![title isEqualToString:item.title]) item.title = title;if (!selected && isActive(sources[i])) selected = item;}if (selected && bar.selectedItem != selected) bar.selectedItem = selected;