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

fix: the redesigned player can no longer be scrolled up (#83)

Vojtěch Škopek62eee3363981
diff --git a/harness/player/main.m b/harness/player/main.m
index fd210477..45566d24 100644
--- a/harness/player/main.m
+++ b/harness/player/main.m
@@ -6,6 +6,7 @@
// HARNESS_SCENARIO (simctl launch passes it as SIMCTL_CHILD_HARNESS_SCENARIO) picks what it does:
// lyrics (default) the lyrics opened at 2 s, closed at 6, opened again at 10
// look one track playing, a second one from another album at 8 s, nothing opened
+// scroll the list moved up and down in code; the log says whether it stayed at its top
// artwork issue #58: tracks change while the covers on screen and the picture server lag behind,
// checked by colour at the end of each step; the log says PASS or FAIL
// HARNESS_VOLUME=0 leaves out the volume row the phone has (trees/clean/player/01.txt has none).
@@ -149,8 +150,10 @@ static NSString *colorName(UIImage *image) {
@interface _TtC20NowPlaying_ModesImpl18FooterElementsUnit : UIViewController @end
@implementation _TtC20NowPlaying_ModesImpl18FooterElementsUnit @end
-@interface _TtC21NowPlaying_ScrollImpl23NPVScrollViewController : UIViewController @end
-@implementation _TtC21NowPlaying_ScrollImpl23NPVScrollViewController @end
+@interface _TtC21NowPlaying_ScrollImpl23NPVScrollViewController : UIViewController <UIScrollViewDelegate> @end
+@implementation _TtC21NowPlaying_ScrollImpl23NPVScrollViewController
+- (void)scrollViewDidScroll:(UIScrollView *)list {}
+@end
@interface _TtC35NowPlaying_ContentLayerPlatformImpl24AccessibleCollectionView : UICollectionView @end
@implementation _TtC35NowPlaying_ContentLayerPlatformImpl24AccessibleCollectionView @end
@@ -301,6 +304,7 @@ static void loadLyrics(void) {
UIImageView *_cover, *_barCover;
UIViewController *_bar;
UICollectionView *_covers;
+ UIScrollView *_list;
NSUInteger _failures, _checks;
}
@@ -332,6 +336,8 @@ static void loadLyrics(void) {
[page addSubview:list];
UIViewController *scrollUnit = [_TtC21NowPlaying_ScrollImpl23NPVScrollViewController new];
scrollUnit.view = page;
+ list.delegate = (id<UIScrollViewDelegate>)scrollUnit;
+ _list = list;
// NPVBackgroundViewController's plane, the field's home (trees/clean/player/01.txt:449), under the player.
UIView *plane = box(list, UIView.class, CGRectMake(0, 0, W, H), nil);
@@ -477,6 +483,7 @@ static void loadLyrics(void) {
});
if ([scenario() isEqualToString:@"artwork"]) [self runArtworkChecks];
else if ([scenario() isEqualToString:@"look"]) [self runLook];
+ else if ([scenario() isEqualToString:@"scroll"]) [self runScrollChecks];
// Opened, closed and opened again, so a screenshot can be taken of each state and of the move itself.
else for (NSNumber *at in @[@2, @6, @10]) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(at.doubleValue * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
@@ -586,6 +593,23 @@ static void after(NSTimeInterval seconds, dispatch_block_t block) {
});
}
+// Up must be taken back to the top, down (the dismissal's pull) left where it went.
+- (void)runScrollChecks {
+ after(2, ^{
+ UIScrollView *list = self->_list;
+ CGFloat top = -list.adjustedContentInset.top;
+ list.contentOffset = CGPointMake(0, top + 120);
+ BOOL up = list.contentOffset.y == top;
+ list.contentOffset = CGPointMake(0, top - 80);
+ BOOL down = list.contentOffset.y == top - 80;
+ [list setContentOffset:CGPointMake(0, top + 300) animated:NO];
+ BOOL again = list.contentOffset.y == top;
+ list.contentOffset = CGPointMake(0, top);
+ NSLog(@"[harness] scroll checks: up %@, down %@, again %@ -- %@", up ? @"held" : @"moved", down ? @"kept" : @"lost",
+ again ? @"held" : @"moved", up && down && again ? @"PASS" : @"FAIL");
+ });
+}
+
// One track, then another album's at 8 s, its picture on the screens 0.4 s later.
- (void)runLook {
UIImage *second = secondArtwork();
diff --git a/tweak/Sources/Redesigned/Player/Player.h b/tweak/Sources/Redesigned/Player/Player.h
index ce5e1ea5..8335ae86 100644
--- a/tweak/Sources/Redesigned/Player/Player.h
+++ b/tweak/Sources/Redesigned/Player/Player.h
@@ -11,7 +11,7 @@
// PlayerControls.x previous, play and next as bare glyphs, monospaced times
// PlayerFooter.x share gone, lyrics, Connect and queue as one row of three glyphs
// PlayerCards.x every card under the player collapsed, so the list closes up
-// PlayerScroll.x the list pinned to the top, so the player is one screen and cannot be scrolled
+// PlayerScroll.x the list held at its top, so the player is one screen and cannot be scrolled up
// 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
diff --git a/tweak/Sources/Redesigned/Player/PlayerScroll.x b/tweak/Sources/Redesigned/Player/PlayerScroll.x
index 78c5237f..b89d9daa 100644
--- a/tweak/Sources/Redesigned/Player/PlayerScroll.x
+++ b/tweak/Sources/Redesigned/Player/PlayerScroll.x
@@ -1,66 +1,29 @@
-// Player redesign: the player is one screen. Spotify's is a list with the player as its header and the
-// cards under it, and the Music app's player does not scroll at all -- the lyrics arrive in the player
-// itself (PlayerLyrics.x), from the footer's glyph, rather than from under it. Every card is collapsed
-// already (PlayerCards.x), so all that is left below is the gaps the list leaves between them.
-//
-// The list is not switched off: the pull that dismisses the player rides on its own pan recogniser.
-// -[SPTBarInteractivePresentationController scrollViewDidAppear:] takes the list's panGestureRecognizer,
-// adds dismissPanWithGestureRecognizer: to it and makes its own dismiss recogniser wait for it to fail,
-// and that handler starts the dismissal only while the list is at or above its top (Spotify 9.1.78,
-// 0x109814898 and 0x109814400). Turning scrolling off takes that recogniser out with it and the player
-// can no longer be swiped away.
-//
-// So the range is closed instead: the bottom inset is set to whatever makes the furthest the list can
-// scroll its own top. A drag upward then only stretches and springs back, a drag downward still carries
-// the offset below zero, and the dismissal is untouched. It is worked out again on every layout pass
-// and on every scroll, since the cards arrive long after the player does and change the content's height.
-//
-// Tree (trees/clean/player/01.txt:20): UICollectionView 402x874 id=scrolling_npv_collection_view_accessibility_identifier,
-// with the player as an Element_List.SupplementaryItemView the size of the screen and a cell per card
-// under it. NPVScrollViewController is its delegate (:567).
+// Player redesign: the player never scrolls up. Scrolling stays on because Spotify's dismiss pull rides on
+// the list's own pan and starts only at its top, so the offset is clamped instead; the insets stay
+// Spotify's, since changing one mid-drag moves the offset under the finger.
#import "Core/SGCore.h"
#import "Redesigned/Kit/SGRKit.h"
static NSString *const kListIdentifier = @"scrolling_npv_collection_view_accessibility_identifier";
-// Insets are never compared for equality, only for being a point or so out.
-static const CGFloat kSlack = 0.5;
-static char kListKey;
+static __weak UIScrollView *sg_loggedList;
-static void pinToTop(UIScrollView *list) {
- if (!list || list.bounds.size.height < 1) return;
- UIEdgeInsets own = list.contentInset, adjusted = list.adjustedContentInset;
- // What the safe area adds on top of the inset of its own, which has to be left in place.
- CGFloat safeArea = adjusted.bottom - own.bottom;
- CGFloat over = list.contentSize.height - list.bounds.size.height;
- // The furthest it may scroll is where it rests: -adjusted.top, its own top.
- CGFloat want = -adjusted.top - over - safeArea;
- if (want >= 0 || fabs(want - own.bottom) < kSlack) return;
- own.bottom = want;
- list.contentInset = own;
+static void holdAtTop(UIScrollView *list) {
+ if (![list.accessibilityIdentifier isEqualToString:kListIdentifier]) return;
+ CGFloat top = -list.adjustedContentInset.top;
+ CGPoint offset = list.contentOffset;
+ if (offset.y <= top) return;
+ CGFloat past = offset.y - top;
+ list.contentOffset = CGPointMake(offset.x, top);
- static dispatch_once_t once;
- dispatch_once(&once, ^{ SGLog(@"redesign player: the list pinned to its top, %.0fpt of cards closed off", -want); });
+ if (sg_loggedList == list) return;
+ sg_loggedList = list;
+ SGLog(@"redesign player: scroll held at the top, %.0fpt up taken back (%@)", past, list.isDragging ? @"drag" : @"no finger");
}
%hook _TtC21NowPlaying_ScrollImpl23NPVScrollViewController
-- (void)viewDidLayoutSubviews {
- %orig;
- UIView *page = ((UIViewController *)self).viewIfLoaded;
- UIView *list = SGRFindByIdentifier(page, kListIdentifier, &kListKey);
- if ([list isKindOfClass:UIScrollView.class]) pinToTop((UIScrollView *)list);
-}
-
-// A card arriving, or one of them settling on its height, grows the content without a pass of the page's.
-- (void)collectionView:(UICollectionView *)list willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)path {
- %orig;
- pinToTop(list);
- // The height a cell reports is asked for after this, so the last word on the content is a runloop away.
- dispatch_async(dispatch_get_main_queue(), ^{ pinToTop(list); });
-}
-
- (void)scrollViewDidScroll:(UIScrollView *)list {
- pinToTop(list);
+ holdAtTop(list);
%orig;
}
%end