Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix: with Reduce Motion on, layout changes crossfade and a paused cover dims
My-Name-Is-Jeffe7a24827b2f4
diff --git a/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.m b/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.mindex 8f39a4df..4d05e610 100644--- a/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.m+++ b/tweak/Sources/Redesigned/Kit/SGRHeaderInfo.m@@ -144,7 +144,7 @@ UIImageView *SGRCreatorPicture(UIView *root) {return;}SGRAnimate(SGRMotionFade, fade, faded);- SGRAnimate(SGRMotionLayout, ^{ [self layoutIfNeeded]; }, nil);+ SGRAnimateLayout(self, ^{ [self layoutIfNeeded]; }, nil);}// The space under a line: a picture needs more room under it than a line of text does.@@ -211,7 +211,7 @@ UIImageView *SGRCreatorPicture(UIView *root) {if (!appears || !self.window) return;_picture.alpha = 0;SGRAnimate(SGRMotionFade, ^{ self->_picture.alpha = 1; }, nil);- SGRAnimate(SGRMotionLayout, ^{ [self layoutIfNeeded]; }, nil);+ SGRAnimateLayout(self, ^{ [self layoutIfNeeded]; }, nil);}// The creator line takes a touch only where its text and its picture are; everything else of the view is thediff --git a/tweak/Sources/Redesigned/Kit/SGRTokens.h b/tweak/Sources/Redesigned/Kit/SGRTokens.hindex 4050f806..c989e0ab 100644--- a/tweak/Sources/Redesigned/Kit/SGRTokens.h+++ b/tweak/Sources/Redesigned/Kit/SGRTokens.h@@ -5,7 +5,8 @@// SGRPrimary and SGRSecondary both pass WCAG AA on it. Type is the system font (SF Pro) sized by the// text style and capped, since Spotify's pages lay out for a fixed header height. Motion is springs,// critically damped for layout and a little bounce for press feedback; under Reduce Motion both-// become instant, while crossfades, responses and exits stay, a fade not being motion.+// become instant without a host; SGRAnimateLayout crossfades its host instead. Crossfades, responses+// and exits stay, a fade not being motion.//// Threading: the constants and the colors are safe anywhere; fonts, SGRAnimate and the// accessibility reads are main thread only.@@ -63,3 +64,6 @@ typedef NS_ENUM(NSInteger, SGRMotion) {// Runs `animations` with the motion's timing, or at once under Reduce Motion (except a fade, a response or an exit), and// always calls `completion`. Only transform, alpha and color belong in it while a page scrolls.void SGRAnimate(SGRMotion motion, void (^animations)(void), void (^completion)(BOOL finished));++// Layout with an explicit host: Reduce Motion crossfades the old and new layout in place.+void SGRAnimateLayout(UIView *host, void (^animations)(void), void (^completion)(BOOL finished));diff --git a/tweak/Sources/Redesigned/Kit/SGRTokens.m b/tweak/Sources/Redesigned/Kit/SGRTokens.mindex 7e4d0729..15aab681 100644--- a/tweak/Sources/Redesigned/Kit/SGRTokens.m+++ b/tweak/Sources/Redesigned/Kit/SGRTokens.m@@ -127,3 +127,15 @@ void SGRAnimate(SGRMotion motion, void (^animations)(void), void (^completion)(Bbreak;}}++void SGRAnimateLayout(UIView *host, void (^animations)(void), void (^completion)(BOOL finished)) {+ if (!animations) return;+ if (!SGRReduceMotion() || !host.window) {+ SGRAnimate(SGRMotionLayout, animations, completion);+ return;+ }+ // Snapshot the host, so the layout changes in place while the old picture dissolves.+ [UIView transitionWithView:host duration:0.2+ options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction+ animations:animations completion:completion];+}diff --git a/tweak/Sources/Redesigned/Lyrics/SGRSingButton.m b/tweak/Sources/Redesigned/Lyrics/SGRSingButton.mindex c41249b7..d57bc1d0 100644--- a/tweak/Sources/Redesigned/Lyrics/SGRSingButton.m+++ b/tweak/Sources/Redesigned/Lyrics/SGRSingButton.m@@ -298,7 +298,7 @@ static void tell(NSString *message, NSString *action, void (^then)(void)) {SGRShowGlass(glass, YES);self->_slider.alpha = self->_mark.alpha = self->_level.alpha = 1;}, nil);- SGRAnimate(SGRMotionLayout, ^{ self->_panel.transform = CGAffineTransformIdentity; }, nil);+ SGRAnimateLayout(self, ^{ self->_panel.transform = CGAffineTransformIdentity; }, nil);[self letPanelGo];}diff --git a/tweak/Sources/Redesigned/Player/PlayerArtwork.x b/tweak/Sources/Redesigned/Player/PlayerArtwork.xindex 02929400..3e7b1533 100644--- a/tweak/Sources/Redesigned/Player/PlayerArtwork.x+++ b/tweak/Sources/Redesigned/Player/PlayerArtwork.x@@ -18,7 +18,7 @@#import "Shared/Player/SpeedPitch.h"#import "Player.h"-static const CGFloat kPausedScale = 0.84, kPausedScaleReduceMotion = 0.92;+static const CGFloat kPausedScale = 0.84;// The bar's 40pt cover lives in a tilt view of its own; the player's is 354.static const CGFloat kCoverMinWidth = 200;@@ -31,7 +31,7 @@ static NSMapTable<UIView *, UIView *> *sg_covers;static CGFloat currentScale(void) {SPTPlayerState *state = SGPlayerState();if (!state.isPaused) return 1;- return SGRReduceMotion() ? kPausedScaleReduceMotion : kPausedScale;+ return SGRReduceMotion() ? 1 : kPausedScale;}// The child of the tilt view the size of the cover.@@ -113,7 +113,7 @@ CGRect SGRPlayerArtworkAreaIn(UIView *host) {static __weak UIView *sg_hiddenCover, *sg_hiddenPlate;void SGRPlayerSetCoverHidden(BOOL hidden) {- sg_hiddenCover.alpha = 1;+ sg_hiddenCover.alpha = SGRReduceMotion() && SGPlayerState().isPaused ? 0.75 : 1;sg_hiddenPlate.alpha = 1;sg_hiddenCover = sg_hiddenPlate = nil;if (!hidden) return;@@ -133,9 +133,13 @@ static void scaleEveryCover(BOOL animated) {CGFloat scale = currentScale();NSArray<UIView *> *tilts = sg_tilts.allObjects;void (^apply)(void) = ^{- for (UIView *tilt in tilts) scaleCover(tilt, scale);+ for (UIView *tilt in tilts) {+ scaleCover(tilt, scale);+ UIView *cover = coverIn(tilt);+ if (cover != sg_hiddenCover) cover.alpha = SGRReduceMotion() && SGPlayerState().isPaused ? 0.75 : 1;+ }};- if (animated) SGRAnimate(SGRMotionLayout, apply, nil);+ if (animated) SGRAnimate(SGRReduceMotion() ? SGRMotionRespond : SGRMotionLayout, apply, nil);else apply();}diff --git a/tweak/Sources/Redesigned/Player/PlayerLyrics.x b/tweak/Sources/Redesigned/Player/PlayerLyrics.xindex d1ff8b00..1975ebe7 100644--- a/tweak/Sources/Redesigned/Player/PlayerLyrics.x+++ b/tweak/Sources/Redesigned/Player/PlayerLyrics.x@@ -527,7 +527,7 @@ static void setAlone(BOOL alone, BOOL animated) {l.stage = aloneStage(host, l);}SGRPlayerLyricsOverlay *overlay = objc_getAssociatedObject(host, &kOverlayKey);- // What moves and what fades are animated apart: Reduce Motion takes the move and keeps the fade.+ // Layout and opacity have their own timing; Reduce Motion dissolves the layout in place.void (^move)(void) = ^{if (!overlay.superview || !l.ok) return;place(overlay, host, l);@@ -543,7 +543,7 @@ static void setAlone(BOOL alone, BOOL animated) {sg_wake.enabled = alone;if (overlay) letLinesSeek(overlay, !alone);if (animated) {- SGRAnimate(SGRMotionLayout, move, nil);+ SGRAnimateLayout(host, move, nil);// Going, the controls take their time, since nobody waits on them; coming back at a touch, they answer at// once, from wherever the fade out has got to.SGRAnimate(alone ? SGRMotionFade : SGRMotionRespond, fade, nil);@@ -632,12 +632,12 @@ static void setOpen(BOOL open, BOOL animated) {settled(YES);} else {sg_moving = YES;- // Settled once both are done: under Reduce Motion the move is over at once and the fade is not.+ // Settled once both the layout transition and the fade are done.__block NSInteger running = 2;void (^done)(BOOL) = ^(BOOL finished) {if (--running == 0) settled(finished);};- SGRAnimate(SGRMotionLayout, move, done);+ SGRAnimateLayout(host, move, done);SGRAnimate(SGRMotionFade, fade, done);// The lines come in behind the cover leaving, and go before it comes back.[UIView animateWithDuration:open ? kLyricsIn : kLyricsOut delay:open ? kLyricsInDelay : 0