mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-15 21:45:19 +00:00
Fix side button capture in chat camera
This commit is contained in:
parent
d94a9e9bb7
commit
f21d2ccd84
@ -1,11 +1,12 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface PGCameraVolumeButtonHandler : NSObject
|
||||
|
||||
@property (nonatomic, assign) bool enabled;
|
||||
@property (nonatomic, assign) bool ignoring;
|
||||
|
||||
- (instancetype)initWithUpButtonPressedBlock:(void (^)(void))upButtonPressedBlock upButtonReleasedBlock:(void (^)(void))upButtonReleasedBlock downButtonPressedBlock:(void (^)(void))downButtonPressedBlock downButtonReleasedBlock:(void (^)(void))downButtonReleasedBlock;
|
||||
- (instancetype)initWithIsCameraSpecific:(bool)isCameraSpecific eventView:(UIView *)eventView upButtonPressedBlock:(void (^)(void))upButtonPressedBlock upButtonReleasedBlock:(void (^)(void))upButtonReleasedBlock downButtonPressedBlock:(void (^)(void))downButtonPressedBlock downButtonReleasedBlock:(void (^)(void))downButtonReleasedBlock;
|
||||
|
||||
- (void)enableIn:(NSTimeInterval)timeInterval;
|
||||
- (void)disableFor:(NSTimeInterval)timeInterval;
|
||||
|
@ -5,6 +5,8 @@
|
||||
#import "TGStringUtils.h"
|
||||
#import "Freedom.h"
|
||||
|
||||
#import <AVKit/AVKit.h>
|
||||
|
||||
static NSString *encodeText(NSString *string, int key) {
|
||||
NSMutableString *result = [[NSMutableString alloc] init];
|
||||
|
||||
@ -19,8 +21,11 @@ static NSString *encodeText(NSString *string, int key) {
|
||||
|
||||
@interface PGCameraVolumeButtonHandler () {
|
||||
id _dataSource;
|
||||
id<UIInteraction> _eventInteraction;
|
||||
}
|
||||
|
||||
@property (nonatomic, weak) UIView *eventView;
|
||||
|
||||
@property (nonatomic, copy) void(^upButtonPressedBlock)(void);
|
||||
@property (nonatomic, copy) void(^upButtonReleasedBlock)(void);
|
||||
@property (nonatomic, copy) void(^downButtonPressedBlock)(void);
|
||||
@ -30,11 +35,13 @@ static NSString *encodeText(NSString *string, int key) {
|
||||
|
||||
@implementation PGCameraVolumeButtonHandler
|
||||
|
||||
- (instancetype)initWithUpButtonPressedBlock:(void (^)(void))upButtonPressedBlock upButtonReleasedBlock:(void (^)(void))upButtonReleasedBlock downButtonPressedBlock:(void (^)(void))downButtonPressedBlock downButtonReleasedBlock:(void (^)(void))downButtonReleasedBlock
|
||||
- (instancetype)initWithIsCameraSpecific:(bool)isCameraSpecific eventView:(UIView *)eventView upButtonPressedBlock:(void (^)(void))upButtonPressedBlock upButtonReleasedBlock:(void (^)(void))upButtonReleasedBlock downButtonPressedBlock:(void (^)(void))downButtonPressedBlock downButtonReleasedBlock:(void (^)(void))downButtonReleasedBlock
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil)
|
||||
{
|
||||
self.eventView = eventView;
|
||||
|
||||
self.upButtonPressedBlock = upButtonPressedBlock;
|
||||
self.upButtonReleasedBlock = upButtonReleasedBlock;
|
||||
self.downButtonPressedBlock = downButtonPressedBlock;
|
||||
@ -45,9 +52,47 @@ static NSString *encodeText(NSString *string, int key) {
|
||||
self.enabled = true;
|
||||
|
||||
if (@available(iOS 17.2, *)) {
|
||||
NSString *className = encodeText(@"NQWpmvnfDpouspmmfsTztufnEbubTpvsdf", -1);
|
||||
Class c = NSClassFromString(className);
|
||||
_dataSource = [[c alloc] init];
|
||||
if (isCameraSpecific) {
|
||||
__weak PGCameraVolumeButtonHandler *weakSelf = self;
|
||||
AVCaptureEventInteraction *interaction = [[AVCaptureEventInteraction alloc] initWithPrimaryEventHandler:^(AVCaptureEvent * _Nonnull event) {
|
||||
__strong PGCameraVolumeButtonHandler *strongSelf = weakSelf;
|
||||
switch (event.phase) {
|
||||
case AVCaptureEventPhaseBegan:
|
||||
strongSelf.downButtonPressedBlock();
|
||||
break;
|
||||
case AVCaptureEventPhaseEnded:
|
||||
strongSelf.downButtonReleasedBlock();
|
||||
break;
|
||||
case AVCaptureEventPhaseCancelled:
|
||||
strongSelf.downButtonReleasedBlock();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} secondaryEventHandler:^(AVCaptureEvent * _Nonnull event) {
|
||||
__strong PGCameraVolumeButtonHandler *strongSelf = weakSelf;
|
||||
switch (event.phase) {
|
||||
case AVCaptureEventPhaseBegan:
|
||||
strongSelf.upButtonPressedBlock();
|
||||
break;
|
||||
case AVCaptureEventPhaseEnded:
|
||||
strongSelf.upButtonReleasedBlock();
|
||||
break;
|
||||
case AVCaptureEventPhaseCancelled:
|
||||
strongSelf.upButtonReleasedBlock();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}];
|
||||
interaction.enabled = true;
|
||||
[eventView addInteraction:interaction];
|
||||
_eventInteraction = interaction;
|
||||
} else {
|
||||
NSString *className = encodeText(@"NQWpmvnfDpouspmmfsTztufnEbubTpvsdf", -1);
|
||||
Class c = NSClassFromString(className);
|
||||
_dataSource = [[c alloc] init];
|
||||
}
|
||||
}
|
||||
}
|
||||
return self;
|
||||
@ -55,6 +100,8 @@ static NSString *encodeText(NSString *string, int key) {
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[self.eventView removeInteraction:_eventInteraction];
|
||||
|
||||
self.enabled = false;
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
@ -510,7 +510,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
|
||||
strongSelf->_interfaceView.shutterReleased(true);
|
||||
};
|
||||
|
||||
_buttonHandler = [[PGCameraVolumeButtonHandler alloc] initWithUpButtonPressedBlock:buttonPressed upButtonReleasedBlock:buttonReleased downButtonPressedBlock:buttonPressed downButtonReleasedBlock:buttonReleased];
|
||||
_buttonHandler = [[PGCameraVolumeButtonHandler alloc] initWithIsCameraSpecific:true eventView:self.view upButtonPressedBlock:buttonPressed upButtonReleasedBlock:buttonReleased downButtonPressedBlock:buttonPressed downButtonReleasedBlock:buttonReleased];
|
||||
|
||||
[self _configureCamera];
|
||||
}
|
||||
|
@ -441,7 +441,7 @@ typedef enum
|
||||
[self.view addGestureRecognizer:_pinchGestureRecognizer];
|
||||
|
||||
void (^voidBlock)(void) = ^{};
|
||||
_buttonHandler = [[PGCameraVolumeButtonHandler alloc] initWithUpButtonPressedBlock:voidBlock upButtonReleasedBlock:voidBlock downButtonPressedBlock:voidBlock downButtonReleasedBlock:voidBlock];
|
||||
_buttonHandler = [[PGCameraVolumeButtonHandler alloc] initWithIsCameraSpecific:true eventView:self.view upButtonPressedBlock:voidBlock upButtonReleasedBlock:voidBlock downButtonPressedBlock:voidBlock downButtonReleasedBlock:voidBlock];
|
||||
|
||||
[self configureCamera];
|
||||
}
|
||||
|
@ -16,15 +16,19 @@ private final class LegacyHandlerImpl: VolumeButtonHandlerImpl {
|
||||
context: SharedAccountContext,
|
||||
performAction: @escaping (VolumeButtonsListener.Action) -> Void
|
||||
) {
|
||||
self.handler = PGCameraVolumeButtonHandler(upButtonPressedBlock: {
|
||||
performAction(.up)
|
||||
}, upButtonReleasedBlock: {
|
||||
performAction(.upRelease)
|
||||
}, downButtonPressedBlock: {
|
||||
performAction(.down)
|
||||
}, downButtonReleasedBlock: {
|
||||
performAction(.downRelease)
|
||||
})
|
||||
self.handler = PGCameraVolumeButtonHandler(
|
||||
isCameraSpecific: false,
|
||||
eventView: context.mainWindow?.viewController?.view,
|
||||
upButtonPressedBlock: {
|
||||
performAction(.up)
|
||||
}, upButtonReleasedBlock: {
|
||||
performAction(.upRelease)
|
||||
}, downButtonPressedBlock: {
|
||||
performAction(.down)
|
||||
}, downButtonReleasedBlock: {
|
||||
performAction(.downRelease)
|
||||
}
|
||||
)
|
||||
self.handler.enabled = true
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user