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 large Home cards' covers reach the card's edges, square at the footer
My-Name-Is-Jeffd74d05e49ed9
diff --git a/tweak/Sources/Redesigned/Home/HomeCards.x b/tweak/Sources/Redesigned/Home/HomeCards.xindex 672bbd27..21cd8ee2 100644--- a/tweak/Sources/Redesigned/Home/HomeCards.x+++ b/tweak/Sources/Redesigned/Home/HomeCards.x@@ -130,6 +130,15 @@ static void relayoutButtonAround(UIView *label) {}%end+// A new card's labels get their text before the card is in the window, under no button yet: once Spotify's label+// joins the window under a card or tile, that button is marked, so the pass that styles it sees the labels.+%hook SPTEncoreLabel+- (void)didMoveToWindow {+ %orig;+ if (((UIView *)self).window) relayoutButtonAround((UIView *)self);+}+%end+%hook UILabel- (void)setText:(NSString *)text {%orig;@@ -152,5 +161,5 @@ static void relayoutButtonAround(UIView *label) {]);if (!SGRHomeLook()) return;%init(SGRHomeLook);- SGRequireClasses(@[@"_TtC11Home_ECMKit36ShortcutCardHomePlayingIndicatorView"]);+ SGRequireClasses(@[@"_TtC11Home_ECMKit36ShortcutCardHomePlayingIndicatorView", @"SPTEncoreLabel"]);}diff --git a/tweak/Sources/Redesigned/Home/HomeHeader.x b/tweak/Sources/Redesigned/Home/HomeHeader.xindex e14e0fb0..92cd8cad 100644--- a/tweak/Sources/Redesigned/Home/HomeHeader.x+++ b/tweak/Sources/Redesigned/Home/HomeHeader.x@@ -25,7 +25,7 @@// Tries at finding the tab's name before settling for the English one: a miss walks the window.static const NSUInteger kTitleTries = 8;-static char kTitleKey, kTabKey, kPillGlassKey, kGlassKey, kButtonsKey, kConnectKey, kTintKey;+static char kTitleKey, kTabKey, kPillGlassKey, kGlassKey, kButtonsKey, kConnectKey, kTintKey, kWatchKey;// The title row's pill: a glass capsule around the filter button and the avatar, 44pt tall, as the reference has// it; the menu drives Spotify's own filter chips, hidden in the stack, and offers the device picker when Spotify// has one (a now playing bar) and the large shelf's Show all, its heading being gone (HomeTopPicks.x).@@ -218,13 +218,26 @@ static UIView *glassIn(UIView *header) {}// Lays the pill out around the avatar, which stays Spotify's in its stack; the pill's leading edge.+// The stack's place in the header with no transform on it (its center and bounds, which a transform leaves+// alone): Spotify animates the stack in with a transform, and the one pass this ran in on a 440pt phone saw the+// stack's frame half a width to the left, with no pass after to put the pill right.+static CGRect stackPlace(UIStackView *stack) {+ CGSize size = stack.bounds.size;+ return CGRectMake(stack.center.x - size.width / 2, stack.center.y - size.height / 2, size.width, size.height);+}++static CGRect facePlace(UIStackView *stack, UIView *face) {+ CGRect place = stackPlace(stack);+ return CGRectOffset(face.frame, place.origin.x - stack.bounds.origin.x, place.origin.y - stack.bounds.origin.y);+}+static CGFloat layoutPill(UIView *header, UIStackView *stack, UIView *face) {SGRHomePillButtons *buttons = buttonsIn(header);UIView *glass = glassIn(header);- CGRect faceFrame = face ? [stack convertRect:face.frame toView:header] : CGRectZero;+ CGRect faceFrame = face ? facePlace(stack, face) : CGRectZero;CGFloat width = kPillPad + kPillButton + (face ? faceFrame.size.width + kPillPad * 2 : kPillPad);CGFloat maxX = face ? CGRectGetMaxX(faceFrame) + kPillPad : header.bounds.size.width - SGRSideMargin;- CGFloat midY = face ? CGRectGetMidY(faceFrame) : CGRectGetMidY(stack.frame);+ CGFloat midY = face ? CGRectGetMidY(faceFrame) : CGRectGetMidY(stackPlace(stack));CGRect pill = CGRectMake(round(maxX - width), round(midY - kPillHeight / 2), width, kPillHeight);if (!CGRectEqualToRect(glass.frame, pill)) glass.frame = pill;if (!CGRectEqualToRect(buttons.frame, pill)) buttons.frame = pill;@@ -341,12 +354,33 @@ static void follow(UIView *view) {followScroll(feed);}+static void layoutHeader(UIViewController *page);++// The page's own pass can run before Spotify has sized its header at all (the header's view 0 by 0, its stack still+// a width to the left and centered on the origin: seen on a 440pt phone, with no pass of the page after, which+// left the pill beside the title). While the header has no size, this comes back a little later, for a few seconds+// at most, until it has one.+static const NSUInteger kHeaderWaits = 30;+static const NSTimeInterval kHeaderWait = 0.1;+static void layoutHeaderOnceSized(UIViewController *page, UIView *header) {+ if (!CGRectIsEmpty(header.bounds)) return;+ NSUInteger waits = [objc_getAssociatedObject(header, &kWatchKey) unsignedIntegerValue];+ if (waits >= kHeaderWaits) return;+ objc_setAssociatedObject(header, &kWatchKey, @(waits + 1), OBJC_ASSOCIATION_RETAIN_NONATOMIC);+ __weak UIViewController *weakPage = page;+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kHeaderWait * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ UIViewController *strongPage = weakPage;+ if (strongPage) layoutHeader(strongPage);+ });+}+static void layoutHeader(UIViewController *page) {UIView *view = page.viewIfLoaded;if (!view || !findHeader(view)) return;UIView *header = sg_header;UIStackView *stack = sg_stack;vanish(sg_scrim);+ layoutHeaderOnceSized(page, header);UIView *face = nil;for (UIView *part in stack.arrangedSubviews) {@@ -365,7 +399,7 @@ static void layoutHeader(UIViewController *page) {}[stack layoutIfNeeded];// With the Home look off, the avatar stands alone in the stack and the title ends before it, as before.- CGFloat pillLeading = face ? CGRectGetMinX([stack convertRect:face.frame toView:header]) : header.bounds.size.width - SGRSideMargin + SGRGrid;+ CGFloat pillLeading = face ? CGRectGetMinX(facePlace(stack, face)) : header.bounds.size.width - SGRSideMargin + SGRGrid;if (SGRHomeLook()) {pillLeading = layoutPill(header, stack, face);layoutTint(view);@@ -382,7 +416,7 @@ static void layoutHeader(UIViewController *page) {CGFloat trailing = pillLeading - SGRGrid;CGFloat height = ceil(font.lineHeight);- CGRect frame = CGRectMake(SGRSideMargin, round(CGRectGetMidY(stack.frame) - height / 2), MAX(0, trailing - SGRSideMargin), height);+ CGRect frame = CGRectMake(SGRSideMargin, round(CGRectGetMidY(stackPlace(stack)) - height / 2), MAX(0, trailing - SGRSideMargin), height);// By bounds and center: the title carries the scroll's transform.CGRect bounds = (CGRect){CGPointZero, frame.size};CGPoint center = CGPointMake(CGRectGetMidX(frame), CGRectGetMidY(frame));diff --git a/tweak/Sources/Redesigned/Home/HomeTopPicks.x b/tweak/Sources/Redesigned/Home/HomeTopPicks.xindex 3b43ff69..d299a92d 100644--- a/tweak/Sources/Redesigned/Home/HomeTopPicks.x+++ b/tweak/Sources/Redesigned/Home/HomeTopPicks.x@@ -419,6 +419,7 @@ static char kPartsKey, kCoverKey, kShownKey;@interface SGRLargeCardParts : NSObject@property (nonatomic, strong) UIView *surface;+@property (nonatomic, strong) UIImageView *cover; // the Kit's, edge to edge at the card's top@property (nonatomic, strong) UILabel *lead, *second;@property (nonatomic, copy) NSArray<UILabel *> *theirs; // Spotify's labels made transparent, to bring back@end@@ -451,14 +452,10 @@ static NSArray<UILabel *> *spotifyLabels(UIView *card, SGRLargeCardParts *parts)static void restore(UIView *card, SGRLargeCardParts *parts) {UIView *holder = SGRFindByIdentifier(card, @"Encore.ImageView", &kCoverKey);- if (holder && !CGAffineTransformIsIdentity(holder.transform)) holder.transform = CGAffineTransformIdentity;- // The corners go back to all four; roundCover (HomeCards.x) sets the small card's radius on its next pass.- CACornerMask all = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner | kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner;- for (UIView *sub in holder.subviews) {- if ([sub isKindOfClass:UIImageView.class] && sub.layer.maskedCorners != all) sub.layer.maskedCorners = all;- }+ if (holder.alpha == 0) holder.alpha = 1;card.layer.cornerRadius = 0;card.layer.masksToBounds = NO;+ [parts.cover removeFromSuperview];[parts.surface removeFromSuperview];[parts.lead removeFromSuperview];[parts.second removeFromSuperview];@@ -536,12 +533,27 @@ static BOOL styleLargeCard(UIView *card) {parts.surface.backgroundColor = SGRElevated(UIColor.blackColor);parts.lead = footerLabel(SGRFont(UIFontTextStyleBody, UIFontWeightSemibold, UIContentSizeCategoryLarge), SGRPrimary());parts.second = footerLabel(SGRFont(UIFontTextStyleFootnote, UIFontWeightRegular, UIContentSizeCategoryLarge), SGRSecondary());+ // The cover drawn by the Kit, edge to edge at the card's top: Spotify keeps its own 2pt in on every side (9.1.90),+ // and a transform scaling its holder out to the edges was reset by the stack's later pass. Spotify's image view+ // goes transparent and keeps everything else (the button's touches, its accessibility label, the image the tint+ // and this view read).+ parts.cover = [UIImageView new];+ parts.cover.contentMode = UIViewContentModeScaleAspectFill;+ // Spotify's card covers come with rounded corners in the bitmap (about 3pt of 237, transparent); the outer+ // 1.5% of each side is left out so the cover's bottom meets the footer square.+ parts.cover.layer.contentsRect = CGRectInset(CGRectMake(0, 0, 1, 1), 0.015, 0.015);+ parts.cover.clipsToBounds = YES;+ parts.cover.userInteractionEnabled = NO;+ parts.cover.accessibilityElementsHidden = YES;objc_setAssociatedObject(card, &kPartsKey, parts, OBJC_ASSOCIATION_RETAIN_NONATOMIC);__weak UIView *weakCard = card;// The block is replaced on every pass, so a cover taken into another card tells the card it is in now.SGRObserveImage(cover, ^(UIImageView *view) {UIView *strongCard = weakCard;- if (strongCard && [view isDescendantOfView:strongCard]) tintCard(strongCard, view);+ if (!strongCard || ![view isDescendantOfView:strongCard]) return;+ SGRLargeCardParts *now = objc_getAssociatedObject(strongCard, &kPartsKey);+ if (now.cover.image != view.image) now.cover.image = view.image;+ tintCard(strongCard, view);});static dispatch_once_t once;dispatch_once(&once, ^{ SGLog(@"redesign home: top picks card %@ styled", NSStringFromCGRect(card.bounds)); });@@ -550,30 +562,18 @@ static BOOL styleLargeCard(UIView *card) {if (layer.cornerRadius != SGRRadiusCard) layer.cornerRadius = SGRRadiusCard;if (layer.cornerCurve != kCACornerCurveContinuous) layer.cornerCurve = kCACornerCurveContinuous;if (!layer.masksToBounds) layer.masksToBounds = YES;- CALayer *coverLayer = cover.layer;- if (coverLayer.cornerRadius != SGRRadiusCard) coverLayer.cornerRadius = SGRRadiusCard;- if (coverLayer.cornerCurve != kCACornerCurveContinuous) coverLayer.cornerCurve = kCACornerCurveContinuous;- CACornerMask top = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;- if (coverLayer.maskedCorners != top) coverLayer.maskedCorners = top;- if (!coverLayer.masksToBounds) coverLayer.masksToBounds = YES;- // Spotify keeps the cover 2pt in from the card on every side (9.1.90; none on 9.1.78); the reference's reaches- // the card's top and sides, so the holder is scaled up about its middle by what the inset takes, a transform its- // layout never reads. Only once Spotify has laid the holder out to the card (HomeCards.x asks for this pass- // again when it does): scaled from its first, small size, the cover filled the whole card.- CGAffineTransform was = holder.transform;- holder.transform = CGAffineTransformIdentity;- CGRect laid = [holder.superview convertRect:holder.frame toView:card];- CGFloat inset = CGRectGetMinX(laid), cardWidth = card.bounds.size.width;- CGAffineTransform flush = was;- if (inset > 0 && inset <= 4 && fabs(CGRectGetWidth(laid) + inset * 2 - cardWidth) < 1) {- flush = CGAffineTransformMakeScale(cardWidth / CGRectGetWidth(laid), cardWidth / CGRectGetWidth(laid));- } else if (CGRectGetWidth(laid) + 1 < cardWidth - 4) {- flush = CGAffineTransformIdentity;- }- holder.transform = flush;+ // The card's own corners round the cover's top; its bottom meets the footer square. Spotify's holder goes+ // transparent as a whole: its image view's alpha is Spotify's to fade in as the image loads.+ if (parts.cover.layer.cornerRadius != 0) parts.cover.layer.cornerRadius = 0;+ if (holder.alpha != 0) holder.alpha = 0;+ if (parts.cover.image != cover.image) parts.cover.image = cover.image;if (parts.surface.superview != card) [card insertSubview:parts.surface atIndex:0];if (!CGRectEqualToRect(parts.surface.frame, card.bounds)) parts.surface.frame = card.bounds;+ // Above the surface and under Spotify's views, which draw nothing over it but keep their place for touches.+ if (parts.cover.superview != card) [card insertSubview:parts.cover aboveSubview:parts.surface];+ CGRect square = CGRectMake(0, 0, card.bounds.size.width, card.bounds.size.width);+ if (!CGRectEqualToRect(parts.cover.frame, square)) parts.cover.frame = square;NSArray<UILabel *> *theirs = spotifyLabels(card, parts);for (UILabel *label in theirs) {