Fix bugs, only allow one seek gesture

This commit is contained in:
Bryce Hackel
2024-08-25 22:10:27 -07:00
parent 6aa1f62140
commit 235e2966bc
2 changed files with 23 additions and 7 deletions

View File

@@ -46,6 +46,7 @@
#import "Tweaks/YouTubeHeader/YTMainAppControlsOverlayView.h" #import "Tweaks/YouTubeHeader/YTMainAppControlsOverlayView.h"
#import "Tweaks/YouTubeHeader/YTMultiSizeViewController.h" #import "Tweaks/YouTubeHeader/YTMultiSizeViewController.h"
#import "Tweaks/YouTubeHeader/YTWatchLayerViewController.h" #import "Tweaks/YouTubeHeader/YTWatchLayerViewController.h"
#import "Tweaks/YouTubeHeader/YTInlinePlayerBarView.h"
#define LOC(x) [tweakBundle localizedStringForKey:x value:nil table:nil] #define LOC(x) [tweakBundle localizedStringForKey:x value:nil table:nil]
#define YT_BUNDLE_ID @"com.google.ios.youtube" #define YT_BUNDLE_ID @"com.google.ios.youtube"
@@ -163,15 +164,19 @@ typedef NS_ENUM(NSUInteger, GestureSection) {
@property (nonatomic, assign, readwrite) float volumeValue; @property (nonatomic, assign, readwrite) float volumeValue;
@end @end
@interface YTPlayerBarController (YTLitePlus) @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)didScrub:(UIPanGestureRecognizer *)gestureRecognizer;
- (void)seekAnywhereDidScrubWithRecognizer:(UIPanGestureRecognizer *)recognizer; - (void)startScrubbing;
- (void)didScrubToPoint:(CGPoint)point;
- (void)endScrubbingForSeekSource:(int)seekSource;
@end @end
@interface YTMainAppVideoPlayerOverlayViewController (YTLitePlus) @interface YTMainAppVideoPlayerOverlayViewController (YTLitePlus)
@property (nonatomic, strong, readwrite) YTPlayerBarController *playerBarController; @property (nonatomic, strong, readwrite) YTPlayerBarController *playerBarController;
@end @end
@interface YTInlinePlayerBarContainerView (YTLitePlus)
@property UIPanGestureRecognizer *scrubGestureRecognizer;
- (CGFloat)scrubXForScrubRange:(CGFloat)scrubRange;
@end
// Hide Collapse Button - @arichornlover // Hide Collapse Button - @arichornlover
@interface YTMainAppControlsOverlayView (YTLitePlus) @interface YTMainAppControlsOverlayView (YTLitePlus)

View File

@@ -714,7 +714,7 @@ BOOL isTabSelected = NO;
// Get objects used to seek nicely in the video player // Get objects used to seek nicely in the video player
static YTMainAppVideoPlayerOverlayViewController *mainVideoPlayerController = (YTMainAppVideoPlayerOverlayViewController *)self.childViewControllers.firstObject; static YTMainAppVideoPlayerOverlayViewController *mainVideoPlayerController = (YTMainAppVideoPlayerOverlayViewController *)self.childViewControllers.firstObject;
static YTPlayerBarController *playerBarController = mainVideoPlayerController.playerBarController; static YTPlayerBarController *playerBarController = mainVideoPlayerController.playerBarController;
// static YTInlinePlayerBarContainerView *playerBar = playerBarController.playerBar; static YTInlinePlayerBarContainerView *playerBar = playerBarController.playerBar;
/***** Helper functions for adjusting player state *****/ /***** Helper functions for adjusting player state *****/
// Helper function to adjust brightness // Helper function to adjust brightness
@@ -742,14 +742,14 @@ BOOL isTabSelected = NO;
// Get the location in view for the current video time // Get the location in view for the current video time
CGFloat totalTime = self.currentVideoTotalMediaTime; CGFloat totalTime = self.currentVideoTotalMediaTime;
CGFloat videoFraction = initialTime / totalTime; CGFloat videoFraction = initialTime / totalTime;
CGFloat initialTimeXPosition = scrubXForScrubRange(videoFraction); CGFloat initialTimeXPosition = [playerBar scrubXForScrubRange:videoFraction];
// Calculate the new seek X position // Calculate the new seek X position
CGFloat sensitivityFactor = 1; // Adjust this value to make seeking more/less sensitive CGFloat sensitivityFactor = 1; // Adjust this value to make seeking more/less sensitive
CGFloat newSeekXPosition = initialTimeXPosition + translationX * sensitivityFactor; CGFloat newSeekXPosition = initialTimeXPosition + translationX * sensitivityFactor;
// Create a CGPoint using this new X position // Create a CGPoint using this new X position
CGPoint newSeekPoint = CGPointMake(newSeekXPosition, 0); CGPoint newSeekPoint = CGPointMake(newSeekXPosition, 0);
// Send this to a seek method in the player bar controller // 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 // 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 // If outside the deadzone, activate the pan gesture and store the initial values
isValidHorizontalPan = YES; isValidHorizontalPan = YES;
deadzoneStartingXTranslation = translation.x; deadzoneStartingXTranslation = translation.x;
adjustedTranslationX = 0;
smoothedTranslationX = 0;
// Run the setup for the selected gesture mode // Run the setup for the selected gesture mode
switch (gestureSection) { switch (gestureSection) {
case GestureSectionTop: case GestureSectionTop:
@@ -960,6 +962,15 @@ BOOL isTabSelected = NO;
// allow the pan gesture to be recognized simultaneously with other gestures // allow the pan gesture to be recognized simultaneously with other gestures
%new %new
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { - (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; return YES;
} }
%end %end