Skip to content

Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.

C

feat: the redesigned Home gets large cards, tinted shortcuts and its own settings page

My-Name-Is-Jefff9f672a08729
diff --git a/docs/tweaks.md b/docs/tweaks.md
index f0762769..e3ef346d 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -538,9 +538,15 @@ Redesigned:
preview of the view playing a song of its own (LyricsLookSettings.m). Laid out on the Mac against
harness/lyrics/; the page against harness/lyrics-page/
Home/ Home decluttered to music on black (an allow list of its sections: shortcuts, the DJ without its heading and
- transcript, the shelves of cards), a large title where the filter pills were with the avatar at the trailing
- edge, the title rising and fading with the feed as it scrolls, as the Music app's does, the shelves' headings at the Music app's size, each shortcut tile's cover run across it blurred
- (SGRPalette's extension), continuous corners on the covers, and in FLEX builds a meter of each scroll's
+ transcript, the shelves of cards, each with a switch on the Home page of Mod Settings; the previews and the
+ song suggestions only when switched on), a large title where the filter pills were, the title rising and
+ fading with the feed as it scrolls, as the Music app's does, the shelves' headings at the Music app's size,
+ continuous corners on the covers, and, under the Home look switch (the Home page's first row; off, none of
+ its hooks install and Home is as before it): at the trailing edge a glass pill of the filter (a menu that
+ drives Spotify's own chips, with the device picker and the top shelf's Show all) and the avatar, Top picks
+ (the first shelf, or the one Cards from names, moved above the shortcuts and drawn as large cards in their
+ covers' colors with no heading, the page tinted by the first card) and each shortcut tile as a glass pill
+ in its cover's color with its name in bold on up to two lines; in FLEX builds a meter of each scroll's
frames and the hooks' time (Home.h lists its files)
Search/ the Browse page decluttered to its category cards (an allow list of the list's cells: the watch feed
carousels and promos collapse, and the cards move up by the spacing they leave), the header the way Home
@@ -708,8 +714,8 @@ page. It sorts every
setting by the part of Spotify it changes, so a part's glass, its hide switches and its flags sit on
one page, the mod's own rows first and Spotify's flags below them or on a sub page named after what
they change. Its main page groups the rows by what they are, in cards with no headings as Settings has its own,
-under the signing and environment warnings: Redesigned UI, Appearance and Tab bar, with a restart note; Home & Library
-(in the native look), Player, Lyrics, Albums and Artists; Karaoke, Spatial voice (where the iPhone reads headphone
+under the signing and environment warnings: Redesigned UI, Appearance and Tab bar, with a restart note; Home (Home &
+Library in the native look), Player, Lyrics, Albums and Artists; Karaoke, Spatial voice (where the iPhone reads headphone
motion), Audio effects, Live Activity, AirPods gestures and Listening stats; Lock screen, Vibrations and Premium, ads &
privacy; Labs and All flags; Mod. It is checked in the simulator
against harness/mod-settings/. The Appearance page has, in the native look, AMOLED (the redesign is always black), then the stored look's Accent color
diff --git a/tweak/Sources/App/ModSettings.x b/tweak/Sources/App/ModSettings.x
index 9b9c5a9e..402250b4 100644
--- a/tweak/Sources/App/ModSettings.x
+++ b/tweak/Sources/App/ModSettings.x
@@ -19,6 +19,7 @@
#import "Settings/SGPageStyle.h"
#import "Settings/SGModPage.h"
#import "Native/Home/Home.h"
+#import "Redesigned/Home/Home.h"
#import "Shared/AdBlock/AdBlock.h"
#import "Shared/Flags/Flags.h"
#import "Shared/AudioEffects/AudioEffectsPage.h"
@@ -73,7 +74,10 @@ static UIViewController *modSettingsPage(void) {
artists.visible = redesigned;
SGModRow *home = pageRow(@"Home & Library", @"house.fill", UIColor.systemBrownColor, ^UIViewController *{ return SGHomeSettingsPage(); });
home.visible = native;
+ SGModRow *redesignedHome = pageRow(@"Home", @"house.fill", UIColor.systemBrownColor, ^UIViewController *{ return SGRHomeSettingsPage(); });
+ redesignedHome.visible = redesigned;
[sections addObject:SGSection(nil, @[
+ redesignedHome,
home,
pageRow(@"Player", @"play.fill", UIColor.systemPinkColor, ^UIViewController *{ return SGPlayerSettingsPage(); }),
pageRow(@"Lyrics", @"quote.bubble.fill", UIColor.systemOrangeColor, ^UIViewController *{ return SGLyricsSettingsPage(); }),
diff --git a/tweak/Sources/App/Pages.m b/tweak/Sources/App/Pages.m
index 396e3ac5..c8181d7f 100644
--- a/tweak/Sources/App/Pages.m
+++ b/tweak/Sources/App/Pages.m
@@ -18,7 +18,6 @@
#import "Native/Player/NowPlaying.h"
#import "Shared/LiveActivity/LiveActivity.h"
#import "Shared/Lossless/SGLossless.h"
-#import "Redesigned/Home/Home.h"
#import "Redesigned/Lyrics/LyricsText.h"
#import "Redesigned/Lyrics/LyricsLook.h"
#import "Redesigned/Navbar/Navbar.h"
@@ -95,7 +94,7 @@ UIViewController *SGAppearancePage(void) {
SGModRow *icon = SGAppIconRow();
if (icon) [everywhere addObject:icon];
return [[SGModPage alloc] initWithTitle:@"Appearance" intro:SGRestartNote sections:@[
- SGSection(nil, SGRedesignedUIStored() ? [SGRAppearanceRows() arrayByAddingObject:SGRHomeTopPicksRow()] : SGNativeAppearanceRows()),
+ SGSection(nil, SGRedesignedUIStored() ? SGRAppearanceRows() : SGNativeAppearanceRows()),
SGSection(nil, everywhere),
] footer:nil];
}
diff --git a/tweak/Sources/Redesigned/Home/Home.h b/tweak/Sources/Redesigned/Home/Home.h
index 65076bcf..fc0e2afa 100644
--- a/tweak/Sources/Redesigned/Home/Home.h
+++ b/tweak/Sources/Redesigned/Home/Home.h
@@ -1,31 +1,96 @@
// The Home redesign: Spotify's Home page kept, with its controllers, lists and cards, decluttered to a
-// music app on black and restyled from the Kit. Its one setting, Top picks, is on the Appearance page.
+// music app on black and restyled from the Kit. Its settings are the Home page of Mod Settings (HomeSettings.m).
//
// HomeSections.x an allow list of the feed's sections: the shortcuts grid, the DJ and the shelves of
-// cards stay; video and episode previews, episode cards and any new kind collapse. The
-// DJ loses its heading, and the flags the redesign forces on Home
+// cards stay unless switched off; video and playlist previews and the song suggestions
+// stay only when switched on; episode cards and any new kind collapse. The DJ loses its
+// heading, and the flags the redesign forces on Home
+// HomeShelves.m a shelf's identity from its heading, the shelves seen lately and which are hidden
+// HomeSettings.m the Home page of Mod Settings: Top picks, what stays on Home, one switch per shelf
// HomeHeader.x a large title where the filter pills were, the avatar at the trailing edge, no scrim
// HomeHeadings.x the shelves' headings in the Music app's size, drawn over Spotify's
// HomeCards.x the Encore button every card is: shortcut tiles (HomeTiles.m), continuous corners on the
// shelf covers, the DJ card at the card radius without its talking transcript
// HomeTiles.m a shortcut tile's picture run across the tile, blurred behind its title
-// HomeTopPicks.x Top picks: the shelf nearest the top drawn large, as the Music app draws its first
+// HomeTopPicks.x Top picks: the shelf nearest the top drawn large and moved above the shortcuts, each card
+// the cover over a footer in its color
// HomePerf.x FLEX builds: the frames of each scroll of Home and the time the hooks above took
//
// Every hook installs only while Redesigned UI is on (SGRedesignedUI).
// Threading: main thread only.
#import <UIKit/UIKit.h>
-// Top picks (HomeTopPicks.x): the shelf nearest the top drawn large, as the Music app draws its first. On until switched off.
+// The Home look (the first row of the Home page): Top picks and the color behind it, the tinted glass shortcut
+// pills with their bold names, the title's glass pill with the filter menu and the page's color. Off, none of
+// those hooks install and Home is as the redesign drew it before (main at 5051da55). On until switched off; read
+// at launch (SGRHomeLook).
+#define SGRKeyHomeLook @"spotifyglass.redesign.home.look"
+BOOL SGRHomeLook(void);
+// Top picks (HomeTopPicks.x): the shelf nearest the top drawn large above the shortcuts. On until switched off.
#define SGRKeyHomeTopPicks @"spotifyglass.redesign.home.topPicks"
+// The shelf Top picks draws, by its identity (SGRHomeShelfIdentity); unset, the first shelf.
+#define SGRKeyHomeTopPicksFrom @"spotifyglass.redesign.home.topPicksFrom"
+// The footer of a large card in its cover's color. On until switched off; off, the footer is the plain surface.
+#define SGRKeyHomeTopPicksColour @"spotifyglass.redesign.home.topPicksColour"
+// Parts of Home hidden when set (HomeSections.x): the shortcuts grid and the DJ.
+#define SGRKeyHomeHideShortcuts @"spotifyglass.redesign.home.hide.shortcuts"
+#define SGRKeyHomeHideDJ @"spotifyglass.redesign.home.hide.dj"
+// Parts of Home the redesign drops unless these are set: Spotify's carousel of songs to try and rate
+// (Home_ContentEvaluationListElementKit) and its video and playlist previews (Discovery_MediumDensityCardKit,
+// Discovery_PreviewElement).
+#define SGRKeyHomeSongSuggestions @"spotifyglass.redesign.home.songSuggestions"
+#define SGRKeyHomePreviews @"spotifyglass.redesign.home.previews"
+// A shelf hidden when set: this prefix and the shelf's identity (SGRHomeShelfHideKey).
+#define SGRKeyHomeShelfHidePrefix @"spotifyglass.redesign.home.hide.shelf."
+// The shelves seen lately: identity -> the date it was last on Home (HomeShelves.m).
+#define SGRKeyHomeShelvesSeen @"spotifyglass.redesign.home.shelvesSeen"
+
@class SGModRow;
-SGModRow *SGRHomeTopPicksRow(void); // for the Appearance page (App/Pages.m)
+SGModRow *SGRHomeTopPicksRow(void);
+UIViewController *SGRHomeSettingsPage(void); // for Mod Settings (App/ModSettings.x)
+
+// HomeShelves.m. A shelf's identity is what its heading says, read off its labels after the shelf is laid out:
+// the small line over the title when there is one ("More like …", for any artist), else the title ("Recents",
+// an artist's name). nil while the shelf has no heading to read. Language-bound, as the headings are.
+NSString *SGRHomeShelfIdentity(UIView *shelf);
+NSString *SGRHomeShelfTitle(UIView *shelf); // the heading's title alone ("Chief Keef" under "More like")
+void SGRHomeNoteShelf(NSString *identity); // seen on Home now
+NSArray<NSString *> *SGRHomeShelvesSeen(void); // seen within 30 days, in the order first seen
+NSString *SGRHomeShelfHideKey(NSString *identity);
+BOOL SGRHomeShelfHidden(NSString *identity);
+NSString *SGRHomeTopPicksFrom(void); // the identity stored under SGRKeyHomeTopPicksFrom, nil for the first shelf
// Whether HomeSections.x has collapsed the section in this cell.
BOOL SGRHomeSectionCollapsed(UIView *cell);
+// Has the page's list measure the section around `view` again, on the next turn of the run loop: for a shelf
+// whose heading came in after the list sized it (HomeSections.x).
+void SGRHomeMeasureAgain(UIView *view);
// Styles a shortcut tile (id=Shortcut.Card.Home) and keeps its picture in step with its cover (HomeTiles.m).
void SGRHomeStyleTile(UIView *tile);
+// Takes a tile's styling off a button Spotify has reused for something else (a shelf card), which would wear the
+// tile's surface and rim otherwise.
+void SGRHomeUnstyleTile(UIView *button);
+// A tile's corner radius: 14, measured off the reference's 48pt pills (41px at 3px/pt), continuous.
+extern const CGFloat SGRHomeTileRadius;
+
+// The surface color a cover gives a tile or a card (Kit/SGRPalette.h, +tintForImage:), kept by the image while it
+// lives: from the cache at once, else worked out off the main thread. nil when the image has no bitmap to read.
+// Main thread, calls back on it.
+void SGRHomeTintForCover(UIImage *image, void (^completion)(UIColor *color));
+
+// Styles a shelf card (id=Components.UI.HomeCard) drawn large by Top picks (HomeTopPicks.x): a footer in the
+// cover's color under the cover. NO, and the card left as Spotify's, for one at Spotify's own size.
+BOOL SGRHomeStyleLargeCard(UIView *card);
+
+// Whether `view` is in the shelf Top picks draws large (HomeTopPicks.x), whose heading goes (HomeHeadings.x).
+BOOL SGRHomeInTopPicks(UIView *view);
+// Spotify's "Show all" of the shelf Top picks draws, while the shelf is on screen and offers one, and the shelf's
+// title with it: the header's menu offers it (HomeHeader.x), the heading it sits in being gone.
+UIControl *SGRHomeTopPicksShowAll(NSString **title);
+// The page's color from the first large card's cover (HomeHeader.x draws it behind the title, fading to black);
+// nil for none.
+void SGRHomeSetPageTint(UIColor *color);
// FLEX builds only (HomePerf.x): a hook takes the time as it starts and hands it back as it ends; outside
// a FLEX build Begin returns 0 and End does nothing.
@@ -35,6 +100,14 @@ typedef NS_ENUM(NSUInteger, SGRHomeProbe) {
SGRHomeProbeHeadings,
SGRHomeProbeCards,
SGRHomeProbeTiles,
+ // The hooks of the Home look (HomeCards.x, HomeTopPicks.x, HomeTiles.m).
+ SGRHomeProbeLabels, // UILabel setText:/setAttributedText: hook, every call
+ SGRHomeProbeLabelsMatched, // ... the ones under a Home card or tile, which mark the button
+ SGRHomeProbeFrames, // the playing indicator's and PassthroughView's setFrame: hooks
+ SGRHomeProbeListAttrs, // the page list's layoutAttributesForElementsInRect:/ForItem: hooks
+ SGRHomeProbeShelfLayout, // the shelf's layoutSubviews hook (TouchCancellingCollectionView)
+ SGRHomeProbeLargeCard, // SGRHomeStyleLargeCard
+ SGRHomeProbeTint, // SGRHomeTintForCover asks (cache misses go off the main thread)
SGRHomeProbeCount,
};
CFTimeInterval SGRHomeProbeBegin(void);
diff --git a/tweak/Sources/Redesigned/Home/HomeCards.x b/tweak/Sources/Redesigned/Home/HomeCards.x
index 824ac3e4..fe017e39 100644
--- a/tweak/Sources/Redesigned/Home/HomeCards.x
+++ b/tweak/Sources/Redesigned/Home/HomeCards.x
@@ -49,14 +49,19 @@ static void calmDJ(UIView *card) {
static void style(UIView *button) {
NSString *identifier = button.accessibilityIdentifier;
+ // Spotify reuses a button across kinds (a tile's became a shelf card on the phone, 2026-10-11): what the other
+ // kind put on it comes off first.
if ([identifier isEqualToString:@"Shortcut.Card.Home"]) {
- roundCorners(button, SGRRadiusCover);
- if (button.superview.layer.cornerRadius > 0) roundCorners(button.superview, SGRRadiusCover);
+ SGRHomeStyleLargeCard(button);
+ CGFloat radius = SGRHomeLook() ? SGRHomeTileRadius : SGRRadiusCover;
+ roundCorners(button, radius);
+ if (button.superview.layer.cornerRadius > 0) roundCorners(button.superview, radius);
SGRHomeStyleTile(button);
return;
}
if ([identifier isEqualToString:@"Components.UI.HomeCard"]) {
- roundCover(button);
+ SGRHomeUnstyleTile(button);
+ if (!SGRHomeStyleLargeCard(button)) roundCover(button);
return;
}
static Class dj;
@@ -78,6 +83,68 @@ static void style(UIView *button) {
}
%end
+// Spotify gives a reused card or tile its new text, and a feed switched by the filter its new cards, without
+// laying the button out again: a label of its own (Encore.Label-internal, the tile title's -internal) given text
+// under a card or tile marks the button, so the next layout pass styles it with the text as it is then. Spotify's
+// SPTEncoreLabel is KVO-observed, so the Kit's per-instance observers cannot take it (SGRRestyle.h).
+static void relayoutButtonAround(UIView *view);
+
+static void retextedUnder(UIView *label) {
+ CFTimeInterval began = SGRHomeProbeBegin();
+ BOOL ours = [label.accessibilityIdentifier hasSuffix:@"-internal"] || [label.accessibilityIdentifier hasSuffix:@".playback"];
+ if (ours) relayoutButtonAround(label);
+ SGRHomeProbeEnd(SGRHomeProbeLabels, began);
+ if (ours) SGRHomeProbeEnd(SGRHomeProbeLabelsMatched, began);
+}
+
+static void relayoutButtonAround(UIView *label) {
+ static Class backing;
+ if (!backing) backing = NSClassFromString(@"_TtC19LegacyUI_ECMCoreKit31InteractableLayoutBackingButton");
+ UIView *button = label.superview;
+ for (NSUInteger depth = 0; button && depth < 16 && ![button isKindOfClass:backing]; depth++) button = button.superview;
+ if (![button isKindOfClass:backing]) return;
+ NSString *identifier = button.accessibilityIdentifier;
+ if ([identifier isEqualToString:@"Shortcut.Card.Home"] || [identifier isEqualToString:@"Components.UI.HomeCard"]) [button setNeedsLayout];
+}
+
+// The hooks the Home look needs (SGRKeyHomeLook): none of them install while it is off.
+%group SGRHomeLook
+
+// The tile's playing indicator is placed by Spotify's row after the tile's own pass; its placing asks for the
+// tile's pass again, so HomeTiles.m moves it to the trailing edge from where Spotify put it.
+%hook _TtC11Home_ECMKit36ShortcutCardHomePlayingIndicatorView
+- (void)setFrame:(CGRect)frame {
+ %orig;
+ CFTimeInterval began = SGRHomeProbeBegin();
+ relayoutButtonAround((UIView *)self);
+ SGRHomeProbeEnd(SGRHomeProbeFrames, began);
+}
+%end
+
+// A card's cover holder is laid out to the card by Spotify's own Encore.Card pass, after the button's; the large
+// card (HomeTopPicks.x) sizes its cover from that, so the pass is asked for again when the card's inner view is placed.
+%hook _TtCE19Encore_StackViewKitO16EncoreFoundation6Encore15PassthroughView
+- (void)setFrame:(CGRect)frame {
+ %orig;
+ CFTimeInterval began = SGRHomeProbeBegin();
+ relayoutButtonAround((UIView *)self);
+ SGRHomeProbeEnd(SGRHomeProbeFrames, began);
+}
+%end
+
+%hook UILabel
+- (void)setText:(NSString *)text {
+ %orig;
+ retextedUnder((UIView *)self);
+}
+- (void)setAttributedText:(NSAttributedString *)text {
+ %orig;
+ retextedUnder((UIView *)self);
+}
+%end
+
+%end // SGRHomeLook
+
%ctor {
if (!SGRedesignedUI()) return;
%init;
@@ -85,4 +152,10 @@ static void style(UIView *button) {
@"_TtC19LegacyUI_ECMCoreKit31InteractableLayoutBackingButton",
@"_TtC30Discovery_MediumDensityCardKit9DJMDCView",
]);
+ if (!SGRHomeLook()) return;
+ %init(SGRHomeLook);
+ SGRequireClasses(@[
+ @"_TtC11Home_ECMKit36ShortcutCardHomePlayingIndicatorView",
+ @"_TtCE19Encore_StackViewKitO16EncoreFoundation6Encore15PassthroughView",
+ ]);
}
diff --git a/tweak/Sources/Redesigned/Home/HomeHeader.x b/tweak/Sources/Redesigned/Home/HomeHeader.x
index fe5bb1cf..e5b0347d 100644
--- a/tweak/Sources/Redesigned/Home/HomeHeader.x
+++ b/tweak/Sources/Redesigned/Home/HomeHeader.x
@@ -25,7 +25,33 @@
// Tries at finding the tab's name before settling for the English one: a miss walks the window.
static const NSUInteger kTitleTries = 8;
-static char kTitleKey, kTabKey;
+static char kTitleKey, kTabKey, kPillGlassKey, kGlassKey, kButtonsKey, kConnectKey, kTintKey;
+// The title row's pill: a glass capsule around the filter button and the avatar, 44pt tall, as the reference has
+// it; the menu drives Spotify's own filter chips, hidden in the stack, and offers the device picker when Spotify
+// has one (a now playing bar) and the large shelf's Show all, its heading being gone (HomeTopPicks.x).
+static const CGFloat kPillHeight = 44, kPillButton = 44, kPillPad = 6;
+// The page's color behind the title (SGRHomeSetPageTint), fading to black over this height.
+static const CGFloat kTintHeight = 480;
+
+// The pill's buttons sit above Spotify's stack, which would take every touch in the header otherwise; a touch
+// outside a button goes through to the avatar under them.
+@interface SGRHomePillButtons : UIView
+@property (nonatomic, strong) UIButton *filter;
+@end
+@implementation SGRHomePillButtons
+- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
+ UIView *hit = [super hitTest:point withEvent:event];
+ return hit == self ? nil : hit;
+}
+@end
+
+@interface SGRHomeTintView : UIView
+@end
+@implementation SGRHomeTintView
++ (Class)layerClass {
+ return CAGradientLayer.class;
+}
+@end
static NSString *sg_tabName;
static void vanish(UIView *view) {
@@ -80,6 +106,186 @@ static UILabel *titleIn(UIView *header) {
static __weak UIView *sg_header;
static __weak UIStackView *sg_stack;
static __weak UIView *sg_scrim;
+static UIControl *connectButton(UIView *window);
+
+#pragma mark - the pill
+
+// Spotify's filter chips (All, Music, Podcasts, Audiobooks), controls in the stack's hidden pill scroller, in
+// their order there.
+static NSArray<UIControl *> *chips(UIStackView *stack) {
+ NSMutableArray<UIControl *> *found = [NSMutableArray array];
+ SGForEachView(stack, ^(UIView *v) {
+ if ([v.accessibilityIdentifier hasPrefix:@"home-feed-"] && [v isKindOfClass:UIControl.class]) [found addObject:(UIControl *)v];
+ });
+ return [found sortedArrayUsingComparator:^NSComparisonResult(UIView *a, UIView *b) {
+ CGFloat xa = [a convertRect:a.bounds toView:stack].origin.x, xb = [b convertRect:b.bounds toView:stack].origin.x;
+ return xa < xb ? NSOrderedAscending : xa > xb ? NSOrderedDescending : NSOrderedSame;
+ }];
+}
+
+// The chip in effect: selected, or drawn solid with its glass hidden (home-feed-default, trees 2026-10-11).
+static BOOL chosen(UIControl *chip) {
+ if (chip.selected) return YES;
+ __block BOOL solid = NO;
+ SGForEachView(chip, ^(UIView *v) {
+ if ([NSStringFromClass(v.class) containsString:@"ChipGlassView"] && v.hidden) solid = YES;
+ });
+ return solid;
+}
+
+static void press(UIControl *control) {
+ [control sendActionsForControlEvents:UIControlEventTouchUpInside | UIControlEventPrimaryActionTriggered];
+}
+
+static NSArray<UIMenuElement *> *menuElements(void) {
+ NSMutableArray<UIMenuElement *> *elements = [NSMutableArray array];
+ NSMutableArray<UIMenuElement *> *filters = [NSMutableArray array];
+ for (UIControl *chip in chips(sg_stack)) {
+ __weak UIControl *weakChip = chip;
+ UIAction *action = [UIAction actionWithTitle:chip.accessibilityLabel ?: @"" image:nil identifier:nil handler:^(UIAction *a) {
+ if (weakChip) press(weakChip);
+ }];
+ action.state = chosen(chip) ? UIMenuElementStateOn : UIMenuElementStateOff;
+ [filters addObject:action];
+ }
+ if (filters.count) [elements addObject:[UIMenu menuWithTitle:@"" image:nil identifier:nil options:UIMenuOptionsDisplayInline children:filters]];
+ NSMutableArray<UIMenuElement *> *more = [NSMutableArray array];
+ UIControl *connect = connectButton(sg_header.window);
+ if (connect) {
+ __weak UIControl *weakConnect = connect;
+ [more addObject:[UIAction actionWithTitle:@"Devices" image:[UIImage systemImageNamed:@"hifispeaker"] identifier:nil handler:^(UIAction *a) {
+ if (weakConnect) press(weakConnect);
+ }]];
+ }
+ NSString *title = nil;
+ UIControl *showAll = SGRHomeTopPicksShowAll(&title);
+ if (showAll) {
+ __weak UIControl *weakShowAll = showAll;
+ [more addObject:[UIAction actionWithTitle:title.length ? [NSString stringWithFormat:@"Show all · %@", title] : @"Show all"
+ image:[UIImage systemImageNamed:@"rectangle.stack"] identifier:nil handler:^(UIAction *a) {
+ if (weakShowAll) press(weakShowAll);
+ }]];
+ }
+ if (more.count) [elements addObject:[UIMenu menuWithTitle:@"" image:nil identifier:nil options:UIMenuOptionsDisplayInline children:more]];
+ return elements;
+}
+
+// Spotify's device picker button, in the now playing bar (Components.ConnectButtonOutputSwitcher > UIButton,
+// trees 2026-10-11); nil without a bar.
+static UIControl *connectButton(UIView *window) {
+ UIView *holder = window ? SGRFindByIdentifier(window, @"Components.ConnectButtonOutputSwitcher", &kConnectKey) : nil;
+ __block UIControl *button = [holder isKindOfClass:UIControl.class] ? (UIControl *)holder : nil;
+ if (!button) SGForEachView(holder, ^(UIView *v) {
+ if (!button && [v isKindOfClass:UIControl.class]) button = (UIControl *)v;
+ });
+ return button;
+}
+
+static UIButton *pillButton(NSString *symbol, NSString *label) {
+ UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
+ UIImageSymbolConfiguration *config = [UIImageSymbolConfiguration configurationWithPointSize:17 weight:UIImageSymbolWeightMedium];
+ [button setImage:[UIImage systemImageNamed:symbol withConfiguration:config] forState:UIControlStateNormal];
+ button.tintColor = SGRPrimary();
+ button.accessibilityLabel = label;
+ // The menu takes the appearance of its button; outside Spotify's navigation stacks that is the system's.
+ button.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
+ return button;
+}
+
+static SGRHomePillButtons *buttonsIn(UIView *header) {
+ SGRHomePillButtons *buttons = objc_getAssociatedObject(header, &kButtonsKey);
+ if (!buttons) {
+ buttons = [SGRHomePillButtons new];
+ buttons.filter = pillButton(@"line.3.horizontal.decrease", @"Filter Home");
+ buttons.filter.menu = [UIMenu menuWithChildren:@[[UIDeferredMenuElement elementWithUncachedProvider:^(void (^completion)(NSArray<UIMenuElement *> *)) {
+ completion(menuElements());
+ }]]];
+ buttons.filter.showsMenuAsPrimaryAction = YES;
+ [buttons addSubview:buttons.filter];
+ objc_setAssociatedObject(header, &kButtonsKey, buttons, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ }
+ if (buttons.superview != header) [header addSubview:buttons];
+ else if (header.subviews.lastObject != buttons) [header bringSubviewToFront:buttons];
+ return buttons;
+}
+
+static UIView *glassIn(UIView *header) {
+ UIView *glass = objc_getAssociatedObject(header, &kGlassKey);
+ if (!glass) {
+ glass = [UIView new];
+ glass.userInteractionEnabled = NO;
+ objc_setAssociatedObject(header, &kGlassKey, glass, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ }
+ if (glass.superview != header) [header insertSubview:glass atIndex:0];
+ else if (header.subviews.firstObject != glass) [header sendSubviewToBack:glass];
+ return glass;
+}
+
+// Lays the pill out around the avatar, which stays Spotify's in its stack; the pill's leading edge.
+static CGFloat layoutPill(UIView *header, UIStackView *stack, UIView *face) {
+ SGRHomePillButtons *buttons = buttonsIn(header);
+ UIView *glass = glassIn(header);
+ CGRect faceFrame = face ? [stack convertRect:face.frame toView:header] : CGRectZero;
+ CGFloat width = kPillPad + kPillButton + (face ? faceFrame.size.width + kPillPad * 2 : kPillPad);
+ CGFloat maxX = face ? CGRectGetMaxX(faceFrame) + kPillPad : header.bounds.size.width - SGRSideMargin;
+ CGFloat midY = face ? CGRectGetMidY(faceFrame) : CGRectGetMidY(stack.frame);
+ CGRect pill = CGRectMake(round(maxX - width), round(midY - kPillHeight / 2), width, kPillHeight);
+ if (!CGRectEqualToRect(glass.frame, pill)) glass.frame = pill;
+ if (!CGRectEqualToRect(buttons.frame, pill)) buttons.frame = pill;
+ CGRect filter = CGRectMake(kPillPad, 0, kPillButton, kPillHeight);
+ if (!CGRectEqualToRect(buttons.filter.frame, filter)) buttons.filter.frame = filter;
+ SGRGlassCapsuleInside(glass, &kPillGlassKey, pill.size, NO);
+ return CGRectGetMinX(pill);
+}
+
+#pragma mark - the page's color
+
+static UIColor *sg_pageTint;
+static __weak SGRHomeTintView *sg_tintView;
+
+static void paintTint(SGRHomeTintView *tint, BOOL animated) {
+ CAGradientLayer *layer = (CAGradientLayer *)tint.layer;
+ UIColor *top = sg_pageTint ?: UIColor.blackColor;
+ NSArray *colors = @[(id)top.CGColor, (id)[top colorWithAlphaComponent:0].CGColor];
+ if ([layer.colors isEqualToArray:colors]) return;
+ if (animated && tint.window) {
+ CABasicAnimation *fade = [CABasicAnimation animationWithKeyPath:@"colors"];
+ fade.fromValue = layer.colors;
+ fade.duration = SGRCrossfade;
+ [layer addAnimation:fade forKey:@"colors"];
+ }
+ layer.colors = colors;
+}
+
+void SGRHomeSetPageTint(UIColor *color) {
+ if (color == sg_pageTint || [color isEqual:sg_pageTint]) return;
+ sg_pageTint = color;
+ if (sg_tintView) paintTint(sg_tintView, YES);
+}
+
+// The gradient at the back of the page's view (HomePageView, which holds the feed), the feed's own black cleared so
+// it shows through behind the title and the first shelf; the shelves clear theirs (HomeSections.x).
+static void layoutTint(UIView *view) {
+ __block UIView *page = sg_tintView.superview;
+ if (!page) SGForEachView(view, ^(UIView *v) {
+ if (!page && [v.accessibilityIdentifier hasPrefix:@"HomePageView"]) page = v;
+ });
+ if (!page) return;
+ SGRHomeTintView *tint = objc_getAssociatedObject(page, &kTintKey);
+ if (!tint) {
+ tint = [SGRHomeTintView new];
+ tint.userInteractionEnabled = NO;
+ objc_setAssociatedObject(page, &kTintKey, tint, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ sg_tintView = tint;
+ paintTint(tint, NO);
+ }
+ if (tint.superview != page) [page insertSubview:tint atIndex:0];
+ CGRect frame = CGRectMake(0, 0, page.bounds.size.width, kTintHeight);
+ if (!CGRectEqualToRect(tint.frame, frame)) tint.frame = frame;
+ for (UIView *sub in page.subviews) {
+ if ([sub isKindOfClass:UICollectionView.class] && ![sub.backgroundColor isEqual:UIColor.clearColor]) sub.backgroundColor = UIColor.clearColor;
+ }
+}
static BOOL findHeader(UIView *view) {
if (sg_stack && [sg_stack isDescendantOfView:view]) return YES;
@@ -161,6 +367,12 @@ static void layoutHeader(UIViewController *page) {
[stack setNeedsLayout];
}
[stack layoutIfNeeded];
+ // With the Home look off, the avatar stands alone in the stack and the title ends before it, as before.
+ CGFloat pillLeading = face ? CGRectGetMinX([stack convertRect:face.frame toView:header]) : header.bounds.size.width - SGRSideMargin + SGRGrid;
+ if (SGRHomeLook()) {
+ pillLeading = layoutPill(header, stack, face);
+ layoutTint(view);
+ }
UILabel *title = titleIn(header);
NSString *text = tabName(header.window);
@@ -171,7 +383,7 @@ static void layoutHeader(UIViewController *page) {
UIFont *font = SGRFont(UIFontTextStyleLargeTitle, UIFontWeightBold, UIContentSizeCategoryLarge);
if (![title.font isEqual:font]) title.font = font;
- CGFloat trailing = face ? CGRectGetMinX([stack convertRect:face.frame toView:header]) - SGRGrid : header.bounds.size.width - SGRSideMargin;
+ CGFloat trailing = pillLeading - SGRGrid;
CGFloat height = ceil(font.lineHeight);
CGRect frame = CGRectMake(SGRSideMargin, round(CGRectGetMidY(stack.frame) - height / 2), MAX(0, trailing - SGRSideMargin), height);
// By bounds and center: the title carries the scroll's transform.
diff --git a/tweak/Sources/Redesigned/Home/HomeHeadings.x b/tweak/Sources/Redesigned/Home/HomeHeadings.x
index f1086d2a..b01e8907 100644
--- a/tweak/Sources/Redesigned/Home/HomeHeadings.x
+++ b/tweak/Sources/Redesigned/Home/HomeHeadings.x
@@ -22,7 +22,7 @@
#import "Redesigned/Kit/SGRKit.h"
#import "Home.h"
-static char kTitleKey, kShowAllKey, kHeldKey, kTriesKey;
+static char kTitleKey, kShowAllKey, kHeldKey, kTriesKey, kAskedKey;
// How often a heading with no title yet is looked at again.
static const NSUInteger kTries = 3;
@@ -68,6 +68,18 @@ static UILabel *titleLabelIn(UIView *button, UILabel *mine) {
static void restyle(UIView *button) {
UIView *heading = headingAround(button);
if (!heading) return;
+ // The heading names the shelf (HomeShelves.m). The page's list may have sized the shelf before the heading
+ // was in; one switched off, or the one Top picks is to draw, is then measured again now that it is known. The
+ // large shelf's heading goes with the band above its cards (HomeTopPicks.x).
+ UIView *shelf = heading.superview;
+ while (shelf && ![shelf isKindOfClass:UICollectionView.class]) shelf = shelf.superview;
+ NSString *identity = SGRHomeShelfIdentity(shelf);
+ if (identity && ![objc_getAssociatedObject(shelf, &kAskedKey) isEqualToString:identity]) {
+ objc_setAssociatedObject(shelf, &kAskedKey, identity, OBJC_ASSOCIATION_COPY_NONATOMIC);
+ SGRHomeNoteShelf(identity);
+ BOOL wanted = !SGRHomeInTopPicks(heading) && SGEnabled(SGRKeyHomeTopPicks) && [identity isEqualToString:SGRHomeTopPicksFrom()];
+ if (SGRHomeShelfHidden(identity) || wanted) SGRHomeMeasureAgain(heading);
+ }
UILabel *mine = objc_getAssociatedObject(button, &kTitleKey);
UILabel *theirs = titleLabelIn(button, mine);
SGRHeadingHold *held = objc_getAssociatedObject(button, &kHeldKey);
diff --git a/tweak/Sources/Redesigned/Home/HomePerf.x b/tweak/Sources/Redesigned/Home/HomePerf.x
index c86dbe00..b3c28588 100644
--- a/tweak/Sources/Redesigned/Home/HomePerf.x
+++ b/tweak/Sources/Redesigned/Home/HomePerf.x
@@ -23,7 +23,8 @@ static const CFTimeInterval kLongFrame = 0.1;
static const NSUInteger kLongFramesDescribed = 5;
// Section sizing includes Spotify's own measuring of the cell, which the hook calls through.
-static const char *const kProbeNames[SGRHomeProbeCount] = {"section sizing", "header", "headings", "cards", "tiles"};
+static const char *const kProbeNames[SGRHomeProbeCount] = {"section sizing", "header", "headings", "cards", "tiles",
+ "labels", "labels matched", "setFrame hooks", "list attrs", "shelf layout", "large card", "tint asks"};
static NSUInteger sg_calls[SGRHomeProbeCount];
static CFTimeInterval sg_time[SGRHomeProbeCount];
static __weak UIScrollView *sg_list;
@@ -35,6 +36,55 @@ static BOOL probing(void) {
return state == 1;
}
+// Home at rest: once a second, the calls and time of each hook since the last line, the list's layouts and the
+// frames the display link saw late, logged only for a second in which any of them happened. A Home that is
+// still and quiet logs nothing, which is the proof that nothing fires at rest (`make log | grep "home perf/s"`).
+static NSUInteger sg_restFrames, sg_restHitches, sg_listLayouts;
+static CFTimeInterval sg_restLast;
+@interface SGRHomeRestMeter : NSObject
+@end
+@implementation SGRHomeRestMeter
+- (void)tick:(CADisplayLink *)link {
+ CFTimeInterval expected = link.targetTimestamp - link.timestamp;
+ if (sg_restLast > 0 && expected > 0) {
+ sg_restFrames++;
+ if (link.timestamp - sg_restLast > expected * 1.5) sg_restHitches++;
+ }
+ sg_restLast = link.timestamp;
+}
+@end
+static void startRestMeter(void) {
+ static dispatch_source_t timer;
+ static NSUInteger calls[SGRHomeProbeCount];
+ static CFTimeInterval time[SGRHomeProbeCount];
+ static SGRHomeRestMeter *meter;
+ if (timer) return;
+ meter = [SGRHomeRestMeter new];
+ CADisplayLink *link = [CADisplayLink displayLinkWithTarget:meter selector:@selector(tick:)];
+ if (@available(iOS 15.0, *)) link.preferredFrameRateRange = CAFrameRateRangeMake(80, 120, 120);
+ [link addToRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
+ timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
+ dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC), NSEC_PER_SEC, NSEC_PER_SEC / 20);
+ dispatch_source_set_event_handler(timer, ^{
+ NSMutableString *line = [NSMutableString string];
+ CFTimeInterval total = 0;
+ for (NSUInteger i = 0; i < SGRHomeProbeCount; i++) {
+ NSUInteger n = sg_calls[i] - calls[i];
+ CFTimeInterval t = sg_time[i] - time[i];
+ calls[i] = sg_calls[i];
+ time[i] = sg_time[i];
+ total += t;
+ if (n) [line appendFormat:@" %s %lu/%.2fms", kProbeNames[i], (unsigned long)n, t * 1000];
+ }
+ if (line.length || sg_restHitches || sg_listLayouts) {
+ SGLog(@"home perf/s: frames %lu hitches %lu list layouts %lu hooks %.2f ms%@", (unsigned long)sg_restFrames,
+ (unsigned long)sg_restHitches, (unsigned long)sg_listLayouts, total * 1000, line.length ? line : @" (none)");
+ }
+ sg_restFrames = sg_restHitches = sg_listLayouts = 0;
+ });
+ dispatch_resume(timer);
+}
+
CFTimeInterval SGRHomeProbeBegin(void) {
return probing() ? CACurrentMediaTime() : 0;
}
@@ -166,6 +216,7 @@ static BOOL isHomeTab(UIViewController *page) {
}
if (!sg_list) return;
SGLog(@"home perf: measuring the scrolls of %@", NSStringFromClass(sg_list.class));
+ startRestMeter();
// The lag reported came in the first half minute after launch, scrolling or not.
static dispatch_once_t once;
dispatch_once(&once, ^{ SGHangSamplerStart(@"after launch", 90); });
@@ -177,6 +228,7 @@ static BOOL isHomeTab(UIViewController *page) {
- (void)layoutSubviews {
%orig;
if ((UIView *)self != sg_list) return;
+ sg_listLayouts++;
if (!sg_meter) sg_meter = [SGRHomeScrollMeter new];
[sg_meter watch:(UIScrollView *)self];
}
diff --git a/tweak/Sources/Redesigned/Home/HomeSections.x b/tweak/Sources/Redesigned/Home/HomeSections.x
index 43bd24c0..6f1892cd 100644
--- a/tweak/Sources/Redesigned/Home/HomeSections.x
+++ b/tweak/Sources/Redesigned/Home/HomeSections.x
@@ -127,18 +127,40 @@ static SGRHomeKind gridKind(UICollectionView *grid) {
if (grid.accessibilityIdentifier.length) return SGRHomeKindDrop;
UIView *cell = grid.visibleCells.firstObject;
// A grid the list sized before it laid its own cells out: nothing but the shortcuts has come as one.
- if (!cell) return SGRHomeKindKeep;
- return contentNames(cell.subviews.firstObject, @"Home_AnchorsAndShortcutsKit") ? SGRHomeKindKeep : SGRHomeKindDrop;
+ if (cell && !contentNames(cell.subviews.firstObject, @"Home_AnchorsAndShortcutsKit")) return SGRHomeKindDrop;
+ return SGHidden(SGRKeyHomeHideShortcuts) ? SGRHomeKindDrop : SGRHomeKindKeep;
+}
+
+// The previews (a video or a playlist playing as Home scrolls) are medium density cards, on their own or under a
+// heading; the song suggestions are Spotify's content evaluation carousel. Each stays only when asked for.
+static SGRHomeKind optionalKind(NSString *name) {
+ if ([name containsString:@"MediumDensityCard"] || [name containsString:@"Discovery_Preview"]) {
+ return SGHidden(SGRKeyHomePreviews) ? SGRHomeKindKeep : SGRHomeKindDrop;
+ }
+ if ([name containsString:@"ContentEvaluationList"]) return SGHidden(SGRKeyHomeSongSuggestions) ? SGRHomeKindKeep : SGRHomeKindDrop;
+ return SGRHomeKindDrop;
}
// A LazyElementView names the element it will hold before it holds it.
static SGRHomeKind stackKind(UIStackView *stack) {
for (UIView *part in stack.arrangedSubviews) {
- if ([NSStringFromClass(part.class) containsString:@"Discovery_DJElementKit"]) return SGRHomeKindKeep;
+ NSString *name = NSStringFromClass(part.class);
+ if ([name containsString:@"Discovery_DJElementKit"]) return SGHidden(SGRKeyHomeHideDJ) ? SGRHomeKindDrop : SGRHomeKindKeep;
+ SGRHomeKind optional = optionalKind(name);
+ if (optional == SGRHomeKindKeep) return optional;
}
return stack.arrangedSubviews.count >= 2 ? SGRHomeKindDrop : SGRHomeKindPending;
}
+// A shelf stays unless its heading names one that is switched off; one with no heading to read yet stays, and
+// HomeHeadings.x asks the cell to measure again once there is one.
+static SGRHomeKind shelfKind(UIView *shelf) {
+ NSString *identity = SGRHomeShelfIdentity(shelf);
+ if (!identity) return SGRHomeKindKeep;
+ SGRHomeNoteShelf(identity);
+ return SGRHomeShelfHidden(identity) ? SGRHomeKindDrop : SGRHomeKindKeep;
+}
+
// Before the cell is measured, so the height it reports is without the heading.
static void dropDJHeading(UIView *content) {
UIStackView *stack = (UIStackView *)content.subviews.firstObject.subviews.firstObject;
@@ -156,10 +178,21 @@ static SGRHomeKind kindOf(UIView *content, NSString **rootName) {
*rootName = NSStringFromClass(root.class);
static Class shelf;
if (!shelf) shelf = NSClassFromString(@"_TtC16Home_CarouselKit29TouchCancellingCollectionView");
- if (shelf && [root isKindOfClass:shelf]) return SGRHomeKindKeep;
+ if (shelf && [root isKindOfClass:shelf]) return shelfKind(root);
if ([root isKindOfClass:UICollectionView.class]) return gridKind((UICollectionView *)root);
if ([root isKindOfClass:UIStackView.class]) return stackKind((UIStackView *)root);
- return SGRHomeKindDrop;
+ return optionalKind(*rootName);
+}
+
+void SGRHomeMeasureAgain(UIView *view) {
+ UIView *cell = view;
+ while (cell && ![cell isKindOfClass:UICollectionViewCell.class]) cell = cell.superview;
+ // A cell of a shelf's own list: the page's cell is the one around that.
+ for (UIView *v = cell.superview; v; v = v.superview) {
+ if ([v isKindOfClass:UICollectionViewCell.class]) cell = v;
+ }
+ if (!cell || !isSection(((UICollectionViewCell *)cell).contentView)) return;
+ dispatch_async(dispatch_get_main_queue(), ^{ [cell invalidateIntrinsicContentSize]; });
}
// A dropped section's cell is 0 tall, but what it holds keeps the height it measured at, hidden and cut off
@@ -207,6 +240,9 @@ static void expand(UICollectionViewCell *cell) {
} else if (kind == SGRHomeKindKeep) {
// Cells are reused across kinds: one collapsed before holds a section to keep now.
if (collapsed) expand(cell);
+ // The page's color (HomeHeader.x) shows through a kept section; Spotify paints a shelf black on each configure.
+ UIView *root = content.subviews.firstObject.subviews.firstObject;
+ if (SGRHomeLook() && [root isKindOfClass:UICollectionView.class] && ![root.backgroundColor isEqual:UIColor.clearColor]) root.backgroundColor = UIColor.clearColor;
markDropped(cell, attributes.indexPath.section, NO);
logOnce([@"kept a section of " stringByAppendingString:rootName]);
} else {
diff --git a/tweak/Sources/Redesigned/Home/HomeSettings.m b/tweak/Sources/Redesigned/Home/HomeSettings.m
new file mode 100644
index 00000000..d5d22088
--- /dev/null
+++ b/tweak/Sources/Redesigned/Home/HomeSettings.m
@@ -0,0 +1,40 @@
+// The redesign's Home page of Mod Settings: Top picks and where its cards come from, what stays on Home, and
+// one switch per shelf Home has shown lately (HomeShelves.m). Every switch is read as Home lays out, so a
+// change needs a restart (SGRestartNote).
+#import "Core/SGCore.h"
+#import "Settings/SGModPage.h"
+#import "Home.h"
+
+static NSString *const kFirstShelf = @"First shelf";
+
+UIViewController *SGRHomeSettingsPage(void) {
+ NSArray<NSString *> *shelves = SGRHomeShelvesSeen();
+ NSArray<NSString *> *sources = [@[kFirstShelf] arrayByAddingObjectsFromArray:shelves];
+ SGModRow *from = SGMenuRow(@"Cards from", sources, ^NSString *{ return SGRHomeTopPicksFrom() ?: kFirstShelf; }, ^(NSInteger index) {
+ if (index == 0) [NSUserDefaults.standardUserDefaults removeObjectForKey:SGRKeyHomeTopPicksFrom];
+ else [NSUserDefaults.standardUserDefaults setObject:sources[(NSUInteger)index] forKey:SGRKeyHomeTopPicksFrom];
+ });
+ SGModRow *look = SGSwitchRow(@"Home look", @"Top picks, the tinted shortcut pills and the title's glass pill; off, Home as the redesign had it", SGRKeyHomeLook);
+ SGModRow *topPicks = SGRHomeTopPicksRow();
+ topPicks.waitsOn = SGRKeyHomeLook;
+ from.waitsOn = SGRKeyHomeLook;
+ SGModRow *colour = SGSwitchRow(@"Color behind Top picks", nil, SGRKeyHomeTopPicksColour);
+ colour.waitsOn = SGRKeyHomeLook;
+
+ NSMutableArray<SGModRow *> *rows = [NSMutableArray array];
+ for (NSString *identity in shelves) [rows addObject:SGShownRow(identity, nil, SGRHomeShelfHideKey(identity))];
+ if (!rows.count) [rows addObject:SGStatRow(@"None seen yet", ^NSString *{ return @""; })];
+
+ return [[SGModPage alloc] initWithTitle:@"Home" intro:SGRestartNote sections:@[
+ SGNotedSection(nil, @[look, topPicks, from, colour],
+ @"A shelf Home does not show today leaves Top picks off until it is back."),
+ SGSection(@"On Home", @[
+ SGShownRow(@"Shortcuts", nil, SGRKeyHomeHideShortcuts),
+ SGShownRow(@"DJ", nil, SGRKeyHomeHideDJ),
+ SGOptionRow(@"Song suggestions", @"Spotify's carousel of songs to try, when Home offers one", SGRKeyHomeSongSuggestions),
+ SGOptionRow(@"Video and playlist previews", @"The cards that play as Home scrolls", SGRKeyHomePreviews),
+ ]),
+ SGNotedSection(@"Shelves", rows, @"The shelves Home has shown in the last 30 days. A shelf is known by its heading, so one "
+ @"Spotify names differently in another language is listed again."),
+ ] footer:nil];
+}
diff --git a/tweak/Sources/Redesigned/Home/HomeShelves.m b/tweak/Sources/Redesigned/Home/HomeShelves.m
new file mode 100644
index 00000000..5c4a86a5
--- /dev/null
+++ b/tweak/Sources/Redesigned/Home/HomeShelves.m
@@ -0,0 +1,150 @@
+// Home redesign: which shelf a shelf is. Spotify's feed names a shelf only in its heading (no id or URI reaches
+// the view tree), so a shelf is known by what the heading says: "Recents", an artist's name, or the small line
+// over a title ("More like" over an artist, stored as "More like …") so one switch covers that kind whoever the
+// artist is today. The heading is a supplementary view of the shelf's own collection view, dequeued when the
+// shelf lays out, so the shelf is laid out first, the way Native/Home/HomeDeclutter.x lays nested lists out
+// before it reads them.
+//
+// Tree (out/sim/home/tree-before.txt, 9.1.90): TouchCancellingCollectionView > ... > SupplementaryItemView >
+// UIView id=Components.UI.SectionHeadingHome > ... > NoIntrinsicContentSizeButton (a11y "More like Chief Keef")
+// > SPTEncoreLabels "More like " 11pt and "Chief Keef" 17pt, each over a UILabel id=Encore.Label-internal.
+//
+// The shelves seen lately are kept as identity -> date, so the settings page can list them when Home is not
+// open. Threading: main thread only.
+#import "Core/SGCore.h"
+#import "Redesigned/Kit/SGRKit.h"
+#import "Home.h"
+
+static const NSTimeInterval kSeenFor = 30 * 24 * 3600, kSeenWriteEvery = 3600;
+static char kHeadingKey;
+
+static BOOL shown(UIView *view, UIView *root) {
+ for (UIView *v = view; v && v != root; v = v.superview) {
+ if (v.hidden) return NO;
+ }
+ return YES;
+}
+
+// The labels found last time, good while the title label is the same one with the same text: a shelf is measured
+// and laid out many times a scroll, and the walk (and the layout it forces first) would run on each.
+@interface SGRHomeHeadingCache : NSObject
+@property (nonatomic, weak) UILabel *title, *over;
+@property (nonatomic, copy) NSString *text;
+@end
+@implementation SGRHomeHeadingCache
+@end
+static char kCacheKey;
+
+// The heading's labels: Spotify's only (the Kit's title in HomeHeadings.x has no identifier), the largest being
+// the title and a smaller one above it the line over it.
+static BOOL headingLabels(UIView *shelf, UILabel **title, UILabel **over) {
+ if (![shelf isKindOfClass:UICollectionView.class]) return NO;
+ SGRHomeHeadingCache *cache = objc_getAssociatedObject(shelf, &kCacheKey);
+ UILabel *cached = cache.title;
+ if (cached && cached.window && [cached.text isEqualToString:cache.text]) {
+ *title = cached;
+ *over = cache.over;
+ return YES;
+ }
+ [shelf layoutIfNeeded];
+ UIView *heading = SGRFindByIdentifier(shelf, @"Components.UI.SectionHeadingHome", &kHeadingKey);
+ if (!heading) return NO;
+ __block UIView *button = nil;
+ SGForEachView(heading, ^(UIView *v) {
+ if (!button && [NSStringFromClass(v.class) containsString:@"NoIntrinsicContentSizeButton"]) button = v;
+ });
+ if (!button) return NO;
+ __block UILabel *largest = nil, *small = nil;
+ SGForEachView(button, ^(UIView *v) {
+ if (![v isKindOfClass:UILabel.class] || ![v.accessibilityIdentifier containsString:@"Encore.Label"]) return;
+ UILabel *label = (UILabel *)v;
+ if (!label.text.length || !shown(label, button)) return;
+ if (!largest || label.font.pointSize > largest.font.pointSize) {
+ if (largest) small = largest;
+ largest = label;
+ } else if (!small || label.font.pointSize < small.font.pointSize) {
+ small = label;
+ }
+ });
+ *title = largest;
+ *over = small;
+ if (largest) {
+ cache = [SGRHomeHeadingCache new];
+ cache.title = largest;
+ cache.over = small;
+ cache.text = largest.text;
+ objc_setAssociatedObject(shelf, &kCacheKey, cache, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ }
+ return largest != nil;
+}
+
+static NSString *trimmed(UILabel *label) {
+ return [label.text stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
+}
+
+NSString *SGRHomeShelfIdentity(UIView *shelf) {
+ UILabel *title = nil, *over = nil;
+ if (!headingLabels(shelf, &title, &over)) return nil;
+ NSString *small = trimmed(over);
+ return small.length ? [small stringByAppendingString:@" …"] : trimmed(title);
+}
+
+NSString *SGRHomeShelfTitle(UIView *shelf) {
+ UILabel *title = nil, *over = nil;
+ return headingLabels(shelf, &title, &over) ? trimmed(title) : nil;
+}
+
+// identity -> @{first: the date it was first seen, last: the date it was last seen}.
+static NSMutableDictionary<NSString *, NSDictionary<NSString *, NSDate *> *> *seen(void) {
+ static NSMutableDictionary *table;
+ if (!table) {
+ table = [NSMutableDictionary dictionary];
+ NSDictionary *stored = [NSUserDefaults.standardUserDefaults dictionaryForKey:SGRKeyHomeShelvesSeen];
+ NSDate *cutoff = [NSDate dateWithTimeIntervalSinceNow:-kSeenFor];
+ for (NSString *identity in stored) {
+ NSDictionary *dates = stored[identity];
+ if (![identity isKindOfClass:NSString.class] || ![dates isKindOfClass:NSDictionary.class]) continue;
+ NSDate *first = dates[@"first"], *last = dates[@"last"];
+ if ([first isKindOfClass:NSDate.class] && [last isKindOfClass:NSDate.class] && [last compare:cutoff] == NSOrderedDescending) table[identity] = dates;
+ }
+ }
+ return table;
+}
+
+void SGRHomeNoteShelf(NSString *identity) {
+ if (!identity.length) return;
+ NSDictionary<NSString *, NSDate *> *dates = seen()[identity];
+ // A pass of Home sees every shelf again; the store is written once an hour per shelf.
+ if (dates && -dates[@"last"].timeIntervalSinceNow < kSeenWriteEvery) return;
+ NSDate *now = [NSDate date];
+ seen()[identity] = @{@"first": dates[@"first"] ?: now, @"last": now};
+ [NSUserDefaults.standardUserDefaults setObject:seen() forKey:SGRKeyHomeShelvesSeen];
+ if (!dates) SGLog(@"redesign home: shelf \"%@\" seen for the first time", identity);
+}
+
+// In the order first seen: Home's own order on the first day, a new shelf after the ones before it.
+NSArray<NSString *> *SGRHomeShelvesSeen(void) {
+ NSDictionary<NSString *, NSDictionary<NSString *, NSDate *> *> *table = seen();
+ return [table.allKeys sortedArrayUsingComparator:^NSComparisonResult(NSString *a, NSString *b) {
+ return [table[a][@"first"] compare:table[b][@"first"]];
+ }];
+}
+
+NSString *SGRHomeShelfHideKey(NSString *identity) {
+ return [SGRKeyHomeShelfHidePrefix stringByAppendingString:identity];
+}
+
+BOOL SGRHomeShelfHidden(NSString *identity) {
+ return identity.length > 0 && SGHidden(SGRHomeShelfHideKey(identity));
+}
+
+BOOL SGRHomeLook(void) {
+ static int state = -1;
+ if (state < 0) state = SGEnabled(SGRKeyHomeLook) ? 1 : 0;
+ return state == 1;
+}
+
+NSString *SGRHomeTopPicksFrom(void) {
+ NSString *from = [NSUserDefaults.standardUserDefaults stringForKey:SGRKeyHomeTopPicksFrom];
+ return from.length ? from : nil;
+}
diff --git a/tweak/Sources/Redesigned/Home/HomeTiles.m b/tweak/Sources/Redesigned/Home/HomeTiles.m
index fe60f5b4..d0da224b 100644
--- a/tweak/Sources/Redesigned/Home/HomeTiles.m
+++ b/tweak/Sources/Redesigned/Home/HomeTiles.m
@@ -16,10 +16,18 @@
#import "Redesigned/Kit/SGRKit.h"
#import "Home.h"
-// How far the cover sits in from the tile's top, bottom and leading edges, and its corners there.
-static const CGFloat kInset = 5, kCoverRadius = 4;
+// How far the cover sits in from the tile's top, bottom and leading edges, and its corners there (the reference's
+// 37pt covers at 5pt in, with corners of about 6).
+static const CGFloat kInset = 5, kCoverRadius = 6, kCoverRadiusBefore = 4; // Before: with the Home look off.
+const CGFloat SGRHomeTileRadius = 14;
+// The glass rim: a hairline of white around the tile, lit at the top and bottom edges and faint along the sides,
+// as the reference's pills are (brightness 178 over a fill of 65 in the first pixel row, none at the sides).
+static const CGFloat kRimAlpha = 0.5, kRimSideShare = 0.3;
-static char kSurfaceKey, kImageKey, kShownKey;
+static char kSurfaceKey, kImageKey, kShownKey, kTitleKey, kMineKey, kPlayingKey, kRimKey;
+static void rim(UIView *surface);
+// The tile's trailing padding, after the title or the playing indicator.
+static const CGFloat kTrailing = 12;
// Tints already worked out, by the image object while it lives (main thread only).
static NSMapTable<UIImage *, UIColor *> *tints(void) {
@@ -69,9 +77,35 @@ static UIView *surfaceIn(UIView *tile, UIView *fill) {
else [tile insertSubview:surface atIndex:0];
}
if (!CGRectEqualToRect(surface.frame, tile.bounds)) surface.frame = tile.bounds;
+ if (SGRHomeLook()) rim(surface);
return surface;
}
+// The rim is a 1pt white border on a layer over the surface, its mask a vertical gradient opaque at the top and
+// bottom edges and kRimSideShare in between, so the sides carry a faint line and the edges the lit one.
+static void rim(UIView *surface) {
+ CALayer *border = objc_getAssociatedObject(surface, &kRimKey);
+ if (!border) {
+ border = [CALayer layer];
+ // Half of it lies outside the tile's own corner mask.
+ border.borderWidth = 1.5;
+ border.borderColor = [UIColor colorWithWhite:1 alpha:kRimAlpha].CGColor;
+ border.cornerCurve = kCACornerCurveContinuous;
+ CAGradientLayer *mask = [CAGradientLayer layer];
+ UIColor *edge = UIColor.whiteColor, *side = [UIColor colorWithWhite:1 alpha:kRimSideShare];
+ mask.colors = @[(id)edge.CGColor, (id)side.CGColor, (id)side.CGColor, (id)edge.CGColor];
+ mask.locations = @[@0, @0.2, @0.8, @1];
+ border.mask = mask;
+ [surface.layer addSublayer:border];
+ objc_setAssociatedObject(surface, &kRimKey, border, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ }
+ [CATransaction begin];
+ [CATransaction setDisableActions:YES];
+ if (!CGRectEqualToRect(border.frame, surface.bounds)) border.frame = border.mask.frame = surface.bounds;
+ if (border.cornerRadius != SGRHomeTileRadius) border.cornerRadius = SGRHomeTileRadius;
+ [CATransaction commit];
+}
+
// The square scaled about its center so it clears the tile's edges by kInset, and everything after it in the
// row moved in by what that took off its trailing side.
static void inset(UIView *square) {
@@ -82,7 +116,7 @@ static void inset(UIView *square) {
if (!CGAffineTransformEqualToTransform(square.transform, shrink)) square.transform = shrink;
CALayer *layer = square.layer;
// The radius is drawn scaled with the square.
- CGFloat radius = kCoverRadius / scale;
+ CGFloat radius = (SGRHomeLook() ? kCoverRadius : kCoverRadiusBefore) / scale;
if (layer.cornerRadius != radius) layer.cornerRadius = radius;
if (layer.cornerCurve != kCACornerCurveContinuous) layer.cornerCurve = kCACornerCurveContinuous;
if (!layer.masksToBounds) layer.masksToBounds = YES;
@@ -98,6 +132,69 @@ static void inset(UIView *square) {
}
}
+// The title in semibold on up to two lines, a label of the Kit's own over Spotify's one, which goes transparent
+// (it keeps the tile's layout and the button's accessibility label). The playing indicator, which Spotify sets
+// right after its own title, moves to the tile's trailing edge once Spotify has laid it out (HomeCards.x asks
+// for this pass again when it does; moved before that, the move and Spotify's own placing added up and put it
+// past the tile's edge), and the title ends before it.
+static void retitle(UIView *tile) {
+ UIView *theirs = SGRFindByIdentifier(tile, @"Shortcut.Card.Home.Content.title-internal", &kTitleKey);
+ if (![theirs isKindOfClass:UILabel.class]) return;
+ UILabel *mine = objc_getAssociatedObject(tile, &kMineKey);
+ if (!mine) {
+ mine = [UILabel new];
+ mine.numberOfLines = 2;
+ mine.lineBreakMode = NSLineBreakByTruncatingTail;
+ mine.textColor = SGRPrimary();
+ mine.userInteractionEnabled = NO;
+ mine.accessibilityElementsHidden = YES;
+ objc_setAssociatedObject(tile, &kMineKey, mine, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ }
+ // 13pt: the reference's "DRIP" is 27px of cap height at 3px/pt.
+ UIFont *font = SGRFont(UIFontTextStyleFootnote, UIFontWeightSemibold, UIContentSizeCategoryLarge);
+ if (![mine.font isEqual:font]) mine.font = font;
+ NSString *text = ((UILabel *)theirs).text;
+ if (text ? ![mine.text isEqualToString:text] : mine.text != nil) mine.text = text;
+ if (theirs.alpha != 0) theirs.alpha = 0;
+ if (mine.superview != tile) [tile addSubview:mine];
+
+ CGFloat x = CGRectGetMinX([theirs convertRect:theirs.bounds toView:tile]);
+ CGFloat end = tile.bounds.size.width - kTrailing;
+ UIView *playing = SGRFindByIdentifier(tile, @"Shortcut.Card.Home.Content.playback", &kPlayingKey);
+ if (playing && !playing.hidden) {
+ CGAffineTransform was = playing.transform;
+ playing.transform = CGAffineTransformIdentity;
+ CGRect base = [playing.superview convertRect:playing.frame toView:tile];
+ // Laid out by Spotify: after the title, with a size. Before that it sits at the row's origin.
+ if (base.size.width > 0 && CGRectGetMinX(base) > x) {
+ CGAffineTransform moved = CGAffineTransformMakeTranslation(end - CGRectGetMaxX(base), 0);
+ playing.transform = CGAffineTransformEqualToTransform(was, moved) ? was : moved;
+ end = CGRectGetMinX(base) + moved.tx - SGRGrid;
+ } else {
+ playing.transform = was;
+ }
+ }
+ CGRect frame = CGRectMake(x, 0, MAX(0, end - x), tile.bounds.size.height);
+ if (!CGRectEqualToRect(mine.frame, frame)) mine.frame = frame;
+}
+
+void SGRHomeUnstyleTile(UIView *button) {
+ UIView *surface = objc_getAssociatedObject(button, &kSurfaceKey);
+ UILabel *mine = objc_getAssociatedObject(button, &kMineKey);
+ if (!surface && !mine) return;
+ [surface removeFromSuperview];
+ [mine removeFromSuperview];
+ objc_setAssociatedObject(button, &kSurfaceKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ objc_setAssociatedObject(button, &kMineKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ objc_setAssociatedObject(button, &kShownKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ UIView *theirs = SGRFindByIdentifier(button, @"Shortcut.Card.Home.Content.title-internal", &kTitleKey);
+ if (theirs.alpha == 0) theirs.alpha = 1;
+ UIView *square = partsOf(button).square;
+ for (UIView *sibling in square.superview.subviews) {
+ if (!CGAffineTransformIsIdentity(sibling.transform)) sibling.transform = CGAffineTransformIdentity;
+ }
+}
+
static void tint(UIView *tile, UIView *surface, UIColor *color, BOOL animated) {
color = color ?: untinted();
if ([surface.backgroundColor isEqual:color]) return;
@@ -115,6 +212,7 @@ static void refresh(UIView *tile) {
if (!cover || !square || square.bounds.size.width < 20 || tile.bounds.size.width <= square.bounds.size.width) return;
UIView *surface = surfaceIn(tile, parts.fill);
inset(square);
+ if (SGRHomeLook()) retitle(tile);
UIImage *image = cover.image;
if (!image) {
@@ -122,22 +220,28 @@ static void refresh(UIView *tile) {
tint(tile, surface, nil, NO);
return;
}
- UIColor *known = [tints() objectForKey:image];
- if (known) {
- objc_setAssociatedObject(tile, &kShownKey, image, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- tint(tile, surface, known, YES);
- return;
- }
if (objc_getAssociatedObject(tile, &kShownKey) == image) return;
objc_setAssociatedObject(tile, &kShownKey, image, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
__weak UIView *weakTile = tile;
- [SGRPalette tintForImage:image surface:untinted() completion:^(UIColor *color) {
+ SGRHomeTintForCover(image, ^(UIColor *color) {
UIView *strongTile = weakTile;
- if (color) [tints() setObject:color forKey:image];
// A tile reused for another cover in the meantime has asked for that one.
if (!strongTile || objc_getAssociatedObject(strongTile, &kShownKey) != image) return;
tint(strongTile, surfaceIn(strongTile, partsOf(strongTile).fill), color, YES);
+ });
+}
+
+void SGRHomeTintForCover(UIImage *image, void (^completion)(UIColor *color)) {
+ SGRHomeProbeEnd(SGRHomeProbeTint, SGRHomeProbeBegin());
+ UIColor *known = [tints() objectForKey:image];
+ if (known) {
+ completion(known);
+ return;
+ }
+ [SGRPalette tintForImage:image surface:untinted() strong:SGRHomeLook() completion:^(UIColor *color) {
+ if (color) [tints() setObject:color forKey:image];
+ completion(color);
}];
}
diff --git a/tweak/Sources/Redesigned/Home/HomeTopPicks.x b/tweak/Sources/Redesigned/Home/HomeTopPicks.x
index 3e93e7d4..aa925e56 100644
--- a/tweak/Sources/Redesigned/Home/HomeTopPicks.x
+++ b/tweak/Sources/Redesigned/Home/HomeTopPicks.x
@@ -1,25 +1,50 @@
-// Home redesign: Top picks, the first shelf of cards drawn large the way the Music app draws its top shelf.
+// Home redesign: Top picks, the first shelf of cards drawn large the way the Music app draws its top shelf:
+// each card the cover edge to edge over a footer in the cover's color, 60% of the page wide so the next one
+// shows at the trailing edge.
//
// A shelf is a Home_CarouselKit.TouchCancellingCollectionView in a cell of the page's list (HomeSections.x), a
-// compositional layout of its own with cards 149 by 195 under a 40pt heading (trees: the 393x235 shelf, cards at
-// {149, 195}: a square picture over 46pt of text). Its sizes are Spotify's, made by the layout's section provider each
-// time the layout is asked for one. So every compositional layout's provider is wrapped, and while the large shelf's
-// provider runs, a size kSmallest or more wide is made kScale as wide and taller by as much as it widened: the
-// picture grows, the text under it does not. The page's cell is made taller by the same amount.
+// compositional layout of its own with cards under a 40pt heading (9.1.78: cards 149 by 195, a square picture
+// over 46pt of text; 9.1.90's Recents: 98 by 144, the picture 94 at 2pt in, over 38pt of text). Its sizes are
+// Spotify's, made by the layout's section provider each time the layout is asked for one. So every
+// compositional layout's provider is wrapped, and while the large shelf's provider runs, a size kSmallest or
+// more wide is made as many times wider as the card needs to reach kCardShare of the page, and taller by what
+// the card grows: the card to its new width plus kFooter, the row that holds the cards by the same amount.
+// The page's cell is made taller by the same amount.
//
// The shelf drawn large is the one nearest the top of the page: the lowest index any shelf has been measured at.
// Cells are reused across shelves, so each measuring sets or clears the mark on the layout it holds.
+//
+// A large card (SGRHomeStyleLargeCard, from HomeCards.x on every layout of the card) keeps Spotify's button, cover
+// and touch. A surface in the cover's color (SGRHomeTintForCover) goes behind everything, the cover's top corners
+// take the card's radius, and two labels of the Kit's own stand in the footer over Spotify's, which go
+// transparent: the leading one bold with what Spotify says under the title ("Album • Artist", or the makers of a
+// mix), the other the title in the secondary color, which is how the reference lays its footer out. A card with
+// no second line leads with its title.
#import <objc/runtime.h>
#import "Core/SGCore.h"
#import "Settings/SGModPage.h"
#import "Redesigned/Kit/SGRKit.h"
#import "Home.h"
-static const CGFloat kScale = 1.7, kSmallest = 120, kHeading = 40;
-static char kLargeKey, kNaturalKey, kWrappedKey, kWidthKey, kAskedKey;
+static const CGFloat kCardShare = 0.6, kFooter = 76, kSmallest = 80, kHeading = 40;
+// A card this wide or wider is one drawn large: Spotify's widest is 153.
+static const CGFloat kLargeCard = 200;
+static const CGFloat kFooterTop = 12, kFooterGap = 2;
+// How far under the page's title the large shelf's cards sit, once its heading has gone.
+// The reference's cards start 2pt above the feed's top (110pt on a 393pt phone against the feed's 112).
+static const CGFloat kBandAbove = -2;
+// The footer's text, in from the card's edges (the reference's first glyph sits 13.7pt in; a glyph's side bearing
+// is about 1.5).
+static const CGFloat kFooterInset = 12;
+static char kLargeKey, kNaturalKey, kWrappedKey, kGrowKey, kAskedKey, kListKey, kOffsetKey, kHeldKey, kShowAllKey, kHeadingKey;
+static __weak UICollectionView *sg_largeShelf;
static _Thread_local BOOL sg_enlarging;
-// The narrowest size kSmallest or more wide the running provider made, at Spotify's width: its cards.
-static _Thread_local CGFloat sg_cardWidth;
+// The list section the shortcuts grid is in, from its measuring; NSNotFound until one is.
+static NSInteger sg_gridSection = NSNotFound;
+static _Thread_local CGFloat sg_containerWidth;
+// Spotify's card in the running provider: the narrowest size kSmallest or more wide, and how much taller the
+// large one is than it. 0 until a card is made.
+static _Thread_local CGFloat sg_cardWidth, sg_cardGrow;
static NSInteger sg_topIndex = NSIntegerMax;
// The layout a wrapped provider belongs to, set once the layout is made.
@@ -29,17 +54,24 @@ static NSInteger sg_topIndex = NSIntegerMax;
@implementation SGRLayoutBox
@end
+static CGFloat targetWidth(void) {
+ return round(sg_containerWidth * kCardShare);
+}
+
static UICollectionViewCompositionalLayoutSectionProvider wrapped(UICollectionViewCompositionalLayoutSectionProvider provider, SGRLayoutBox *box) {
return ^NSCollectionLayoutSection *(NSInteger section, id<NSCollectionLayoutEnvironment> environment) {
UICollectionViewCompositionalLayout *layout = box.layout;
BOOL was = sg_enlarging;
- CGFloat wasWidth = sg_cardWidth;
+ CGFloat wasWidth = sg_cardWidth, wasGrow = sg_cardGrow, wasContainer = sg_containerWidth;
sg_enlarging = layout && objc_getAssociatedObject(layout, &kLargeKey) != nil;
- sg_cardWidth = 0;
+ sg_containerWidth = environment.container.effectiveContentSize.width;
+ sg_cardWidth = sg_cardGrow = 0;
NSCollectionLayoutSection *made = provider(section, environment);
- if (layout && sg_cardWidth > 0) objc_setAssociatedObject(layout, &kWidthKey, @(sg_cardWidth), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ if (layout && sg_cardGrow > 0) objc_setAssociatedObject(layout, &kGrowKey, @(sg_cardGrow), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
sg_enlarging = was;
sg_cardWidth = wasWidth;
+ sg_cardGrow = wasGrow;
+ sg_containerWidth = wasContainer;
return made;
};
}
@@ -50,6 +82,70 @@ static UICollectionViewCompositionalLayout *boxed(UICollectionViewCompositionalL
return made;
}
+#pragma mark - the shelf above the grid
+
+// Spotify's feed puts the shortcuts grid first and the shelves after it; the reference puts the large shelf first,
+// right under the title, and the grid under it. The list's layout is Spotify's, one cell per section, so its
+// attributes are moved as the list asks for them: the shelf's block takes the grid's place and the grid's moves
+// down by the shelf's height, the gap between them kept. The sections between (dropped, 0 tall) stay where they
+// are. Nothing else about the layout changes: its content size and every other section's place are its own.
+static _Thread_local BOOL sg_unmoved; // reading the layout's own frames, not the moved ones
+
+// The grid's and the shelf's frames as the layout has them, and where the sections before the shelf end (the
+// grid's bottom, or a kept shelf's when Cards from names a later one); NO while there is no swap to make.
+static BOOL blocks(UICollectionViewLayout *layout, CGRect *grid, CGRect *shelf, CGFloat *before) {
+ NSInteger shelfSection = sg_topIndex == NSIntegerMax ? NSNotFound : sg_topIndex / 10000;
+ if (sg_gridSection == NSNotFound || shelfSection == NSNotFound || sg_gridSection >= shelfSection) return NO;
+ if (!objc_getAssociatedObject(layout, &kListKey)) return NO;
+ sg_unmoved = YES;
+ UICollectionViewLayoutAttributes *a = [layout layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:sg_gridSection]];
+ UICollectionViewLayoutAttributes *b = [layout layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:sg_topIndex % 10000 inSection:shelfSection]];
+ CGFloat last = CGRectGetMaxY(a.frame);
+ if (a && b) {
+ for (UICollectionViewLayoutAttributes *between in [layout layoutAttributesForElementsInRect:CGRectUnion(a.frame, b.frame)]) {
+ NSInteger section = between.indexPath.section;
+ if (section >= sg_gridSection && section < shelfSection) last = MAX(last, CGRectGetMaxY(between.frame));
+ }
+ }
+ sg_unmoved = NO;
+ if (!a || !b || last > CGRectGetMinY(b.frame)) return NO;
+ *grid = a.frame;
+ *shelf = b.frame;
+ *before = last;
+ return YES;
+}
+
+// The shelf's block takes the grid's place; the grid and everything between it and the shelf move down by the
+// shelf's block, the gap above the shelf (its section inset) kept between the two.
+static void move(UICollectionViewLayoutAttributes *attributes, CGRect grid, CGRect shelf, CGFloat before) {
+ NSInteger section = attributes.indexPath.section, shelfSection = sg_topIndex / 10000;
+ CGRect frame = attributes.frame;
+ if (section >= sg_gridSection && section < shelfSection) frame.origin.y += CGRectGetMaxY(shelf) - before;
+ else if (section == shelfSection) frame.origin.y += CGRectGetMinY(grid) - CGRectGetMinY(shelf);
+ else return;
+ attributes.frame = frame;
+}
+
+// The large shelf's heading, scrolled out of its bounds, would be recycled by the shelf, and with it the Show all
+// the header's menu offers: its attributes stay in what the layout answers, so the shelf keeps the view (clipped,
+// and transparent). Which supplementary it is, the layout said itself while the heading was in view.
+static char kHeadingKindKey, kHeadingPathKey;
+static NSArray<UICollectionViewLayoutAttributes *> *keptHeading(UICollectionViewLayout *layout, NSArray<UICollectionViewLayoutAttributes *> *made) {
+ NSString *kind = objc_getAssociatedObject(layout, &kHeadingKindKey);
+ NSIndexPath *path = objc_getAssociatedObject(layout, &kHeadingPathKey);
+ for (UICollectionViewLayoutAttributes *attributes in made) {
+ if (attributes.representedElementCategory != UICollectionElementCategorySupplementaryView) continue;
+ if (!kind) {
+ objc_setAssociatedObject(layout, &kHeadingKindKey, attributes.representedElementKind, OBJC_ASSOCIATION_COPY_NONATOMIC);
+ objc_setAssociatedObject(layout, &kHeadingPathKey, attributes.indexPath, OBJC_ASSOCIATION_COPY_NONATOMIC);
+ }
+ return made;
+ }
+ if (!kind || !path) return made;
+ UICollectionViewLayoutAttributes *heading = [layout layoutAttributesForSupplementaryViewOfKind:kind atIndexPath:path];
+ return heading ? [made arrayByAddingObject:heading] : made;
+}
+
%hook UICollectionViewCompositionalLayout
- (instancetype)initWithSectionProvider:(UICollectionViewCompositionalLayoutSectionProvider)provider
configuration:(UICollectionViewCompositionalLayoutConfiguration *)configuration {
@@ -62,24 +158,54 @@ static UICollectionViewCompositionalLayout *boxed(UICollectionViewCompositionalL
SGRLayoutBox *box = [SGRLayoutBox new];
return boxed(%orig(wrapped(provider, box)), box);
}
-%end
+- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect {
+ CGRect grid, shelf;
+ CGFloat before;
+ if (objc_getAssociatedObject(self, &kLargeKey)) {
+ NSArray<UICollectionViewLayoutAttributes *> *made = %orig;
+ return keptHeading((UICollectionViewLayout *)self, made);
+ }
+ if (sg_unmoved || !blocks((UICollectionViewLayout *)self, &grid, &shelf, &before)) return %orig;
+ // Everything between the two blocks moves within their band, so the band is asked for whole.
+ CGRect band = CGRectUnion(grid, shelf);
+ if (!CGRectIntersectsRect(rect, band)) return %orig;
+ NSMutableArray<UICollectionViewLayoutAttributes *> *moved = [NSMutableArray array];
+ CGRect whole = CGRectUnion(rect, band);
+ NSArray<UICollectionViewLayoutAttributes *> *all = %orig(whole);
+ for (UICollectionViewLayoutAttributes *attributes in all) {
+ UICollectionViewLayoutAttributes *copy = [attributes copy];
+ move(copy, grid, shelf, before);
+ if (CGRectIntersectsRect(copy.frame, rect)) [moved addObject:copy];
+ }
+ return moved;
+}
-// How much a card of Spotify's `width` grows: its picture is as wide as it is, so it grows as much in height.
-static CGFloat growth(CGFloat width) {
- return round(width * kScale) - width;
+- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
+ UICollectionViewLayoutAttributes *attributes = %orig;
+ CGRect grid, shelf;
+ CGFloat before;
+ if (sg_unmoved || !attributes || !blocks((UICollectionViewLayout *)self, &grid, &shelf, &before)) return attributes;
+ UICollectionViewLayoutAttributes *copy = [attributes copy];
+ move(copy, grid, shelf, before);
+ return copy;
}
+%end
%hook NSCollectionLayoutSize
+ (instancetype)sizeWithWidthDimension:(NSCollectionLayoutDimension *)width heightDimension:(NSCollectionLayoutDimension *)height {
- if (!width.isAbsolute || width.dimension < kSmallest) return %orig;
+ if (!width.isAbsolute || width.dimension < kSmallest || sg_containerWidth <= 0) return %orig;
+ BOOL sized = height.isAbsolute || height.isEstimated;
// The cards come first, then the row that holds them all (1634 by 195 on the phone): the row is as many cards
- // wide, so it widens by kScale too, but grows in height only as much as a card does.
- sg_cardWidth = sg_cardWidth > 0 ? MIN(sg_cardWidth, width.dimension) : width.dimension;
- if (!sg_enlarging || !(height.isAbsolute || height.isEstimated)) return %orig;
- CGFloat grow = growth(sg_cardWidth);
- NSCollectionLayoutDimension *wider = [NSCollectionLayoutDimension absoluteDimension:round(width.dimension * kScale)];
- NSCollectionLayoutDimension *taller = height.isAbsolute ? [NSCollectionLayoutDimension absoluteDimension:height.dimension + grow]
- : [NSCollectionLayoutDimension estimatedDimension:height.dimension + grow];
+ // wide, so it widens as much, but grows in height only as much as a card does.
+ if (sg_cardWidth == 0 || width.dimension < sg_cardWidth) {
+ sg_cardWidth = width.dimension;
+ if (sized) sg_cardGrow = MAX(0, targetWidth() + kFooter - height.dimension);
+ }
+ if (!sg_enlarging || !sized || sg_cardGrow <= 0) return %orig;
+ CGFloat scale = targetWidth() / sg_cardWidth;
+ NSCollectionLayoutDimension *wider = [NSCollectionLayoutDimension absoluteDimension:round(width.dimension * scale)];
+ NSCollectionLayoutDimension *taller = height.isAbsolute ? [NSCollectionLayoutDimension absoluteDimension:height.dimension + sg_cardGrow]
+ : [NSCollectionLayoutDimension estimatedDimension:height.dimension + sg_cardGrow];
return %orig(wider, taller);
}
%end
@@ -94,19 +220,37 @@ static CGFloat growth(CGFloat width) {
if (![NSStringFromClass(object_getClass(content)) containsString:@"Home_EvoPageImpl13HomeStructure"]) return result;
UIView *root = content.subviews.firstObject;
NSInteger index = attributes.indexPath.section * 10000 + attributes.indexPath.item;
+ UIView *list = ((UIView *)self).superview;
+ while (list && ![list isKindOfClass:UICollectionView.class]) list = list.superview;
+ if (list) objc_setAssociatedObject(((UICollectionView *)list).collectionViewLayout, &kListKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
if (!shelf || ![root isKindOfClass:shelf] || result.size.height <= kHeading) {
// The top's place holds something else now (the feed came again): the next shelf measured takes it.
if (index == sg_topIndex) sg_topIndex = NSIntegerMax;
+ // The shortcuts grid is the one bare list Home has (HomeSections.x); a section of anything else in its place
+ // (no shortcuts) leaves the order alone.
+ BOOL grid = [root isKindOfClass:UICollectionView.class] && !root.accessibilityIdentifier.length && result.size.height > 0;
+ if (grid) sg_gridSection = attributes.indexPath.section;
+ else if (attributes.indexPath.section == sg_gridSection) sg_gridSection = NSNotFound;
return result;
}
UICollectionViewLayout *layout = ((UICollectionView *)root).collectionViewLayout;
- if (index < sg_topIndex) sg_topIndex = index;
+ // The shelf drawn large: the one Cards from names, else the one nearest the top; never one switched off.
+ NSString *identity = SGRHomeShelfIdentity(root), *from = SGRHomeTopPicksFrom();
+ BOOL candidate = !SGRHomeShelfHidden(identity) && (!from || [identity isEqualToString:from]);
+ if (candidate && index < sg_topIndex) sg_topIndex = index;
+ else if (!candidate && index == sg_topIndex) sg_topIndex = NSIntegerMax;
BOOL large = index == sg_topIndex, was = objc_getAssociatedObject(layout, &kLargeKey) != nil;
+ if (large) sg_largeShelf = (UICollectionView *)root;
// The shelf's height as Spotify sizes it, from a measuring before it was large.
if (!was) objc_setAssociatedObject(layout, &kNaturalKey, @(result.size.height), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
if (large != was) {
objc_setAssociatedObject(layout, &kLargeKey, large ? @YES : nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[layout invalidateLayout];
+ // The shelf laid its cells out at Spotify's sizes before the mark changed (reading its heading lays it out), and
+ // a cell the new layout puts off screen kept its old frame on screen: the cells are made again from the new
+ // layout, the heading with them.
+ __weak UICollectionView *weakShelf = (UICollectionView *)root;
+ dispatch_async(dispatch_get_main_queue(), ^{ [weakShelf reloadData]; });
static dispatch_once_t once;
dispatch_once(&once, ^{
SGLog(@"redesign home: top picks at %ld, its layout %@ (%@)", (long)index, NSStringFromClass(layout.class),
@@ -121,24 +265,36 @@ static CGFloat growth(CGFloat width) {
natural = @(result.size.height);
objc_setAssociatedObject(layout, &kNaturalKey, natural, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- NSNumber *card = objc_getAssociatedObject(layout, &kWidthKey);
+ NSNumber *grow = objc_getAssociatedObject(layout, &kGrowKey);
+ // The large shelf's heading goes (HomeHeadings.x), and so does the band it took: the shelf is scrolled past it
+ // (keptAbove below), and its cell is that much shorter, so the cards sit kBandAbove under the page's title.
+ CGFloat offset = 0;
+ if (large) {
+ CGRect first = [layout layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]].frame;
+ offset = MAX(0, CGRectGetMinY(first) - kBandAbove);
+ }
+ objc_setAssociatedObject(layout, &kOffsetKey, offset > 0 ? @(offset) : nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
// Never shorter than what the shelf lays out: Spotify's height can be taken before its tallest card sized
// itself (a title on 4 lines), and the shelf then scrolls inside its cell. The shelf's height comes from its
// cards, not from the cell, so taking it does not feed back.
- if (natural && large && card) result.size = CGSizeMake(result.size.width, MAX(natural.doubleValue + growth(card.doubleValue),
- ceil(layout.collectionViewContentSize.height)));
+ if (natural && large && grow) result.size = CGSizeMake(result.size.width, MAX(natural.doubleValue + grow.doubleValue,
+ ceil(layout.collectionViewContentSize.height)) - offset);
else if (natural && was) result.size = CGSizeMake(result.size.width, natural.doubleValue);
return result;
}
%end
-// The large shelf's cards sized themselves after its cell was measured and no longer fit: measure the cell again.
+static CGFloat keptAbove(UICollectionView *shelf) {
+ return [objc_getAssociatedObject(shelf.collectionViewLayout, &kOffsetKey) doubleValue];
+}
+
%hook _TtC16Home_CarouselKit29TouchCancellingCollectionView
+// The large shelf's cards sized themselves after its cell was measured and no longer fit: measure the cell again.
- (void)setContentSize:(CGSize)size {
%orig;
UICollectionView *shelf = (UICollectionView *)self;
UICollectionViewLayout *layout = shelf.collectionViewLayout;
- if (!objc_getAssociatedObject(layout, &kLargeKey) || size.height <= shelf.bounds.size.height + 0.5) return;
+ if (!objc_getAssociatedObject(layout, &kLargeKey) || size.height - keptAbove(shelf) <= shelf.bounds.size.height + 0.5) return;
NSNumber *asked = objc_getAssociatedObject(layout, &kAskedKey);
if (asked && asked.doubleValue == size.height) return;
objc_setAssociatedObject(layout, &kAskedKey, @(size.height), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
@@ -146,13 +302,291 @@ static CGFloat growth(CGFloat width) {
while (cell && ![cell isKindOfClass:UICollectionViewCell.class]) cell = cell.superview;
dispatch_async(dispatch_get_main_queue(), ^{ [cell invalidateIntrinsicContentSize]; });
}
+
+// VoiceOver reads a list's cells in their index order, which the swap no longer draws: the page's list reads
+// them in the order they are on screen.
+- (NSArray *)accessibilityElements {
+ UICollectionView *list = (UICollectionView *)self;
+ if (!objc_getAssociatedObject(list.collectionViewLayout, &kListKey) || sg_gridSection == NSNotFound) return %orig;
+ NSArray<UICollectionViewCell *> *cells = [list.visibleCells sortedArrayUsingComparator:^NSComparisonResult(UIView *a, UIView *b) {
+ return a.frame.origin.y < b.frame.origin.y ? NSOrderedAscending : a.frame.origin.y > b.frame.origin.y ? NSOrderedDescending : NSOrderedSame;
+ }];
+ NSMutableArray *elements = [NSMutableArray array];
+ for (UICollectionViewCell *cell in cells) {
+ if (!cell.accessibilityElementsHidden && cell.bounds.size.height > 0) [elements addObject:cell];
+ }
+ return elements;
+}
+
+// The large shelf stays scrolled past its heading, and cannot be dragged back down to it: its own vertical pan
+// goes, the cards' sideways one being the orthogonal scroll view's. A shelf no longer large gets the pan back.
+- (void)layoutSubviews {
+ %orig;
+ CFTimeInterval began = SGRHomeProbeBegin();
+ UICollectionView *shelf = (UICollectionView *)self;
+ CGFloat above = keptAbove(shelf);
+ BOOL held = objc_getAssociatedObject(shelf, &kHeldKey) != nil;
+ // Every shelf and the page's list are this class: only the large one, or one that was, has work here.
+ if (above <= 0 && !held) {
+ SGRHomeProbeEnd(SGRHomeProbeShelfLayout, began);
+ return;
+ }
+ // The heading goes with the band (its point still in view would show a sliver), and comes back with it. Set
+ // here, on the shelf's own pass, since the heading's button lays out before the shelf is marked and not after.
+ UIView *heading = SGRFindByIdentifier(shelf, @"Components.UI.SectionHeadingHome", &kHeadingKey);
+ if (heading && heading.alpha != (above > 0 ? 0 : 1)) {
+ heading.alpha = above > 0 ? 0 : 1;
+ heading.userInteractionEnabled = above <= 0;
+ heading.accessibilityElementsHidden = above > 0;
+ }
+ if (above > 0) {
+ if (shelf.contentOffset.y != above) shelf.contentOffset = CGPointMake(shelf.contentOffset.x, above);
+ if (shelf.scrollEnabled) shelf.scrollEnabled = NO;
+ // The heading scrolled past the top would draw over the page's title otherwise: Spotify's shelf does not clip.
+ if (!shelf.clipsToBounds) shelf.clipsToBounds = YES;
+ if (!held) objc_setAssociatedObject(shelf, &kHeldKey, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ } else if (held) {
+ objc_setAssociatedObject(shelf, &kHeldKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ shelf.scrollEnabled = YES;
+ shelf.clipsToBounds = NO;
+ }
+ SGRHomeProbeEnd(SGRHomeProbeShelfLayout, began);
+}
%end
+UIControl *SGRHomeTopPicksShowAll(NSString **title) {
+ UICollectionView *shelf = sg_largeShelf;
+ if (!shelf.window) return nil;
+ UIView *showAll = SGRFindByIdentifier(shelf, @"Components.UI.NavigationButtonHome", &kShowAllKey);
+ __block UIControl *control = [showAll isKindOfClass:UIControl.class] ? (UIControl *)showAll : nil;
+ if (!control) SGForEachView(showAll, ^(UIView *v) {
+ if (!control && [v isKindOfClass:UIControl.class]) control = (UIControl *)v;
+ });
+ if (!control || showAll.bounds.size.width < 1) return nil;
+ for (UIView *v = showAll; v && v != shelf; v = v.superview) {
+ if (v.hidden) return nil;
+ }
+ if (title) *title = SGRHomeShelfTitle(shelf);
+ return control;
+}
+
+#pragma mark - the large card
+
+static char kPartsKey, kCoverKey, kShownKey;
+
+@interface SGRLargeCardParts : NSObject
+@property (nonatomic, strong) UIView *surface;
+@property (nonatomic, strong) UILabel *lead, *second;
+@property (nonatomic, copy) NSArray<UILabel *> *theirs; // Spotify's labels made transparent, to bring back
+@end
+@implementation SGRLargeCardParts
+@end
+
+static UILabel *footerLabel(UIFont *font, UIColor *color) {
+ UILabel *label = [UILabel new];
+ label.font = font;
+ label.textColor = color;
+ label.lineBreakMode = NSLineBreakByTruncatingTail;
+ label.userInteractionEnabled = NO;
+ label.accessibilityElementsHidden = YES; // the button reads the whole card out already
+ return label;
+}
+
+static BOOL shown(UIView *view, UIView *root) {
+ for (UIView *v = view; v && v != root; v = v.superview) {
+ if (v.hidden) return NO;
+ }
+ return YES;
+}
+
+// Spotify's labels with text, top to bottom: its first line, then its second (the kind over the name on a
+// "More like" card, the name over "Album • Artist" in Recents), then the sponsored line when there is one.
+static NSArray<UILabel *> *spotifyLabels(UIView *card, SGRLargeCardParts *parts) {
+ NSMutableArray<UILabel *> *labels = [NSMutableArray array];
+ SGForEachView(card, ^(UIView *v) {
+ if (![v isKindOfClass:UILabel.class] || v == parts.lead || v == parts.second) return;
+ if (((UILabel *)v).text.length && shown(v, card)) [labels addObject:(UILabel *)v];
+ });
+ return [labels sortedArrayUsingComparator:^NSComparisonResult(UILabel *a, UILabel *b) {
+ CGFloat ya = [a convertRect:a.bounds toView:card].origin.y, yb = [b convertRect:b.bounds toView:card].origin.y;
+ return ya < yb ? NSOrderedAscending : ya > yb ? NSOrderedDescending : NSOrderedSame;
+ }];
+}
+
+static void restore(UIView *card, SGRLargeCardParts *parts) {
+ UIView *holder = SGRFindByIdentifier(card, @"Encore.ImageView", &kCoverKey);
+ if (holder && !CGAffineTransformIsIdentity(holder.transform)) holder.transform = CGAffineTransformIdentity;
+ [parts.surface removeFromSuperview];
+ [parts.lead removeFromSuperview];
+ [parts.second removeFromSuperview];
+ for (UILabel *label in parts.theirs) label.alpha = 1;
+ objc_setAssociatedObject(card, &kPartsKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ objc_setAssociatedObject(card, &kShownKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+}
+
+static void setColor(SGRLargeCardParts *parts, UIColor *color, BOOL animated) {
+ color = color ?: SGRElevated(UIColor.blackColor);
+ if ([parts.surface.backgroundColor isEqual:color]) return;
+ if (!animated || !parts.surface.window) {
+ parts.surface.backgroundColor = color;
+ return;
+ }
+ SGRAnimate(SGRMotionFade, ^{ parts.surface.backgroundColor = color; }, nil);
+}
+
+// The first card of the large shelf: the page takes its color.
+static BOOL isFirstCard(UIView *card) {
+ UIView *cell = card;
+ while (cell && ![cell isKindOfClass:UICollectionViewCell.class]) cell = cell.superview;
+ UICollectionView *shelf = sg_largeShelf;
+ if (!cell || !shelf || ![cell isDescendantOfView:shelf]) return NO;
+ NSIndexPath *path = [shelf indexPathForCell:(UICollectionViewCell *)cell];
+ return path && path.item == 0;
+}
+
+static void tintCard(UIView *card, UIImageView *cover) {
+ SGRLargeCardParts *parts = objc_getAssociatedObject(card, &kPartsKey);
+ UIImage *image = cover.image;
+ if (!parts) return;
+ if (!image || !SGEnabled(SGRKeyHomeTopPicksColour)) {
+ objc_setAssociatedObject(card, &kShownKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ setColor(parts, nil, NO);
+ if (isFirstCard(card)) SGRHomeSetPageTint(nil);
+ return;
+ }
+ if (objc_getAssociatedObject(card, &kShownKey) == image) return;
+ objc_setAssociatedObject(card, &kShownKey, image, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ __weak UIView *weakCard = card;
+ SGRHomeTintForCover(image, ^(UIColor *color) {
+ UIView *strongCard = weakCard;
+ // A card reused for another cover in the meantime has asked for that one.
+ if (!strongCard || objc_getAssociatedObject(strongCard, &kShownKey) != image) return;
+ SGRLargeCardParts *now = objc_getAssociatedObject(strongCard, &kPartsKey);
+ if (now) setColor(now, color, YES);
+ if (isFirstCard(strongCard)) SGRHomeSetPageTint(color);
+ });
+}
+
+static BOOL styleLargeCard(UIView *card);
+BOOL SGRHomeStyleLargeCard(UIView *card) {
+ CFTimeInterval began = SGRHomeProbeBegin();
+ BOOL styled = styleLargeCard(card);
+ SGRHomeProbeEnd(SGRHomeProbeLargeCard, began);
+ return styled;
+}
+static BOOL styleLargeCard(UIView *card) {
+ SGRLargeCardParts *parts = objc_getAssociatedObject(card, &kPartsKey);
+ UIView *holder = SGRFindByIdentifier(card, @"Encore.ImageView", &kCoverKey);
+ UIImageView *cover = nil;
+ for (UIView *sub in holder.subviews) {
+ if ([sub isKindOfClass:UIImageView.class]) cover = (UIImageView *)sub;
+ }
+ if (card.bounds.size.width < kLargeCard || !cover) {
+ if (parts) restore(card, parts);
+ return NO;
+ }
+ if (!parts) {
+ parts = [SGRLargeCardParts new];
+ parts.surface = [UIView new];
+ parts.surface.userInteractionEnabled = NO;
+ parts.surface.backgroundColor = SGRElevated(UIColor.blackColor);
+ parts.lead = footerLabel(SGRFont(UIFontTextStyleBody, UIFontWeightSemibold, UIContentSizeCategoryLarge), SGRPrimary());
+ parts.second = footerLabel(SGRFont(UIFontTextStyleFootnote, UIFontWeightRegular, UIContentSizeCategoryLarge), SGRSecondary());
+ objc_setAssociatedObject(card, &kPartsKey, parts, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ __weak UIView *weakCard = card;
+ // The block is replaced on every pass, so a cover taken into another card tells the card it is in now.
+ SGRObserveImage(cover, ^(UIImageView *view) {
+ UIView *strongCard = weakCard;
+ if (strongCard && [view isDescendantOfView:strongCard]) tintCard(strongCard, view);
+ });
+ static dispatch_once_t once;
+ dispatch_once(&once, ^{ SGLog(@"redesign home: top picks card %@ styled", NSStringFromCGRect(card.bounds)); });
+ }
+ CALayer *layer = card.layer;
+ if (layer.cornerRadius != SGRRadiusCard) layer.cornerRadius = SGRRadiusCard;
+ if (layer.cornerCurve != kCACornerCurveContinuous) layer.cornerCurve = kCACornerCurveContinuous;
+ if (!layer.masksToBounds) layer.masksToBounds = YES;
+ CALayer *coverLayer = cover.layer;
+ if (coverLayer.cornerRadius != SGRRadiusCard) coverLayer.cornerRadius = SGRRadiusCard;
+ if (coverLayer.cornerCurve != kCACornerCurveContinuous) coverLayer.cornerCurve = kCACornerCurveContinuous;
+ CACornerMask top = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
+ if (coverLayer.maskedCorners != top) coverLayer.maskedCorners = top;
+ if (!coverLayer.masksToBounds) coverLayer.masksToBounds = YES;
+ // Spotify keeps the cover 2pt in from the card on every side (9.1.90; none on 9.1.78); the reference's reaches
+ // the card's top and sides, so the holder is scaled up about its middle by what the inset takes, a transform its
+ // layout never reads. Only once Spotify has laid the holder out to the card (HomeCards.x asks for this pass
+ // again when it does): scaled from its first, small size, the cover filled the whole card.
+ CGAffineTransform was = holder.transform;
+ holder.transform = CGAffineTransformIdentity;
+ CGRect laid = [holder.superview convertRect:holder.frame toView:card];
+ CGFloat inset = CGRectGetMinX(laid), cardWidth = card.bounds.size.width;
+ CGAffineTransform flush = was;
+ if (inset > 0 && inset <= 4 && fabs(CGRectGetWidth(laid) + inset * 2 - cardWidth) < 1) {
+ flush = CGAffineTransformMakeScale(cardWidth / CGRectGetWidth(laid), cardWidth / CGRectGetWidth(laid));
+ } else if (CGRectGetWidth(laid) + 1 < cardWidth - 4) {
+ flush = CGAffineTransformIdentity;
+ }
+ holder.transform = flush;
+
+ if (parts.surface.superview != card) [card insertSubview:parts.surface atIndex:0];
+ if (!CGRectEqualToRect(parts.surface.frame, card.bounds)) parts.surface.frame = card.bounds;
+
+ NSArray<UILabel *> *theirs = spotifyLabels(card, parts);
+ for (UILabel *label in theirs) {
+ if (label.alpha != 0) label.alpha = 0;
+ }
+ if (![parts.theirs isEqualToArray:theirs]) {
+ for (UILabel *label in parts.theirs) {
+ if (![theirs containsObject:label]) label.alpha = 1;
+ }
+ parts.theirs = theirs;
+ }
+ // Spotify's lines in Spotify's order, the first bold and the rest on one line ("Album" over "Name – Artist"
+ // for a card of three). A sponsored card's "Limited ads" is an ad's line and stays out.
+ NSMutableArray<NSString *> *lines = [NSMutableArray array];
+ for (UILabel *label in theirs) {
+ if (![label.accessibilityIdentifier containsString:@"SponsoredLabel"]) [lines addObject:label.text];
+ }
+ NSString *lead = lines.firstObject;
+ NSString *second = lines.count > 1 ? [[lines subarrayWithRange:NSMakeRange(1, lines.count - 1)] componentsJoinedByString:@" – "] : nil;
+ // An album's "Album • Kendrick Lamar" under "DAMN." leads with the kind, "DAMN. – Kendrick Lamar" under it.
+ NSRange dot = lines.count > 1 ? [lines[1] rangeOfString:@" • "] : NSMakeRange(NSNotFound, 0);
+ if (dot.location != NSNotFound && dot.location > 0) {
+ lead = [lines[1] substringToIndex:dot.location];
+ second = [NSString stringWithFormat:@"%@ – %@", lines[0], [lines[1] substringFromIndex:NSMaxRange(dot)]];
+ }
+ if (![parts.lead.text isEqualToString:lead]) parts.lead.text = lead;
+ if (second ? ![parts.second.text isEqualToString:second] : parts.second.text != nil) parts.second.text = second;
+ if (parts.lead.superview != card) [card addSubview:parts.lead];
+ if (parts.second.superview != card) [card addSubview:parts.second];
+
+ // The footer is the card's bottom kFooter: the card is that much taller than its cover is wide. Spotify's stack
+ // lays the cover out after this pass, so its frame is not the one to go by.
+ CGFloat footerTop = card.bounds.size.height - kFooter;
+ CGFloat x = kFooterInset, width = MAX(0, card.bounds.size.width - x * 2);
+ CGFloat leadHeight = ceil(parts.lead.font.lineHeight), secondHeight = ceil(parts.second.font.lineHeight);
+ CGRect leadFrame = CGRectMake(x, footerTop + kFooterTop, width, leadHeight);
+ CGRect secondFrame = CGRectMake(x, CGRectGetMaxY(leadFrame) + kFooterGap, width, secondHeight);
+ if (!CGRectEqualToRect(parts.lead.frame, leadFrame)) parts.lead.frame = leadFrame;
+ if (!CGRectEqualToRect(parts.second.frame, secondFrame)) parts.second.frame = secondFrame;
+ tintCard(card, cover);
+ return YES;
+}
+
+BOOL SGRHomeInTopPicks(UIView *view) {
+ static Class shelf;
+ if (!shelf) shelf = NSClassFromString(@"_TtC16Home_CarouselKit29TouchCancellingCollectionView");
+ for (UIView *v = view; v; v = v.superview) {
+ if (shelf && [v isKindOfClass:shelf]) return objc_getAssociatedObject(((UICollectionView *)v).collectionViewLayout, &kLargeKey) != nil;
+ }
+ return NO;
+}
+
SGModRow *SGRHomeTopPicksRow(void) {
- return SGWithSymbol(SGSwitchRow(@"Top picks", @"Home's first shelf drawn large", SGRKeyHomeTopPicks), @"rectangle.stack");
+ return SGWithSymbol(SGSwitchRow(@"Top picks", @"Home's first shelf above the shortcuts, as large cards in their covers' colors", SGRKeyHomeTopPicks), @"rectangle.stack");
}
%ctor {
- if (!SGRedesignedUI() || !SGEnabled(SGRKeyHomeTopPicks)) return;
+ if (!SGRedesignedUI() || !SGRHomeLook() || !SGEnabled(SGRKeyHomeTopPicks)) return;
%init;
}
diff --git a/tweak/Sources/Redesigned/Kit/SGRPalette.h b/tweak/Sources/Redesigned/Kit/SGRPalette.h
index fa59ddaa..10ea8296 100644
--- a/tweak/Sources/Redesigned/Kit/SGRPalette.h
+++ b/tweak/Sources/Redesigned/Kit/SGRPalette.h
@@ -40,13 +40,15 @@ typedef struct {
// nil to the completion when the image has no bitmap to read (a symbol, a CIImage).
+ (void)paletteForImage:(UIImage *)image request:(SGRPaletteRequest)request completion:(void (^)(SGRPalette *palette))completion;
-// `surface` tinted a little toward the artwork's dominant color (brought down to a luminance of 0.05, then
-// 35% of it mixed in), so a tile or row on the surface quietly takes its cover's color while white text on
-// it keeps its contrast. Never dimmer than `surface`: a mix that came out darker is lifted back to its
+// The artwork's dominant color as a surface: its saturation lifted a fifth, brought down to a luminance of 0.04
+// (the reference's card and tile surfaces), so a tile or card wears its cover's color while white text on it
+// keeps better than 11:1. Never dimmer than `surface`: a color that came out darker is lifted back to its
// luminance keeping its hue, so a near-black cover cannot cost the tile the step of elevation it stands on,
// nor sink it into the gray band SGRAmoled.x turns pure black. nil to the completion when the image has no
// bitmap to read.
-+ (void)tintForImage:(UIImage *)image surface:(UIColor *)surface completion:(void (^)(UIColor *tint))completion;
+// `strong` NO is the tint as it was before the Home look (2026-10-11): the dominant color at a luminance of 0.05
+// with 35% of it mixed into `surface`, a faint cast rather than the cover's color.
++ (void)tintForImage:(UIImage *)image surface:(UIColor *)surface strong:(BOOL)strong completion:(void (^)(UIColor *tint))completion;
@end
// Any color made fit to be a field, the same way the edge color is: for a color Spotify hands over
diff --git a/tweak/Sources/Redesigned/Kit/SGRPalette.m b/tweak/Sources/Redesigned/Kit/SGRPalette.m
index b7edd354..aaef881d 100644
--- a/tweak/Sources/Redesigned/Kit/SGRPalette.m
+++ b/tweak/Sources/Redesigned/Kit/SGRPalette.m
@@ -10,9 +10,15 @@ static const CGFloat kMaxLuminance = 0.07, kMaxLuminanceContrast = 0.04;
static const CGFloat kBackdropWidth = 160, kBackdropMaxHeight = 400, kBackdropSigma = 12;
static const CGFloat kDissolveWidth = 96, kDissolveSigma = 5;
static const CGFloat kFadeFrom = 0.55, kDissolveOpaque = 0.85;
-// A tint: the artwork's dominant color brought down to this luminance, then this share of it mixed into
-// the surface it tints.
-static const CGFloat kTintLuminance = 0.05, kTintShare = 0.35;
+// A tint: the artwork's dominant color, its saturation lifted by kTintSaturationLift up to kTintSaturationMax,
+// brought down to kTintLuminance, then kTintShare of it mixed into the surface it tints. Measured off the
+// reference's Home (IMG_4025, 2026-10-11): its card and tile surfaces sit at a luminance of 0.03 to 0.04 with the
+// cover's saturation about 1.2 times (0.73 to 0.86, 0.57 to 0.71, 0.29 to 0.36). White text keeps better than
+// 11:1 on anything under 0.04.
+static const CGFloat kTintLuminance = 0.04, kTintShare = 1.0;
+static const CGFloat kTintSaturationLift = 1.2, kTintSaturationMax = 0.85;
+// The faint tint of before (strong NO): no lift, 35% of the color held under 0.05 mixed into the surface.
+static const CGFloat kFaintTintLuminance = 0.05, kFaintTintShare = 0.35;
// A moving field's colors: luminance held between these (the ceiling 0.07 with Increase Contrast, as a
// field's), saturation lifted by this much up to a cap, and a near-black one lifted by at most this factor.
static const CGFloat kFlowLuminanceMin = 0.03, kFlowLuminanceMax = 0.13;
@@ -240,15 +246,23 @@ static NSArray<UIColor *> *flowColorsOf(CGImageRef image, CGFloat ceiling) {
return colors.count == 5 ? colors : nil;
}
-static UIColor *tintOf(CGImageRef image, UIColor *surface) {
+static UIColor *tintOf(CGImageRef image, UIColor *surface, BOOL strong) {
CGFloat linear[3];
CGFloat r = 0, g = 0, b = 0, a = 1;
if (!dominantColorOf(image, linear) || ![surface getRed:&r green:&g blue:&b alpha:&a]) return nil;
+ if (strong) {
+ // The saturation lift, in HSB on the encoded color, then back to linear light for the luminance cap.
+ CGFloat h = 0, s = 0, v = 0, lr = 0, lg = 0, lb = 0;
+ [[UIColor colorWithRed:toEncoded(linear[0]) green:toEncoded(linear[1]) blue:toEncoded(linear[2]) alpha:1] getHue:&h saturation:&s brightness:&v alpha:&a];
+ [[UIColor colorWithHue:h saturation:MIN(kTintSaturationMax, MAX(s, s * kTintSaturationLift)) brightness:v alpha:1] getRed:&lr green:&lg blue:&lb alpha:&a];
+ linear[0] = toLinear(lr), linear[1] = toLinear(lg), linear[2] = toLinear(lb);
+ }
+ CGFloat cap = strong ? kTintLuminance : kFaintTintLuminance;
CGFloat luminance = 0.2126 * linear[0] + 0.7152 * linear[1] + 0.0722 * linear[2];
- if (luminance > kTintLuminance) {
- for (int k = 0; k < 3; k++) linear[k] *= kTintLuminance / luminance;
+ if (luminance > cap) {
+ for (int k = 0; k < 3; k++) linear[k] *= cap / luminance;
}
- CGFloat t = kTintShare;
+ CGFloat t = strong ? kTintShare : kFaintTintShare;
CGFloat mixed[3] = {r * (1 - t) + toEncoded(linear[0]) * t,
g * (1 - t) + toEncoded(linear[1]) * t,
b * (1 - t) + toEncoded(linear[2]) * t};
@@ -312,11 +326,11 @@ static UIColor *tintOf(CGImageRef image, UIColor *surface) {
});
}
-+ (void)tintForImage:(UIImage *)image surface:(UIColor *)surface completion:(void (^)(UIColor *tint))completion {
++ (void)tintForImage:(UIImage *)image surface:(UIColor *)surface strong:(BOOL)strong completion:(void (^)(UIColor *tint))completion {
if (!completion) return;
dispatch_async(paletteQueue(), ^{
CGImageRef cg = image.CGImage;
- UIColor *tint = cg && CGImageGetWidth(cg) && CGImageGetHeight(cg) ? tintOf(cg, surface) : nil;
+ UIColor *tint = cg && CGImageGetWidth(cg) && CGImageGetHeight(cg) ? tintOf(cg, surface, strong) : nil;
static dispatch_once_t once;
if (tint) dispatch_once(&once, ^{ SGLog(@"redesign kit: first tint %@", tint); });
dispatch_async(dispatch_get_main_queue(), ^{ completion(tint); });
diff --git a/tweak/Sources/Settings/SGModPage.h b/tweak/Sources/Settings/SGModPage.h
index 5b9b16fc..4e1ca997 100644
--- a/tweak/Sources/Settings/SGModPage.h
+++ b/tweak/Sources/Settings/SGModPage.h
@@ -25,6 +25,8 @@
@property (nonatomic, strong) UIColor *tint; // the square under the symbol, gray when nil (SGWithTile)
// A switch row that changes the whole app draws SGGlowSwitch instead of a UISwitch.
@property (nonatomic) BOOL glows;
+// The switch shows the opposite of what is stored under its key (SGShownRow).
+@property (nonatomic) BOOL inverted;
// An ⓘ button beside the row's switch, whose tap reads this out under the row's title.
@property (nonatomic, copy) NSString *info;
// The row shows only while this answers YES, asked again whenever a switch on the page is flipped, the
@@ -69,6 +71,9 @@ extern NSString *const SGRestartNote;
SGModRow *SGSwitchRow(NSString *title, NSString *subtitle, NSString *key); // on until switched off
SGModRow *SGHideRow(NSString *title, NSString *subtitle, NSString *key); // off until switched on
+// A part of Spotify the mod can take away, named for the part and shown on: turning it off stores YES under
+// `hideKey`, the way SGHideRow does, so a reset (stock) shows the part again.
+SGModRow *SGShownRow(NSString *title, NSString *subtitle, NSString *hideKey);
// A switch for something the mod adds rather than takes away: off until it is asked for.
SGModRow *SGOptionRow(NSString *title, NSString *subtitle, NSString *key);
// A switch whose work is not finished: turning it on says so first, and offers the repo.
diff --git a/tweak/Sources/Settings/SGModPage.m b/tweak/Sources/Settings/SGModPage.m
index d53db3d1..5b9e5d44 100644
--- a/tweak/Sources/Settings/SGModPage.m
+++ b/tweak/Sources/Settings/SGModPage.m
@@ -27,6 +27,12 @@ SGModRow *SGHideRow(NSString *title, NSString *subtitle, NSString *key) {
return row;
}
+SGModRow *SGShownRow(NSString *title, NSString *subtitle, NSString *hideKey) {
+ SGModRow *row = SGHideRow(title, subtitle, hideKey);
+ row.inverted = YES;
+ return row;
+}
+
// A switch for something the mod adds rather than takes away: off until it is asked for.
SGModRow *SGOptionRow(NSString *title, NSString *subtitle, NSString *key) {
SGModRow *row = SGSwitchRow(title, subtitle, key);
@@ -887,7 +893,7 @@ static void showWaiting(UITableViewCell *cell, BOOL waiting, NSString *switchTit
BOOL beats = NO;
if (locked) SGLockedFlagValue(row.key, &beats);
BOOL showsLock = locked && (beats || !SGFlagOverride(row.key));
- BOOL on = row.flag ? (showsLock ? lockedRowOn(row) : flagRowOn(row)) : SGFlag(row.key, row.defaultOn);
+ BOOL on = row.flag ? (showsLock ? lockedRowOn(row) : flagRowOn(row)) : SGFlag(row.key, row.defaultOn) != row.inverted;
UIControl *toggle;
if (row.glows) {
SGGlowSwitch *glow = [SGGlowSwitch new];
@@ -1010,7 +1016,7 @@ static void showWaiting(UITableViewCell *cell, BOOL waiting, NSString *switchTit
if (!path) return;
SGModRow *row = [self rowAt:path];
if (row.flag) SGSetFlagOverride(row.key, on ? @(!row.forceOff) : nil);
- else SGSetEnabled(row.key, on);
+ else SGSetEnabled(row.key, on != row.inverted);
if (row.changed) row.changed(on);
// A glowing switch is let finish its slide before the reload puts a new one in its place; rows coming
// or going are let finish first too.