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

fix: the minimized bar keeps tab names whole and restores both bars at a tap

My-Name-Is-Jeffe6141dad8c0b
diff --git a/docs/tweaks.md b/docs/tweaks.md
index 4df9d942..6623358e 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -359,8 +359,13 @@ Redesigned:
minimizes the bar to two circles, the first or current tab and the last, with the now playing card
between them, and a scroll back up, its top, another tab or the player brings it back
(TabBarMinimize.x, MinimizeStep.h; the Player page's Apple Music style). Spotify's container is no
- UITabBarController, so UIKit's tabBarMinimizeBehavior and bottomAccessory cannot do it. Laid out on
- the Mac against harness/tabbar/ (`mini`), the scroll's steps checked by harness/tabbar/minimize-check.c
+ UITabBarController, so UIKit's tabBarMinimizeBehavior and bottomAccessory cannot do it. The bars,
+ their circles and the card move as one, on one spring of their own (SGRMotionBar, 0.34 s, no
+ overshoot; at once under Reduce Motion), from what is on screen, so a change turned back half way
+ carries on from there. Laid out on
+ the Mac against harness/tabbar/ (`mini`; a tap on the leading circle `tap`, real flings that turn
+ the bar half way `turns`, a minimize from inside Spotify's own animations `nested`, every frame of
+ the move sampled `motion`), the scroll's steps checked by harness/tabbar/minimize-check.c
NowPlayingBar/ the glass now playing bar (NowPlayingBar.x), with Spotify's device button on it hidden on request
(BarConnect.x, its own key and its own row on the Player page, apart from the native look's). In a Jam the
glass stays on the track and Spotify's Jam strip gets a pane of its own above it (harness/tabbar/, jam)
diff --git a/harness/addtab/stubs.m b/harness/addtab/stubs.m
index 42cda7aa..9a2c5936 100644
--- a/harness/addtab/stubs.m
+++ b/harness/addtab/stubs.m
@@ -1,12 +1,20 @@
// 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).
+// the glass bar's refresh, the Kit's accent, the titles' shrink as TabBar.x has it, 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) {}
+void SGRShrinkTabTitles(UIView *bar) {
+ for (UIView *sub in bar.subviews) {
+ SGRShrinkTabTitles(sub);
+ if (![sub isKindOfClass:UILabel.class]) continue;
+ ((UILabel *)sub).adjustsFontSizeToFitWidth = YES;
+ ((UILabel *)sub).minimumScaleFactor = 0.8;
+ }
+}
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.
diff --git a/harness/tabbar/README.md b/harness/tabbar/README.md
index 5e582969..4003e620 100644
--- a/harness/tabbar/README.md
+++ b/harness/tabbar/README.md
@@ -53,6 +53,61 @@ playing bar (through the hook on the page's `TouchPassthroughView`); expanded ag
it. Every report also gives the frame of the fade under the bars. The mock card's labels have fixed
frames, so how Spotify's own content takes the narrower card is not shown here.
+`names` logs every title the glass bars show and whether UIKit cut it short ("CUT", against the width the text
+needs at the smallest size its label may shrink to): at rest, as the bar starts to expand from minimized, mid-way,
+once expanded, after four turns 0.1 s apart, after a minimize and an expand with no animation (the player opening
+and closing), and after another layout pass. Each line ends with how many are cut, which should be 0. `split2`
+sets Create apart as well as Search, `five` adds a fifth tab and `long` gives two tabs long names (`names split2`,
+`names split five long`). The log is read most reliably from the console:
+`xcrun simctl launch --console-pty <udid> com.vojta.tabbarharness names split2`.
+
+2026-10-06, iPhone 17 Pro on iOS 27.0, before the fix: every name read "…" while the bar grew (8 cut), Search and Your Library stayed cut after the minimize and expand with no animation, and with two
+split tabs their names stayed "Sea…" and "Cre…" at rest for good. A split Search (32 pt for 35) and long names
+were cut at rest. After it, 0 everywhere, except a name that does not fit even at 8 pt ("Your Library and
+Downloads" beside a split tab), which UIKit still cuts.
+
+`touch.m` makes touches the way a finger's arrive (a `UITouch` and the touches event with the IOHIDEvent
+UIKit's gesture recognizers read, the private calls KIF makes), so the scenarios below tap the glass bar and
+fling the list through UIKit's own recognizers and scrolling. Checked on iOS 27.0 in the simulator only.
+
+`tap` minimizes the bar at 1 s, logs at 2.5 s what a finger on the leading circle lands on (and with `split`
+on the trailing one), and taps it. Both should land on a `_UITabButton` of their own glass bar, and after
+the tap at 3.5 s and 5 s the bar should be expanded with Home selected, as `none` has it. 2026-10-06, iPhone
+17 Pro on iOS 27.0, before the fix: the leading circle's touch landed on the now playing bar's container
+view (a plain `UIView` here), which the hook on `TouchPassthroughView` handed it because that view keeps the
+screen's width when the card is narrowed into the row; the bar stayed minimized. After it, `_UITabButton`,
+and the bar expanded.
+
+`turns` flings the list for real: down from its top to minimize, back up and down again half way through
+that, back up with a finger stopping the list, and four turns 0.15 s apart. `nested` minimizes the bar from
+inside a property animator left paused a third of the way (as a header that follows the scroll keeps one)
+and expands it inside a 3 s animation block. Each check says whether the bar and the card agree (the
+circle 21 pt in and the card in its row, or the whole platter and the card above it), what the screen
+shows, how many animations are left, and IN STEP or OUT OF STEP. 2026-10-06, iPhone 17 Pro on iOS 27.0,
+before the fix: `nested` stopped with the circle at x 107 on its way along the row and the card 22 of its
+67 pt down, 50 animations held, the phone's screenshot of a bar left half minimized; the expand took
+the block's 3 s. After it, every check IN STEP with one animation (UIKit's own), at rest at once.
+
+`motion` samples what the screen shows (the presentation layers) every 1/60 s: the main bar's platter, its
+leftmost glyph, the split bar's platter and the card's glass, across six stretches of 1 s: a minimize, an
+expand, each of them turned back 0.15 s in, a minimize again, and four turns 0.1 s apart. Each logs the largest
+change in x, y, width or height from one frame to the next (a frame the simulator skipped counts as that many)
+and how often the view watched was a new one, then a check and the names. `timeline` logs every sample. The
+stretches run one after another and time their turns from their own start: dispatch_after may run a block a
+tenth of its delay late, so steps timed from the launch, as `names` times its quick turns and `tap` its tap and
+the report after it, can fall together (one `tap` run in three reported the bar before the tap's touch-up).
+A critically damped spring moving the platter's 298 pt peaks at some 50 pt a frame over 0.34 s; more is a jump.
+A single sample off its neighbours at a turn is one read in the turn's own run loop pass, before its animations
+are committed.
+
+2026-10-06, iPhone 17 Pro on iOS 27.0. Before the fix, every minimize laid the circle's one item out in the
+full bar first: the platter went from 360 pt wide at x 21 to 100 pt at x 145 in one frame (259.7 pt) and the
+Home glyph from x 40 to 183 (142.7 pt), then slid back to the leading end; an expand turned back jumped 108 pt
+and four quick turns 191.6 pt. The tabs' titles were made again after the spring had started. After it: the
+largest step 49 pt for the platter (36 with a split tab), 16 for the card (27), 3.8 for the glyph away from the
+turns, no title cut at any point, every check IN STEP. Under Reduce Motion (`defaults write
+com.apple.Accessibility ReduceMotionEnabled` in the simulator) the bar and the card change in the same frame.
+
`minimize-check.c` runs the scroll's steps (`MinimizeStep.h`) on the Mac:
cc -I../../tweak/Sources/Redesigned/Navbar minimize-check.c -o build/minimize-check && build/minimize-check
diff --git a/harness/tabbar/build.sh b/harness/tabbar/build.sh
index a39d05a1..65f82498 100755
--- a/harness/tabbar/build.sh
+++ b/harness/tabbar/build.sh
@@ -14,13 +14,13 @@ SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)
xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-arc -g -O0 \
-I"$SRC" -I"$SRC/Redesigned/Navbar" -I"$SRC/Redesigned/NowPlayingBar" -I"$SRC/Shared/Navigation" -I"$OUT/gen" -isysroot "$SDK" \
-Wno-deprecated-declarations \
- "$(dirname "$0")/main.m" "$(dirname "$0")/stubs.m" \
+ "$(dirname "$0")/main.m" "$(dirname "$0")/stubs.m" "$(dirname "$0")/touch.m" \
"$OUT"/gen/*.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 \
"$SRC"/Redesigned/Kit/SGRTokens.m "$SRC"/Redesigned/Kit/SGRGlass.m \
"$SRC"/Redesigned/Navbar/NavbarLayout.m "$SRC"/Shared/Navigation/TabIcons.m \
- -framework UIKit -framework QuartzCore -framework CoreGraphics -framework Foundation \
+ -framework UIKit -framework IOKit -framework QuartzCore -framework CoreGraphics -framework Foundation \
-o "$OUT/TabBarHarness.app/TabBarHarness"
# iOS 27 ends an app without a scene delegate at launch, so the scene is named here.
diff --git a/harness/tabbar/main.m b/harness/tabbar/main.m
index 0ef1cddc..26a4c59b 100644
--- a/harness/tabbar/main.m
+++ b/harness/tabbar/main.m
@@ -234,12 +234,19 @@ static UIView *item(Class cls, NSString *title, NSString *symbol, BOOL active) {
UIView *compact = [_TtC23NavigationUI_TabBarImpl17TabBarCompactView new];
compact.translatesAutoresizingMaskIntoConstraints = NO;
[self.bar addSubview:compact];
- UIStackView *row = [[UIStackView alloc] initWithArrangedSubviews:@[
+ // `five` adds a fifth tab, `long` gives two tabs long names, as tabs of the user's own can have.
+ NSArray<NSString *> *args = NSProcessInfo.processInfo.arguments;
+ BOOL longNames = [args containsObject:@"long"];
+ NSMutableArray<UIView *> *tabs = [NSMutableArray arrayWithArray:@[
item(_TtC23NavigationUI_TabBarImpl21TabBarItemElementView.class, @"Home", @"house.fill", YES),
item(_TtC23NavigationUI_TabBarImpl21TabBarItemElementView.class, @"Search", @"magnifyingglass", NO),
- item(_TtC23NavigationUI_TabBarImpl21TabBarItemElementView.class, @"Your Library", @"books.vertical", NO),
+ item(_TtC23NavigationUI_TabBarImpl21TabBarItemElementView.class, longNames ? @"Your Library and Downloads" : @"Your Library", @"books.vertical", NO),
item(_TtC25CreateMenu_TabBarItemImpl24CreateMenuTabBarItemView.class, @"Create", @"plus", NO),
]];
+ if ([args containsObject:@"five"]) {
+ [tabs addObject:item(_TtC23NavigationUI_TabBarImpl21TabBarItemElementView.class, longNames ? @"Discover Weekly" : @"Liked Songs", @"heart", NO)];
+ }
+ UIStackView *row = [[UIStackView alloc] initWithArrangedSubviews:tabs];
row.distribution = UIStackViewDistributionFillEqually;
row.accessibilityIdentifier = @"tabs-container-view-identifier";
row.translatesAutoresizingMaskIntoConstraints = NO;
@@ -375,6 +382,10 @@ static UIView *item(Class cls, NSString *title, NSString *symbol, BOOL active) {
extern CGRect SGRNowPlayingCardFrameIn(UIView *host, CGFloat *radius);
extern void SGRSetTabBarMinimized(BOOL minimized, BOOL animated);
+extern BOOL SGRTabBarMinimized(void);
+// touch.m: a finger's touches, through UIKit's own recognizers.
+extern void SGHarnessTap(UIWindow *window, CGPoint point);
+extern void SGHarnessDrag(UIWindow *window, CGPoint from, CGPoint to, NSTimeInterval seconds);
static UIView *platterIn(UIView *root) {
// UIKit._UITabBarItemPlatterView on iOS 27; BarTransition.x looks for the same suffix.
@@ -482,6 +493,179 @@ static void report(SGHarnessChrome *chrome, NSString *moment) {
}
}
+// Every title the glass bars show, and whether UIKit cut it short: the width its text needs at the
+// smallest size the label may shrink to, against the width it was given.
+static void reportNames(SGHarnessChrome *chrome, NSString *moment) {
+ NSMutableString *out = [NSMutableString stringWithFormat:@"[harness] %@ names", moment];
+ NSUInteger cut = 0;
+ for (UITabBar *bar in systemBarsIn(chrome.tabs.bar)) {
+ if (bar.hidden) continue;
+ [out appendFormat:@" | bar %.0f wide:", bar.bounds.size.width];
+ NSMutableArray<UIView *> *walk = [NSMutableArray arrayWithObject:bar];
+ while (walk.count) {
+ UIView *v = walk.firstObject;
+ [walk removeObjectAtIndex:0];
+ [walk addObjectsFromArray:v.subviews];
+ if (![v isKindOfClass:UILabel.class] || !v.window) continue;
+ BOOL shown = YES;
+ for (UIView *up = v; up && up != bar; up = up.superview) shown &= !up.hidden && up.alpha > 0.01;
+ if (!shown) continue;
+ UILabel *label = (UILabel *)v;
+ if (!label.text.length) continue;
+ CGFloat need = [label.text sizeWithAttributes:@{NSFontAttributeName: label.font}].width;
+ CGFloat scale = label.adjustsFontSizeToFitWidth && label.minimumScaleFactor > 0 ? label.minimumScaleFactor : 1;
+ BOOL isCut = need * scale > label.bounds.size.width + 1;
+ cut += isCut;
+ if ([NSProcessInfo.processInfo.arguments containsObject:@"tree"]) {
+ NSMutableString *chain = [NSMutableString string];
+ for (UIView *up = label; up && up != bar; up = up.superview) [chain appendFormat:@" < %@%@", NSStringFromClass(up.class), NSStringFromCGRect(up.frame)];
+ NSLog(@"[harness] %@ label%@", moment, chain);
+ }
+ [out appendFormat:@" \"%@\" %.0f/%.0f@%.1fpt%@", label.text, label.bounds.size.width, ceil(need), label.font.pointSize, isCut ? @" CUT" : @""];
+ }
+ }
+ [out appendFormat:@" | %lu cut", (unsigned long)cut];
+ NSLog(@"%@", out);
+}
+
+// Whether the bar and the card agree: minimized, the platter is the 62 pt circle 21 pt in and the card is in
+// its row; expanded, the platter is the whole bar's and the card stands above it. With what the screen shows
+// (the presentation layers) and how many animations are still on the bar, its items and the card.
+static void check(SGHarnessChrome *chrome, NSString *moment) {
+ UIWindow *window = chrome.view.window;
+ UITabBar *bar = systemBarIn(chrome.tabs.bar);
+ UIView *platter = platterIn(bar);
+ CGRect circle = [platter convertRect:platter.bounds toView:window];
+ CGRect card = SGRNowPlayingCardFrameIn(window, NULL);
+ BOOL minimized = SGRTabBarMinimized();
+ BOOL leads = fabs(circle.size.width - 62) < 1 && fabs(circle.origin.x - 21) < 1;
+ BOOL docked = CGRectGetMinY(card) > CGRectGetMinY(circle) - 1;
+ UIView *moved = chrome.npb.subviews.firstObject;
+ CALayer *shown = platter.layer.presentationLayer, *shownCard = moved.layer.presentationLayer;
+ CGRect shownCircle = shown ? [shown convertRect:shown.bounds toLayer:window.layer] : CGRectNull;
+ __block NSUInteger running = 0;
+ SGForEachView(bar, ^(UIView *v) { running += v.layer.animationKeys.count; });
+ SGForEachView(moved, ^(UIView *v) { running += v.layer.animationKeys.count; });
+ BOOL inStep = minimized == leads && minimized == docked;
+ NSLog(@"[harness] %@ check: %@ | circle %@ (shown %@) | card %@ (shown moved %.0f) | %lu animations | %@", moment,
+ minimized ? @"minimized" : @"expanded", NSStringFromCGRect(circle), NSStringFromCGRect(shownCircle), NSStringFromCGRect(card),
+ shownCard ? shownCard.transform.m42 : 0, (unsigned long)running, inStep ? @"IN STEP" : @"OUT OF STEP");
+}
+
+// The list from its top, `drag` points up (a scroll down) or down (a scroll back up), let go moving.
+static void fling(SGHarnessChrome *chrome, CGFloat drag) {
+ UIWindow *window = chrome.view.window;
+ CGFloat from = drag > 0 ? 600 : 300;
+ SGHarnessDrag(window, CGPointMake(200, from), CGPointMake(200, from - drag), 0.12);
+}
+
+// What the screen shows of a view: its presentation layer's frame in the window's.
+static CGRect shownFrame(UIView *view, UIWindow *window) {
+ if (!view.window) return CGRectNull;
+ CALayer *layer = view.layer.presentationLayer ?: view.layer, *top = window.layer.presentationLayer ?: window.layer;
+ return [layer convertRect:layer.bounds toLayer:top];
+}
+
+static UIView *firstOf(UIView *root, BOOL (^match)(UIView *)) {
+ if (match(root)) return root;
+ for (UIView *sub in root.subviews) {
+ UIView *found = firstOf(sub, match);
+ if (found) return found;
+ }
+ return nil;
+}
+
+// `motion`: the presentation frames of what moves, sampled every frame across a stretch: the main bar's platter, its
+// leading glyph, the split bar's platter and the card's glass. Each stretch logs the largest change from one frame to
+// the next (x, y, width or height), when it was, and how many times the view under watch was a new one. A spring
+// moves these some 20 pt a frame at most; more is a reversal snapping to the old target, or a view made anew
+// somewhere else.
+static NSString *const kWatched[4] = {@"platter", @"glyph", @"split platter", @"card"};
+
+@interface SGHarnessSampler : NSObject {
+@public
+ CGRect last[4];
+ CGFloat worst[4];
+ NSTimeInterval worstAt[4];
+ NSUInteger replaced[4];
+}
+@property (nonatomic, weak) SGHarnessChrome *chrome;
+@property (nonatomic, copy) NSString *moment;
+@property (nonatomic, strong) CADisplayLink *link;
+@property (nonatomic) NSTimeInterval start, lastTick;
+@property (nonatomic) NSUInteger frames;
+@property (nonatomic, strong) NSMutableArray *views;
+@end
+
+@implementation SGHarnessSampler
+
+- (NSArray *)watched {
+ NSArray<UITabBar *> *bars = systemBarsIn(self.chrome.tabs.bar);
+ UITabBar *main = bars.firstObject, *apart = bars.count > 1 && !bars[1].hidden ? bars[1] : nil;
+ UIWindow *window = self.chrome.view.window;
+ __block UIView *glyph = nil;
+ __block CGFloat leftmost = CGFLOAT_MAX;
+ SGForEachView(main, ^(UIView *v) {
+ if (![v isKindOfClass:UIImageView.class] || !((UIImageView *)v).image || v.bounds.size.width < 10 || v.bounds.size.width > 40) return;
+ for (UIView *up = v; up && up != main; up = up.superview) if (up.hidden || up.alpha < 0.01) return;
+ CGFloat x = CGRectGetMinX(shownFrame(v, window));
+ if (x < leftmost) { leftmost = x; glyph = v; }
+ });
+ UIView *card = firstOf(self.chrome.npb.subviews.firstObject, ^BOOL(UIView *v) {
+ return [v isKindOfClass:UIVisualEffectView.class] && ((UIVisualEffectView *)v).effect && v.bounds.size.height > 40;
+ });
+ return @[platterIn(main) ?: NSNull.null, glyph ?: NSNull.null, (apart ? platterIn(apart) : nil) ?: NSNull.null, card ?: NSNull.null];
+}
+
+- (void)begin:(NSString *)moment {
+ self.moment = moment;
+ for (int i = 0; i < 4; i++) { last[i] = CGRectNull; worst[i] = 0; replaced[i] = 0; }
+ self.views = [NSMutableArray arrayWithArray:@[NSNull.null, NSNull.null, NSNull.null, NSNull.null]];
+ self.frames = 0;
+ self.lastTick = 0;
+ self.start = CACurrentMediaTime();
+ self.link = [CADisplayLink displayLinkWithTarget:self selector:@selector(tick)];
+ self.link.preferredFrameRateRange = CAFrameRateRangeMake(60, 60, 60);
+ [self.link addToRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
+}
+
+- (void)tick {
+ NSArray *now = [self watched];
+ UIWindow *window = self.chrome.view.window;
+ self.frames++;
+ // A frame the simulator skipped counts as that many: the step is per 1/60 s.
+ NSTimeInterval time = CACurrentMediaTime();
+ CGFloat elapsed = self.lastTick > 0 ? MAX(1, round((time - self.lastTick) * 60)) : 1;
+ self.lastTick = time;
+ NSMutableString *line = [NSMutableString stringWithFormat:@"[harness] %@ %.3f", self.moment, time - self.start];
+ for (int i = 0; i < 4; i++) {
+ UIView *v = now[i] == NSNull.null ? nil : now[i];
+ CGRect frame = v ? shownFrame(v, window) : CGRectNull;
+ if (v && self.views[i] != NSNull.null && self.views[i] != v) replaced[i]++;
+ self.views[i] = v ?: NSNull.null;
+ if (!CGRectIsNull(frame) && !CGRectIsNull(last[i])) {
+ CGFloat step = MAX(MAX(fabs(frame.origin.x - last[i].origin.x), fabs(frame.origin.y - last[i].origin.y)),
+ MAX(fabs(frame.size.width - last[i].size.width), fabs(frame.size.height - last[i].size.height))) / elapsed;
+ if (step > worst[i]) { worst[i] = step; worstAt[i] = time - self.start; }
+ }
+ last[i] = frame;
+ if (!CGRectIsNull(frame)) [line appendFormat:@" | %@ x %.1f y %.1f w %.1f", kWatched[i], frame.origin.x, frame.origin.y, frame.size.width];
+ }
+ // `timeline` logs every sample.
+ if ([NSProcessInfo.processInfo.arguments containsObject:@"timeline"]) NSLog(@"%@", line);
+}
+
+- (void)end {
+ [self.link invalidate];
+ NSMutableString *out = [NSMutableString stringWithFormat:@"[harness] %@ motion over %lu frames:", self.moment, (unsigned long)self.frames];
+ for (int i = 0; i < 4; i++) {
+ if (CGRectIsNull(last[i]) && !worst[i]) continue;
+ [out appendFormat:@" | %@ largest step %.1f pt at %.2f s, made anew %lu times", kWatched[i], worst[i], worstAt[i], (unsigned long)replaced[i]];
+ }
+ NSLog(@"%@", out);
+}
+@end
+
#pragma mark - the app
// Before every %ctor, so the redesign's gate reads on.
@@ -531,6 +715,150 @@ static void after(double seconds, dispatch_block_t block) {
after(3.5, ^{ SGRSetTabBarMinimized(NO, YES); });
after(5.0, ^{ report(chrome, @"expanded again"); });
}
+ // `tap`: the bar minimized at 1 s, then what a finger on the leading circle lands on, and that tap played.
+ if ([mode isEqualToString:@"tap"]) {
+ after(1.0, ^{ SGRSetTabBarMinimized(YES, YES); });
+ after(2.5, ^{
+ report(chrome, @"minimized");
+ UITabBar *bar = systemBarIn(chrome.tabs.bar);
+ UIView *platter = platterIn(bar);
+ UIWindow *window = chrome.view.window;
+ CGRect circle = [platter convertRect:platter.bounds toView:window];
+ UIView *hit = [window hitTest:CGPointMake(CGRectGetMidX(circle), CGRectGetMidY(circle)) withEvent:nil];
+ NSLog(@"[harness] touch on the leading circle %@ lands on %@, on the glass bar: %d", NSStringFromCGRect(circle),
+ NSStringFromClass(hit.class), [hit isDescendantOfView:bar]);
+ for (UIView *v = hit; v && v != window; v = v.superview) {
+ for (UIGestureRecognizer *r in v.gestureRecognizers) NSLog(@"[harness] recognizer %@ on %@", NSStringFromClass(r.class), NSStringFromClass(v.class));
+ if ([v isKindOfClass:UIControl.class]) NSLog(@"[harness] control %@", NSStringFromClass(v.class));
+ }
+ // With `split`, the trailing circle keeps its own touches too.
+ for (UITabBar *other in systemBarsIn(chrome.tabs.bar)) {
+ UIView *otherPlatter = other == bar || other.hidden ? nil : platterIn(other);
+ if (!otherPlatter) continue;
+ CGRect trailing = [otherPlatter convertRect:otherPlatter.bounds toView:window];
+ UIView *otherHit = [window hitTest:CGPointMake(CGRectGetMidX(trailing), CGRectGetMidY(trailing)) withEvent:nil];
+ NSLog(@"[harness] touch on the trailing circle %@ lands on %@, on its glass bar: %d", NSStringFromCGRect(trailing),
+ NSStringFromClass(otherHit.class), [otherHit isDescendantOfView:other]);
+ }
+ SGHarnessTap(window, CGPointMake(CGRectGetMidX(circle), CGRectGetMidY(circle)));
+ });
+ after(3.5, ^{ report(chrome, @"after the tap"); });
+ after(3.6, ^{ reportSelection(chrome, @"after the tap"); });
+ // It stays expanded until the list is scrolled down again.
+ after(5.0, ^{ report(chrome, @"a while after the tap"); });
+ }
+ // `turns`: real flings on the list, from its top: one down that minimizes the bar, one back up that turns it
+ // half way, then down again half way through that, and a finger stopping the list as the bar minimizes.
+ // Every check at rest should be IN STEP with no animations left.
+ if ([mode isEqualToString:@"turns"]) {
+ UITableView *list = (UITableView *)chrome.tabs.childViewControllers.firstObject.view;
+ after(0.7, ^{ [list setContentOffset:CGPointMake(0, -list.adjustedContentInset.top) animated:NO]; });
+ after(1.0, ^{ fling(chrome, 250); });
+ after(1.3, ^{ check(chrome, @"minimizing"); });
+ after(2.4, ^{ check(chrome, @"minimized"); });
+ // Room both ways again after the report at 2.5 takes the list to its end.
+ after(2.7, ^{ [list setContentOffset:CGPointMake(0, 300) animated:NO]; });
+ after(3.0, ^{ fling(chrome, -150); });
+ after(3.25, ^{ fling(chrome, 250); });
+ after(5.0, ^{ check(chrome, @"after turning back half way"); });
+ after(5.5, ^{ fling(chrome, -150); });
+ after(5.75, ^{ SGHarnessTap(chrome.view.window, CGPointMake(200, 400)); });
+ after(7.0, ^{ check(chrome, @"after a finger stopped the list"); });
+ after(7.5, ^{ fling(chrome, 250); });
+ after(7.65, ^{ fling(chrome, -150); });
+ after(7.8, ^{ fling(chrome, 250); });
+ after(7.95, ^{ fling(chrome, -150); });
+ after(9.5, ^{ check(chrome, @"after four quick turns"); });
+ }
+ // `motion`: a minimize and an expand, each turned back 0.15 s in, and four turns 0.1 s apart, sampled every
+ // frame (SGHarnessSampler). No largest step should be much over a spring's, nothing should be made anew while it
+ // moves, names should be whole mid-expand, and every check IN STEP.
+ if ([mode isEqualToString:@"motion"]) {
+ static SGHarnessSampler *sampler;
+ sampler = [SGHarnessSampler new];
+ sampler.chrome = chrome;
+ // Each stretch lasts 1 s and the next starts 0.3 s after it; turns are timed from the stretch's start,
+ // since dispatch_after may run a block up to a tenth of its delay late, which at 3 s swallowed a turn
+ // 0.15 s after another. The first turn of each goes the other way from where the bar is.
+ NSArray *stretches = @[
+ @[@"minimize", @[@0]],
+ @[@"expand", @[@0]],
+ @[@"minimize turned back", @[@0, @0.15]],
+ @[@"minimize again", @[@0]],
+ @[@"expand turned back", @[@0, @0.15]],
+ @[@"four quick turns", @[@0, @0.1, @0.2, @0.3]],
+ ];
+ static void (^run)(NSUInteger);
+ run = ^(NSUInteger index) {
+ if (index >= stretches.count) {
+ reportNames(chrome, @"after the turns");
+ return;
+ }
+ NSString *moment = stretches[index][0];
+ NSArray<NSNumber *> *turns = stretches[index][1];
+ BOOL first = !SGRTabBarMinimized();
+ [sampler begin:moment];
+ for (NSUInteger i = 0; i < turns.count; i++) {
+ BOOL minimize = i % 2 == 0 ? first : !first;
+ after(turns[i].doubleValue, ^{ SGRSetTabBarMinimized(minimize, YES); });
+ }
+ after(0.15, ^{
+ if (!first) reportNames(chrome, [moment stringByAppendingString:@", 0.15 s in"]);
+ });
+ after(1.0, ^{
+ [sampler end];
+ check(chrome, moment);
+ reportNames(chrome, [moment stringByAppendingString:@", at rest"]);
+ after(0.3, ^{ run(index + 1); });
+ });
+ };
+ after(1.0, ^{ run(0); });
+ }
+ // `nested`: the bar minimized from inside someone else's animation: a property animator scrubbed by hand and
+ // left paused a third of the way, as a header that follows the scroll keeps one (at 1 s), and a plain
+ // animation block (at 4 s, expanding). Each check at rest should be IN STEP with no animations left.
+ if ([mode isEqualToString:@"nested"]) {
+ static UIViewPropertyAnimator *scrub;
+ after(1.0, ^{
+ UIView *page = chrome.tabs.childViewControllers.firstObject.view;
+ scrub = [[UIViewPropertyAnimator alloc] initWithDuration:1 curve:UIViewAnimationCurveLinear animations:^{
+ page.alpha = 0.9;
+ SGRSetTabBarMinimized(YES, YES);
+ }];
+ scrub.fractionComplete = 0.33;
+ });
+ after(2.4, ^{ check(chrome, @"minimized in a paused animator"); });
+ after(4.0, ^{
+ [UIView animateWithDuration:3 animations:^{ SGRSetTabBarMinimized(NO, YES); }];
+ });
+ after(4.4, ^{ check(chrome, @"expanding in a slow animation block"); });
+ after(5.6, ^{ check(chrome, @"expanded in a slow animation block"); });
+ }
+ // `names`: the titles at rest, after a minimize and expand, after scrolls that turn the bar back before
+ // it settles, and mid-expand; `split`, `five` and `long` change the bar. Every report should say 0 cut.
+ if ([mode isEqualToString:@"names"]) {
+ after(1.0, ^{ reportNames(chrome, @"at rest"); });
+ after(1.2, ^{ SGRSetTabBarMinimized(YES, YES); });
+ after(2.4, ^{
+ SGRSetTabBarMinimized(NO, YES);
+ reportNames(chrome, @"expanding");
+ });
+ after(2.55, ^{ reportNames(chrome, @"mid-expand"); });
+ after(4.0, ^{ reportNames(chrome, @"expanded"); });
+ after(4.2, ^{ SGRSetTabBarMinimized(YES, YES); });
+ after(4.3, ^{ SGRSetTabBarMinimized(NO, YES); });
+ after(4.4, ^{ SGRSetTabBarMinimized(YES, YES); });
+ after(4.5, ^{ SGRSetTabBarMinimized(NO, YES); });
+ after(6.0, ^{ reportNames(chrome, @"after quick turns"); });
+ after(6.2, ^{ SGRSetTabBarMinimized(YES, NO); });
+ after(6.4, ^{ SGRSetTabBarMinimized(NO, NO); });
+ after(7.0, ^{ reportNames(chrome, @"after a cut"); });
+ after(7.2, ^{
+ [chrome.tabs.bar setNeedsLayout];
+ [chrome.tabs.bar layoutIfNeeded];
+ });
+ after(7.5, ^{ reportNames(chrome, @"after Spotify lays out"); });
+ }
// `lit`: Library stands in for a tab of the mod's own whose page is up at 2 s, while Spotify still paints
// Home white: the glass bar selects Library. Home picked at 3.5 s takes the light back.
if ([mode isEqualToString:@"lit"]) {
diff --git a/harness/tabbar/stubs.m b/harness/tabbar/stubs.m
index e34ffffc..c53df6c0 100644
--- a/harness/tabbar/stubs.m
+++ b/harness/tabbar/stubs.m
@@ -12,11 +12,16 @@ __weak UIView *sgr_artistRoot = nil;
void SGRComposeTabBar(UIView *tabBar) {}
-// With `split` among the launch words, Search is a split tab, which TabBar.x stands on a bar of its own.
+// With `split` among the launch words, Search is a split tab, which TabBar.x stands on a bar of its own;
+// with `split2`, Create is one too.
BOOL SGRTabIsApart(UIView *item) {
- if (![NSProcessInfo.processInfo.arguments containsObject:@"split"]) return NO;
+ NSArray<NSString *> *args = NSProcessInfo.processInfo.arguments;
+ BOOL two = [args containsObject:@"split2"];
+ if (![args containsObject:@"split"] && !two) return NO;
for (UIView *sub in item.subviews) {
- if ([sub isKindOfClass:UILabel.class] && [((UILabel *)sub).text isEqualToString:@"Search"]) return YES;
+ if (![sub isKindOfClass:UILabel.class]) continue;
+ NSString *text = ((UILabel *)sub).text;
+ if ([text isEqualToString:@"Search"] || (two && [text isEqualToString:@"Create"])) return YES;
}
return NO;
}
diff --git a/harness/tabbar/touch.m b/harness/tabbar/touch.m
new file mode 100644
index 00000000..f8739f49
--- /dev/null
+++ b/harness/tabbar/touch.m
@@ -0,0 +1,111 @@
+// Touches made in the app, the way a finger's arrive: a UITouch and the touches event, each carrying the
+// IOHIDEvent UIKit's gesture recognizers read since iOS 9. The private calls are the ones KIF has made for
+// years; they let the harness tap the glass bar and fling the list with UIKit's own recognizers and
+// scrolling, not by calling the delegate. Checked on iOS 27.0 in the simulator only.
+#import <UIKit/UIKit.h>
+#import <mach/mach_time.h>
+
+typedef struct __IOHIDEvent *IOHIDEventRef;
+typedef double IOHIDFloat;
+IOHIDEventRef IOHIDEventCreateDigitizerEvent(CFAllocatorRef, uint64_t, uint32_t type, uint32_t index, uint32_t identity, uint32_t mask,
+ uint32_t buttons, IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, IOHIDFloat pressure,
+ IOHIDFloat barrel, Boolean range, Boolean touch, uint32_t options);
+IOHIDEventRef IOHIDEventCreateDigitizerFingerEventWithQuality(CFAllocatorRef, uint64_t, uint32_t index, uint32_t identity, uint32_t mask,
+ IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, IOHIDFloat pressure, IOHIDFloat twist,
+ IOHIDFloat minor, IOHIDFloat major, IOHIDFloat quality, IOHIDFloat density,
+ IOHIDFloat irregularity, Boolean range, Boolean touch, uint32_t options);
+void IOHIDEventAppendEvent(IOHIDEventRef parent, IOHIDEventRef child, uint32_t options);
+void IOHIDEventSetIntegerValue(IOHIDEventRef event, uint32_t field, long value);
+
+@interface UITouch (SGHarness)
+- (void)setWindow:(UIWindow *)window;
+- (void)setView:(UIView *)view;
+- (void)setPhase:(UITouchPhase)phase;
+- (void)setTimestamp:(NSTimeInterval)timestamp;
+- (void)setTapCount:(NSUInteger)count;
+- (void)_setLocationInWindow:(CGPoint)location resetPrevious:(BOOL)reset;
+- (void)_setIsFirstTouchForView:(BOOL)first;
+- (void)_setHidEvent:(IOHIDEventRef)event;
+- (void)setGestureView:(UIView *)view;
+@end
+
+@interface UIEvent (SGHarness)
+- (void)_clearTouches;
+- (void)_addTouch:(UITouch *)touch forDelayedDelivery:(BOOL)delayed;
+- (void)_setHIDEvent:(IOHIDEventRef)event;
+@end
+
+@interface UIApplication (SGHarness)
+- (UIEvent *)_touchesEvent;
+@end
+
+static const uint32_t kDigitizer = 11, kHand = 3, kRange = 1 << 0, kTouch = 1 << 1, kPosition = 1 << 2;
+static const uint32_t kDisplayIntegrated = (kDigitizer << 16) + 25;
+
+static IOHIDEventRef hidFor(UITouch *touch) {
+ uint64_t now = mach_absolute_time();
+ IOHIDEventRef hand = IOHIDEventCreateDigitizerEvent(kCFAllocatorDefault, now, kHand, 0, 0, kTouch, 0, 0, 0, 0, 0, 0, 0, 1, 0);
+ IOHIDEventSetIntegerValue(hand, kDisplayIntegrated, 1);
+ BOOL moved = touch.phase == UITouchPhaseMoved, down = touch.phase != UITouchPhaseEnded;
+ CGPoint at = [touch locationInView:touch.window];
+ IOHIDEventRef finger = IOHIDEventCreateDigitizerFingerEventWithQuality(kCFAllocatorDefault, now, 1, 2, moved ? kPosition : kRange | kTouch,
+ at.x, at.y, 0, 0, 0, 5, 5, 1, 1, 1, down, down, 0);
+ IOHIDEventSetIntegerValue(finger, kDisplayIntegrated, 1);
+ IOHIDEventAppendEvent(hand, finger, 0);
+ CFRelease(finger);
+ return hand;
+}
+
+static void deliver(UITouch *touch) {
+ IOHIDEventRef hid = hidFor(touch);
+ [touch _setHidEvent:hid];
+ UIEvent *event = [UIApplication.sharedApplication _touchesEvent];
+ [event _clearTouches];
+ [event _setHIDEvent:hid];
+ [event _addTouch:touch forDelayedDelivery:NO];
+ CFRelease(hid);
+ [UIApplication.sharedApplication sendEvent:event];
+}
+
+static UITouch *touchDown(UIWindow *window, CGPoint point) {
+ UITouch *touch = [UITouch new];
+ UIView *view = [window hitTest:point withEvent:nil];
+ [touch setWindow:window];
+ [touch _setLocationInWindow:point resetPrevious:YES];
+ [touch setView:view];
+ if ([touch respondsToSelector:@selector(setGestureView:)]) [touch setGestureView:view];
+ [touch setPhase:UITouchPhaseBegan];
+ [touch _setIsFirstTouchForView:YES];
+ [touch setTapCount:1];
+ [touch setTimestamp:NSProcessInfo.processInfo.systemUptime];
+ deliver(touch);
+ return touch;
+}
+
+static void touchTo(UITouch *touch, CGPoint point, UITouchPhase phase) {
+ [touch setTimestamp:NSProcessInfo.processInfo.systemUptime];
+ [touch _setLocationInWindow:point resetPrevious:NO];
+ [touch setPhase:phase];
+ deliver(touch);
+}
+
+// A tap at `point`, down and up 0.08 s apart.
+void SGHarnessTap(UIWindow *window, CGPoint point) {
+ UITouch *touch = touchDown(window, point);
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.08 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ touchTo(touch, point, UITouchPhaseEnded);
+ });
+}
+
+// A finger from `from` to `to` over `seconds`, a move every 1/60 s, let go while still moving: a fling.
+void SGHarnessDrag(UIWindow *window, CGPoint from, CGPoint to, NSTimeInterval seconds) {
+ UITouch *touch = touchDown(window, from);
+ NSUInteger steps = MAX(2, (NSUInteger)(seconds * 60));
+ for (NSUInteger i = 1; i <= steps; i++) {
+ CGFloat t = (CGFloat)i / steps;
+ CGPoint at = CGPointMake(from.x + (to.x - from.x) * t, from.y + (to.y - from.y) * t);
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(i * NSEC_PER_SEC / 60)), dispatch_get_main_queue(), ^{
+ touchTo(touch, at, i == steps ? UITouchPhaseEnded : UITouchPhaseMoved);
+ });
+ }
+}
diff --git a/tweak/Sources/Redesigned/Kit/SGRTokens.h b/tweak/Sources/Redesigned/Kit/SGRTokens.h
index 63c47ee2..ffad113d 100644
--- a/tweak/Sources/Redesigned/Kit/SGRTokens.h
+++ b/tweak/Sources/Redesigned/Kit/SGRTokens.h
@@ -56,6 +56,9 @@ typedef NS_ENUM(NSInteger, SGRMotion) {
// An ease out over 0.15 s, for what goes once the finger has let it go (the hold's 2x badge): nothing is
// watched on its way out. Kept under Reduce Motion like a fade.
SGRMotionExit,
+ // A spring with no overshoot over 0.34 s, for the tab bar minimizing and expanding with the now playing card:
+ // it happens many times a session, so it is quicker than a layout spring. At once under Reduce Motion.
+ SGRMotionBar,
};
// Runs `animations` with the motion's timing, or at once under Reduce Motion (except a fade, a response or an exit), and
// always calls `completion`. Only transform, alpha and colour belong in it while a page scrolls.
diff --git a/tweak/Sources/Redesigned/Kit/SGRTokens.m b/tweak/Sources/Redesigned/Kit/SGRTokens.m
index 8877689f..a18465af 100644
--- a/tweak/Sources/Redesigned/Kit/SGRTokens.m
+++ b/tweak/Sources/Redesigned/Kit/SGRTokens.m
@@ -17,6 +17,8 @@ const NSTimeInterval SGRCrossfade = 0.35;
// A layout spring settles in about this long without overshooting; a press gives a little back.
static const NSTimeInterval kLayoutDuration = 0.45, kPressDuration = 0.32;
+// The tab bar's minimize, in the 0.3 to 0.4 s Apple gives a repositioning spring.
+static const NSTimeInterval kBarDuration = 0.34;
static const CGFloat kPressDamping = 0.62;
// A response lands within the press feedback's budget, on a curve that is most of the way there at once.
static const NSTimeInterval kRespondDuration = 0.2;
@@ -89,7 +91,7 @@ BOOL SGRIncreaseContrast(void) {
void SGRAnimate(SGRMotion motion, void (^animations)(void), void (^completion)(BOOL finished)) {
if (!animations) return;
- if ((motion == SGRMotionLayout || motion == SGRMotionPress) && SGRReduceMotion()) {
+ if ((motion == SGRMotionLayout || motion == SGRMotionPress || motion == SGRMotionBar) && SGRReduceMotion()) {
[UIView performWithoutAnimation:animations];
if (completion) completion(YES);
return;
@@ -99,6 +101,9 @@ void SGRAnimate(SGRMotion motion, void (^animations)(void), void (^completion)(B
case SGRMotionLayout:
[UIView animateWithDuration:kLayoutDuration delay:0 usingSpringWithDamping:1 initialSpringVelocity:0 options:options animations:animations completion:completion];
break;
+ case SGRMotionBar:
+ [UIView animateWithDuration:kBarDuration delay:0 usingSpringWithDamping:1 initialSpringVelocity:0 options:options animations:animations completion:completion];
+ break;
case SGRMotionPress:
[UIView animateWithDuration:kPressDuration delay:0 usingSpringWithDamping:kPressDamping initialSpringVelocity:0 options:options animations:animations completion:completion];
break;
diff --git a/tweak/Sources/Redesigned/Navbar/Navbar.h b/tweak/Sources/Redesigned/Navbar/Navbar.h
index 9a3119dc..19e32bd9 100644
--- a/tweak/Sources/Redesigned/Navbar/Navbar.h
+++ b/tweak/Sources/Redesigned/Navbar/Navbar.h
@@ -43,7 +43,9 @@ void SGRNavbarForgetTab(void);
// now playing card coming down between them. On unless switched off; read as each scroll goes.
#define SGRKeyNavbarMinimize @"spotifyglass.redesign.navbar.minimize"
BOOL SGRTabBarMinimized(void);
-// TabBar.x lays both bars out for it, the now playing bar in the same animation; `animated` NO is a cut.
+// TabBar.x lays both bars out for it, the now playing bar in the same animation, at once; asked for inside an
+// animation, on the main queue's next turn (SGRTabBarMinimized changes then too). `animated` NO is a cut, made
+// at once.
void SGRSetTabBarMinimized(BOOL minimized, BOOL animated);
// The room between the minimized bar's two tabs, `height` high and centred on them, in `host`'s
// coordinates: where the now playing card goes. CGRectNull while the bar is not minimized or not on screen.
@@ -51,6 +53,8 @@ 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);
+// Lets a laid out bar's titles shrink a little before UIKit cuts them short (TabBar.x), for the page's preview too.
+void SGRShrinkTabTitles(UIView *bar);
UIViewController *SGRNavbarSettingsPage(void); // the tab editor, in Mod Settings
UIViewController *SGRNavbarEditorPage(void); // the tab editor alone, for the welcome tour
diff --git a/tweak/Sources/Redesigned/Navbar/NavbarSettings.m b/tweak/Sources/Redesigned/Navbar/NavbarSettings.m
index 5b76a4fc..0f1a877d 100644
--- a/tweak/Sources/Redesigned/Navbar/NavbarSettings.m
+++ b/tweak/Sources/Redesigned/Navbar/NavbarSettings.m
@@ -233,6 +233,10 @@ static NSArray<UITabBarItem *> *itemsFor(NSArray<NSDictionary *> *entries, BOOL
}
_main.frame = main;
_apart.frame = apart;
+ for (UITabBar *bar in @[_main, _apart]) {
+ [bar layoutIfNeeded];
+ SGRShrinkTabTitles(bar);
+ }
}
@end
diff --git a/tweak/Sources/Redesigned/Navbar/TabBar.x b/tweak/Sources/Redesigned/Navbar/TabBar.x
index ea91b23d..0fa39e4d 100644
--- a/tweak/Sources/Redesigned/Navbar/TabBar.x
+++ b/tweak/Sources/Redesigned/Navbar/TabBar.x
@@ -209,8 +209,24 @@ static void forwardTap(UIView *item) {
#pragma mark - the system bar
+// A name too long for its tab (one of the user's own, a split tab's circle) shrinks a little before UIKit cuts
+// it short, to 8 pt from 10.
+void SGRShrinkTabTitles(UIView *bar) {
+ SGForEachView(bar, ^(UIView *v) {
+ if (![v isKindOfClass:UILabel.class] || ((UILabel *)v).adjustsFontSizeToFitWidth) return;
+ ((UILabel *)v).adjustsFontSizeToFitWidth = YES;
+ ((UILabel *)v).minimumScaleFactor = 0.8;
+ });
+}
+
@implementation SGRSystemTabBar
+// UIKit makes the labels as it lays the items out, so they are shrunk after each pass.
+- (void)layoutSubviews {
+ [super layoutSubviews];
+ SGRShrinkTabTitles(self);
+}
+
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
NSUInteger index = [self.items indexOfObject:item];
if (index == NSNotFound || index >= self.sources.count) return;
@@ -541,18 +557,6 @@ static void syncBar(UIView *stockBar) {
apartBar.hidden = !apart.count && !sg_keepApart;
if (apartBar.hidden) apartBar.sources = nil;
- BOOL missing = fillBar(bar, main, hideLabels);
- if (apart.count) missing |= fillBar(apartBar, apart, hideLabels);
- selectActive(bar, active);
- if (apart.count) selectActive(apartBar, active);
- // An icon view Spotify has not built yet is looked for again shortly, not on the next touch.
- static NSUInteger retries;
- if (missing && retries++ < 40) {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- syncBar(stockBar);
- });
- }
-
CGRect bounds = stockBar.bounds;
CGFloat width = bounds.size.width;
CGFloat height = MAX(bounds.size.height, glassHeight(bar, stockBar));
@@ -571,6 +575,22 @@ static void syncBar(UIView *stockBar) {
}
if (!CGRectEqualToRect(bar.frame, mainFrame)) bar.frame = mainFrame;
if (apart.count && !CGRectEqualToRect(apartBar.frame, apartFrame)) apartBar.frame = apartFrame;
+
+ // The items go in once the bars are laid out at their frames. UIKit sizes an item's title by the platter it
+ // is made in and never again when the bar grows, so items made while a bar was still a circle kept "…" for
+ // their names at full width (harness/tabbar, `names`).
+ [host layoutIfNeeded];
+ BOOL missing = fillBar(bar, main, hideLabels);
+ if (apart.count) missing |= fillBar(apartBar, apart, hideLabels);
+ selectActive(bar, active);
+ if (apart.count) selectActive(apartBar, active);
+ // An icon view Spotify has not built yet is looked for again shortly, not on the next touch.
+ static NSUInteger retries;
+ if (missing && retries++ < 40) {
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ syncBar(stockBar);
+ });
+ }
if (host.superview != stockBar) [stockBar addSubview:host];
else if (stockBar.subviews.lastObject != host) [stockBar bringSubviewToFront:host];
logBarOnce(bar);
@@ -584,13 +604,184 @@ static void syncBar(UIView *stockBar) {
// UIKit's tabBarMinimizeBehavior and bottomAccessory have nothing to act on. The minimized bar is built
// from the two bars this file already has: the main bar narrowed to one circle at the leading end, the
// second bar to one at the trailing end, and the now playing card between them (NowPlayingBar.x). The
-// items are swapped at once and the bars' frames then move from where they were, so UIKit's platters
-// shrink and grow in the spring; nothing fades a bar's glass.
+// bars get their new items and are laid out where they are going at once; then every view of theirs goes back
+// to where it was and moves on one spring with the card (see "one move"); nothing fades a bar's glass.
BOOL SGRTabBarMinimized(void) {
return sg_minimized;
}
+static void setMinimized(BOOL minimized, BOOL animated);
+
+// The scroll asks from inside -[UIScrollView setContentOffset:], which Spotify can call inside an animation of
+// its own: a block, whose length the spring then took, or a property animator held part way, which kept the bar's
+// and the card's moves at its fraction for good, the circle stopped half way along the row and the card half way
+// down to it (harness/tabbar, `nested`). So an animated change asked for inside an animation is made on the main
+// queue's next turn, outside it, and only if nothing was asked for since; one asked for outside any is made at
+// once. A change with no animation stays at once too: the player's transition takes its pictures of the bars
+// right after asking.
+static NSUInteger sg_request;
+
void SGRSetTabBarMinimized(BOOL minimized, BOOL animated) {
+ NSUInteger request = ++sg_request;
+ if (!animated) {
+ [UIView performWithoutAnimation:^{ setMinimized(minimized, NO); }];
+ return;
+ }
+ if (UIView.areAnimationsEnabled && UIView.inheritedAnimationDuration <= 0) {
+ setMinimized(minimized, YES);
+ return;
+ }
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if (request == sg_request) setMinimized(minimized, YES);
+ });
+}
+
+#pragma mark - one move
+
+// The bars, the circles and the card move as one: on one spring (SGRMotionBar), from what is on screen. UIKit
+// lays a bar's items out by its width, so a bar laid out where it was with its new items put them where they
+// never were: minimizing, the circle's tab stood in the middle of the old full bar and slid to the leading end
+// from there (harness/tabbar, `motion`: 124 pt in one frame). So each bar is laid out where it is going, and
+// every view of the bars that was already there goes back to its frame from before, under its animations still
+// running, and moves to its new one in the spring. UIView's animations add up, so a change that turns one back
+// carries on from where the screen is, at the speed it had. UIKit takes the animations off its platters when it
+// lays new items out, though, and a platter turned back half way then started from the old move's end, 62 pt from
+// where it was shown (`motion`, four quick turns); one whose move was taken off starts from what was shown. The
+// selected tab's new button starts with its glyph where the old one's was; the other new buttons fade in, and the
+// buttons that went fade out from where they were.
+typedef struct {
+ NSMapTable<UIView *, NSArray<NSValue *> *> *frames; // every view of the host: its frame, the frame shown, moving
+ NSMutableDictionary<NSString *, NSValue *> *glyphs; // the selected tab's glyph centre in the host (buttonKey)
+ NSMapTable<UIView *, UIView *> *buttons; // each tab button, a picture of it
+} SGRBarState;
+
+// UIKit draws every tab twice, the second time in the accent under the selection's bubble only.
+static BOOL isLitCopy(UIView *view, UIView *host) {
+ for (UIView *up = view.superview; up && up != host; up = up.superview) {
+ if ([NSStringFromClass(up.class) containsString:@"SelectedContent"]) return YES;
+ }
+ return NO;
+}
+
+static BOOL isMoving(UIView *view) {
+ for (NSString *key in view.layer.animationKeys) if ([key hasPrefix:@"position"] || [key hasPrefix:@"bounds"]) return YES;
+ return NO;
+}
+
+static UIImageView *glyphView(UIView *button) {
+ __block UIImageView *glyph = nil;
+ SGForEachView(button, ^(UIView *v) {
+ if (!glyph && [v isKindOfClass:UIImageView.class] && !v.hidden && ((UIImageView *)v).image) glyph = (UIImageView *)v;
+ });
+ return glyph;
+}
+
+static BOOL isTabButton(UIView *view) {
+ return [view isKindOfClass:UIControl.class] && glyphView(view) != nil;
+}
+
+// Which old button a new one takes over from. UIKit draws its glyphs anew with each set of items (each copy a
+// UIImage of its own), so the selected tab is what the two share, in each of the two copies.
+static NSString *buttonKey(UIView *button, UIView *host) {
+ if (!isTabButton(button) || !((UIControl *)button).selected) return nil;
+ return isLitCopy(button, host) ? @"lit" : @"plain";
+}
+
+static CGRect shownIn(UIView *view, UIView *host) {
+ CALayer *layer = view.layer.presentationLayer ?: view.layer, *top = host.layer.presentationLayer ?: host.layer;
+ return [layer convertRect:layer.bounds toLayer:top];
+}
+
+static SGRBarState barState(UIView *host) {
+ SGRBarState state = {
+ [NSMapTable mapTableWithKeyOptions:NSPointerFunctionsWeakMemory | NSPointerFunctionsObjectPointerPersonality valueOptions:NSPointerFunctionsStrongMemory],
+ [NSMutableDictionary dictionary],
+ [NSMapTable mapTableWithKeyOptions:NSPointerFunctionsWeakMemory | NSPointerFunctionsObjectPointerPersonality valueOptions:NSPointerFunctionsStrongMemory],
+ };
+ SGForEachView(host, ^(UIView *v) {
+ CALayer *shownLayer = v.layer.presentationLayer;
+ [state.frames setObject:@[[NSValue valueWithCGRect:v.frame], [NSValue valueWithCGRect:shownLayer ? shownLayer.frame : v.frame], @(isMoving(v))] forKey:v];
+ if (!v.window || v == host || !isTabButton(v)) return;
+ CGRect shown = shownIn(v, host), glyph = shownIn(glyphView(v), host);
+ NSString *key = buttonKey(v, host);
+ if (key) state.glyphs[key] = [NSValue valueWithCGPoint:CGPointMake(CGRectGetMidX(glyph), CGRectGetMidY(glyph))];
+ // The lit copy is left out, or its picture would show the tab lit outside the bubble.
+ if (isLitCopy(v, host)) return;
+ UIView *picture = [v snapshotViewAfterScreenUpdates:NO];
+ if (picture) {
+ picture.frame = shown;
+ [state.buttons setObject:picture forKey:v];
+ }
+ });
+ return state;
+}
+
+// Moves the host's views from `before` to where they are now, with `along` (the card) in the same spring.
+static void moveFrom(UIView *host, SGRBarState before, void (^along)(void), void (^completion)(BOOL)) {
+ NSMutableArray<UIView *> *moved = [NSMutableArray array], *faded = [NSMutableArray array];
+ NSMutableArray<NSValue *> *starts = [NSMutableArray array], *targets = [NSMutableArray array];
+ NSMutableSet<NSString *> *taken = [NSMutableSet set];
+ SGForEachView(host, ^(UIView *v) {
+ if (v == host) return;
+ NSArray<NSValue *> *old = [before.frames objectForKey:v];
+ if (old) {
+ BOOL stopped = [(NSNumber *)old[2] boolValue] && !isMoving(v);
+ CGRect start = stopped ? old[1].CGRectValue : old[0].CGRectValue;
+ if (!stopped && CGRectEqualToRect(start, v.frame)) return;
+ [moved addObject:v];
+ [starts addObject:[NSValue valueWithCGRect:start]];
+ [targets addObject:[NSValue valueWithCGRect:v.frame]];
+ return;
+ }
+ // A view made for the new items, whose superview was there before. The selected tab's button starts where
+ // the old one's glyph was, another fades in where it is going; the rest (the selection's bubble) are there
+ // at once, or the selected tab's glyph, drawn under the bubble, went with it.
+ if (![before.frames objectForKey:v.superview] || [v isKindOfClass:UITabBar.class]) return;
+ NSString *key = buttonKey(v, host);
+ NSValue *was = key ? before.glyphs[key] : nil;
+ if (was) {
+ [moved addObject:v];
+ [starts addObject:was]; // a centre in the host, placed once the views above it are back
+ [targets addObject:[NSValue valueWithCGRect:v.frame]];
+ [taken addObject:key];
+ } else if (isTabButton(v) && v.alpha > 0.01) {
+ [faded addObject:v];
+ }
+ });
+ NSMutableArray<UIView *> *gone = [NSMutableArray array];
+ for (UIView *button in before.buttons) {
+ BOOL replaced = ((UIControl *)button).selected && [taken containsObject:@"plain"];
+ if (!button.window && !replaced) [gone addObject:[before.buttons objectForKey:button]];
+ }
+
+ [UIView performWithoutAnimation:^{
+ // Top down, so a button's centre is placed in its platter where the platter starts.
+ for (NSUInteger i = 0; i < moved.count; i++) {
+ UIView *v = moved[i];
+ if (strcmp(starts[i].objCType, @encode(CGPoint)) != 0) {
+ v.frame = starts[i].CGRectValue;
+ continue;
+ }
+ // Its glyph where the old one's was: the button moved by as much as its glyph is off its centre.
+ UIImageView *glyph = glyphView(v);
+ CGPoint inButton = [v convertPoint:glyph.center fromView:glyph.superview], to = [host convertPoint:starts[i].CGPointValue toView:v.superview];
+ v.center = CGPointMake(to.x - (inButton.x - CGRectGetMidX(v.bounds)), to.y - (inButton.y - CGRectGetMidY(v.bounds)));
+ }
+ for (UIView *v in faded) v.alpha = 0;
+ for (UIView *picture in gone) [host addSubview:picture];
+ }];
+ SGRAnimate(SGRMotionBar, ^{
+ for (NSUInteger i = 0; i < moved.count; i++) moved[i].frame = targets[i].CGRectValue;
+ if (along) along();
+ }, completion);
+ // The buttons that went leave quickly, and those that came arrive as the platter reaches them.
+ SGRAnimate(SGRMotionExit, ^{ for (UIView *picture in gone) picture.alpha = 0; }, ^(BOOL finished) {
+ for (UIView *picture in gone) [picture removeFromSuperview];
+ });
+ SGRAnimate(SGRMotionFade, ^{ for (UIView *v in faded) v.alpha = 1; }, nil);
+}
+
+static void setMinimized(BOOL minimized, BOOL animated) {
UIView *stockBar = sg_stockBar;
if (minimized == sg_minimized) return;
// Spotify's regular width bar is not the glass one's row of tabs; it stays as it is.
@@ -600,37 +791,33 @@ void SGRSetTabBarMinimized(BOOL minimized, BOOL animated) {
SGLog(@"tab bar: %@", minimized ? @"minimized" : @"expanded");
if (!stockBar) return;
UIView *host = objc_getAssociatedObject(stockBar, &kHostKey);
- UIView *bar = objc_getAssociatedObject(stockBar, &kBarKey);
- UIView *apartBar = objc_getAssociatedObject(stockBar, &kApartBarKey);
- BOOL apartShown = apartBar && !apartBar.hidden;
- CGRect fromMain = bar.frame, fromApart = apartBar.frame;
- [UIView performWithoutAnimation:^{ syncBar(stockBar); }];
- apartBar = objc_getAssociatedObject(stockBar, &kApartBarKey);
- CGRect toMain = bar.frame, toApart = apartBar.frame;
void (^settle)(BOOL) = ^(BOOL finished) {
if (sg_minimized != minimized) return;
sg_keepApart = NO;
- // The items made for the full bar were laid out while it was a circle, and UIKit kept their titles cut
- // short to that width once it had grown (harness/tabbar, `mini`): they are made again at full width.
- if (!minimized) ((SGRSystemTabBar *)bar).sources = nil;
syncBar(stockBar);
};
- if (!animated || !host.window) {
- [UIView performWithoutAnimation:^{ SGRNowPlayingBarFollowTabBar(); }];
- settle(YES);
- return;
- }
+ animated &= host.window != nil;
+ SGRBarState before = animated ? barState(host) : (SGRBarState){0};
+ // The items are made where the bars are going, before anything moves. UIKit sizes a tab's name by the platter
+ // its item is made in and never again, and the first pass made the expanding row's items while the bar still
+ // held the circle's one item, its platter a circle: "Your Library" stayed cut. So they are made a second time,
+ // the platters now the full row's, and the names are whole all the way.
[UIView performWithoutAnimation:^{
- bar.frame = fromMain;
- if (apartShown) apartBar.frame = fromApart;
+ syncBar(stockBar);
[host layoutIfNeeded];
+ if (!minimized) {
+ ((SGRSystemTabBar *)objc_getAssociatedObject(stockBar, &kBarKey)).sources = nil;
+ ((SGRSystemTabBar *)objc_getAssociatedObject(stockBar, &kApartBarKey)).sources = nil;
+ syncBar(stockBar);
+ [host layoutIfNeeded];
+ }
+ if (!animated) SGRNowPlayingBarFollowTabBar();
}];
- SGRAnimate(SGRMotionLayout, ^{
- bar.frame = toMain;
- apartBar.frame = toApart;
- [host layoutIfNeeded];
- SGRNowPlayingBarFollowTabBar();
- }, settle);
+ if (!animated) {
+ settle(YES);
+ return;
+ }
+ moveFrom(host, before, ^{ SGRNowPlayingBarFollowTabBar(); }, settle);
}
CGRect SGRTabBarInlineSlot(UIView *host, CGFloat height) {
diff --git a/tweak/Sources/Redesigned/Navbar/TabBarMinimize.x b/tweak/Sources/Redesigned/Navbar/TabBarMinimize.x
index 7b572bd7..45f69136 100644
--- a/tweak/Sources/Redesigned/Navbar/TabBarMinimize.x
+++ b/tweak/Sources/Redesigned/Navbar/TabBarMinimize.x
@@ -1,5 +1,7 @@
// What minimizes the glass bar and what brings it back (TabBar.x draws it): a page scrolled down by a
-// finger or the fling after it, and scrolled back up or to its top (MinimizeStep.h); another tab (TabBar.x);
+// finger or the fling after it, and scrolled back up or to its top (MinimizeStep.h). After the bar changes some
+// other way (a tap on its circle, a tab, the player), only a new touch minimizes it again: the fling still
+// running would otherwise undo the tap at once; another tab (TabBar.x);
// and the full screen player opening or closing, which takes Spotify's pictures of the bars to move with it
// and would have moved the card from the tab bar's row back up to its place above the bar.
//
@@ -13,6 +15,7 @@
static Class sg_containerClass;
static __weak UIScrollView *sg_page, *sg_other;
static SGRMinimizeTrack sg_track;
+static BOOL sg_waitForTouch;
static BOOL inContainer(UIView *view) {
for (UIResponder *r = view.nextResponder; r; r = r.nextResponder) if ([r isKindOfClass:sg_containerClass]) return YES;
@@ -31,11 +34,16 @@ static void scrolled(UIScrollView *scrollView) {
sg_track = (SGRMinimizeTrack){offset, SGRTabBarMinimized()};
}
// The bar changed some other way (a tab, the player): the scroll counts from here.
- if (sg_track.minimized != SGRTabBarMinimized()) sg_track = (SGRMinimizeTrack){offset, SGRTabBarMinimized()};
+ if (sg_track.minimized != SGRTabBarMinimized()) {
+ sg_track = (SGRMinimizeTrack){offset, SGRTabBarMinimized()};
+ sg_waitForTouch = YES;
+ }
+ if (scrollView.isTracking) sg_waitForTouch = NO;
UIEdgeInsets inset = scrollView.adjustedContentInset;
CGFloat top = -inset.top, bottom = scrollView.contentSize.height + inset.bottom - scrollView.bounds.size.height;
BOOL minimized = SGRMinimizeStep(&sg_track, offset, top, bottom);
if (minimized == SGRTabBarMinimized() || (minimized && !SGEnabled(SGRKeyNavbarMinimize))) return;
+ if (minimized && sg_waitForTouch) return;
SGRSetTabBarMinimized(minimized, YES);
}
diff --git a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x
index 1cf05056..f0b740d5 100644
--- a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x
+++ b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x
@@ -375,14 +375,15 @@ static void styleNowPlayingBar(UIViewController *container) {
%end
// The page the bar stands in passes touches outside the bar through, and the bar in the tab bar's row is
-// below the page's bounds: a touch there reaches the bar only through this.
+// below the page's bounds: a touch there reaches the bar only through this. Only the narrowed card takes
+// one: the container's view keeps the screen's width, and took the touches meant for the tab bar's circles.
%hook _TtC22NowPlaying_BarPageImplP33_CCC0D2EEA6D4725EECD8965E8C38C86D20TouchPassthroughView
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *hit = %orig;
UIView *moved = sg_inline;
if ((hit && hit != (UIView *)self) || ![moved isDescendantOfView:(UIView *)self]) return hit;
- CGPoint inMoved = [(UIView *)self convertPoint:point toView:moved];
- return [moved pointInside:inMoved withEvent:event] ? ([moved hitTest:inMoved withEvent:event] ?: hit) : hit;
+ UIView *inside = [moved hitTest:[(UIView *)self convertPoint:point toView:moved] withEvent:event];
+ return inside && inside != moved ? inside : hit;
}
%end