Allow other gestures

This commit is contained in:
Bryce Hackel
2024-08-07 13:24:51 -07:00
parent d4679b8414
commit 91290efdfe

View File

@@ -542,9 +542,10 @@ BOOL isTabSelected = NO;
} }
%end %end
@interface YTPlayerViewController (YTLitePlus) @interface YTPlayerViewController (YTLitePlus) <UIGestureRecognizerDelegate>
// the long press gesture that will be created and added to the player view // the long press gesture that will be created and added to the player view
@property (nonatomic, retain) UIPanGestureRecognizer *YTLitePlusPanGesture; @property (nonatomic, retain) UIPanGestureRecognizer *YTLitePlusPanGesture;
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
@end @end
@interface YTWatchFullscreenViewController : YTMultiSizeViewController @interface YTWatchFullscreenViewController : YTMultiSizeViewController
@end @end
@@ -562,78 +563,80 @@ BOOL isTabSelected = NO;
if (!playerViewController.YTLitePlusPanGesture) { if (!playerViewController.YTLitePlusPanGesture) {
playerViewController.YTLitePlusPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:playerViewController playerViewController.YTLitePlusPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:playerViewController
action:@selector(YTLitePlusHandlePanGesture:)]; action:@selector(YTLitePlusHandlePanGesture:)];
playerViewController.YTLitePlusPanGesture.delegate = playerViewController;
[playerViewController.playerView addGestureRecognizer:playerViewController.YTLitePlusPanGesture]; [playerViewController.playerView addGestureRecognizer:playerViewController.YTLitePlusPanGesture];
} }
} }
%orig; %orig;
} }
%end %end
%hook YTPlayerViewController %hook YTPlayerViewController
// the pan gesture that will be created and added to the player view // the pan gesture that will be created and added to the player view
%property (nonatomic, retain) UIPanGestureRecognizer *YTLitePlusPanGesture; %property (nonatomic, retain) UIPanGestureRecognizer *YTLitePlusPanGesture;
%new %new
- (void)YTLitePlusHandlePanGesture:(UIPanGestureRecognizer *)panGestureRecognizer { - (void)YTLitePlusHandlePanGesture:(UIPanGestureRecognizer *)panGestureRecognizer {
static float initialVolume; static float initialVolume;
static BOOL isHorizontalPan = NO;
if (panGestureRecognizer.state == UIGestureRecognizerStateBegan) { if (panGestureRecognizer.state == UIGestureRecognizerStateBegan) {
// Store the initial volume at the beginning of the pan gesture // Store the initial volume at the beginning of the pan gesture
initialVolume = [[AVAudioSession sharedInstance] outputVolume]; initialVolume = [[AVAudioSession sharedInstance] outputVolume];
// Reset the horizontal pan flag
isHorizontalPan = NO;
} }
if (panGestureRecognizer.state == UIGestureRecognizerStateChanged) { if (panGestureRecognizer.state == UIGestureRecognizerStateChanged) {
// Calculate the horizontal translation // Calculate the translation
CGPoint translation = [panGestureRecognizer translationInView:self.view]; CGPoint translation = [panGestureRecognizer translationInView:self.view];
float newVolume = initialVolume + (translation.x / 1000.0); // Adjust the divisor to control the sensitivity
// Clamp the volume between 0 and 1 // Determine if the gesture is predominantly horizontal
newVolume = fmaxf(fminf(newVolume, 1.0), 0.0); if (!isHorizontalPan) {
if (fabs(translation.x) > fabs(translation.y)) {
/* isHorizontalPan = YES;
// Navigate to existing volume slider view } else {
YTWatchViewController *watchViewController = (YTWatchViewController *)[self valueForKey:@"_parentViewController"]; // If vertical movement is greater, cancel the gesture recognizer
YTWatchLayerViewController *watchLayerViewController = (YTWatchLayerViewController *)[watchViewController valueForKey:@"_watchLayerViewController"]; panGestureRecognizer.state = UIGestureRecognizerStateCancelled;
YTWatchFullscreenViewController *watchFullscreenViewController = (YTWatchFullscreenViewController *)[watchLayerViewController valueForKey:@"_fullscreenViewController"]; return;
MPVolumeView *volumeView = (MPVolumeView *)[watchFullscreenViewController valueForKey:@"_hiddenVolumeView"];
// https://stackoverflow.com/questions/50737943/how-to-change-volume-programmatically-on-ios-11-4/50740074#50740074
UISlider *volumeViewSlider = nil;
for (UIView *view in volumeView.subviews) {
if ([view isKindOfClass:[UISlider class]]) {
volumeViewSlider = (UISlider *)view;
break;
}
}
// Get the controller from this view
MPVolumeController *volumeController = [volumeViewSlider valueForKey:@"volumeController"];
// Set the volume
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
volumeController.volumeValue = newVolume;
});
*/
MPVolumeView *volumeView = [[MPVolumeView alloc] init];
UISlider *volumeViewSlider = nil;
for (UIView *view in volumeView.subviews) {
if ([view isKindOfClass:[UISlider class]]) {
volumeViewSlider = (UISlider *)view;
break;
} }
} }
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ if (isHorizontalPan) {
volumeViewSlider.value = newVolume; float newVolume = initialVolume + (translation.x / 1000.0); // Adjust the divisor to control the sensitivity
});
// Clamp the volume between 0 and 1
newVolume = fmaxf(fminf(newVolume, 1.0), 0.0);
// https://stackoverflow.com/questions/50737943/how-to-change-volume-programmatically-on-ios-11-4/50740074#50740074
MPVolumeView *volumeView = [[MPVolumeView alloc] init];
UISlider *volumeViewSlider = nil;
for (UIView *view in volumeView.subviews) {
if ([view isKindOfClass:[UISlider class]]) {
volumeViewSlider = (UISlider *)view;
break;
}
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
volumeViewSlider.value = newVolume;
});
}
} }
if (panGestureRecognizer.state == UIGestureRecognizerStateEnded) { if (panGestureRecognizer.state == UIGestureRecognizerStateEnded) {
// Haptic feedback if (isHorizontalPan) {
UINotificationFeedbackGenerator *feedbackGenerator = [[UINotificationFeedbackGenerator alloc] init]; // Haptic feedback
[feedbackGenerator notificationOccurred:UINotificationFeedbackTypeSuccess]; UINotificationFeedbackGenerator *feedbackGenerator = [[UINotificationFeedbackGenerator alloc] init];
feedbackGenerator = nil; [feedbackGenerator notificationOccurred:UINotificationFeedbackTypeSuccess];
feedbackGenerator = nil;
}
} }
} }
// allow the pan gesture to be recognized simultaneously with other gestures
%new
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
%end %end
%end %end