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 player grows out of the now playing bar's card and the cover flies out of its artwork, the way the Music app opens its player

Vojtěch Škopek9eebe8d89129
diff --git a/harness/morph/README.md b/harness/morph/README.md
new file mode 100644
index 00000000..ec4101ca
--- /dev/null
+++ b/harness/morph/README.md
@@ -0,0 +1,23 @@
+# Morph harness
+
+`PlayerMorph.x` run for real against a mock of Spotify's `SPTBarOverlayPresentationTransition`: the
+mock sets the player's frame, its alpha and the bar stand-in from `-setProgress:` the way 9.1.78 does
+(0x109815464), driven by a display link on a spring, and makes the bar's stand-in the way Spotify
+does (a snapshot view opening, a `renderInContext:` image closing). The bar, the player and the cover
+are plain views standing in for Spotify's; the morph's inputs from `NowPlayingBar.x` and
+`PlayerArtwork.x` are stubbed in `main.m`.
+
+ THEOS=$HOME/theos ./build.sh
+ xcrun simctl install booted build/MorphHarness.app
+ xcrun simctl launch booted com.vojta.morphharness # opens, closes, repeats
+
+Held at one progress, for a screenshot (the positions are logged as `MORPH` lines):
+
+ SIMCTL_CHILD_MORPH_T=0.3 xcrun simctl launch --console-pty booted com.vojta.morphharness
+ xcrun simctl io booted screenshot shot.png
+
+A recording shows the move: `xcrun simctl io booted recordVideo -f run.mp4`, then
+`ffmpeg -ss T -t 0.5 -i run.mp4 -vf "fps=24,scale=160:-1,tile=8x1" -frames:v 1 strip.png`.
+
+What it does not cover: Spotify's real player and list, the tab bar's stand-in, the bar's glass on the
+closing stand-in (`BarTransition.x`), a drag, and the field's colour (the sheet is black here).
diff --git a/harness/morph/build.sh b/harness/morph/build.sh
new file mode 100755
index 00000000..438a52c8
--- /dev/null
+++ b/harness/morph/build.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+set -e
+SRC=/Users/vojta/Documents/quick/custom_spotify/custom_spotify/tweak/Sources
+OUT=$(dirname "$0")/build
+rm -rf "$OUT"; mkdir -p "$OUT/gen" "$OUT/MorphHarness.app"
+"$THEOS/bin/logos.pl" -c generator=internal "$SRC/Redesigned/Player/PlayerMorph.x" > "$OUT/gen/PlayerMorph.m"
+SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)
+xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-arc -g -O0 \
+ -I"$SRC" -I"$SRC/Redesigned/Player" -isysroot "$SDK" -Wno-deprecated-declarations \
+ "$(dirname "$0")/main.m" "$OUT/gen/PlayerMorph.m" \
+ -framework UIKit -framework QuartzCore -framework CoreGraphics -framework Foundation \
+ -o "$OUT/MorphHarness.app/MorphHarness"
+cat > "$OUT/MorphHarness.app/Info.plist" <<'PLIST'
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0"><dict>
+<key>CFBundleExecutable</key><string>MorphHarness</string>
+<key>CFBundleIdentifier</key><string>com.vojta.morphharness</string>
+<key>CFBundleName</key><string>MorphHarness</string>
+<key>CFBundleVersion</key><string>1</string>
+<key>CFBundleShortVersionString</key><string>1.0</string>
+<key>UIUserInterfaceStyle</key><string>Dark</string>
+<key>UILaunchScreen</key><dict/>
+</dict></plist>
+PLIST
+codesign -f -s - "$OUT/MorphHarness.app" >/dev/null 2>&1
+echo "built $OUT/MorphHarness.app"
diff --git a/harness/morph/main.m b/harness/morph/main.m
new file mode 100644
index 00000000..2ff7ae2d
--- /dev/null
+++ b/harness/morph/main.m
@@ -0,0 +1,287 @@
+// Morph harness: PlayerMorph.x run for real against a mock of Spotify's
+// SPTBarOverlayPresentationTransition, which sets the player's frame, its alpha and the bar stand-in's
+// frame and alpha from -setProgress: the way 9.1.78 does (0x109815464), driven by a display link on a
+// spring. The page opens the player one second after launch, closes it two seconds later, and repeats.
+// Stubbed: the bar's card and artwork (NowPlayingBar.x), the player's cover (PlayerArtwork.x), the
+// artwork, the field and the log.
+#import <UIKit/UIKit.h>
+#import <QuartzCore/QuartzCore.h>
+
+static const CGFloat kW = 402, kH = 874;
+
+#pragma mark - stubs for what PlayerMorph.x reads
+
+static __weak UIView *sg_card, *sg_barArt, *sg_cover;
+static UIImage *sg_art;
+
+CGRect SGRNowPlayingCardFrameIn(UIView *host, CGFloat *radius) {
+ if (!sg_card.window) return CGRectNull;
+ if (radius) *radius = 24;
+ return [host convertRect:sg_card.bounds fromView:sg_card];
+}
+CGRect SGRNowPlayingArtworkFrameIn(UIView *host) {
+ return sg_barArt.window ? [host convertRect:sg_barArt.bounds fromView:sg_barArt] : CGRectNull;
+}
+CGRect SGRPlayerCoverFrameIn(UIView *host) {
+ return sg_cover.window ? [host convertRect:sg_cover.bounds fromView:sg_cover] : CGRectNull;
+}
+void SGRPlayerSetCoverHidden(BOOL hidden) { sg_cover.alpha = hidden ? 0 : 1; }
+id SGRPlayerField(void) { return nil; }
+UIImage *SGRNowPlayingArtwork(NSString **uri, NSString **identity) { return sg_art; }
+const CGFloat SGRRadiusArtwork = 12;
+BOOL SGRReduceMotion(void) { return NO; }
+BOOL SGRedesignedUI(void) { return YES; }
+void SGRequireClasses(NSArray *names) {}
+
+#pragma mark - Spotify's transition, as 9.1.78 runs it
+
+@interface SGHarnessContext : NSObject
+@property (nonatomic, strong) UIView *containerView;
+@end
+@implementation SGHarnessContext
+@end
+
+@interface SPTBarOverlayPresentationTransition : NSObject
+@property (nonatomic, strong) SGHarnessContext *transitioningContext;
+@property (nonatomic, strong) UIView *overlayView, *barSnapshotView, *bottomBarView;
+@property (nonatomic) CGRect barFrame;
+@property (nonatomic) double progress;
+@property (nonatomic) BOOL presenting;
+@end
+
+@implementation SPTBarOverlayPresentationTransition {
+ CADisplayLink *_link;
+ CFTimeInterval _start;
+ void (^_done)(void);
+}
+
+- (void)setProgress:(double)progress {
+ _progress = MIN(1, MAX(0, progress));
+ UIView *container = self.transitioningContext.containerView;
+ CGFloat maxY = CGRectGetMaxY(self.barFrame);
+ self.overlayView.frame = CGRectOffset(container.bounds, 0, maxY - maxY * _progress);
+ CGRect bar = self.barSnapshotView.frame;
+ bar.origin.y = self.barFrame.origin.y - (self.barFrame.origin.y) * _progress * 0.2;
+ self.barSnapshotView.frame = bar;
+ self.barSnapshotView.alpha = 1 - MIN(_progress, 0.5) * 2;
+ self.overlayView.alpha = MIN(1, _progress * 2);
+}
+
+- (void)runFrom:(UIView *)container done:(void (^)(void))done {
+ self.transitioningContext = [SGHarnessContext new];
+ self.transitioningContext.containerView = container;
+ self.barFrame = [container convertRect:self.bottomBarView.bounds fromView:self.bottomBarView];
+ [container addSubview:self.overlayView];
+ if (self.presenting) {
+ self.barSnapshotView = [self.bottomBarView snapshotViewAfterScreenUpdates:NO];
+ } else {
+ // Closing, the bar is hidden: Spotify shows it, renders it into an image and hides it again.
+ self.bottomBarView.hidden = NO;
+ UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithBounds:self.bottomBarView.bounds];
+ UIView *bar = self.bottomBarView;
+ self.barSnapshotView = [[UIImageView alloc] initWithImage:[renderer imageWithActions:^(UIGraphicsImageRendererContext *c) {
+ [bar.layer renderInContext:c.CGContext];
+ }]];
+ }
+ self.barSnapshotView.frame = self.barFrame;
+ [container addSubview:self.barSnapshotView];
+ self.bottomBarView.hidden = YES;
+ [self setProgress:self.presenting ? 0 : 1];
+ _done = done;
+ _start = CACurrentMediaTime();
+ _link = [CADisplayLink displayLinkWithTarget:self selector:@selector(update)];
+ _link.preferredFrameRateRange = CAFrameRateRangeMake(60, 120, 120);
+ [_link addToRunLoop:NSRunLoop.mainRunLoop forMode:NSRunLoopCommonModes];
+}
+
+- (void)holdFrom:(UIView *)container at:(double)progress {
+ self.transitioningContext = [SGHarnessContext new];
+ self.transitioningContext.containerView = container;
+ self.barFrame = [container convertRect:self.bottomBarView.bounds fromView:self.bottomBarView];
+ [container addSubview:self.overlayView];
+ self.barSnapshotView = [self.bottomBarView snapshotViewAfterScreenUpdates:NO];
+ self.barSnapshotView.frame = self.barFrame;
+ [container addSubview:self.barSnapshotView];
+ self.bottomBarView.hidden = YES;
+ [self setProgress:0];
+ [self setProgress:progress];
+}
+
+- (void)update {
+ double t = CACurrentMediaTime() - _start, w = 13;
+ double x = 1 - (1 + w * t) * exp(-w * t);
+ BOOL settled = x > 0.999;
+ [self setProgress:self.presenting ? x : 1 - x];
+ if (!settled) return;
+ [_link invalidate];
+ _link = nil;
+ [self setProgress:self.presenting ? 1 : 0];
+ [self destroyTransitioningContext];
+ [self.barSnapshotView removeFromSuperview];
+ if (!self.presenting) [self.overlayView removeFromSuperview];
+ self.bottomBarView.hidden = self.presenting;
+ if (_done) _done();
+}
+
+- (void)destroyTransitioningContext {
+ self.transitioningContext = nil;
+}
+@end
+
+#pragma mark - the page
+
+static UIImage *artworkImage(void) {
+ UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:CGSizeMake(300, 300)];
+ return [renderer imageWithActions:^(UIGraphicsImageRendererContext *c) {
+ CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
+ NSArray *colors = @[(id)UIColor.systemOrangeColor.CGColor, (id)UIColor.systemPurpleColor.CGColor];
+ CGGradientRef g = CGGradientCreateWithColors(space, (__bridge CFArrayRef)colors, NULL);
+ CGContextDrawLinearGradient(c.CGContext, g, CGPointZero, CGPointMake(300, 300), 0);
+ CGGradientRelease(g);
+ CGColorSpaceRelease(space);
+ [@"♫" drawAtPoint:CGPointMake(110, 90) withAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:100], NSForegroundColorAttributeName: UIColor.whiteColor}];
+ }];
+}
+
+static UILabel *label(NSString *text, CGRect frame, CGFloat size, UIColor *color) {
+ UILabel *l = [[UILabel alloc] initWithFrame:frame];
+ l.text = text;
+ l.font = [UIFont systemFontOfSize:size weight:UIFontWeightSemibold];
+ l.textColor = color;
+ return l;
+}
+
+@interface VC : UIViewController
+@end
+
+@implementation VC {
+ UIView *_bar, *_player, *_container;
+}
+
+- (UIView *)makeBar {
+ UIView *bar = [[UIView alloc] initWithFrame:CGRectMake(0, kH - 83 - 64, kW, 56)];
+ UIVisualEffectView *glass = [[UIVisualEffectView alloc] initWithEffect:[NSClassFromString(@"UIGlassEffect") effectWithStyle:0]];
+ glass.frame = CGRectMake(8, 0, 386, 56);
+ glass.layer.cornerRadius = 24;
+ glass.clipsToBounds = YES;
+ [bar addSubview:glass];
+ sg_card = glass;
+ UIImageView *art = [[UIImageView alloc] initWithImage:sg_art];
+ art.frame = CGRectMake(16, 8, 40, 40);
+ art.layer.cornerRadius = 20;
+ art.clipsToBounds = YES;
+ [bar addSubview:art];
+ sg_barArt = art;
+ [bar addSubview:label(@"Song Title", CGRectMake(66, 9, 200, 18), 15, UIColor.whiteColor)];
+ [bar addSubview:label(@"Artist", CGRectMake(66, 28, 200, 16), 13, [UIColor colorWithWhite:1 alpha:0.6])];
+ [bar addSubview:label(@"▶︎", CGRectMake(340, 14, 30, 28), 22, UIColor.whiteColor)];
+ return bar;
+}
+
+- (UIView *)makePlayer {
+ UIView *player = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kW, kH)];
+ // Spotify paints the player in a plane inside its list (PlayerField.x); a black base of its own.
+ player.backgroundColor = UIColor.blackColor;
+ UIView *field = [[UIView alloc] initWithFrame:player.bounds];
+ field.backgroundColor = [UIColor colorWithRed:0.35 green:0.16 blue:0.3 alpha:1];
+ [player addSubview:field];
+ [player addSubview:label(@"⌄", CGRectMake(24, 60, 40, 30), 28, UIColor.whiteColor)];
+ UIImageView *cover = [[UIImageView alloc] initWithImage:sg_art];
+ cover.frame = CGRectMake(24, 118, 354, 354);
+ cover.layer.cornerRadius = 12;
+ cover.clipsToBounds = YES;
+ [player addSubview:cover];
+ sg_cover = cover;
+ [player addSubview:label(@"Song Title", CGRectMake(24, 520, 300, 28), 24, UIColor.whiteColor)];
+ [player addSubview:label(@"Artist", CGRectMake(24, 552, 300, 22), 18, [UIColor colorWithWhite:1 alpha:0.6])];
+ UIView *slider = [[UIView alloc] initWithFrame:CGRectMake(24, 600, 354, 4)];
+ slider.backgroundColor = [UIColor colorWithWhite:1 alpha:0.4];
+ [player addSubview:slider];
+ [player addSubview:label(@"⏮ ⏸ ⏭", CGRectMake(90, 650, 260, 50), 40, UIColor.whiteColor)];
+ return player;
+}
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+ sg_art = artworkImage();
+ self.view.backgroundColor = UIColor.blackColor;
+ for (int i = 0; i < 8; i++) {
+ UIView *row = [[UIView alloc] initWithFrame:CGRectMake(16, 70 + i * 90, kW - 32, 80)];
+ row.backgroundColor = [UIColor colorWithHue:i / 8.0 saturation:0.5 brightness:0.5 alpha:1];
+ row.layer.cornerRadius = 12;
+ [self.view addSubview:row];
+ }
+ UIVisualEffectView *tabs = [[UIVisualEffectView alloc] initWithEffect:[NSClassFromString(@"UIGlassEffect") effectWithStyle:0]];
+ tabs.frame = CGRectMake(21, kH - 83, 280, 62);
+ tabs.layer.cornerRadius = 31;
+ tabs.clipsToBounds = YES;
+ [self.view addSubview:tabs];
+ _bar = [self makeBar];
+ [self.view addSubview:_bar];
+ _player = [self makePlayer];
+ _container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kW, kH)];
+ _container.userInteractionEnabled = NO;
+ [self.view addSubview:_container];
+ // SIMCTL_CHILD_MORPH_T=0.4 holds the open at that progress, for a screenshot.
+ NSString *hold = NSProcessInfo.processInfo.environment[@"MORPH_T"];
+ if (hold) {
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC / 2), dispatch_get_main_queue(), ^{ [self holdAt:hold.doubleValue]; });
+ return;
+ }
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC), dispatch_get_main_queue(), ^{ [self cycle]; });
+}
+
+- (void)transition:(BOOL)presenting done:(void (^)(void))done {
+ SPTBarOverlayPresentationTransition *t = [SPTBarOverlayPresentationTransition new];
+ t.presenting = presenting;
+ t.overlayView = _player;
+ t.bottomBarView = _bar;
+ static SPTBarOverlayPresentationTransition *running;
+ running = t;
+ [t runFrom:_container done:done];
+}
+
+- (void)holdAt:(double)progress {
+ static SPTBarOverlayPresentationTransition *held;
+ held = [SPTBarOverlayPresentationTransition new];
+ held.presenting = YES;
+ held.overlayView = _player;
+ held.bottomBarView = _bar;
+ [held holdFrom:_container at:progress];
+ UIView *player = _player, *container = _container, *cover = sg_cover;
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC / 2), dispatch_get_main_queue(), ^{
+ NSLog(@"MORPH overlay frame %@ alpha %.2f", NSStringFromCGRect(player.frame), player.alpha);
+ NSLog(@"MORPH mask %@ sublayer %@", NSStringFromCGRect(player.layer.mask.frame), [NSValue valueWithCATransform3D:player.layer.sublayerTransform]);
+ CALayer *shown = container.layer.presentationLayer ?: container.layer;
+ NSLog(@"MORPH cover model %@ presented top-left %@", NSStringFromCGRect([container convertRect:cover.bounds fromView:cover]),
+ NSStringFromCGPoint([cover.layer.presentationLayer convertPoint:CGPointZero toLayer:shown]));
+ for (UIView *v in container.subviews) NSLog(@"MORPH sub %@ %@", v.class, NSStringFromCGRect(v.frame));
+ });
+}
+
+- (void)cycle {
+ [self transition:YES done:^{
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
+ [self transition:NO done:^{
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ [self cycle]; });
+ }];
+ });
+ }];
+}
+@end
+
+@interface AppDelegate : UIResponder <UIApplicationDelegate>
+@property (nonatomic, strong) UIWindow *window;
+@end
+@implementation AppDelegate
+- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)options {
+ self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
+ self.window.rootViewController = [VC new];
+ [self.window makeKeyAndVisible];
+ return YES;
+}
+@end
+
+int main(int argc, char **argv) {
+ @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass(AppDelegate.class)); }
+}
diff --git a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.h b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.h
index 6ea5ecd7..7f3d0180 100644
--- a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.h
+++ b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.h
@@ -1,5 +1,6 @@
// The redesign's now playing bar: the glass card it becomes (NowPlayingBar.x), Spotify's device button
-// on that card hidden on request (BarConnect.x), and the bar's page in Mod Settings
+// on that card hidden on request (BarConnect.x), glass behind the bar's and the tab bar's stand-ins while
+// the player opens and closes (BarTransition.x), and the bar's page in Mod Settings
// (NowPlayingBarSettings.m). The redesign keeps its own copy of the hide switch and its own key; the
// native look's lives in Native/NowPlayingBar/.
#import <UIKit/UIKit.h>
@@ -7,3 +8,10 @@
#define SGRHideBarConnect @"spotifyglass.redesign.hide.barConnect" // the device button on the card
UIViewController *SGRNowPlayingBarSettingsPage(void);
+
+// The bar's glass card in `host`'s coordinates, with its corner radius; CGRectNull before the bar has
+// been styled or while it is out of a window (NowPlayingBar.x). The bar keeps its geometry while
+// Spotify hides it for the player's open and close.
+CGRect SGRNowPlayingCardFrameIn(UIView *host, CGFloat *radius);
+// The round artwork on that card in `host`'s coordinates; CGRectNull when none was found.
+CGRect SGRNowPlayingArtworkFrameIn(UIView *host);
diff --git a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x
index 3e285751..492bc076 100644
--- a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x
+++ b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x
@@ -5,16 +5,33 @@
// written to hand itself back to Spotify for that animation, from NowPlaying_ViewPageImpl's
// Show/CloseFullscreenAnimatedTransitioning, but Spotify 9.1.78 never runs the player through those,
// so the handback never happened and is gone; if the morph ever reads as a cut, the place to start is
-// Shared/Player/PlayerEvents.h, which does fire.
+// Shared/Player/PlayerEvents.h, which does fire. What does move with the player is a stand-in of the
+// bar, which BarTransition.x keeps glass behind.
//
// Tree (trees/home.txt): NowPlayingBarContainerViewController.view 402x56 > NowPlayingBarViewController.view
// at {8,0} 386x56 > UIView 386x56 (the painted card) > artwork 40x40 r=4, title stack,
// progress line 370x2 at the bottom. The glass pane goes on the container's view.
#import "Core/SGCore.h"
#import "Redesigned/Kit/SGRRepaint.h"
+#import "NowPlayingBar.h"
static const CGFloat kCardRadius = 24;
static char kGlassKey;
+static __weak UIVisualEffectView *sg_cardGlass;
+static __weak UIView *sg_cardArtwork;
+
+CGRect SGRNowPlayingCardFrameIn(UIView *host, CGFloat *radius) {
+ UIVisualEffectView *glass = sg_cardGlass;
+ if (!glass.superview || !glass.window || !host) return CGRectNull;
+ if (radius) *radius = MIN(kCardRadius, glass.bounds.size.height / 2);
+ return [host convertRect:glass.bounds fromView:glass];
+}
+
+CGRect SGRNowPlayingArtworkFrameIn(UIView *host) {
+ UIView *artwork = sg_cardArtwork;
+ if (!artwork.window || !host) return CGRectNull;
+ return [host convertRect:artwork.bounds fromView:artwork];
+}
static UIView *detectColoredCard(UIView *bar) {
__block UIView *best = nil;
@@ -50,11 +67,18 @@ static void restyleCardContent(UIView *card) {
SGForEachView(card, ^(UIView *v) {
CGSize size = v.bounds.size;
BOOL square = size.width >= 36 && size.width <= 48 && fabs(size.width - size.height) < 1;
- if (!square || v.layer.cornerRadius <= 0 || v.layer.cornerRadius >= size.width / 2) return;
+ if (!square || v.layer.cornerRadius <= 0) return;
+ if (v.layer.cornerRadius >= size.width / 2) {
+ if (!sg_cardArtwork) sg_cardArtwork = v;
+ return;
+ }
+ UIView *outer = v;
for (UIView *u = v; u && u != card && CGSizeEqualToSize(u.bounds.size, size); u = u.superview) {
roundView(u, size.width / 2);
u.clipsToBounds = YES;
+ outer = u;
}
+ sg_cardArtwork = outer;
});
SGForEachView(card, ^(UIView *v) {
CGRect f = v.frame;
@@ -90,6 +114,7 @@ static void styleNowPlayingBar(UIViewController *container) {
}
UIVisualEffectView *glass = SGGlassFor(container.view, &kGlassKey);
+ sg_cardGlass = glass;
glass.frame = frame;
SGShapeGlass(glass, radius, NO);
diff --git a/tweak/Sources/Redesigned/Player/Player.h b/tweak/Sources/Redesigned/Player/Player.h
index 48cb2567..309973d3 100644
--- a/tweak/Sources/Redesigned/Player/Player.h
+++ b/tweak/Sources/Redesigned/Player/Player.h
@@ -14,6 +14,7 @@
// PlayerScroll.x the list pinned to the top, so the player is one screen and cannot be scrolled
// PlayerLyrics.x the lyrics in the player: the cover as a thumbnail, the title up beside it
// PlayerGestures.x the gestures' hookup
+// PlayerMorph.x the open and close grown out of the now playing bar's card, the cover flown
// PlayerMenu.x Speed and pitch, an expandable row with two sliders in the more button's menu
// PlayerSpeedPitch.x speed and pitch done to Spotify's audio, between its mixer and its speaker unit
// SGRTimePitch.m Apple's time and pitch unit, pulling the mixer or working in place
@@ -37,6 +38,9 @@ CGRect SGRPlayerCoverFrameIn(UIView *host);
// The band that cover sits in -- the room the player gives its artwork, between the header row and the
// title -- in `host`'s coordinates; CGRectNull when no cover has laid out.
CGRect SGRPlayerArtworkAreaIn(UIView *host);
+// Hides the cover on screen and its shadow, or shows them again, for a stand-in to fly in its place
+// (PlayerMorph.x).
+void SGRPlayerSetCoverHidden(BOOL hidden);
#pragma mark - the lyrics in the player (PlayerLyrics.x)
diff --git a/tweak/Sources/Redesigned/Player/PlayerArtwork.x b/tweak/Sources/Redesigned/Player/PlayerArtwork.x
index b386e525..c3694807 100644
--- a/tweak/Sources/Redesigned/Player/PlayerArtwork.x
+++ b/tweak/Sources/Redesigned/Player/PlayerArtwork.x
@@ -101,6 +101,24 @@ CGRect SGRPlayerArtworkAreaIn(UIView *host) {
return CGRectNull;
}
+// The cover hidden for a stand-in, so the same one comes back if the list moved on meanwhile.
+static __weak UIView *sg_hiddenCover, *sg_hiddenPlate;
+
+void SGRPlayerSetCoverHidden(BOOL hidden) {
+ sg_hiddenCover.alpha = 1;
+ sg_hiddenPlate.alpha = 1;
+ sg_hiddenCover = sg_hiddenPlate = nil;
+ if (!hidden) return;
+ UIView *tilt = showingTilt();
+ UIView *cover = coverIn(tilt);
+ if (!cover) return;
+ UIView *plate = SGRShadowPlateIn(tilt, &kPlateKey);
+ cover.alpha = 0;
+ plate.alpha = 0;
+ sg_hiddenCover = cover;
+ sg_hiddenPlate = plate;
+}
+
#pragma mark - the paused shrink
static void scaleEveryCover(BOOL animated) {
diff --git a/tweak/Sources/Redesigned/Player/PlayerMorph.x b/tweak/Sources/Redesigned/Player/PlayerMorph.x
new file mode 100644
index 00000000..2838d4cf
--- /dev/null
+++ b/tweak/Sources/Redesigned/Player/PlayerMorph.x
@@ -0,0 +1,256 @@
+// Player redesign: the player grows out of the now playing bar's card and the cover flies out of the
+// card's artwork, the way the Music app opens its player, instead of Spotify's slide up and fade.
+//
+// Spotify 9.1.78 runs the open and the close through SPTBarOverlayPresentationTransition: it hides the
+// real bar and tab bar, moves stand-ins, and sets -setProgress: (0 the bar, 1 the player, clamped) on
+// every frame of its own display link, from a spring when tapped and from the finger when dragged
+// (setProgress: at 0x109815464). There it sets the player's frame to the container's bounds moved down by
+// the bar's bottom edge times (1 - progress), and the player's alpha, and moves and fades the bar's stand-in.
+//
+// The morph rides on that progress, after Spotify's own, so taps, drags and cancelled drags follow:
+// the sheet a rounded rect from the card's frame and radius to the screen's, filled with the
+// field's colour, under the player, showing at once;
+// the player masked to the sheet, its content scaled and moved so its top left is the sheet's
+// (sublayerTransform, and the frame's top moved to the sheet's; Spotify's gesture code
+// reads back only the frame's height), its own background colour lifted off meanwhile
+// (a sublayerTransform does not move it), and faded in over the first part of the growth;
+// the bar Spotify's stand-in riding the sheet's top edge, gone by a quarter of the way;
+// the cover a copy flown from the card's artwork to the player's cover, moved within the sheet,
+// the player's own cover and shadow hidden meanwhile.
+// All of it is taken down in -destroyTransitioningContext, which Spotify calls from -animationEnded:.
+//
+// Skipped on a regular width (Spotify's iPad branch), with Reduce Motion on, or while the bar has no
+// card (hidden, not styled yet): Spotify's own transition then runs untouched.
+#import "Core/SGCore.h"
+#import "Redesigned/Kit/SGRKit.h"
+#import "Redesigned/NowPlayingBar/NowPlayingBar.h"
+#import "Player.h"
+
+@interface SPTBarOverlayPresentationTransition : NSObject
+- (id<UIViewControllerContextTransitioning>)transitioningContext;
+- (UIView *)overlayView;
+- (UIView *)barSnapshotView;
+- (CGRect)barFrame;
+- (double)progress;
+@end
+
+static const CGFloat kScreenRadiusFallback = 55;
+
+static CGFloat lerp(CGFloat a, CGFloat b, CGFloat t) {
+ return a + (b - a) * t;
+}
+
+static CGRect lerpRect(CGRect a, CGRect b, CGFloat t) {
+ return CGRectMake(lerp(a.origin.x, b.origin.x, t), lerp(a.origin.y, b.origin.y, t),
+ lerp(a.size.width, b.size.width, t), lerp(a.size.height, b.size.height, t));
+}
+
+// 0 until `from`, 1 from `to`, eased between.
+static CGFloat ramp(CGFloat from, CGFloat to, CGFloat t) {
+ CGFloat x = MIN(1, MAX(0, (t - from) / (to - from)));
+ return x * x * (3 - 2 * x);
+}
+
+static CGFloat screenRadius(void) {
+ static CGFloat radius;
+ static dispatch_once_t once;
+ dispatch_once(&once, ^{
+ radius = kScreenRadiusFallback;
+ @try {
+ id value = [UIScreen.mainScreen valueForKey:@"_displayCornerRadius"];
+ if ([value respondsToSelector:@selector(doubleValue)] && [value doubleValue] > 0) radius = [value doubleValue];
+ } @catch (__unused NSException *e) {}
+ });
+ return radius;
+}
+
+@interface SGRPlayerMorph : NSObject
+@end
+
+@implementation SGRPlayerMorph {
+ __weak UIView *_container, *_overlay, *_bar;
+ UIView *_sheet;
+ UIImageView *_cover;
+ CALayer *_mask;
+ CGRect _card, _barArtwork, _barRest, _spotifyFrame;
+ CGFloat _cardRadius, _spotifyAlpha;
+ CGColorRef _overlayColor;
+ BOOL _coverHidden;
+}
+
+- (instancetype)initWithContainer:(UIView *)container overlay:(UIView *)overlay bar:(UIView *)bar barRest:(CGRect)barRest {
+ CGFloat radius = 0;
+ CGRect card = SGRNowPlayingCardFrameIn(container, &radius);
+ if (CGRectIsNull(card) || CGRectIsEmpty(card)) return nil;
+ if (!(self = [super init])) return nil;
+ _container = container;
+ _overlay = overlay;
+ _bar = bar;
+ _barRest = barRest;
+ _card = card;
+ _cardRadius = radius;
+ _barArtwork = SGRNowPlayingArtworkFrameIn(container);
+ _spotifyAlpha = overlay.alpha;
+
+ _sheet = [[UIView alloc] initWithFrame:card];
+ _sheet.userInteractionEnabled = NO;
+ _sheet.backgroundColor = SGRPlayerField().fieldColor ?: UIColor.blackColor;
+ _sheet.layer.cornerCurve = kCACornerCurveContinuous;
+ _sheet.clipsToBounds = YES;
+ [container insertSubview:_sheet belowSubview:overlay];
+
+ // The player's own paint is not a sublayer, so the content's transform would leave it where Spotify
+ // put the player, a band below the sheet's top edge; the sheet paints instead.
+ _overlayColor = CGColorRetain(overlay.layer.backgroundColor);
+ overlay.layer.backgroundColor = NULL;
+
+ _mask = [CALayer layer];
+ _mask.backgroundColor = UIColor.blackColor.CGColor;
+ _mask.cornerCurve = kCACornerCurveContinuous;
+ overlay.layer.mask = _mask;
+
+ if (bar.superview == container) [container bringSubviewToFront:bar];
+
+ UIImage *artwork = SGRNowPlayingArtwork(NULL, NULL);
+ if (artwork && !CGRectIsNull(_barArtwork)) {
+ _cover = [[UIImageView alloc] initWithImage:artwork];
+ _cover.userInteractionEnabled = NO;
+ _cover.contentMode = UIViewContentModeScaleAspectFill;
+ _cover.clipsToBounds = YES;
+ _cover.layer.cornerCurve = kCACornerCurveContinuous;
+ [container addSubview:_cover];
+ }
+
+ static NSUInteger logged;
+ if (logged++ < 3) SGLog(@"player morph: card %@ r=%.0f, artwork %@, cover %@, screen r=%.0f", NSStringFromCGRect(card), radius,
+ NSStringFromCGRect(_barArtwork), _cover ? @"flown" : @"not flown", screenRadius());
+ return self;
+}
+
+- (void)apply:(CGFloat)t {
+ UIView *container = _container, *overlay = _overlay, *bar = _bar;
+ if (!container || !overlay) return;
+ t = MIN(1, MAX(0, t));
+ _spotifyAlpha = overlay.alpha;
+ _spotifyFrame = overlay.frame;
+
+ CGRect full = container.bounds;
+ CGRect sheet = lerpRect(_card, full, t);
+ CGFloat radius = lerp(_cardRadius, screenRadius(), t);
+ CGFloat scale = full.size.width > 0 ? sheet.size.width / full.size.width : 1;
+ // The player's top goes to the sheet's: a mask clips nothing above the layer's bounds, so content
+ // raised above Spotify's frame would show square corners. Spotify reads back only the player's
+ // height (0x109815b4c, 0x109815c28), which stays.
+ CGPoint origin = CGPointMake(_spotifyFrame.origin.x, sheet.origin.y);
+ CGSize size = overlay.bounds.size;
+ CGPoint middle = CGPointMake(size.width / 2, size.height / 2);
+ CGPoint target = CGPointMake(sheet.origin.x - origin.x, sheet.origin.y - origin.y);
+ // A point q of the player lands at middle + scale * (q - middle) + shift; the top left at target.
+ CGPoint shift = CGPointMake(target.x - middle.x + scale * middle.x, target.y - middle.y + scale * middle.y);
+
+ [CATransaction begin];
+ [CATransaction setDisableActions:YES];
+ [UIView performWithoutAnimation:^{
+ overlay.layer.sublayerTransform = CATransform3DIdentity;
+ overlay.frame = (CGRect){origin, self->_spotifyFrame.size};
+ CGRect coverInPlayer = SGRPlayerCoverFrameIn(overlay);
+
+ overlay.layer.sublayerTransform = CATransform3DScale(CATransform3DMakeTranslation(shift.x, shift.y, 0), scale, scale, 1);
+ self->_mask.frame = CGRectMake(target.x, target.y, sheet.size.width, sheet.size.height);
+ self->_mask.cornerRadius = radius;
+ overlay.alpha = ramp(0.08, 0.55, t);
+
+ self->_sheet.frame = sheet;
+ self->_sheet.layer.cornerRadius = radius;
+ self->_sheet.alpha = ramp(0, 0.15, t);
+
+ // The card's top edge is the sheet's.
+ CGFloat rise = sheet.origin.y - self->_card.origin.y;
+ if (bar) {
+ CGRect frame = bar.frame;
+ frame.origin.y = self->_barRest.origin.y + rise;
+ bar.frame = frame;
+ bar.alpha = 1 - ramp(0, 0.25, t);
+ }
+
+ if (self->_cover) {
+ // Worked out relative to the sheet, so the cover stays on it the whole way rather than
+ // heading for where the player's cover is while that is still below the screen.
+ CGRect from = CGRectOffset(self->_barArtwork, -self->_card.origin.x, -self->_card.origin.y);
+ if (CGRectIsNull(coverInPlayer)) {
+ self->_cover.hidden = YES;
+ } else {
+ CGRect to = CGRectMake(middle.x + scale * (coverInPlayer.origin.x - middle.x) + shift.x + origin.x,
+ middle.y + scale * (coverInPlayer.origin.y - middle.y) + shift.y + origin.y,
+ coverInPlayer.size.width * scale, coverInPlayer.size.height * scale);
+ self->_cover.hidden = NO;
+ // The first open lays the cover out mid-way, so it is hidden once it is there.
+ if (!self->_coverHidden) {
+ SGRPlayerSetCoverHidden(YES);
+ self->_coverHidden = YES;
+ }
+ to = CGRectOffset(to, -sheet.origin.x, -sheet.origin.y);
+ self->_cover.frame = CGRectOffset(lerpRect(from, to, t), sheet.origin.x, sheet.origin.y);
+ self->_cover.layer.cornerRadius = lerp(from.size.width / 2, SGRRadiusArtwork * scale, t);
+ }
+ }
+ }];
+ [CATransaction commit];
+}
+
+- (void)tearDown {
+ UIView *overlay = _overlay;
+ [CATransaction begin];
+ [CATransaction setDisableActions:YES];
+ overlay.layer.sublayerTransform = CATransform3DIdentity;
+ if (overlay.layer.mask == _mask) overlay.layer.mask = nil;
+ overlay.alpha = _spotifyAlpha;
+ if (overlay) overlay.frame = _spotifyFrame;
+ if (!overlay.layer.backgroundColor) overlay.layer.backgroundColor = _overlayColor;
+ CGColorRelease(_overlayColor);
+ _overlayColor = NULL;
+ [_sheet removeFromSuperview];
+ [_cover removeFromSuperview];
+ [CATransaction commit];
+ if (_coverHidden) SGRPlayerSetCoverHidden(NO);
+ _coverHidden = NO;
+ _cover = nil;
+}
+
+@end
+
+static char kMorphKey;
+
+static SGRPlayerMorph *morphFor(SPTBarOverlayPresentationTransition *transition, BOOL create) {
+ SGRPlayerMorph *morph = objc_getAssociatedObject(transition, &kMorphKey);
+ if (morph || !create || SGRReduceMotion()) return morph;
+ id<UIViewControllerContextTransitioning> context = [transition transitioningContext];
+ UIView *container = context.containerView, *overlay = [transition overlayView];
+ if (!container || !overlay || overlay.superview != container) return nil;
+ if (container.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassRegular) return nil;
+ morph = [[SGRPlayerMorph alloc] initWithContainer:container overlay:overlay bar:[transition barSnapshotView] barRest:[transition barFrame]];
+ if (morph) objc_setAssociatedObject(transition, &kMorphKey, morph, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ return morph;
+}
+
+%hook SPTBarOverlayPresentationTransition
+- (void)setProgress:(double)progress {
+ %orig;
+ [morphFor(self, YES) apply:[self progress]];
+}
+
+- (void)destroyTransitioningContext {
+ SGRPlayerMorph *morph = morphFor(self, NO);
+ if (morph) {
+ [morph tearDown];
+ objc_setAssociatedObject(self, &kMorphKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ }
+ %orig;
+}
+%end
+
+%ctor {
+ if (!SGRedesignedUI()) return;
+ %init;
+ SGRequireClasses(@[@"SPTBarOverlayPresentationTransition"]);
+}