Commit b4e72ef6 authored by Mike Pinkerton's avatar Mike Pinkerton Committed by Chromium LUCI CQ

[ios] Improve edge cases for NTP pointer support.

Remove the pointer interaction when the view goes away. Also check the
view is in a window before creating a pointer style.

Bug: 1162914
Change-Id: I2835f453391b291afdce3baabfedf40a3fee10fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2627709Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Commit-Queue: Mike Pinkerton <pinkerton@chromium.org>
Auto-Submit: Mike Pinkerton <pinkerton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843653}
parent 9bb1a28a
......@@ -23,6 +23,13 @@ const CGFloat kPreferredMaxWidth = 73;
} // namespace
@interface NTPTileView ()
// Hold onto the created interaction for pointer support so it can be removed
// when the view goes away.
@property(nonatomic, strong)
UIPointerInteraction* pointerInteraction API_AVAILABLE(ios(13.4));
@end
@implementation NTPTileView
- (instancetype)initWithFrame:(CGRect)frame {
......@@ -71,14 +78,24 @@ const CGFloat kPreferredMaxWidth = 73;
#ifdef __IPHONE_13_4
if (@available(iOS 13.4, *)) {
[self addInteraction:[[UIPointerInteraction alloc]
initWithDelegate:self]];
_pointerInteraction =
[[UIPointerInteraction alloc] initWithDelegate:self];
[self addInteraction:self.pointerInteraction];
}
#endif
}
return self;
}
- (void)dealloc {
#ifdef __IPHONE_13_4
if (@available(iOS 13.4, *)) {
[self removeInteraction:self.pointerInteraction];
self.pointerInteraction = nil;
}
#endif
}
// Returns the font size for the location label.
- (UIFont*)titleLabelFont {
return PreferredFontForTextStyleWithMaxCategory(
......@@ -111,6 +128,11 @@ const CGFloat kPreferredMaxWidth = 73;
- (UIPointerStyle*)pointerInteraction:(UIPointerInteraction*)interaction
styleForRegion:(UIPointerRegion*)region
API_AVAILABLE(ios(13.4)) {
// The preview APIs require the view to be in a window. Ensure they are before
// proceeding.
if (!self.window)
return nil;
UITargetedPreview* preview =
[[UITargetedPreview alloc] initWithView:_imageContainerView];
UIPointerHighlightEffect* effect =
......
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