Commit 2b853444 authored by Yuwei Huang's avatar Yuwei Huang Committed by Commit Bot

[CRD iOS] Blur remote host content when going to background

This CL adds a blur view to the HostView when the app becomes inactive
(transitioning to background, etc.) and removes it when the app becomes
active again.

Screenshot: https://drive.google.com/open?id=1UrWMUc-j0rRS-DQJ5zLLZ4_dTGgLohVr

Bug: 791112
Change-Id: Ic66c57c939bb607ad7b740cb8112bd449cd20d45
Reviewed-on: https://chromium-review.googlesource.com/807402
Commit-Queue: Yuwei Huang <yuweih@chromium.org>
Reviewed-by: default avatarJamie Walch <jamiewalch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521567}
parent 1ba911a4
...@@ -47,6 +47,9 @@ static const CGFloat kMoveFABAnimationTime = 0.3; ...@@ -47,6 +47,9 @@ static const CGFloat kMoveFABAnimationTime = 0.3;
BOOL _surfaceCreated; BOOL _surfaceCreated;
HostSettings* _settings; HostSettings* _settings;
// Used to blur the content when the app enters background.
UIView* _blurView;
// Only change this by calling setFabIsRight:. // Only change this by calling setFabIsRight:.
BOOL _fabIsRight; BOOL _fabIsRight;
NSArray<NSLayoutConstraint*>* _fabLeftConstraints; NSArray<NSLayoutConstraint*>* _fabLeftConstraints;
...@@ -214,6 +217,7 @@ static const CGFloat kMoveFABAnimationTime = 0.3; ...@@ -214,6 +217,7 @@ static const CGFloat kMoveFABAnimationTime = 0.3;
[[ClientGestures alloc] initWithView:_hostView client:_client]; [[ClientGestures alloc] initWithView:_hostView client:_client];
_clientGestures.delegate = self; _clientGestures.delegate = self;
} }
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
addObserver:self addObserver:self
selector:@selector(keyboardWillShow:) selector:@selector(keyboardWillShow:)
...@@ -226,6 +230,25 @@ static const CGFloat kMoveFABAnimationTime = 0.3; ...@@ -226,6 +230,25 @@ static const CGFloat kMoveFABAnimationTime = 0.3;
name:UIKeyboardWillHideNotification name:UIKeyboardWillHideNotification
object:nil]; object:nil];
[NSNotificationCenter.defaultCenter
addObserver:self
selector:@selector(applicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
[NSNotificationCenter.defaultCenter
addObserver:self
selector:@selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification
object:nil];
// If the host view is presented when the app is inactive, synthesize an
// initial UIApplicationWillResignActiveNotification event.
if (UIApplication.sharedApplication.applicationState !=
UIApplicationStateActive) {
[self applicationWillResignActive:UIApplication.sharedApplication];
}
_surfaceSizeAnimationLink = _surfaceSizeAnimationLink =
[CADisplayLink displayLinkWithTarget:self [CADisplayLink displayLinkWithTarget:self
selector:@selector(animateHostSurfaceSize:)]; selector:@selector(animateHostSurfaceSize:)];
...@@ -602,4 +625,31 @@ static const CGFloat kMoveFABAnimationTime = 0.3; ...@@ -602,4 +625,31 @@ static const CGFloat kMoveFABAnimationTime = 0.3;
} }
} }
- (void)applicationDidBecomeActive:(UIApplication*)application {
if (!_blurView) {
LOG(DFATAL) << "Blur view does not exist.";
return;
}
[_blurView removeFromSuperview];
_blurView = nil;
}
- (void)applicationWillResignActive:(UIApplication*)application {
if (_blurView) {
LOG(DFATAL) << "Blur view already exists.";
return;
}
UIBlurEffect* effect =
[UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
_blurView = [[UIVisualEffectView alloc] initWithEffect:effect];
_blurView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view insertSubview:_blurView aboveSubview:_hostView];
[NSLayoutConstraint activateConstraints:@[
[_blurView.leadingAnchor constraintEqualToAnchor:_hostView.leadingAnchor],
[_blurView.trailingAnchor constraintEqualToAnchor:_hostView.trailingAnchor],
[_blurView.topAnchor constraintEqualToAnchor:_hostView.topAnchor],
[_blurView.bottomAnchor constraintEqualToAnchor:_hostView.bottomAnchor],
]];
}
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment