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: Animated artwork crosses over with the cover and holds Fluid still

My-Name-Is-Jeffba2c8b037af9
diff --git a/docs/tweaks.md b/docs/tweaks.md
index e94c6228..2fd6e679 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -231,9 +231,11 @@ Redesigned:
cover plays at 2x until the finger lifts (PlayerArtwork.x), an octave higher while Pitch follows
speed is on. Animated artwork (PlayerMotion.x)
runs the clip edge to edge from the top over its own last rows drawn on down, with a blur coming in
- from the seam under the controls and over the whole clip behind the lyrics; the menu switches it
- between Animated and Fluid without a restart. Checked in the simulator against harness/player/
- (`motion`)
+ from the seam under the controls and over the whole clip behind the lyrics. The clip and the cover
+ cross over as one comes and the other goes, the clip from its poster frame before the video has
+ decoded one, and the Fluid field under a clip holds still and, once the clip has faded in, is hidden
+ (SGRArtworkField's covered); the menu switches it between Animated
+ and Fluid without a restart. Checked in the simulator against harness/player/ (`motion`)
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): lines sung over each other lit together,
the stack moving on once the first is sung out; an instrumental break of 7 s or more held by three dots
diff --git a/harness/player/README.md b/harness/player/README.md
index d3c82e8c..7e76dac2 100644
--- a/harness/player/README.md
+++ b/harness/player/README.md
@@ -42,7 +42,9 @@ come late, out of order, or not at all.
is served as the track's Canvas before the player's background has laid out; then the background lays
out, the lyrics open and close, the background is built again, and the ⋯ menu's switch goes off, on, and
off with the player out of its window. Each step is checked (the clip on the field, the cover hidden, the
- foot and the blur, the thumbnail) and the log ends with `motion checks: n of 9 right -- PASS` or `FAIL`.
+ poster under the video and the Fluid field held under it, the foot and the blur, the thumbnail, the clip
+ and the cover crossing over half way through the switch) and the log ends with
+ `motion checks: n of 11 right -- PASS` or `FAIL`.
`HARNESS_VOLUME=0` leaves out the volume row that the phone has and the tree does not.
diff --git a/harness/player/build.sh b/harness/player/build.sh
index b7f6ba4f..09c0c5c4 100755
--- a/harness/player/build.sh
+++ b/harness/player/build.sh
@@ -22,7 +22,7 @@ xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-ar
"$SRC"/Redesigned/Kit/SGRTokens.m "$SRC"/Redesigned/Kit/SGRPalette.m "$SRC"/Redesigned/Kit/SGRField.m "$SRC"/Redesigned/Kit/SGRFlow.m "$SRC"/Redesigned/Kit/SGRFluid.m "$SRC"/Shared/AnimatedArtwork/SGMotionCatalog.m "$SRC"/Shared/AnimatedArtwork/SGMotionStore.m \
"$SRC"/Redesigned/Kit/SGRGlass.m "$SRC"/Redesigned/Kit/SGRGlyph.m "$SRC"/Redesigned/Kit/SGRRestyle.m \
"$SRC"/Redesigned/Kit/SGRedesign.m \
- "$SRC"/Redesigned/Lyrics/SGRKaraokeView.m "$SRC"/Redesigned/Lyrics/MeaningSheet.m "$SRC"/Redesigned/Lyrics/LyricsText.m "$SRC"/Shared/Lyrics/KaraokeTiming.m "$SRC"/Shared/Lyrics/Protobuf.m \
+ "$SRC"/Redesigned/Lyrics/SGRKaraokeView.m "$SRC"/Redesigned/Lyrics/SGRSingButton.m "$SRC"/Redesigned/Lyrics/MeaningSheet.m "$SRC"/Redesigned/Lyrics/LyricsText.m "$SRC"/Shared/Lyrics/KaraokeTiming.m "$SRC"/Shared/Lyrics/Protobuf.m \
-framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreImage -framework Foundation -framework Symbols -framework AVFoundation -framework CoreMedia \
-o "$OUT/PlayerHarness.app/PlayerHarness"
diff --git a/harness/player/main.m b/harness/player/main.m
index a6572949..9d178433 100644
--- a/harness/player/main.m
+++ b/harness/player/main.m
@@ -690,6 +690,13 @@ static UIView *motionView(void) {
NSLog(@"[harness] motion check %@: %@ -- %@", step, detail, ok ? @"ok" : @"WRONG");
}
+// The field covered by the clip, and its Fluid copies hidden for it.
+static BOOL fieldCovered(void) {
+ SGRArtworkField *field = SGRPlayerField();
+ CALayer *fluid = [field valueForKey:@"_fluidLayer"];
+ return field.covered && fluid && fluid.hidden;
+}
+
- (void)runMotionChecks {
// The clip comes in before the player has laid out, as for the track restored at launch.
after(3, ^{
@@ -712,6 +719,15 @@ static UIView *motionView(void) {
&& foot.contents && foot.contentsRect.size.height < 0.05 && CGRectGetMaxY(foot.contentsRect) > 0.999;
[self expect:footDown step:@"the foot"
detail:[NSString stringWithFormat:@"clip %@, foot %@ from rows %@", NSStringFromCGRect(clip.frame), NSStringFromCGRect(foot.frame), NSStringFromCGRect(foot.contentsRect)]];
+ // The poster under the video, so the clip has a picture before its first frame is decoded; and the
+ // Fluid field under it held still and, the clip being opaque, hidden.
+ CALayer *still = clip.superlayer;
+ [self expect:still.contents && CGRectEqualToRect(still.bounds, clip.frame) && still.mask && SGRPlayerField().motionHeld
+ && fieldCovered()
+ step:@"the poster and the held field"
+ detail:[NSString stringWithFormat:@"poster %@ at %@, video %@, fade %@, field %@, %@", still.contents ? @"in" : @"missing",
+ NSStringFromCGRect(still.frame), NSStringFromCGRect(clip.frame), still.mask ? @"on the poster" : @"missing",
+ SGRPlayerField().motionHeld ? @"held" : @"moving", fieldCovered() ? @"its Fluid copies hidden" : @"its Fluid copies drawn"]];
[self expect:seam.effect && !lyrics.effect step:@"the blur from the seam"
detail:[NSString stringWithFormat:@"seam blur %@, from %@ of the height, lyrics blur %@", seam.effect ? @"on" : @"off",
[[seam.maskView.layer.sublayers.firstObject valueForKey:@"locations"] componentsJoinedByString:@" to "], lyrics.effect ? @"on" : @"off"]];
@@ -745,25 +761,42 @@ static UIView *motionView(void) {
self->_units = units;
self->_background = background;
[self layOut];
- [self expect:SGRPlayerField() != old && motionView() != nil step:@"a field built again" detail:motionView() ? @"the clip moved onto it" : @"the clip left behind"];
+ [self expect:SGRPlayerField() != old && motionView() != nil && fieldCovered() step:@"a field built again"
+ detail:[NSString stringWithFormat:@"%@, its Fluid copies %@", motionView() ? @"the clip moved onto it" : @"the clip left behind",
+ fieldCovered() ? @"hidden" : @"drawn"]];
});
+ // Switched off, the clip and the cover cross over: the clip's fade out and the cover's fade in start
+ // together, over the same time.
after(12.5, ^{
SGPlayerMenuSetAnimatedArtwork(NO);
+ UIView *fading = motionView();
+ CALayer *picture = ((UIView *)[fading valueForKey:@"_picture"]).layer, *mask = self->_covers.layer.mask;
+ CAAnimation *out = [picture animationForKey:@"opacity"], *in = [mask animationForKey:@"opacity"];
+ [self expect:!SGRPlayerMotionShowing() && fading && out && in && fabs(out.duration - in.duration) < 0.01 && picture.opacity == 0
+ && mask.opacity == 1 && !SGRPlayerField().motionHeld && !fieldCovered()
+ step:@"switched off, crossing over"
+ detail:[NSString stringWithFormat:@"clip %@ to %.0f over %.2f s, cover to %.0f over %.2f s, field %@, its Fluid copies %@", fading ? @"fading" : @"gone",
+ picture.opacity, out.duration, mask.opacity, in.duration, SGRPlayerField().motionHeld ? @"held" : @"moving",
+ fieldCovered() ? @"hidden" : @"drawn"]];
+ });
+ after(13.2, ^{
[self expect:!SGRPlayerMotionShowing() && !motionView() && !self->_covers.layer.mask && !SGPlayerMenuAnimatedArtwork()
step:@"switched off from the menu" detail:[NSString stringWithFormat:@"clip %@, cover %@", motionView() ? @"still there" : @"gone",
self->_covers.layer.mask ? @"hidden" : @"back"]];
SGPlayerMenuSetAnimatedArtwork(YES);
});
- after(14, ^{
- [self expect:motionView() && self->_covers.layer.mask step:@"switched on again"
- detail:[NSString stringWithFormat:@"clip %@, cover %@", motionView() ? @"back" : @"missing", self->_covers.layer.mask ? @"hidden" : @"shown"]];
+ after(14.7, ^{
+ // Faded in on screen this time, so the field is covered once the fade has finished.
+ [self expect:motionView() && self->_covers.layer.mask && fieldCovered() step:@"switched on again"
+ detail:[NSString stringWithFormat:@"clip %@, cover %@, its Fluid copies %@", motionView() ? @"back" : @"missing",
+ self->_covers.layer.mask ? @"hidden" : @"shown", fieldCovered() ? @"hidden" : @"drawn"]];
// The player closed: the cover list cannot be found, and switching off must still bring its cover back.
[self->_host removeFromSuperview];
SGPlayerMenuSetAnimatedArtwork(NO);
[self expect:!self->_covers.layer.mask step:@"switched off with the player closed" detail:self->_covers.layer.mask ? @"cover still hidden" : @"cover back"];
[self->_list addSubview:self->_host];
});
- after(15, ^{
+ after(15.7, ^{
NSLog(@"[harness] motion checks: %lu of %lu right -- %@", (unsigned long)(self->_checks - self->_failures), (unsigned long)self->_checks,
self->_failures ? @"FAIL" : @"PASS");
});
diff --git a/harness/player/stubs.m b/harness/player/stubs.m
index 348d87e1..7df7f0fe 100644
--- a/harness/player/stubs.m
+++ b/harness/player/stubs.m
@@ -145,3 +145,21 @@ static double sg_speed = 1;
double SGPlayerSpeed(void) { return sg_speed; }
BOOL SGPlayerSpeedAllowed(void) { return YES; }
void SGSetPlayerSpeed(double speed) { sg_speed = speed; NSLog(@"[harness] speed %.2f", speed); }
+
+// Sing (the mic on the lyrics, SGRSingButton.m): never available, as on a phone that cannot run it.
+#import "Shared/Sing/Sing.h"
+NSString *const SGSingChangedNotification = @"harness.singChanged";
+SGSingState SGSingCurrentState(void) { return SGSingStateUnavailable; }
+NSString *SGSingStatusText(void) { return @"Unavailable"; }
+NSString *SGSingStatusDetail(void) { return nil; }
+NSString *SGSingMissing(void) { return @"the harness"; }
+BOOL SGSingOn(void) { return NO; }
+void SGSetSingOn(BOOL on) {}
+float SGSingLevel(void) { return 0; }
+void SGSetSingLevel(float level) {}
+NSString *SGSingLevelText(double level) { return @""; }
+double SGSingModelProgress(void) { return 0; }
+NSString *SGSingModelError(void) { return nil; }
+NSString *SGSingModelSizeText(void) { return @""; }
+void SGSingDownloadModel(void) {}
+void SGSingCancelModelDownload(void) {}
diff --git a/tweak/Sources/Redesigned/Kit/SGRField.h b/tweak/Sources/Redesigned/Kit/SGRField.h
index 67ec6e6a..1593bc41 100644
--- a/tweak/Sources/Redesigned/Kit/SGRField.h
+++ b/tweak/Sources/Redesigned/Kit/SGRField.h
@@ -29,8 +29,13 @@ extern NSNotificationName const SGRFieldColorDidChangeNotification;
// Fluid artwork instead (SGRFluid.h): the cover itself blurred and slowly turning over the whole of the
// bounds, under the same conditions for moving as `flows`. Setting one turns the other off.
@property (nonatomic) BOOL fluid;
-// Held still by the owner (the player while playback is paused).
+// Held still by the owner (the player while playback is paused, or while an Animated artwork clip covers
+// the field).
@property (nonatomic) BOOL motionHeld;
+// Covered by something opaque the owner lays over the whole of the bounds (the player's Animated artwork
+// clip): the Fluid copies are hidden rather than composited under it for nothing, and come back where they
+// were when it is NO again. Set it only once the cover is opaque, and back before it starts to fade.
+@property (nonatomic) BOOL covered;
// The backdrop's height in points from the top of the bounds; 0 is the window's height.
@property (nonatomic) CGFloat backdropHeight;
// SGRNeutralField until a colour arrives.
diff --git a/tweak/Sources/Redesigned/Kit/SGRField.m b/tweak/Sources/Redesigned/Kit/SGRField.m
index 40e4c546..5f5fcb13 100644
--- a/tweak/Sources/Redesigned/Kit/SGRField.m
+++ b/tweak/Sources/Redesigned/Kit/SGRField.m
@@ -121,7 +121,7 @@ static NSDictionary *noActions(void) {
[self.layer insertSublayer:_fluidLayer above:_solid];
}
// The fluid field is the whole picture, as the moving one is.
- _fluidLayer.hidden = !fluid;
+ _fluidLayer.hidden = !fluid || _covered;
_black.hidden = fluid || _flows;
if (fluid) _backdrop.hidden = YES;
if (fluid && _image) [_fluidLayer setArtwork:_image animated:NO];
@@ -154,6 +154,15 @@ static NSDictionary *noActions(void) {
[self updateMotion];
}
+- (void)setCovered:(BOOL)covered {
+ if (covered == _covered) return;
+ _covered = covered;
+ [CATransaction begin];
+ [CATransaction setDisableActions:YES];
+ _fluidLayer.hidden = !_fluid || covered;
+ [CATransaction commit];
+}
+
- (void)watch {
if (_watching || (!_flows && !_fluid)) return;
_watching = YES;
diff --git a/tweak/Sources/Redesigned/Player/PlayerField.x b/tweak/Sources/Redesigned/Player/PlayerField.x
index 9236c099..4f768374 100644
--- a/tweak/Sources/Redesigned/Player/PlayerField.x
+++ b/tweak/Sources/Redesigned/Player/PlayerField.x
@@ -66,8 +66,9 @@ static SGRArtworkField *fieldIn(UIView *plane) {
SGRPlayerBackgroundKind background = SGRPlayerBackground();
field.flows = background == SGRPlayerBackgroundColours;
field.fluid = background >= SGRPlayerBackgroundFluid;
- // A paused song holds the colours still, the way it rests the cover (PlayerArtwork.x).
- field.motionHeld = SGPlayerState().isPaused;
+ // A paused song holds the colours still, the way it rests the cover (PlayerArtwork.x), and so does an
+ // animated artwork's clip, which covers the field (PlayerMotion.x).
+ field.motionHeld = SGPlayerState().isPaused || SGRPlayerMotionShowing();
field.bleed = kBleed;
objc_setAssociatedObject(plane, &kFieldKey, field, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
sg_field = field;
@@ -154,7 +155,7 @@ static void publishCover(void) {
}
- (void)playerStateDidChange:(SPTPlayerState *)state {
- sg_field.motionHeld = state.isPaused;
+ sg_field.motionHeld = state.isPaused || SGRPlayerMotionShowing();
NSString *track = SGURIString(state.track.URI);
if (!track || [track isEqualToString:_track]) return;
_track = track;
diff --git a/tweak/Sources/Redesigned/Player/PlayerMotion.x b/tweak/Sources/Redesigned/Player/PlayerMotion.x
index 8382c7a4..88c3481c 100644
--- a/tweak/Sources/Redesigned/Player/PlayerMotion.x
+++ b/tweak/Sources/Redesigned/Player/PlayerMotion.x
@@ -13,7 +13,12 @@
// Spotify built again, gets it.
//
// The clip holds still when the moving field does (SGRField.m): out of a window, with the app not in front,
-// while the player opens or closes, under Reduce Motion and in Low Power Mode.
+// while the player opens or closes, under Reduce Motion and in Low Power Mode. While a clip is showing, the
+// Fluid field under it is held still too, and once the clip has faded in it is hidden (the field's covered):
+// the field's colour is what shows above the clip on the pull that dismisses.
+//
+// The clip and the cover cross over: the clip fades in from its first frame (the poster, under the video
+// until the video has decoded one) as the cover fades out, and fades out as the cover comes back.
#import <AVFoundation/AVFoundation.h>
#import "Core/SGCore.h"
#import "Redesigned/Kit/SGRKit.h"
@@ -35,7 +40,7 @@ static const CGFloat kBlurByControls = 0.6, kBlurRamp = 96;
@interface SGRPlayerMotionView : UIView
@property (nonatomic) CGFloat screenHeight;
- (void)playFile:(NSURL *)file poster:(UIImage *)poster;
-- (void)appear:(BOOL)animated;
+- (void)appear:(BOOL)animated then:(void (^)(void))done;
- (void)setBlurred:(BOOL)blurred animated:(BOOL)animated;
@end
@@ -43,6 +48,7 @@ static const CGFloat kBlurByControls = 0.6, kBlurRamp = 96;
AVQueuePlayer *_player;
AVPlayerLooper *_looper;
UIView *_picture; // the clip over its foot, faded in as one
+ CALayer *_still; // the poster, with the video drawn over it
AVPlayerLayer *_clip;
CAGradientLayer *_clipMask, *_seamMask;
CALayer *_foot;
@@ -65,13 +71,20 @@ static UIBlurEffect *blurEffect(void) {
_foot = [CALayer layer];
_foot.contentsGravity = kCAGravityResize;
[_picture.layer addSublayer:_foot];
+ // An AVPlayerLayer draws nothing until its first frame is decoded, so the poster, the clip's first
+ // frame and where the looper starts, is the contents of the layer the video draws in: there is a
+ // picture from the first frame, and the video covers it exactly.
+ _still = [CALayer layer];
+ _still.contentsGravity = kCAGravityResizeAspectFill;
+ _still.masksToBounds = YES;
_clip = [AVPlayerLayer layer];
_clip.videoGravity = AVLayerVideoGravityResizeAspectFill;
+ [_still addSublayer:_clip];
_clipMask = [CAGradientLayer layer];
_clipMask.colors = @[(id)UIColor.blackColor.CGColor, (id)UIColor.blackColor.CGColor, (id)UIColor.clearColor.CGColor];
_clipMask.locations = @[@0, @(kFootFrom), @1];
- _clip.mask = _clipMask;
- [_picture.layer addSublayer:_clip];
+ _still.mask = _clipMask;
+ [_picture.layer addSublayer:_still];
_seamBlur = [[UIVisualEffectView alloc] initWithEffect:nil];
_seamBlur.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
@@ -118,8 +131,9 @@ static UIBlurEffect *blurEffect(void) {
_lyricsBlur.frame = bounds;
[CATransaction begin];
[CATransaction setDisableActions:YES];
- _clip.frame = CGRectMake(0, 0, width, height);
- _clipMask.frame = _clip.bounds;
+ _still.frame = CGRectMake(0, 0, width, height);
+ _clip.frame = _still.bounds;
+ _clipMask.frame = _still.bounds;
_foot.frame = CGRectMake(0, seam, width, MAX(0, total - seam));
_seamMask.frame = bounds;
_seamMask.locations = @[@(MIN(1, blurFrom / total)), @(MIN(1, (blurFrom + kBlurRamp) / total))];
@@ -131,6 +145,7 @@ static UIBlurEffect *blurEffect(void) {
// The poster's last rows, stretched from the seam to the bottom: the clip goes on down in its own colour.
CGFloat rows = MAX(kFootRows, 1 / MAX(1, poster.size.height * poster.scale));
_foot.contents = (__bridge id)poster.CGImage;
+ _still.contents = (__bridge id)poster.CGImage;
_foot.contentsRect = CGRectMake(0, 1 - rows, 1, rows);
_player = [AVQueuePlayer new];
_player.muted = YES;
@@ -141,14 +156,30 @@ static UIBlurEffect *blurEffect(void) {
[self updateMotion];
}
-- (void)appear:(BOOL)animated {
+// `done` runs once the clip is opaque, unless something cut the fade in short.
+- (void)appear:(BOOL)animated then:(void (^)(void))done {
_picture.alpha = 0;
void (^apply)(void) = ^{
self->_picture.alpha = 1;
self->_seamBlur.effect = blurEffect();
};
- if (animated) SGRAnimate(SGRMotionFade, apply, nil);
- else apply();
+ if (animated) {
+ SGRAnimate(SGRMotionFade, apply, ^(BOOL finished) {
+ if (finished) done();
+ });
+ } else {
+ apply();
+ done();
+ }
+}
+
+// The clip and both blurs fade out; `done` runs once they have.
+- (void)disappear:(void (^)(void))done {
+ SGRAnimate(SGRMotionFade, ^{
+ self->_picture.alpha = 0;
+ self->_seamBlur.effect = nil;
+ self->_lyricsBlur.effect = nil;
+ }, ^(BOOL finished) { done(); });
}
- (void)setBlurred:(BOOL)blurred animated:(BOOL)animated {
@@ -179,9 +210,11 @@ static UIBlurEffect *blurEffect(void) {
static SGRPlayerMotionView *sg_motion;
static NSString *sg_track;
-// The list the empty mask went on, so it comes off even while the player is closed and the list cannot
-// be found.
-static __weak CALayer *sg_maskedCovers;
+// The clip is in and opaque, so the field under it is covered.
+static BOOL sg_covering;
+// The list the mask went on, so it comes off even while the player is closed and the list cannot be found,
+// and the mask, told from any other.
+static __weak CALayer *sg_maskedCovers, *sg_coverMask;
// The clip from the top of the field, as wide as it is, its foot down to the bottom of the field's bleed.
static void layOut(void) {
@@ -193,48 +226,114 @@ static void layOut(void) {
CGRect frame = CGRectMake(0, 0, size.width, MAX(size.height, screen) + field.bleed.bottom);
if (!CGRectEqualToRect(sg_motion.frame, frame)) sg_motion.frame = frame;
sg_motion.screenHeight = screen;
+ // A field Spotify built again, or the first one after a clip that came in before it, is covered too.
+ field.covered = sg_covering;
+}
+
+static void cover(BOOL covering) {
+ sg_covering = covering;
+ SGRPlayerField().covered = covering;
}
-// An empty mask rather than alpha: the covers still take the swipe that changes track, and the lyrics,
-// which fade the list by its alpha as they come and go, cannot bring the cover back.
-static void setCoverShown(BOOL shown) {
+// The Fluid field under a clip holds still, as it does for a paused song (PlayerField.x): the clip covers it.
+static void holdField(void) {
+ SGRPlayerField().motionHeld = SGPlayerState().isPaused || sg_motion != nil;
+}
+
+// The mask's opacity to `opacity`, from where it is drawn now, over the clip's own fade. The frame reaches a
+// few covers past the list's bounds either way, which move as the list scrolls: it counts only during a fade,
+// since at 0 the mask hides everything and at 1 it comes off.
+static void fadeCoverMask(CALayer *covers, CALayer *mask, float opacity, BOOL animated, void (^done)(void)) {
+ // A list out of a window, a closed player's, has nothing to fade.
+ id list = covers.delegate;
+ animated = animated && [list isKindOfClass:UIView.class] && ((UIView *)list).window;
+ CGRect bounds = covers.bounds;
+ float from = (mask.presentationLayer ?: mask).opacity;
+ [CATransaction begin];
+ [CATransaction setDisableActions:YES];
+ mask.frame = CGRectInset(bounds, -3 * bounds.size.width, -bounds.size.height);
+ mask.opacity = opacity;
+ if (animated) {
+ CABasicAnimation *fade = [CABasicAnimation animationWithKeyPath:@"opacity"];
+ fade.fromValue = @(from);
+ fade.toValue = @(opacity);
+ fade.duration = SGRCrossfade;
+ fade.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
+ [CATransaction setCompletionBlock:done];
+ [mask addAnimation:fade forKey:@"opacity"];
+ } else {
+ [mask removeAnimationForKey:@"opacity"];
+ }
+ [CATransaction commit];
+ if (!animated && done) done();
+}
+
+// A mask rather than alpha: the covers still take the swipe that changes track, and the lyrics, which fade
+// the list by its alpha as they come and go, cannot bring the cover back. Asked again for where it is going,
+// it does nothing, so the field's layout passes do not cut a fade short.
+static void setCoverShown(BOOL shown, BOOL animated) {
+ CALayer *covers = shown ? sg_maskedCovers : SGRPlayerCoverList().layer;
+ if (!covers) return;
+ CALayer *mask = covers.mask;
+ BOOL ours = mask && mask == sg_coverMask;
if (shown) {
- sg_maskedCovers.mask = nil;
sg_maskedCovers = nil;
+ if (!ours) return;
+ // A newer fade ends this one early, and the mask stays for it.
+ fadeCoverMask(covers, mask, 1, animated, ^{
+ if (covers.mask == mask && sg_maskedCovers != covers) covers.mask = nil;
+ });
return;
}
- CALayer *covers = SGRPlayerCoverList().layer;
- if (!covers || covers.mask) return;
- covers.mask = [CALayer layer];
+ if (covers == sg_maskedCovers || (mask && !ours)) return;
+ if (!mask) {
+ mask = [CALayer layer];
+ mask.backgroundColor = UIColor.blackColor.CGColor;
+ covers.mask = mask;
+ sg_coverMask = mask;
+ }
sg_maskedCovers = covers;
+ fadeCoverMask(covers, mask, 0, animated, nil);
}
void SGRPlayerMotionFieldLaidOut(void) {
layOut();
- setCoverShown(sg_motion == nil);
+ setCoverShown(sg_motion == nil, NO);
}
BOOL SGRPlayerMotionShowing(void) {
return sg_motion != nil;
}
-static void clear(void) {
- [sg_motion removeFromSuperview];
+// The clip fades out over the cover coming back where the player is on screen, and goes at once where not.
+static void clear(BOOL animated) {
+ SGRPlayerMotionView *old = sg_motion;
sg_motion = nil;
- setCoverShown(YES);
+ // Uncovered before the clip starts to fade, so the field is there under it.
+ cover(NO);
+ holdField();
+ animated = animated && old.window != nil;
+ setCoverShown(YES, animated);
+ if (animated) [old disappear:^{ [old removeFromSuperview]; }];
+ else [old removeFromSuperview];
}
static void show(NSString *track, NSURL *file) {
if (!file || ![track isEqualToString:sg_track]) return;
SGMotionPoster(file, ^(UIImage *poster) {
if (!poster || poster.size.width <= 0 || ![track isEqualToString:sg_track]) return;
- clear();
+ clear(YES);
sg_motion = [[SGRPlayerMotionView alloc] initWithFrame:CGRectZero];
[sg_motion playFile:file poster:poster];
layOut();
+ holdField();
[sg_motion setBlurred:SGRPlayerLyricsOpen() animated:NO];
- [sg_motion appear:sg_motion.window != nil];
- setCoverShown(NO);
+ BOOL animated = sg_motion.window != nil;
+ SGRPlayerMotionView *motion = sg_motion;
+ [motion appear:animated then:^{
+ if (sg_motion == motion) cover(YES);
+ }];
+ setCoverShown(NO, animated);
SGLog(@"redesign player: animated artwork %@, %.0fx%.0f", file.lastPathComponent, poster.size.width, poster.size.height);
});
}
@@ -251,7 +350,7 @@ void SGRPlayerMotionLyricsChanged(void) {
NSString *track = SGURIString(state.track.URI);
if (!track || [track isEqualToString:sg_track]) return;
sg_track = track;
- clear();
+ clear(YES);
// Read on every track, since the ⋯ menu switches it.
if (SGRPlayerBackground() != SGRPlayerBackgroundAnimated) return;
NSDictionary *metadata = [state.track.metadata isKindOfClass:NSDictionary.class] ? state.track.metadata : nil;
@@ -298,7 +397,7 @@ void SGPlayerMenuSetAnimatedArtwork(BOOL on) {
SGLog(@"redesign player: animated artwork switched %@ from the menu", on ? @"on" : @"off");
// The playing track is let go, and looked up again when switched on.
sg_track = nil;
- clear();
+ clear(YES);
[sg_watcher playerStateDidChange:SGPlayerState()];
}