mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2025-07-01 15:26:11 +00:00
Suppress home bar hiding when user is interacting
This commit is contained in:
parent
9f19f5da27
commit
18e2d67f6b
@ -15,11 +15,18 @@
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@protocol UserInteractionDelegate <NSObject>
|
||||||
|
|
||||||
|
- (void) userInteractionBegan;
|
||||||
|
- (void) userInteractionEnded;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@interface StreamView : OSView <UITextFieldDelegate>
|
@interface StreamView : OSView <UITextFieldDelegate>
|
||||||
|
|
||||||
@property (nonatomic, retain) IBOutlet UITextField* keyInputField;
|
@property (nonatomic, retain) IBOutlet UITextField* keyInputField;
|
||||||
|
|
||||||
- (void) setupStreamView:(ControllerSupport*)controllerSupport swipeDelegate:(id<EdgeDetectionDelegate>)swipeDelegate;
|
- (void) setupStreamView:(ControllerSupport*)controllerSupport swipeDelegate:(id<EdgeDetectionDelegate>)swipeDelegate interactionDelegate:(id<UserInteractionDelegate>)interactionDelegate;
|
||||||
- (void) showOnScreenControls;
|
- (void) showOnScreenControls;
|
||||||
- (void) setMouseDeltaFactors:(float)x y:(float)y;
|
- (void) setMouseDeltaFactors:(float)x y:(float)y;
|
||||||
- (OnScreenControlsLevel) getCurrentOscState;
|
- (OnScreenControlsLevel) getCurrentOscState;
|
||||||
|
@ -30,6 +30,10 @@
|
|||||||
UIGestureRecognizer* remoteLongPressRecognizer;
|
UIGestureRecognizer* remoteLongPressRecognizer;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
id<UserInteractionDelegate> interactionDelegate;
|
||||||
|
NSTimer* interactionTimer;
|
||||||
|
BOOL hasUserInteracted;
|
||||||
|
|
||||||
NSDictionary<NSString *, NSNumber *> *dictCodes;
|
NSDictionary<NSString *, NSNumber *> *dictCodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +50,8 @@
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setupStreamView:(ControllerSupport*)controllerSupport swipeDelegate:(id<EdgeDetectionDelegate>)swipeDelegate {
|
- (void) setupStreamView:(ControllerSupport*)controllerSupport swipeDelegate:(id<EdgeDetectionDelegate>)swipeDelegate interactionDelegate:(id<UserInteractionDelegate>)interactionDelegate {
|
||||||
|
self->interactionDelegate = interactionDelegate;
|
||||||
#if TARGET_OS_TV
|
#if TARGET_OS_TV
|
||||||
remotePressRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(remoteButtonPressed:)];
|
remotePressRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(remoteButtonPressed:)];
|
||||||
remotePressRecognizer.allowedPressTypes = @[@(UIPressTypeSelect)];
|
remotePressRecognizer.allowedPressTypes = @[@(UIPressTypeSelect)];
|
||||||
@ -70,6 +75,38 @@
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)startInteractionTimer {
|
||||||
|
// Restart user interaction tracking
|
||||||
|
hasUserInteracted = NO;
|
||||||
|
|
||||||
|
BOOL timerAlreadyRunning = interactionTimer != nil;
|
||||||
|
|
||||||
|
// Start/restart the timer
|
||||||
|
[interactionTimer invalidate];
|
||||||
|
interactionTimer = [NSTimer scheduledTimerWithTimeInterval:2.0
|
||||||
|
target:self
|
||||||
|
selector:@selector(interactionTimerExpired:)
|
||||||
|
userInfo:nil
|
||||||
|
repeats:NO];
|
||||||
|
|
||||||
|
// Notify the delegate if this was a new user interaction
|
||||||
|
if (!timerAlreadyRunning) {
|
||||||
|
[interactionDelegate userInteractionBegan];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)interactionTimerExpired:(NSTimer *)timer {
|
||||||
|
if (!hasUserInteracted) {
|
||||||
|
// User has finished touching the screen
|
||||||
|
interactionTimer = nil;
|
||||||
|
[interactionDelegate userInteractionEnded];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// User is still touching the screen. Restart the timer.
|
||||||
|
[self startInteractionTimer];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void) showOnScreenControls {
|
- (void) showOnScreenControls {
|
||||||
#if !TARGET_OS_TV
|
#if !TARGET_OS_TV
|
||||||
[onScreenControls show];
|
[onScreenControls show];
|
||||||
@ -93,6 +130,10 @@
|
|||||||
|
|
||||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||||
Log(LOG_D, @"Touch down");
|
Log(LOG_D, @"Touch down");
|
||||||
|
|
||||||
|
// Notify of user interaction and start expiration timer
|
||||||
|
[self startInteractionTimer];
|
||||||
|
|
||||||
if (![onScreenControls handleTouchDownEvent:touches]) {
|
if (![onScreenControls handleTouchDownEvent:touches]) {
|
||||||
UITouch *touch = [[event allTouches] anyObject];
|
UITouch *touch = [[event allTouches] anyObject];
|
||||||
originalLocation = touchLocation = [touch locationInView:self];
|
originalLocation = touchLocation = [touch locationInView:self];
|
||||||
@ -115,6 +156,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
|
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||||
|
hasUserInteracted = YES;
|
||||||
|
|
||||||
if (![onScreenControls handleTouchMovedEvent:touches]) {
|
if (![onScreenControls handleTouchMovedEvent:touches]) {
|
||||||
if ([[event allTouches] count] == 1) {
|
if ([[event allTouches] count] == 1) {
|
||||||
UITouch *touch = [[event allTouches] anyObject];
|
UITouch *touch = [[event allTouches] anyObject];
|
||||||
@ -163,6 +206,9 @@
|
|||||||
|
|
||||||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
|
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||||
Log(LOG_D, @"Touch up");
|
Log(LOG_D, @"Touch up");
|
||||||
|
|
||||||
|
hasUserInteracted = YES;
|
||||||
|
|
||||||
if (![onScreenControls handleTouchUpEvent:touches]) {
|
if (![onScreenControls handleTouchUpEvent:touches]) {
|
||||||
[dragTimer invalidate];
|
[dragTimer invalidate];
|
||||||
dragTimer = nil;
|
dragTimer = nil;
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
#if TARGET_OS_TV
|
#if TARGET_OS_TV
|
||||||
@import GameController;
|
@import GameController;
|
||||||
|
|
||||||
@interface StreamFrameViewController : GCEventViewController <ConnectionCallbacks, EdgeDetectionDelegate, GamepadPresenceDelegate>
|
@interface StreamFrameViewController : GCEventViewController <ConnectionCallbacks, EdgeDetectionDelegate, GamepadPresenceDelegate, UserInteractionDelegate>
|
||||||
#else
|
#else
|
||||||
@interface StreamFrameViewController : UIViewController <ConnectionCallbacks, EdgeDetectionDelegate, GamepadPresenceDelegate>
|
@interface StreamFrameViewController : UIViewController <ConnectionCallbacks, EdgeDetectionDelegate, GamepadPresenceDelegate, UserInteractionDelegate>
|
||||||
#endif
|
#endif
|
||||||
@property (strong, nonatomic) IBOutlet UILabel *stageLabel;
|
@property (strong, nonatomic) IBOutlet UILabel *stageLabel;
|
||||||
@property (strong, nonatomic) IBOutlet UILabel *tipLabel;
|
@property (strong, nonatomic) IBOutlet UILabel *tipLabel;
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
UITapGestureRecognizer *_menuDoubleTapGestureRecognizer;
|
UITapGestureRecognizer *_menuDoubleTapGestureRecognizer;
|
||||||
UITextView *_overlayView;
|
UITextView *_overlayView;
|
||||||
StreamView *_streamView;
|
StreamView *_streamView;
|
||||||
|
BOOL _userIsInteracting;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewDidAppear:(BOOL)animated
|
- (void)viewDidAppear:(BOOL)animated
|
||||||
@ -62,7 +63,7 @@
|
|||||||
_inactivityTimer = nil;
|
_inactivityTimer = nil;
|
||||||
|
|
||||||
_streamView = (StreamView*)self.view;
|
_streamView = (StreamView*)self.view;
|
||||||
[_streamView setupStreamView:_controllerSupport swipeDelegate:self];
|
[_streamView setupStreamView:_controllerSupport swipeDelegate:self interactionDelegate:self];
|
||||||
|
|
||||||
#if TARGET_OS_TV
|
#if TARGET_OS_TV
|
||||||
if (!_menuGestureRecognizer || !_menuDoubleTapGestureRecognizer) {
|
if (!_menuGestureRecognizer || !_menuDoubleTapGestureRecognizer) {
|
||||||
@ -343,6 +344,29 @@
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)userInteractionBegan {
|
||||||
|
// Disable hiding home bar when user is interacting.
|
||||||
|
// iOS will force it to be shown anyway, but it will
|
||||||
|
// also discard our edges deferring system gestures unless
|
||||||
|
// we willingly give up home bar hiding preference.
|
||||||
|
_userIsInteracting = YES;
|
||||||
|
#if !TARGET_OS_TV
|
||||||
|
if (@available(iOS 11.0, *)) {
|
||||||
|
[self setNeedsUpdateOfHomeIndicatorAutoHidden];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)userInteractionEnded {
|
||||||
|
// Enable home bar hiding again if conditions allow
|
||||||
|
_userIsInteracting = NO;
|
||||||
|
#if !TARGET_OS_TV
|
||||||
|
if (@available(iOS 11.0, *)) {
|
||||||
|
[self setNeedsUpdateOfHomeIndicatorAutoHidden];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#if !TARGET_OS_TV
|
#if !TARGET_OS_TV
|
||||||
// Require a confirmation when streaming to activate a system gesture
|
// Require a confirmation when streaming to activate a system gesture
|
||||||
- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures {
|
- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures {
|
||||||
@ -351,7 +375,8 @@
|
|||||||
|
|
||||||
- (BOOL)prefersHomeIndicatorAutoHidden {
|
- (BOOL)prefersHomeIndicatorAutoHidden {
|
||||||
if ([_controllerSupport getConnectedGamepadCount] > 0 &&
|
if ([_controllerSupport getConnectedGamepadCount] > 0 &&
|
||||||
[_streamView getCurrentOscState] == OnScreenControlsLevelOff) {
|
[_streamView getCurrentOscState] == OnScreenControlsLevelOff &&
|
||||||
|
_userIsInteracting == NO) {
|
||||||
// Autohide the home bar when a gamepad is connected
|
// Autohide the home bar when a gamepad is connected
|
||||||
// and the on-screen controls are disabled. We can't
|
// and the on-screen controls are disabled. We can't
|
||||||
// do this all the time because any touch on the display
|
// do this all the time because any touch on the display
|
||||||
|
Loading…
x
Reference in New Issue
Block a user