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

refactor: the Kit has an exit motion and SGRShowGlass, and the 2x badge uses both

My-Name-Is-Jeff7cb53aed0955
diff --git a/tweak/Sources/Native/Player/PlayerGestures.x b/tweak/Sources/Native/Player/PlayerGestures.x
index 622c5780..ebf370b7 100644
--- a/tweak/Sources/Native/Player/PlayerGestures.x
+++ b/tweak/Sources/Native/Player/PlayerGestures.x
@@ -21,7 +21,8 @@ static const double kHoldSpeed = 2;
// The now playing bar's cover has a tilt view of its own, 40pt; the player's is about 354.
static const CGFloat kCoverMinWidth = 200;
static char kHoldKey;
-// The badge comes in quickly and goes quicker: the finger is already off the cover.
+// The badge comes in quickly and goes quicker: the finger is already off the cover. The way out is the
+// redesign's SGRMotionExit (Redesigned/Kit/SGRTokens.h), copied since the native look cannot import the Kit.
static const NSTimeInterval kBadgeEnter = 0.2, kBadgeExit = 0.15;
@interface SGCoverHold : UILongPressGestureRecognizer
diff --git a/tweak/Sources/Redesigned/Kit/SGRGlass.h b/tweak/Sources/Redesigned/Kit/SGRGlass.h
index 79142137..fe428f2e 100644
--- a/tweak/Sources/Redesigned/Kit/SGRGlass.h
+++ b/tweak/Sources/Redesigned/Kit/SGRGlass.h
@@ -23,3 +23,9 @@ UIView *SGRGlassInside(UIView *control, const void *key, CGFloat side);
// leads (the playlist header's Play). `prominent` lays a white film inside the shape, so that control
// reads a step brighter than the circles beside it without leaving the same material.
UIView *SGRGlassCapsuleInside(UIView *control, const void *key, CGSize size, BOOL prominent);
+
+// Shows or hides a shape of the Kit's by its effect, never by an alpha on it or on a view above it
+// (Redesigned/Player/PlayerMotion.x): UIKit draws the material wrongly or not at all under a fading alpha.
+// The solid shape Reduce Transparency puts in its place has no effect and fades by its own alpha. Animates
+// in the caller's animation.
+void SGRShowGlass(UIView *shape, BOOL shown);
diff --git a/tweak/Sources/Redesigned/Kit/SGRGlass.m b/tweak/Sources/Redesigned/Kit/SGRGlass.m
index 90a2cc24..b2ed430c 100644
--- a/tweak/Sources/Redesigned/Kit/SGRGlass.m
+++ b/tweak/Sources/Redesigned/Kit/SGRGlass.m
@@ -111,3 +111,12 @@ UIView *SGRGlassInside(UIView *control, const void *key, CGFloat side) {
UIView *SGRGlassCapsuleInside(UIView *control, const void *key, CGSize size, BOOL prominent) {
return glassInside(control, key, size, YES, prominent);
}
+
+void SGRShowGlass(UIView *shape, BOOL shown) {
+ if ([shape isKindOfClass:UIVisualEffectView.class]) {
+ UIVisualEffectView *glass = (UIVisualEffectView *)shape;
+ if ((glass.effect != nil) != shown) glass.effect = shown ? SGGlassEffect() : nil;
+ } else {
+ shape.alpha = shown ? 1 : 0;
+ }
+}
diff --git a/tweak/Sources/Redesigned/Kit/SGRTokens.h b/tweak/Sources/Redesigned/Kit/SGRTokens.h
index 3c0ba993..63c47ee2 100644
--- a/tweak/Sources/Redesigned/Kit/SGRTokens.h
+++ b/tweak/Sources/Redesigned/Kit/SGRTokens.h
@@ -5,7 +5,7 @@
// 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 stay, a fade not being motion.
+// become instant, while crossfades, responses and exits stay, a fade not being motion.
//
// Threading: the constants and the colours are safe anywhere; fonts, SGRAnimate and the
// accessibility reads are main thread only.
@@ -53,7 +53,10 @@ typedef NS_ENUM(NSInteger, SGRMotion) {
// A strong ease out over 0.2 s, for what comes back or opens at a touch: the eye is on it from the
// first frame. Kept under Reduce Motion like a fade, so only alpha, colour and a glass effect go in it.
SGRMotionRespond,
+ // An ease out over 0.15 s, for what goes once the finger has let it go (the hold's 2x badge): nothing is
+ // watched on its way out. Kept under Reduce Motion like a fade.
+ SGRMotionExit,
};
-// Runs `animations` with the motion's timing, or at once under Reduce Motion (except a fade or a response), and
+// Runs `animations` with the motion's timing, or at once under Reduce Motion (except a fade, a response or an exit), and
// always calls `completion`. Only transform, alpha and colour belong in it while a page scrolls.
void SGRAnimate(SGRMotion motion, void (^animations)(void), void (^completion)(BOOL finished));
diff --git a/tweak/Sources/Redesigned/Kit/SGRTokens.m b/tweak/Sources/Redesigned/Kit/SGRTokens.m
index 66727212..8877689f 100644
--- a/tweak/Sources/Redesigned/Kit/SGRTokens.m
+++ b/tweak/Sources/Redesigned/Kit/SGRTokens.m
@@ -20,6 +20,8 @@ static const NSTimeInterval kLayoutDuration = 0.45, kPressDuration = 0.32;
static const CGFloat kPressDamping = 0.62;
// A response lands within the press feedback's budget, on a curve that is most of the way there at once.
static const NSTimeInterval kRespondDuration = 0.2;
+// An exit is quicker still; Native/Player/PlayerGestures.x keeps its own copy of the value.
+static const NSTimeInterval kExitDuration = 0.15;
UIColor *SGRPrimary(void) {
return UIColor.whiteColor;
@@ -87,7 +89,7 @@ BOOL SGRIncreaseContrast(void) {
void SGRAnimate(SGRMotion motion, void (^animations)(void), void (^completion)(BOOL finished)) {
if (!animations) return;
- if (motion != SGRMotionFade && motion != SGRMotionRespond && SGRReduceMotion()) {
+ if ((motion == SGRMotionLayout || motion == SGRMotionPress) && SGRReduceMotion()) {
[UIView performWithoutAnimation:animations];
if (completion) completion(YES);
return;
@@ -114,5 +116,8 @@ void SGRAnimate(SGRMotion motion, void (^animations)(void), void (^completion)(B
[animator startAnimation];
break;
}
+ case SGRMotionExit:
+ [UIView animateWithDuration:kExitDuration delay:0 options:options | UIViewAnimationOptionCurveEaseOut animations:animations completion:completion];
+ break;
}
}
diff --git a/tweak/Sources/Redesigned/Lyrics/SGRSingButton.h b/tweak/Sources/Redesigned/Lyrics/SGRSingButton.h
index 72d5e52b..2a6d975f 100644
--- a/tweak/Sources/Redesigned/Lyrics/SGRSingButton.h
+++ b/tweak/Sources/Redesigned/Lyrics/SGRSingButton.h
@@ -12,12 +12,6 @@
// Threading: main thread only.
#import <UIKit/UIKit.h>
-// Shows or hides a Kit glass shape (Redesigned/Kit/SGRGlass.h) by its effect, never by an alpha on it or on
-// a view above it (PlayerMotion.x): UIKit draws the material wrongly or not at all under a fading alpha. The
-// solid shape Reduce Transparency puts in its place has no effect and fades by its own alpha. For the mic and
-// the pronunciation and translation button across from it; animates in the caller's animation.
-void SGRShowGlass(UIView *shape, BOOL shown);
-
@interface SGRSingButton : UIView
// Goes with the host's controls when they are hidden, in the host's animation: its glass dematerialises
// rather than fading under an alpha, and it takes no touches while tucked.
diff --git a/tweak/Sources/Redesigned/Lyrics/SGRSingButton.m b/tweak/Sources/Redesigned/Lyrics/SGRSingButton.m
index f7f0acbd..725bbe80 100644
--- a/tweak/Sources/Redesigned/Lyrics/SGRSingButton.m
+++ b/tweak/Sources/Redesigned/Lyrics/SGRSingButton.m
@@ -20,15 +20,6 @@ static const float kAsSungCatch = 0.08f;
static const CGFloat kMarkWidth = 14;
static char kButtonGlassKey, kPanelGlassKey;
-void SGRShowGlass(UIView *shape, BOOL shown) {
- if ([shape isKindOfClass:UIVisualEffectView.class]) {
- UIVisualEffectView *glass = (UIVisualEffectView *)shape;
- if ((glass.effect != nil) != shown) glass.effect = shown ? SGGlassEffect() : nil;
- } else {
- shape.alpha = shown ? 1 : 0;
- }
-}
-
@implementation SGRSingButton {
UIButton *_button; // holds no glass, so its alpha is free to fade
CAShapeLayer *_ring;
diff --git a/tweak/Sources/Redesigned/Player/PlayerArtwork.x b/tweak/Sources/Redesigned/Player/PlayerArtwork.x
index 60e5f135..4f5ee04e 100644
--- a/tweak/Sources/Redesigned/Player/PlayerArtwork.x
+++ b/tweak/Sources/Redesigned/Player/PlayerArtwork.x
@@ -140,8 +140,6 @@ static void scaleEveryCover(BOOL animated) {
// It is a speed like the menu's, so with Pitch follows speed on (until switched off) it also plays an
// octave higher, the way a record does. The native look's copy is in Native/Player/PlayerGestures.x.
static const double kHoldSpeed = 2;
-// The badge's way out, quicker than its way in: the finger is already off the cover.
-static const NSTimeInterval kBadgeExit = 0.15;
static char kHoldKey, kBadgeGlassKey;
@interface SGRCoverHold : UILongPressGestureRecognizer
@@ -177,8 +175,8 @@ static char kHoldKey, kBadgeGlassKey;
}
// "2×" and a forward glyph on the Kit's glass capsule at the top of the cover while it is held. What fades
-// is the glass's effect, never an alpha over it, which UIKit draws a blur under wrongly or not at all
-// (PlayerMotion.x); the capsule grows in from 0.9 with the Kit's press spring.
+// is the glass's effect (SGRShowGlass), never an alpha over it; the capsule grows in from 0.9 with the Kit's
+// press spring and goes with its exit, quicker than it came: the finger is already off the cover.
- (void)showBadge:(BOOL)shown on:(UIView *)cover {
if (shown && !_badge) {
_badgeLabel = [UILabel new];
@@ -202,10 +200,8 @@ static char kHoldKey, kBadgeGlassKey;
UIView *badge = _badge, *label = _badgeLabel;
// Made again by the Kit if Reduce Transparency changed: then it is a solid fill, which fades by alpha.
UIView *shape = SGRGlassCapsuleInside(badge, &kBadgeGlassKey, badge.bounds.size, NO);
- UIVisualEffectView *glass = [shape isKindOfClass:UIVisualEffectView.class] ? (UIVisualEffectView *)shape : nil;
void (^state)(BOOL) = ^(BOOL on) {
- if (glass) glass.effect = on ? SGGlassEffect() : nil;
- else shape.alpha = on ? 1 : 0;
+ SGRShowGlass(shape, on);
label.alpha = on ? 1 : 0;
};
if (shown) {
@@ -221,10 +217,9 @@ static char kHoldKey, kBadgeGlassKey;
badge.transform = CGAffineTransformIdentity;
}, nil);
} else {
- [UIView animateWithDuration:kBadgeExit delay:0 options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState
- animations:^{ state(NO); } completion:^(BOOL finished) {
+ SGRAnimate(SGRMotionExit, ^{ state(NO); }, ^(BOOL finished) {
if (finished && !self->_badgeShown) [badge removeFromSuperview];
- }];
+ });
}
}