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 library's header buttons no longer land on its title when the page first opens
Vojtěch Škopek4e5c57669c12
diff --git a/harness/library/README.md b/harness/library/README.mdnew file mode 100644index 00000000..44c8d10d--- /dev/null+++ b/harness/library/README.md@@ -0,0 +1,34 @@+# Library harness++Spotify's Your Library page mocked under its own class names and accessibility identifiers (from+`trees/clean/library/03.txt`, recorded 2026-09-16), so `Redesigned/Library/LibraryHeader.x` can be laid out+and looked at on the Mac without the phone.++ THEOS=$HOME/theos ./build.sh+ xcrun simctl install <udid> build/LibraryHarness.app+ xcrun simctl launch <udid> com.vojta.libraryharness # first look+ xcrun simctl launch <udid> com.vojta.libraryharness back # then the pass the page gets coming back from a playlist+ xcrun simctl io <udid> screenshot shot.png++`build.sh` runs `logos.pl -c generator=internal` over `LibraryHeader.x` from the checkout it sits in and+links it with the real `Core/` and `Redesigned/Kit/` sources; `SRC=<other tweak/Sources> ./build.sh` builds+an older tree instead, to compare. `stubs.m` stands in for the hook files the harness does not compile.++It plays issue #21. The page comes up with the header's control row holding Search alone. At 0.8 s the+header's model lands: Recents and Create show, and the page lays out in the same turn. The mock of+`AutoLayoutStackView` (the real one's ivars are `observationsDictionary` and `needsCoalescedLayoutUpdate`)+places what changed on the next turn of the main queue, in a pass of its own container that reaches+neither the header nor the page. So at the page's pass a button just shown still stands at the row's+origin, where 03.txt has the hidden Recents. Before the fix the moves worked out on that pass stayed:+Search ends up next to the title, left of Recents, and Create goes off the screen. A page pass later (`back`)+put Search on top of Recents, which the old code never placed. After the fix the row's own pass places+everything again.++Launch words: `back` adds the page pass at 2.4 s. `steady` builds the header with the model already in it.+`nocreate` leaves Create out of the model, and `norecents` leaves Recents out (the account the tree was+recorded on). Each moment is logged with where every control landed in the header:++ xcrun simctl spawn <udid> log show --last 1m --style compact --predicate 'eventMessage CONTAINS "[harness]" OR eventMessage CONTAINS "redesign library"'++What it does not cover: the real stack's constraints and when its coalesced update actually runs, the+element framework behind the avatar, the list's rows (`LibraryRows.x`) and the folder page.diff --git a/harness/library/build.sh b/harness/library/build.shnew file mode 100755index 00000000..dcd1e3a8--- /dev/null+++ b/harness/library/build.sh@@ -0,0 +1,44 @@+#!/bin/sh+set -e+# The sources of the checkout this harness sits in, unless SRC names others (an older tree, to compare).+SRC=${SRC:-$(cd "$(dirname "$0")/../../tweak/Sources" && pwd)}+OUT=$(dirname "$0")/build+rm -rf "$OUT"; mkdir -p "$OUT/gen" "$OUT/LibraryHarness.app"++for f in Redesigned/Library/LibraryHeader.x; do+ name=$(basename "$f" .x)+ "$THEOS/bin/logos.pl" -c generator=internal "$SRC/$f" > "$OUT/gen/$name.m"+done++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/Library" -I"$OUT/gen" -isysroot "$SDK" \+ -Wno-deprecated-declarations \+ "$(dirname "$0")/main.m" "$(dirname "$0")/stubs.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/SGRPalette.m "$SRC"/Redesigned/Kit/SGRField.m \+ "$SRC"/Redesigned/Kit/SGRGlass.m "$SRC"/Redesigned/Kit/SGRGlyph.m "$SRC"/Redesigned/Kit/SGRRestyle.m \+ "$SRC"/Redesigned/Kit/SGRActionRow.m "$SRC"/Redesigned/Kit/SGRHeaderInfo.m \+ "$SRC"/Redesigned/Kit/SGRedesign.m \+ -framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreImage -framework Foundation -framework Symbols \+ -o "$OUT/LibraryHarness.app/LibraryHarness"++cat > "$OUT/LibraryHarness.app/Info.plist" <<'PLIST'+<?xml version="1.0" encoding="UTF-8"?>+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">+<plist version="1.0"><dict>+<key>CFBundleExecutable</key><string>LibraryHarness</string>+<key>CFBundleIdentifier</key><string>com.vojta.libraryharness</string>+<key>CFBundleName</key><string>LibraryHarness</string>+<key>CFBundleVersion</key><string>1</string>+<key>CFBundleShortVersionString</key><string>1.0</string>+<key>UIUserInterfaceStyle</key><string>Dark</string>+<key>UILaunchScreen</key><dict/>+<key>UIApplicationSceneManifest</key><dict>+ <key>UIApplicationSupportsMultipleScenes</key><false/>+</dict>+</dict></plist>+PLIST+echo "built $OUT/LibraryHarness.app"diff --git a/harness/library/main.m b/harness/library/main.mnew file mode 100644index 00000000..2ac6b38d--- /dev/null+++ b/harness/library/main.m@@ -0,0 +1,404 @@+// A mock of Spotify's Your Library page under its own class names and accessibility identifiers, built from+// trees/clean/library/03.txt (recorded 2026-09-16), so Redesigned/Library/LibraryHeader.x can be laid out and+// looked at on the Mac. It plays issue #21: the header's model arriving after the page has laid out, the buttons+// it shows placed by Spotify's stack on a pass of its own. `first` on the launch line stops there, `back` then+// gives the page the pass it gets on the way back from a playlist, `steady` builds the header with the model+// already in it. `nocreate` leaves Create out of the model, `norecents` Recents (the account the tree is of).+#import <UIKit/UIKit.h>+#import <os/log.h>++#define HLog(fmt, ...) os_log(OS_LOG_DEFAULT, "[harness] %{public}s", [NSString stringWithFormat:(fmt), ##__VA_ARGS__].UTF8String)++static const CGFloat kHeaderHeight = 159.33;++#pragma mark - Spotify's classes, by name++@interface _TtCO22Reprise_LiquidGlassKit11LiquidGlass12GradientView : UIView @end+@implementation _TtCO22Reprise_LiquidGlassKit11LiquidGlass12GradientView @end++@interface _TtC29ListeningActivity_ElementsKit21AdaptiveFaceContainer : UIView @end+@implementation _TtC29ListeningActivity_ElementsKit21AdaptiveFaceContainer @end++@interface _TtC21YourLibrary_CommonKit35YourLibraryHeaderContentFiltersView : UIView @end+@implementation _TtC21YourLibrary_CommonKit35YourLibraryHeaderContentFiltersView @end++@interface _TtC28YourLibrary_YourLibraryXImpl22YourLibraryContentView : UIView @end+@implementation _TtC28YourLibrary_YourLibraryXImpl22YourLibraryContentView @end++@interface _TtC22YourLibrary_FolderImpl10FolderView : UIView @end+@implementation _TtC22YourLibrary_FolderImpl10FolderView @end++@interface _TtC21YourLibrary_CommonKit25YourLibraryCollectionView : UICollectionView @end+@implementation _TtC21YourLibrary_CommonKit25YourLibraryCollectionView @end++// Encore's button: a 48pt box with its 24pt glyph in the middle.+@interface MockEncoreButton : UIControl @end+@implementation MockEncoreButton @end++// LegacyUI_ECMCoreKit.AutoLayoutStackView: the arranged views in a plain container view, chained by constraints+// the stack rebuilds when one of them shows or hides. The real one watches its views' hidden and folds the+// changes into one update (its ivars: observationsDictionary, needsCoalescedLayoutUpdate); the mock folds them+// into the next turn of the main queue, so a page laying out in the turn the header's model lands in still+// sees each button where it stood before. A hidden view leaves the chain and sits at the container's origin,+// where 03.txt has the hidden Recents.+@interface _TtC19LegacyUI_ECMCoreKit19AutoLayoutStackView : UIView+@property (nonatomic, readonly) UIView *containerView;+@property (nonatomic, copy) NSArray<UIView *> *arrangedSubviews;+@end++@implementation _TtC19LegacyUI_ECMCoreKit19AutoLayoutStackView {+ NSArray<NSLayoutConstraint *> *_layoutConstraints;+ BOOL _needsCoalescedLayoutUpdate;+}++- (instancetype)initWithFrame:(CGRect)frame {+ if (!(self = [super initWithFrame:frame])) return nil;+ _containerView = [[UIView alloc] initWithFrame:self.bounds];+ _containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;+ [self addSubview:_containerView];+ return self;+}++- (void)setArrangedSubviews:(NSArray<UIView *> *)views {+ _arrangedSubviews = [views copy];+ for (UIView *view in views) {+ view.translatesAutoresizingMaskIntoConstraints = NO;+ [_containerView addSubview:view];+ [view addObserver:self forKeyPath:@"hidden" options:0 context:NULL];+ }+ [self rebuild];+}++- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {+ if (_needsCoalescedLayoutUpdate) return;+ _needsCoalescedLayoutUpdate = YES;+ dispatch_async(dispatch_get_main_queue(), ^{+ self->_needsCoalescedLayoutUpdate = NO;+ [self rebuild];+ HLog(@"stack rebuilt its constraints");+ });+}++- (void)rebuild {+ if (_layoutConstraints) [NSLayoutConstraint deactivateConstraints:_layoutConstraints];+ NSMutableArray<NSLayoutConstraint *> *constraints = [NSMutableArray array];+ UIView *previous = nil;+ for (UIView *view in _arrangedSubviews) {+ if (view.hidden) {+ [constraints addObject:[view.leadingAnchor constraintEqualToAnchor:_containerView.leadingAnchor]];+ [constraints addObject:[view.topAnchor constraintEqualToAnchor:_containerView.topAnchor]];+ continue;+ }+ [constraints addObject:[view.centerYAnchor constraintEqualToAnchor:_containerView.centerYAnchor]];+ [constraints addObject:[view.leadingAnchor constraintEqualToAnchor:previous ? previous.trailingAnchor : _containerView.leadingAnchor]];+ previous = view;+ }+ if (previous) [constraints addObject:[previous.trailingAnchor constraintEqualToAnchor:_containerView.trailingAnchor]];+ _layoutConstraints = constraints;+ [NSLayoutConstraint activateConstraints:constraints];+}++- (void)dealloc {+ for (UIView *view in _arrangedSubviews) [view removeObserver:self forKeyPath:@"hidden"];+}+@end++// The header lays its own children out by frame: the scrim over all of it, the control row off the safe area,+// the chips under the row.+@interface _TtC28YourLibrary_YourLibraryXImpl21YourLibraryHeaderView : UIView+@property (nonatomic, strong) UIView *gradient, *row, *filters;+@end++@implementation _TtC28YourLibrary_YourLibraryXImpl21YourLibraryHeaderView+- (void)layoutSubviews {+ [super layoutSubviews];+ CGFloat width = self.bounds.size.width;+ CGFloat top = self.window ? self.window.safeAreaInsets.top : 62;+ self.gradient.frame = CGRectMake(0, 0, width, kHeaderHeight);+ self.row.frame = CGRectMake(0, top, width, 48);+ self.filters.frame = CGRectMake(0, top + 48, width, 49.33);+}+@end++// The page: its content the size of it, the header over it at its full height and the list inset by that height,+// all three stated again on every pass the way Spotify's does.+@interface _TtC28YourLibrary_YourLibraryXImpl15YourLibraryView : UIView+@property (nonatomic, strong) UIView *content, *header;+@property (nonatomic, strong) UICollectionView *list;+@end++@implementation _TtC28YourLibrary_YourLibraryXImpl15YourLibraryView+- (void)layoutSubviews {+ [super layoutSubviews];+ self.content.frame = self.bounds;+ self.list.frame = self.content.bounds;+ self.header.frame = CGRectMake(0, 0, self.bounds.size.width, kHeaderHeight);+ UIEdgeInsets inset = self.list.contentInset;+ inset.top = kHeaderHeight;+ self.list.contentInset = inset;+}+@end++#pragma mark - building the page++static UIView *box(UIView *parent, Class cls, CGRect frame, NSString *identifier) {+ UIView *view = [[cls alloc] initWithFrame:frame];+ view.accessibilityIdentifier = identifier;+ if (parent) [parent addSubview:view];+ return view;+}++static void pinSize(UIView *view, CGFloat width, CGFloat height) {+ [view.widthAnchor constraintEqualToConstant:width].active = YES;+ [view.heightAnchor constraintEqualToConstant:height].active = YES;+}++static UIView *button(NSString *identifier, NSString *symbol) {+ UIView *control = box(nil, MockEncoreButton.class, CGRectMake(0, 0, 48, 48), identifier);+ UIImageSymbolConfiguration *config = [UIImageSymbolConfiguration configurationWithPointSize:20 weight:UIImageSymbolWeightRegular];+ UIImageView *glyph = [[UIImageView alloc] initWithImage:[UIImage systemImageNamed:symbol withConfiguration:config]];+ glyph.frame = CGRectMake(12, 12, 24, 24);+ glyph.contentMode = UIViewContentModeCenter;+ glyph.tintColor = UIColor.whiteColor;+ [control addSubview:glyph];+ pinSize(control, 48, 48);+ return control;+}++static UIImage *avatar(void) {+ UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:CGSizeMake(64, 64)];+ return [renderer imageWithActions:^(UIGraphicsImageRendererContext *ctx) {+ [[UIColor colorWithRed:0.55 green:0.85 blue:0.55 alpha:1] setFill];+ UIRectFill(CGRectMake(0, 0, 64, 64));+ [[UIColor colorWithRed:0.25 green:0.22 blue:0.2 alpha:1] setFill];+ [[UIBezierPath bezierPathWithOvalInRect:CGRectMake(18, 10, 28, 32)] fill];+ [[UIBezierPath bezierPathWithOvalInRect:CGRectMake(6, 40, 52, 40)] fill];+ }];+}++static UIView *face(void) {+ UIView *container = box(nil, _TtC29ListeningActivity_ElementsKit21AdaptiveFaceContainer.class, CGRectMake(0, 0, 48, 48), nil);+ UIView *drawer = box(container, MockEncoreButton.class, CGRectMake(0, 0, 48, 48), @"Components.UI.SideDrawerButton");+ UIImageView *image = [[UIImageView alloc] initWithImage:avatar()];+ image.frame = CGRectMake(8, 8, 32, 32);+ image.layer.cornerRadius = 16;+ image.clipsToBounds = YES;+ [drawer addSubview:image];+ pinSize(container, 48, 48);+ return container;+}++static UIView *spotifyTitle(void) {+ UIView *encore = box(nil, UIView.class, CGRectZero, @"YourLibraryHeader.title");+ UILabel *label = [UILabel new];+ label.text = @"Your Library";+ label.font = [UIFont boldSystemFontOfSize:21];+ label.textColor = UIColor.whiteColor;+ label.accessibilityIdentifier = @"YourLibraryHeader.title-internal";+ label.translatesAutoresizingMaskIntoConstraints = NO;+ [encore addSubview:label];+ [NSLayoutConstraint activateConstraints:@[+ [label.leadingAnchor constraintEqualToAnchor:encore.leadingAnchor],+ [label.trailingAnchor constraintEqualToAnchor:encore.trailingAnchor],+ [label.topAnchor constraintEqualToAnchor:encore.topAnchor],+ [label.bottomAnchor constraintEqualToAnchor:encore.bottomAnchor],+ ]];+ return encore;+}++static UIView *chips(UIView *filters) {+ CGFloat x = 16;+ for (NSString *word in @[@"Playlists", @"Podcasts", @"Albums", @"Artists"]) {+ UILabel *chip = [UILabel new];+ chip.text = word;+ chip.font = [UIFont systemFontOfSize:13 weight:UIFontWeightMedium];+ chip.textColor = UIColor.whiteColor;+ chip.textAlignment = NSTextAlignmentCenter;+ chip.backgroundColor = [UIColor colorWithWhite:0.18 alpha:1];+ chip.layer.cornerRadius = 14.7;+ chip.clipsToBounds = YES;+ CGFloat width = ceil([word sizeWithAttributes:@{NSFontAttributeName: chip.font}].width) + 32;+ chip.frame = CGRectMake(x, 8, width, 29.33);+ [filters addSubview:chip];+ x += width + 8;+ }+ return filters;+}++@interface SGRHarnessCard : UICollectionViewCell+@property (nonatomic, strong) UIView *cover;+@property (nonatomic, strong) UILabel *title;+@end++@implementation SGRHarnessCard+- (instancetype)initWithFrame:(CGRect)frame {+ if (!(self = [super initWithFrame:frame])) return nil;+ CGFloat side = frame.size.width;+ _cover = [[UIView alloc] initWithFrame:CGRectMake(0, 0, side, side)];+ _cover.layer.cornerRadius = 6;+ [self.contentView addSubview:_cover];+ _title = [[UILabel alloc] initWithFrame:CGRectMake(0, side + 6, side, 18)];+ _title.font = [UIFont systemFontOfSize:14 weight:UIFontWeightSemibold];+ _title.textColor = UIColor.whiteColor;+ [self.contentView addSubview:_title];+ return self;+}+@end++@interface SGRHarnessDelegate : UIResponder <UIApplicationDelegate, UICollectionViewDataSource>+@property (nonatomic, strong) UIWindow *window;+@property (nonatomic, strong) _TtC28YourLibrary_YourLibraryXImpl15YourLibraryView *page;+@property (nonatomic, strong) NSDictionary<NSString *, UIView *> *controls;+@end++@implementation SGRHarnessDelegate++- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {+ return 12;+}++- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {+ SGRHarnessCard *card = [collectionView dequeueReusableCellWithReuseIdentifier:@"card" forIndexPath:indexPath];+ NSArray<NSString *> *names = @[@"Great songs", @"70s Hits", @"80s Hits", @"Early 2000's", @"Lofi Girl", @"hololive",+ @"Skepta", @"Real Music", @"Aitch", @"New Episodes", @"Tame Impala", @"Chill Mix"];+ card.title.text = names[indexPath.item % names.count];+ CGFloat hue = fmod(indexPath.item * 0.137, 1);+ card.cover.backgroundColor = [UIColor colorWithHue:hue saturation:0.55 brightness:0.6 alpha:1];+ return card;+}++- (UIView *)control:(NSString *)name {+ return self.controls[name];+}++// What the header's model says: which buttons it shows. Setting them is all Spotify's header does on a render;+// the stack places what changed on its own, later.+- (void)render:(NSArray<NSString *> *)shown {+ for (NSString *name in @[@"recents", @"search", @"plus"]) {+ BOOL hidden = ![shown containsObject:name];+ UIView *control = self.controls[name];+ if (control.hidden != hidden) control.hidden = hidden;+ }+ HLog(@"model: %@ shown", [shown componentsJoinedByString:@", "]);+}++- (void)report:(NSString *)moment {+ UIView *header = self.page.header;+ NSMutableArray<NSString *> *parts = [NSMutableArray array];+ for (NSString *name in @[@"recents", @"search", @"plus", @"face"]) {+ UIView *control = self.controls[name];+ if (control.hidden) {+ [parts addObject:[NSString stringWithFormat:@"%@ hidden", name]];+ continue;+ }+ CGRect frame = [control.superview convertRect:control.frame toView:header];+ [parts addObject:[NSString stringWithFormat:@"%@ %.0f-%.0f", name, CGRectGetMinX(frame), CGRectGetMaxX(frame)]];+ }+ UILabel *title = nil;+ for (UIView *sub in header.subviews) {+ if ([sub isMemberOfClass:UILabel.class]) title = (UILabel *)sub;+ }+ CGFloat textRight = title ? CGRectGetMinX(title.frame) + MIN(title.bounds.size.width, [title.text sizeWithAttributes:@{NSFontAttributeName: title.font}].width) : 0;+ HLog(@"%@: %@; title text %.0f-%.0f, header %.0fpt, list inset %.0f", moment, [parts componentsJoinedByString:@", "],+ CGRectGetMinX(title.frame), textRight, header.bounds.size.height, self.page.list.contentInset.top);+}++- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)options {+ NSArray<NSString *> *args = NSProcessInfo.processInfo.arguments;+ BOOL steady = [args containsObject:@"steady"];+ BOOL back = [args containsObject:@"back"];+ NSArray<NSString *> *model = @[@"recents", @"search", @"plus"];+ if ([args containsObject:@"nocreate"]) model = @[@"recents", @"search"];+ if ([args containsObject:@"norecents"]) model = @[@"search", @"plus"];++ self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];+ self.window.backgroundColor = UIColor.blackColor;+ UIViewController *root = [UIViewController new];++ _TtC28YourLibrary_YourLibraryXImpl15YourLibraryView *page = [[_TtC28YourLibrary_YourLibraryXImpl15YourLibraryView alloc] initWithFrame:self.window.bounds];+ page.backgroundColor = UIColor.blackColor;+ self.page = page;++ page.content = box(page, _TtC28YourLibrary_YourLibraryXImpl22YourLibraryContentView.class, page.bounds, nil);+ UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];+ CGFloat side = floor((page.bounds.size.width - 32 - 2 * 14) / 3);+ layout.itemSize = CGSizeMake(side, side + 44);+ layout.minimumInteritemSpacing = 14;+ layout.minimumLineSpacing = 12;+ layout.sectionInset = UIEdgeInsetsMake(40, 16, 0, 16);+ _TtC21YourLibrary_CommonKit25YourLibraryCollectionView *list = [[_TtC21YourLibrary_CommonKit25YourLibraryCollectionView alloc] initWithFrame:page.bounds collectionViewLayout:layout];+ list.accessibilityIdentifier = @"YourLibraryContent.collectionView";+ list.backgroundColor = UIColor.blackColor;+ list.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;+ [list registerClass:SGRHarnessCard.class forCellWithReuseIdentifier:@"card"];+ list.dataSource = self;+ [page.content addSubview:list];+ page.list = list;++ _TtC28YourLibrary_YourLibraryXImpl21YourLibraryHeaderView *header = (id)box(page, _TtC28YourLibrary_YourLibraryXImpl21YourLibraryHeaderView.class, CGRectMake(0, 0, page.bounds.size.width, kHeaderHeight), nil);+ page.header = header;+ header.gradient = box(header, _TtCO22Reprise_LiquidGlassKit11LiquidGlass12GradientView.class, header.bounds, @"LiquidGlass.GradientView");+ header.gradient.backgroundColor = [UIColor colorWithWhite:0 alpha:0.85];+ header.row = box(header, UIView.class, CGRectMake(0, 62, header.bounds.size.width, 48), nil);+ UIView *inner = box(header.row, UIView.class, header.row.bounds, nil);+ inner.autoresizingMask = UIViewAutoresizingFlexibleWidth;+ _TtC19LegacyUI_ECMCoreKit19AutoLayoutStackView *stack = (id)box(inner, _TtC19LegacyUI_ECMCoreKit19AutoLayoutStackView.class, CGRectMake(8, 0, inner.bounds.size.width - 16, 48), nil);+ stack.autoresizingMask = UIViewAutoresizingFlexibleWidth;+ header.filters = chips(box(header, _TtC21YourLibrary_CommonKit35YourLibraryHeaderContentFiltersView.class, CGRectMake(0, 110, header.bounds.size.width, 49.33), nil));++ UIView *avatarBox = face();+ UIView *title = spotifyTitle();+ UIView *spacer = [UIView new];+ [spacer.heightAnchor constraintEqualToConstant:0].active = YES;+ [spacer setContentHuggingPriority:1 forAxis:UILayoutConstraintAxisHorizontal];+ [spacer setContentCompressionResistancePriority:1 forAxis:UILayoutConstraintAxisHorizontal];+ UIView *recents = button(@"YourLibraryHeader.recents", @"clock.arrow.circlepath");+ UIView *search = button(@"YourLibraryHeader.search", @"magnifyingglass");+ UIView *plus = button(@"YourLibraryHeader.plus", @"plus");+ self.controls = @{@"recents": recents, @"search": search, @"plus": plus, @"face": avatarBox};++ // Built with what the header knows before its model arrives -- Search alone -- unless `steady`.+ NSArray<NSString *> *initial = steady ? model : @[@"search"];+ for (NSString *name in @[@"recents", @"search", @"plus"]) self.controls[name].hidden = ![initial containsObject:name];+ stack.arrangedSubviews = @[avatarBox, title, spacer, recents, search, plus];++ root.view = page;+ self.window.rootViewController = root;+ [self.window makeKeyAndVisible];++ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ [self report:@"page up"];+ if (steady) return;+ // The model lands, and the page lays out in the same turn -- Spotify's page states its list and header+ // again from the same update -- before the stack's own pass has placed what the model showed.+ [self render:model];+ [page setNeedsLayout];+ [page layoutIfNeeded];+ [self report:@"page pass in the model's turn"];+ });+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ [self report:@"first look"];+ });+ if (back) {+ // Opening a playlist and coming back: the page lays out again, nothing else changes.+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ [page setNeedsLayout];+ [page layoutIfNeeded];+ [self report:@"back from a playlist"];+ });+ }+ return YES;+}++@end++// Before every %ctor, so the redesign's gate reads on.+__attribute__((constructor(101))) static void sgr_harnessDefaults(void) {+ [NSUserDefaults.standardUserDefaults setBool:YES forKey:@"spotifyglass.redesign"];+}++int main(int argc, char *argv[]) {+ @autoreleasepool {+ return UIApplicationMain(argc, argv, nil, NSStringFromClass(SGRHarnessDelegate.class));+ }+}diff --git a/harness/library/stubs.m b/harness/library/stubs.mnew file mode 100644index 00000000..9e2549ce--- /dev/null+++ b/harness/library/stubs.m@@ -0,0 +1,10 @@+// What the harness does not compile: the accent hook (SGRAccent.x) and the repaint hook (SGRRepaint.x).+#import <UIKit/UIKit.h>+UIColor *SGRAccentColor(void) { return nil; }+__weak UIView *sgr_nowPlayingRoot = nil;+__weak UIView *sgr_nowPlayingCard = nil;+__weak UIView *sgr_lyricsCardRoot = nil;+__weak UIView *sgr_lyricsPageRoot = nil;+__weak UIView *sgr_playlistRoot = nil;+__weak UIView *sgr_albumRoot = nil;+__weak UIView *sgr_artistRoot = nil;diff --git a/tweak/Sources/Redesigned/Library/LibraryHeader.x b/tweak/Sources/Redesigned/Library/LibraryHeader.xindex 194d9aa8..b92c753e 100644--- a/tweak/Sources/Redesigned/Library/LibraryHeader.x+++ b/tweak/Sources/Redesigned/Library/LibraryHeader.x@@ -10,7 +10,9 @@// ListeningActivity_ElementsKit.AdaptiveFaceContainer (the avatar, id=Components.UI.SideDrawerButton),// id=YourLibraryHeader.title ("Your Library", 21pt), a spacer, a hidden id=YourLibraryHeader.recents,// id=YourLibraryHeader.search and id=YourLibraryHeader.plus; and under the row-// YourLibraryHeaderContentFiltersView {0, 110} 402x49.33, the chips. A folder (trees/continuous/1.txt:325-344)+// YourLibraryHeaderContentFiltersView {0, 110} 402x49.33, the chips. Recents is hidden on the account the tree+// is of; the header's model shows it where it says isRecentsAvailable, a clock between the spacer and Search+// (issue #21), and it goes to the trailing edge with the others. A folder (trees/continuous/1.txt:325-344)// is the same header under YourLibrary_FolderImpl, with id=YourLibraryFolderHeader.back at the leading edge,// its title, then contextMenu, plus and play or pause, and the chips at {0, 118}.//@@ -25,6 +27,15 @@// goes is alpha, touches and accessibility, and the title Spotify draws goes that way while ours is a subview// of the header the stack does not arrange.//+// A move is worked out from where the stack put the control, so it holds only until the stack puts it somewhere+// else, and the stack does that on passes of its own that reach neither the header nor the page: the header's+// model arriving after the page first laid out shows or hides a button, the title gets its text, the avatar+// its size. A button just shown stands where it stood hidden, at the row's leading edge (Recents in 03.txt),+// until the stack's next pass places it. Moves worked out on the page's pass alone were then off by however+// far each control went since -- over the title, off the screen -- until the page laid out again on the way+// back from a playlist (issue #21). So the row the controls stand in is watched too, and every pass of its own+// places them again.+//// The chips leaving takes 49pt off the bottom of the header. What the header is shrunk to is the bottom of its// control row, which hangs off the safe area rather than off the header and so answers the same on every pass,// shrunk header or not; the chips' own top would move with the header and shrink it again pass after pass. The@@ -43,8 +54,8 @@ static const CGFloat kRowInset = 8;// A header shorter than this has not been laid out yet, and nothing is resized from it.static const CGFloat kHeaderFloor = 88;-static char kTitleKey, kListKey, kInsetKey;-static char kSearchKey, kPlusKey, kHeaderTitleKey;+static char kTitleKey, kListKey, kInsetKey, kRowWatchedKey;+static char kRecentsKey, kSearchKey, kPlusKey, kHeaderTitleKey;static char kBackKey, kMenuKey, kFolderPlusKey, kPlayKey, kPauseKey, kFolderTitleKey;static void vanish(UIView *view) {@@ -93,6 +104,32 @@ static CGFloat placeTrailing(UIView *header, NSArray<UIView *> *controls) {return right;}+// `place` again after every pass of the row the controls stand in (see the top of the file), for as long as it+// is in the header. The row is the stack's container, a plain UIView the Kit can watch; what `place` does not+// touch -- the header's height, the list under it -- stays the page's pass's.+static void watchRow(UIView *row, UIView *header, NSArray<UIView *> *(*place)(UIView *header)) {+ if (!row || objc_getAssociatedObject(row, &kRowWatchedKey)) return;+ objc_setAssociatedObject(row, &kRowWatchedKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ __weak UIView *weakHeader = header;+ SGRObserveLayout(row, ^(UIView *view) {+ UIView *owner = weakHeader;+ if (!owner || ![view isDescendantOfView:owner]) return;+ // Once, the first time the row's pass finds a control away from where the page's pass left it.+ static BOOL logged;+ NSMutableArray<NSNumber *> *before = logged ? nil : [NSMutableArray array];+ for (UIView *sub in before ? view.subviews : @[]) [before addObject:@(sub.transform.tx)];+ NSArray<UIView *> *placed = place(owner);+ if (!before || !owner.window) return;+ for (NSUInteger i = 0; i < before.count && i < view.subviews.count; i++) {+ if (fabs(view.subviews[i].transform.tx - before[i].doubleValue) < 0.5) continue;+ logged = YES;+ SGLog(@"redesign library: the header's row laid out on its own after the page, its %lu controls placed again",+ (unsigned long)placed.count);+ break;+ }+ });+}+#pragma mark - the titlestatic NSString *textIn(UIView *label) {@@ -183,34 +220,72 @@ static void resize(UIView *page, UIView *header, UIView *control, UIView *filter#pragma mark - the two headers-static void layoutRoot(UIView *page) {- UIView *header = childNamed(page, @"YourLibraryHeaderView");- if (!header) return;- [header layoutIfNeeded];- SGRLibraryClearScrim(header);- UIView *filters = childNamed(header, @"YourLibraryHeaderContentFiltersView");- vanish(filters);+static BOOL isFace(UIView *view) {+ static Class faceClass;+ if (!faceClass) faceClass = NSClassFromString(@"_TtC29ListeningActivity_ElementsKit21AdaptiveFaceContainer");+ return faceClass && [view isKindOfClass:faceClass];+}+// The root header's controls at its trailing edge, the avatar last, and the title before them. Answers what it+// placed in the order it reads, nothing while the header has no control laid out.+static NSArray<UIView *> *placeRoot(UIView *header) {UIView *spotifyTitle = SGRFindByIdentifier(header, @"YourLibraryHeader.title", &kHeaderTitleKey);vanish(spotifyTitle);- static const void *keys[] = {&kSearchKey, &kPlusKey};- NSMutableArray<UIView *> *trailing = controlsIn(header, @[@"YourLibraryHeader.search", @"YourLibraryHeader.plus"], keys);- static Class faceClass;- if (!faceClass) faceClass = NSClassFromString(@"_TtC29ListeningActivity_ElementsKit21AdaptiveFaceContainer");+ static const void *keys[] = {&kRecentsKey, &kSearchKey, &kPlusKey};+ NSMutableArray<UIView *> *trailing = controlsIn(header, @[+ @"YourLibraryHeader.recents", @"YourLibraryHeader.search", @"YourLibraryHeader.plus",+ ], keys);__block UIView *face = nil;SGForEachView(header, ^(UIView *view) {- if (!face && faceClass && [view isKindOfClass:faceClass] && view.bounds.size.width > 1) face = view;+ if (!face && isFace(view) && view.bounds.size.width > 1) face = view;});if (face) [trailing addObject:face];- if (!trailing.count) return;+ if (!trailing.count) return trailing;CGFloat leading = placeTrailing(header, trailing);CGRect row = SGFrameIn(trailing.firstObject, header);layoutTitle(header, spotifyTitle, SGRSideMargin, leading, CGRectGetMidY(row));+ for (UIView *control in trailing) watchRow(control.superview, header, placeRoot);+ return trailing;+}++// The folder header's controls at its trailing edge and the title between them and the back button, which stays+// where Spotify has it. Answers what it placed in the order it reads, the back button first.+static NSArray<UIView *> *placeFolder(UIView *header) {+ UIView *spotifyTitle = SGRFindByIdentifier(header, @"YourLibraryFolderHeader.title", &kFolderTitleKey);+ vanish(spotifyTitle);+ UIView *back = SGRFindByIdentifier(header, @"YourLibraryFolderHeader.back", &kBackKey);+ static const void *keys[] = {&kMenuKey, &kFolderPlusKey, &kPlayKey, &kPauseKey};+ NSMutableArray<UIView *> *placed = controlsIn(header, @[+ @"YourLibraryFolderHeader.contextMenu", @"YourLibraryFolderHeader.plus",+ @"YourLibraryFolderHeader.play", @"YourLibraryFolderHeader.pause",+ ], keys);+ if (!placed.count && !back) return placed;++ CGFloat trailingEdge = placed.count ? placeTrailing(header, placed) : header.bounds.size.width - kRowInset;+ if (back) [placed insertObject:back atIndex:0];+ CGRect rowFrame = SGFrameIn(placed.firstObject, header);+ CGFloat leading = back ? CGRectGetMaxX(rowFrame) + SGRGrid : SGRSideMargin;+ layoutTitle(header, spotifyTitle, leading, trailingEdge, CGRectGetMidY(rowFrame));+ for (UIView *control in placed) watchRow(control.superview, header, placeFolder);+ return placed;+}++static void layoutRoot(UIView *page) {+ UIView *header = childNamed(page, @"YourLibraryHeaderView");+ if (!header) return;+ [header layoutIfNeeded];+ SGRLibraryClearScrim(header);+ UIView *filters = childNamed(header, @"YourLibraryHeaderContentFiltersView");+ vanish(filters);++ NSArray<UIView *> *trailing = placeRoot(header);+ if (!trailing.count) return;resize(page, header, trailing.firstObject, filters);// The first pass that laid the header out, not the first pass at all: a page appearing lays out before// its controls have a size, and a line off that pass would say the header was left as Spotify's.+ UIView *face = isFace(trailing.lastObject) ? trailing.lastObject : nil;static BOOL logged;if (!logged && header.window && face) {logged = YES;@@ -228,28 +303,17 @@ static void layoutFolder(UIView *page) {UIView *filters = childNamed(header, @"YourLibraryHeaderContentFiltersView");vanish(filters);- UIView *spotifyTitle = SGRFindByIdentifier(header, @"YourLibraryFolderHeader.title", &kFolderTitleKey);- vanish(spotifyTitle);- UIView *back = SGRFindByIdentifier(header, @"YourLibraryFolderHeader.back", &kBackKey);- static const void *keys[] = {&kMenuKey, &kFolderPlusKey, &kPlayKey, &kPauseKey};- NSMutableArray<UIView *> *trailing = controlsIn(header, @[- @"YourLibraryFolderHeader.contextMenu", @"YourLibraryFolderHeader.plus",- @"YourLibraryFolderHeader.play", @"YourLibraryFolderHeader.pause",- ], keys);- if (!trailing.count && !back) return;-- CGFloat trailingEdge = trailing.count ? placeTrailing(header, trailing) : header.bounds.size.width - kRowInset;- UIView *row = back ?: trailing.firstObject;- CGRect rowFrame = SGFrameIn(row, header);- CGFloat leading = back ? CGRectGetMaxX(rowFrame) + SGRGrid : SGRSideMargin;- layoutTitle(header, spotifyTitle, leading, trailingEdge, CGRectGetMidY(rowFrame));- resize(page, header, row, filters);+ NSArray<UIView *> *placed = placeFolder(header);+ if (!placed.count) return;+ resize(page, header, placed.firstObject, filters);+ UIView *back = SGRFindByIdentifier(header, @"YourLibraryFolderHeader.back", &kBackKey);+ NSUInteger trailing = placed.count - (back ? 1 : 0);static BOOL logged;- if (!logged && header.window && trailing.count) {+ if (!logged && header.window && trailing) {logged = YES;SGLog(@"redesign library: folder header %@, back %@, %lu controls at the trailing edge, chips %@",- NSStringFromCGRect(header.frame), back ? @"found" : @"not found", (unsigned long)trailing.count,+ NSStringFromCGRect(header.frame), back ? @"found" : @"not found", (unsigned long)trailing,filters ? @"gone" : @"not found");}}