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
2.2 KB
Raw Blame
// The lyrics card under the player on glass ("Glass lyrics" on the Lyrics page).
//
// Card (trees/now-playing.txt): a Lyrics_CardElementImpl.CardView inside an
// Element_List.CollectionViewCell 370x316. The cell is the painted surface with the 16pt corners,
// so the pane fills it and the cell's own clipping cuts the corners. The page the card expands into
// is Native/Lyrics/LyricsPage.x's.
#import "Core/SGCore.h"
#import "NowPlaying.h"
#import "Native/Appearance/Repaint.h"

static const CGFloat kCardRadius = 16;
static char kCardGlassKey;

#pragma mark - the card in the player's scroll list

// The cell around the card, the view Spotify paints and rounds.
static UIView *cellAround(UIView *view) {
    static Class cell;
    if (!cell) cell = NSClassFromString(@"_TtC12Element_List18CollectionViewCell");
    for (UIView *v = view; v; v = v.superview) {
        if ([v isKindOfClass:cell]) return v;
    }
    return nil;
}

%hook _TtC22Lyrics_CardElementImpl8CardView
- (void)layoutSubviews {
    %orig;
    if (!SGFlag(SGKeyLyricsCard, NO)) return;
    UIView *cell = cellAround((UIView *)self);
    // A card PlayerDeclutter.x collapsed reports no height; leave it alone.
    if (!cell || cell.bounds.size.height < 40) return;
    // Spotify repaints the card with the album color when the track changes, which is no layout
    // pass of its own; Native/Appearance/Repaint.x keeps it clear in between.
    sg_lyricsCardRoot = cell;
    SGStripBackgrounds(cell);
    UIVisualEffectView *glass = SGGlassFor(cell, &kCardGlassKey);
    // Dark whatever the system is set to, as the player's header panes are (Player.x): light glass under
    // white lyrics otherwise, on a phone in light mode.
    if (glass.overrideUserInterfaceStyle != UIUserInterfaceStyleDark) glass.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
    glass.frame = cell.bounds;
    glass.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    SGShapeGlass(glass, kCardRadius, NO);
}
%end

%ctor {
    if (!SGNativeUI()) return;
    %init;
    SGRequireClasses(@[
        @"_TtC22Lyrics_CardElementImpl8CardView",
        @"_TtC12Element_List18CollectionViewCell",
    ]);
}