Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix(lyrics): scrolling the lines hides the controls and scrolling back shows them (#142)
trihmah85501d09ac7b
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 580cafd7..6ea51ea2 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -593,7 +593,8 @@ Redesigned:Lyrics/ the full screen lyrics page on glass with Apple Music style lyrics over it, always on (SGRKaraokeView,which the player shows in itself too, Player/PlayerLyrics.x, where with Hide the controls set toEverything, everything else -- the header row, the thumbnail, the title row and the controls --- fades a few seconds after the last touch and the lines take the whole safe area until a tap; set+ fades a few seconds after the last touch and the lines take the whole safe area until a tap where+ the rest was or a scroll back; setto Keep the title, only the controls under the title row and the lyrics' own button fade and thelines grow down into their room): lines sung over each other lit together, the stack moving ononce the first is sung out; an instrumental break of 7 s or more held by three dotsdiff --git a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.h b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.hindex 036a6bb2..2c051ecb 100644--- a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.h+++ b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.h@@ -14,12 +14,20 @@- (instancetype)initWithSampleLines:(NSArray<SGKaraokeLine *> *)lines length:(NSInteger)length;// Hides Spotify's own lyrics next to this view while it has lyrics to show, and brings them back when not.- (void)syncSiblings;-// Called as a finger starts to scroll the lines, for a host that hides its controls then.-@property (nonatomic, copy) void (^browsingBegan)(void);+// Called as a finger starts to scroll the lines, for a host that hides its controls then. `onward` is a finger+// moving up, toward the lines still to come.+@property (nonatomic, copy) void (^browsingBegan)(BOOL onward);// The pronunciation and translation button goes with the host's controls when they are hidden, and Sing's// mic with it unless keepsSing is set.@property (nonatomic) BOOL extrasHidden;// The mic stays when the extras go, for a host that lets it take its own touches while its controls are// hidden (the player's lines on their own, Redesigned/Player/PlayerLyrics.x), so Sing is always in reach.@property (nonatomic) BOOL keepsSing;+// How far down a tap on the lines seeks, from the view's top; 0 is all the way. Below it, and above+// seeksBelow, the tap is the host's (the player's lines on their own, over the controls that faded).+@property (nonatomic) CGFloat seeksAbove;+@property (nonatomic) CGFloat seeksBelow;+// Whether a tap at point, in the view, seeks: on a timed line, inside the seeking band, and not on the credit+// or a line's explain bubble.+- (BOOL)tapSeeksAt:(CGPoint)point;@enddiff --git a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.mindex af5e3d48..22e7bb27 100644--- a/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m+++ b/tweak/Sources/Redesigned/Lyrics/SGRKaraokeView.m@@ -1467,29 +1467,44 @@ typedef struct {return _sample ?: SGKaraokeLinesForTrack(track);}-- (void)tapped:(UITapGestureRecognizer *)tap {- [self stir];- if (_extrasBox && !_extrasBox.hidden && CGRectContainsPoint(_extrasBox.frame, [tap locationInView:self])) return;- if (_sing.userInteractionEnabled && [_sing pointInside:[tap locationInView:_sing] withEvent:nil]) return;+// What a tap at point (in the view) lands on: the credit, a line's explain bubble (*explains), a line to seek+// to, or nothing.+- (UIView *)tapTargetAt:(CGPoint)point explains:(BOOL *)explains {+ *explains = NO;+ if (_extrasBox && !_extrasBox.hidden && CGRectContainsPoint(_extrasBox.frame, point)) return nil;+ if (_sing.userInteractionEnabled && [_sing pointInside:[self convertPoint:point toView:_sing] withEvent:nil]) return nil;+ CGPoint inScroll = [self convertPoint:point toView:_scroll];if (_creditLinks.count && !_credit.hidden- && CGRectContainsPoint(CGRectInset(_credit.frame, -kCreditSlop, -MAX(kCreditSlop, (44 - _credit.frame.size.height) / 2)),- [tap locationInView:_scroll])) {- SGLyricsOpenCreditLinks(_creditLinks, _credit);- return;+ && CGRectContainsPoint(CGRectInset(_credit.frame, -kCreditSlop, -MAX(kCreditSlop, (44 - _credit.frame.size.height) / 2)), inScroll)) {+ return _credit;}- CGPoint point = [tap locationInView:_scroll];for (SGRKaraokeLineView *view in _shown.allValues) {CGRect target = view.bubbleTarget;- if (CGRectIsNull(target) || !CGRectContainsPoint(target, [_scroll convertPoint:point toView:view])) continue;- [self explainLine:view];- return;+ if (CGRectIsNull(target) || !CGRectContainsPoint(target, [_scroll convertPoint:inScroll toView:view])) continue;+ *explains = YES;+ return view;}- if (_plain) return; // a line with no time has nowhere to seek to+ if (_plain) return nil; // a line with no time has nowhere to seek to+ if (_seeksAbove > 0 && (point.y > _seeksAbove || point.y < _seeksBelow)) return nil; // the host's, where its controls werefor (SGRKaraokeLineView *view in _shown.allValues) {- if (!CGRectContainsPoint(CGRectInset(view.frame, -_margin, -_lineGap / 2), point)) continue;- [self seekToLine:view.line];- return;+ if (CGRectContainsPoint(CGRectInset(view.frame, -_margin, -_lineGap / 2), inScroll)) return view;}+ return nil;+}++- (BOOL)tapSeeksAt:(CGPoint)point {+ BOOL explains;+ UIView *target = [self tapTargetAt:point explains:&explains];+ return target && target != _credit && !explains;+}++- (void)tapped:(UITapGestureRecognizer *)tap {+ [self stir];+ BOOL explains;+ UIView *target = [self tapTargetAt:[tap locationInView:self] explains:&explains];+ if (target == _credit) SGLyricsOpenCreditLinks(_creditLinks, _credit);+ else if (explains) [self explainLine:(SGRKaraokeLineView *)target];+ else if (target) [self seekToLine:((SGRKaraokeLineView *)target).line];}// A tap on a line, or VoiceOver activating it.@@ -1549,7 +1564,7 @@ typedef struct {_browseBreak = _openBreak;}_browsing = YES;- if (self.browsingBegan) self.browsingBegan();+ if (self.browsingBegan) self.browsingBegan([scrollView.panGestureRecognizer translationInView:scrollView].y < 0);for (SGRKaraokeLineView *view in _shown.allValues) view.blur = 0;}diff --git a/tweak/Sources/Redesigned/Player/Player.h b/tweak/Sources/Redesigned/Player/Player.hindex b4011061..44edcdeb 100644--- a/tweak/Sources/Redesigned/Player/Player.h+++ b/tweak/Sources/Redesigned/Player/Player.h@@ -103,8 +103,8 @@ static inline Class SGRDJClass(NSString *name) {}// What fades a few seconds after the last touch while the lyrics play, as the lines grow into the room// (PlayerLyrics.x): nothing, everything but the lines, or the controls under the title row alone. A scroll-// through the lines hides the same views, everything when the choice is Off. The key was a switch first: its-// NO and YES are the first two indexes, and unset reads as the switch did.+// on through the lines hides the same views, everything when the choice is Off, and a scroll back brings them+// back. The key was a switch first: its NO and YES are the first two indexes, and unset reads as the switch did.#define SGRKeyLyricsAutoHide @"spotifyglass.redesign.lyrics.autoHide"typedef NS_ENUM(NSInteger, SGRLyricsHide) { SGRLyricsHideOff, SGRLyricsHideAll, SGRLyricsHideControls };SGRLyricsHide SGRLyricsHideMode(void);diff --git a/tweak/Sources/Redesigned/Player/PlayerLandscape.x b/tweak/Sources/Redesigned/Player/PlayerLandscape.xindex 9004dec6..12796dd3 100644--- a/tweak/Sources/Redesigned/Player/PlayerLandscape.x+++ b/tweak/Sources/Redesigned/Player/PlayerLandscape.x@@ -134,7 +134,7 @@ static UIButton *controlButton(NSString *symbol, CGFloat size, NSString *label,_lyrics.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;[_stage addSubview:_lyrics];__weak SGRLandscapeLyricsController *weakSelf = self;- _lyrics.browsingBegan = ^{ [weakSelf rest]; };+ _lyrics.browsingBegan = ^(BOOL onward) { [weakSelf rest]; };_hide = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rest)];[self.view addGestureRecognizer:_hide];diff --git a/tweak/Sources/Redesigned/Player/PlayerLyrics.x b/tweak/Sources/Redesigned/Player/PlayerLyrics.xindex 8b99bc2c..798e4b51 100644--- a/tweak/Sources/Redesigned/Player/PlayerLyrics.x+++ b/tweak/Sources/Redesigned/Player/PlayerLyrics.x@@ -325,15 +325,16 @@ static CGFloat thumbRadius(SGRLyricsLayout l, BOOL open) {// After kRest without a touch while the song plays, everything but the lines fades -- the header row, the// thumbnail, the title row and the controls -- and the lines grow up and down into the whole safe area, the// way the Music app leaves its lyrics alone. The lines scroll as they always do and leave the rest hidden; a-// tap anywhere brings it all back and is not a seek. A pause brings it back and keeps it; VoiceOver, a sheet-// over the player and the app in the background keep it up. A scroll through the lines hides it at once.+// tap on them where they were with the rest up seeks, and a tap anywhere else brings it all back and is not a+// seek. A pause brings it back and keeps it; VoiceOver, a sheet over the player and the app in the background+// keep it up. A scroll on through the lines hides it at once, and a scroll back brings it back.// Sing's mic stays with the lines, and a touch on it is the mic's: it does not bring the rest back.//// The tap is a recognizer on the player that recognizes with any other, and a button takes its own tap:// UIKit gives a control its tap over a tap recognizer above it. A faded view takes no touch (UIKit's hit// test skips it), so a tap where the thumbnail or a button was only wakes. A drag or a second finger fails-// it. The lines' own tap, the one that seeks, is off while they are alone, which holds whichever of the two-// would have finished first.+// it. While they are alone the lines' own tap, the one that seeks, keeps to where they were with the rest up+// (seeksBelow to seeksAbove), and the recognizer takes no touch where that tap seeks (tapSeeksAt:).// What fades: every view of Spotify's bottom stack but the chips (gone while the lines are up), which is the// title row, the progress bar, the buttons, the footer and a volume row where the phone has one; the header@@ -398,19 +399,6 @@ static CGRect aloneStage(UIView *host, SGRLyricsLayout l) {return CGRectMake(CGRectGetMinX(l.stage), top, l.stage.size.width, CGRectGetMaxY(safe) - kLyricsBottom - top);}-// The lines' tap seeks, so it is off while they are alone. Back on a turn of the run loop later: the tap-// that brought the controls back is still being handed round, and must not reach it.-static void letLinesSeek(SGRPlayerLyricsOverlay *overlay, BOOL seek) {- void (^apply)(void) = ^{- if (seek == sg_alone) return; // alone again since- for (UIGestureRecognizer *recognizer in overlay.lyrics.gestureRecognizers) {- if ([recognizer isKindOfClass:UITapGestureRecognizer.class]) recognizer.enabled = seek;- }- };- if (seek) dispatch_async(dispatch_get_main_queue(), apply);- else apply();-}-static void setAlone(BOOL alone, BOOL animated);// A sheet, a menu or an alert over the player: the top controller on screen is not one the player is drawn@@ -522,10 +510,14 @@ static void restartRest(void) {- (BOOL)gestureRecognizer:(UIGestureRecognizer *)recognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)other {return YES;}-// Sing's mic and its slider stay while the lines are alone, and a touch on them is theirs alone.+// Sing's mic and its slider stay while the lines are alone, and a touch on them is theirs alone. So is a touch+// on a line the lines' own tap would seek to: it seeks and brings nothing back.- (BOOL)gestureRecognizer:(UIGestureRecognizer *)recognizer shouldReceiveTouch:(UITouch *)touch {+ SGRPlayerLyricsOverlay *overlay = objc_getAssociatedObject(sg_host, &kOverlayKey);+ SGRKaraokeView *lines = overlay.lyrics;for (UIView *v = touch.view; v; v = v.superview) {if ([v isKindOfClass:SGRSingButton.class]) return NO;+ if (v == lines) return ![lines tapSeeksAt:[touch locationInView:lines]];}return YES;}@@ -543,12 +535,28 @@ static void setAlone(BOOL alone, BOOL animated) {// lines' tap are given back even when the player can no longer be measured.if (alone && !l.ok) return;sg_alone = alone;+ SGRPlayerLyricsOverlay *overlay = objc_getAssociatedObject(host, &kOverlayKey);+ CGFloat seeksBelow = 0, seeksAbove = 0;if (alone) {[sg_rest invalidate];sg_rest = nil;+ CGRect stage = l.stage;l.stage = aloneStage(host, l);+ seeksBelow = CGRectGetMinY(stage) - CGRectGetMinY(l.stage);+ seeksAbove = CGRectGetMaxY(stage) - CGRectGetMinY(l.stage);+ }+ // Alone, the lines seek only where they reached with the controls up. Coming back, nowhere until a turn of+ // the run loop later, then all the way: the tap that brought the controls back is still being handed round,+ // and must not seek.+ if (alone && overlay.superview) {+ overlay.lyrics.seeksBelow = seeksBelow;+ overlay.lyrics.seeksAbove = seeksAbove;+ } else if (overlay.superview) {+ overlay.lyrics.seeksBelow = CGFLOAT_MAX;+ dispatch_async(dispatch_get_main_queue(), ^{+ if (!sg_alone) overlay.lyrics.seeksAbove = 0; // alone again since+ });}- SGRPlayerLyricsOverlay *overlay = objc_getAssociatedObject(host, &kOverlayKey);// Layout and opacity have their own timing; Reduce Motion dissolves the layout in place.void (^move)(void) = ^{if (!overlay.superview || !l.ok) return;@@ -563,7 +571,6 @@ static void setAlone(BOOL alone, BOOL animated) {fadeControls(alone);};sg_wake.enabled = alone;- if (overlay) letLinesSeek(overlay, !alone);if (animated) {SGRAnimateLayout(host, move, nil);// Going, the controls take their time, since nobody waits on them; coming back at a touch, they answer at@@ -615,9 +622,11 @@ static void setOpen(BOOL open, BOOL animated) {overlay.cover.image = SGRNowPlayingArtwork(NULL, NULL);overlay.stage.alpha = 0;overlay.stage.transform = entering;- // Not under VoiceOver, which keeps the controls up, nor under a sheet.- overlay.lyrics.browsingBegan = ^{- if (!UIAccessibilityIsVoiceOverRunning() && !coveredBySheet()) setAlone(YES, YES);+ // Once a drag, as it starts: the lines resize then and not again under the finger. Scrolling on hides,+ // not under VoiceOver, which keeps the controls up, nor under a sheet; scrolling back brings them back.+ overlay.lyrics.browsingBegan = ^(BOOL onward) {+ if (!onward) setAlone(NO, YES);+ else if (!UIAccessibilityIsVoiceOverRunning() && !coveredBySheet()) setAlone(YES, YES);};// Spotify's cover goes the moment the redesign's own takes its place: the same picture at the// same size with the same corners, so there is nothing to see in the swap. Coming back it waits@@ -695,7 +704,10 @@ static void replace(void) {if (!overlay.superview) return;if (overlay.superview == host && host.subviews.lastObject != overlay) [host bringSubviewToFront:overlay];if (sg_alone) {+ CGRect stage = l.stage;l.stage = aloneStage(host, l);+ overlay.lyrics.seeksBelow = CGRectGetMinY(stage) - CGRectGetMinY(l.stage);+ overlay.lyrics.seeksAbove = CGRectGetMaxY(stage) - CGRectGetMinY(l.stage);fadeControls(YES);}place(overlay, host, l);