From 235e2966bce945af169851d58fcffde8fc38c709 Mon Sep 17 00:00:00 2001 From: Bryce Hackel <34104885+bhackel@users.noreply.github.com> Date: Sun, 25 Aug 2024 22:10:27 -0700 Subject: [PATCH] Fix bugs, only allow one seek gesture --- YTLitePlus.h | 13 +++++++++---- YTLitePlus.xm | 17 ++++++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/YTLitePlus.h b/YTLitePlus.h index 5bb9961..41c1562 100644 --- a/YTLitePlus.h +++ b/YTLitePlus.h @@ -46,6 +46,7 @@ #import "Tweaks/YouTubeHeader/YTMainAppControlsOverlayView.h" #import "Tweaks/YouTubeHeader/YTMultiSizeViewController.h" #import "Tweaks/YouTubeHeader/YTWatchLayerViewController.h" +#import "Tweaks/YouTubeHeader/YTInlinePlayerBarView.h" #define LOC(x) [tweakBundle localizedStringForKey:x value:nil table:nil] #define YT_BUNDLE_ID @"com.google.ios.youtube" @@ -163,15 +164,19 @@ typedef NS_ENUM(NSUInteger, GestureSection) { @property (nonatomic, assign, readwrite) float volumeValue; @end @interface YTPlayerBarController (YTLitePlus) -- (void)inlinePlayerBarContainerViewDidStartFineScrub:(YTInlinePlayerBarContainerView *)playerBar; -- (void)inlinePlayerBarContainerView:(YTInlinePlayerBarContainerView *)playerBar didFineScrubToTime:(CGFloat)time; -- (void)inlinePlayerBarContainerViewDidEndFineScrub:(YTInlinePlayerBarContainerView *)playerBar seekSource:(int)source; - (void)didScrub:(UIPanGestureRecognizer *)gestureRecognizer; -- (void)seekAnywhereDidScrubWithRecognizer:(UIPanGestureRecognizer *)recognizer; +- (void)startScrubbing; +- (void)didScrubToPoint:(CGPoint)point; +- (void)endScrubbingForSeekSource:(int)seekSource; @end @interface YTMainAppVideoPlayerOverlayViewController (YTLitePlus) @property (nonatomic, strong, readwrite) YTPlayerBarController *playerBarController; @end +@interface YTInlinePlayerBarContainerView (YTLitePlus) +@property UIPanGestureRecognizer *scrubGestureRecognizer; +- (CGFloat)scrubXForScrubRange:(CGFloat)scrubRange; +@end + // Hide Collapse Button - @arichornlover @interface YTMainAppControlsOverlayView (YTLitePlus) diff --git a/YTLitePlus.xm b/YTLitePlus.xm index 742b7bf..8cf80d6 100644 --- a/YTLitePlus.xm +++ b/YTLitePlus.xm @@ -714,7 +714,7 @@ BOOL isTabSelected = NO; // Get objects used to seek nicely in the video player static YTMainAppVideoPlayerOverlayViewController *mainVideoPlayerController = (YTMainAppVideoPlayerOverlayViewController *)self.childViewControllers.firstObject; static YTPlayerBarController *playerBarController = mainVideoPlayerController.playerBarController; - // static YTInlinePlayerBarContainerView *playerBar = playerBarController.playerBar; + static YTInlinePlayerBarContainerView *playerBar = playerBarController.playerBar; /***** Helper functions for adjusting player state *****/ // Helper function to adjust brightness @@ -742,14 +742,14 @@ BOOL isTabSelected = NO; // Get the location in view for the current video time CGFloat totalTime = self.currentVideoTotalMediaTime; CGFloat videoFraction = initialTime / totalTime; - CGFloat initialTimeXPosition = scrubXForScrubRange(videoFraction); + CGFloat initialTimeXPosition = [playerBar scrubXForScrubRange:videoFraction]; // Calculate the new seek X position CGFloat sensitivityFactor = 1; // Adjust this value to make seeking more/less sensitive CGFloat newSeekXPosition = initialTimeXPosition + translationX * sensitivityFactor; // Create a CGPoint using this new X position CGPoint newSeekPoint = CGPointMake(newSeekXPosition, 0); // Send this to a seek method in the player bar controller - [playerBarController didScrbToPoint:newSeekPoint]; + [playerBarController didScrubToPoint:newSeekPoint]; }; // Helper function to smooth out the X translation @@ -885,6 +885,8 @@ BOOL isTabSelected = NO; // If outside the deadzone, activate the pan gesture and store the initial values isValidHorizontalPan = YES; deadzoneStartingXTranslation = translation.x; + adjustedTranslationX = 0; + smoothedTranslationX = 0; // Run the setup for the selected gesture mode switch (gestureSection) { case GestureSectionTop: @@ -960,6 +962,15 @@ BOOL isTabSelected = NO; // allow the pan gesture to be recognized simultaneously with other gestures %new - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { + if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) { + // Do not allow this gesture to activate with the normal seek bar gesture + YTMainAppVideoPlayerOverlayViewController *mainVideoPlayerController = (YTMainAppVideoPlayerOverlayViewController *)self.childViewControllers.firstObject; + YTPlayerBarController *playerBarController = mainVideoPlayerController.playerBarController; + YTInlinePlayerBarContainerView *playerBar = playerBarController.playerBar; + if (otherGestureRecognizer == playerBar.scrubGestureRecognizer) { + return NO; + } + } return YES; } %end