Commit 895e2c4c authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Truncate OverscrollActionView labels to be half the view's width.

This can be useful for localized translations of these labels, which
may need to span multiple lines.

Bug: 805100
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I4a4a8b98cb8b7f56f5b7b19dbe8478bf50f4fbf2
Reviewed-on: https://chromium-review.googlesource.com/1018168
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#552229}
parent d016d884
...@@ -89,7 +89,9 @@ const CFTimeInterval kMinimumPullDurationToTransitionToReadyInSeconds = 0.25; ...@@ -89,7 +89,9 @@ const CFTimeInterval kMinimumPullDurationToTransitionToReadyInSeconds = 0.25;
const CGFloat kDirectTouchFrameExpansion = 20; const CGFloat kDirectTouchFrameExpansion = 20;
// The vertical padding between the bottom of the action image view and its // The vertical padding between the bottom of the action image view and its
// corresponding label. // corresponding label.
const CGFloat kActionLabelVerticalPadding = 35.0; const CGFloat kActionLabelVerticalPadding = 25.0;
// The minimum distance between the action labels and the side of the screen.
const CGFloat kActionLabelSidePadding = 15.0;
// The value to use as the R, B, and B components for the action label text and // The value to use as the R, B, and B components for the action label text and
// selection layer animation. // selection layer animation.
const CGFloat kSelectionColor = 0.4; const CGFloat kSelectionColor = 0.4;
...@@ -279,6 +281,7 @@ enum class OverscrollViewState { ...@@ -279,6 +281,7 @@ enum class OverscrollViewState {
_deformationBehaviorEnabled = YES; _deformationBehaviorEnabled = YES;
self.autoresizingMask = self.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.clipsToBounds = YES;
_selectionCircleLayer = [self newSelectionCircleLayer]; _selectionCircleLayer = [self newSelectionCircleLayer];
_selectionCircleMaskLayer = [self newSelectionCircleLayer]; _selectionCircleMaskLayer = [self newSelectionCircleLayer];
_selectionCircleMaskLayer.contentsGravity = kCAGravityCenter; _selectionCircleMaskLayer.contentsGravity = kCAGravityCenter;
...@@ -318,6 +321,9 @@ enum class OverscrollViewState { ...@@ -318,6 +321,9 @@ enum class OverscrollViewState {
if (IsUIRefreshPhase1Enabled()) { if (IsUIRefreshPhase1Enabled()) {
_addTabLabel = [[UILabel alloc] init]; _addTabLabel = [[UILabel alloc] init];
_addTabLabel.numberOfLines = 0;
_addTabLabel.lineBreakMode = NSLineBreakByWordWrapping;
_addTabLabel.textAlignment = NSTextAlignmentLeft;
_addTabLabel.alpha = 0.0; _addTabLabel.alpha = 0.0;
_addTabLabel.font = _addTabLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleCaption1]; [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
...@@ -326,9 +332,11 @@ enum class OverscrollViewState { ...@@ -326,9 +332,11 @@ enum class OverscrollViewState {
[UIColor colorWithWhite:kSelectionColor alpha:1.0]; [UIColor colorWithWhite:kSelectionColor alpha:1.0];
_addTabLabel.text = _addTabLabel.text =
l10n_util::GetNSString(IDS_IOS_OVERSCROLL_ADD_TAB_LABEL); l10n_util::GetNSString(IDS_IOS_OVERSCROLL_ADD_TAB_LABEL);
[_addTabLabel sizeToFit];
[self addSubview:_addTabLabel]; [self addSubview:_addTabLabel];
_refreshLabel = [[UILabel alloc] init]; _refreshLabel = [[UILabel alloc] init];
_refreshLabel.numberOfLines = 0;
_refreshLabel.lineBreakMode = NSLineBreakByWordWrapping;
_refreshLabel.textAlignment = NSTextAlignmentCenter;
_refreshLabel.alpha = 0.0; _refreshLabel.alpha = 0.0;
_refreshLabel.font = _refreshLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleCaption1]; [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
...@@ -337,9 +345,11 @@ enum class OverscrollViewState { ...@@ -337,9 +345,11 @@ enum class OverscrollViewState {
[UIColor colorWithWhite:kSelectionColor alpha:1.0]; [UIColor colorWithWhite:kSelectionColor alpha:1.0];
_refreshLabel.text = _refreshLabel.text =
l10n_util::GetNSString(IDS_IOS_OVERSCROLL_REFRESH_LABEL); l10n_util::GetNSString(IDS_IOS_OVERSCROLL_REFRESH_LABEL);
[_refreshLabel sizeToFit];
[self addSubview:_refreshLabel]; [self addSubview:_refreshLabel];
_closeTabLabel = [[UILabel alloc] init]; _closeTabLabel = [[UILabel alloc] init];
_closeTabLabel.numberOfLines = 0;
_closeTabLabel.lineBreakMode = NSLineBreakByWordWrapping;
_closeTabLabel.textAlignment = NSTextAlignmentRight;
_closeTabLabel.alpha = 0.0; _closeTabLabel.alpha = 0.0;
_closeTabLabel.font = _closeTabLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleCaption1]; [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
...@@ -348,7 +358,6 @@ enum class OverscrollViewState { ...@@ -348,7 +358,6 @@ enum class OverscrollViewState {
[UIColor colorWithWhite:kSelectionColor alpha:1.0]; [UIColor colorWithWhite:kSelectionColor alpha:1.0];
_closeTabLabel.text = _closeTabLabel.text =
l10n_util::GetNSString(IDS_IOS_OVERSCROLL_CLOSE_TAB_LABEL); l10n_util::GetNSString(IDS_IOS_OVERSCROLL_CLOSE_TAB_LABEL);
[_closeTabLabel sizeToFit];
[self addSubview:_closeTabLabel]; [self addSubview:_closeTabLabel];
} }
...@@ -579,27 +588,33 @@ enum class OverscrollViewState { ...@@ -579,27 +588,33 @@ enum class OverscrollViewState {
if (!IsUIRefreshPhase1Enabled()) if (!IsUIRefreshPhase1Enabled())
return; return;
// Lay out labels within a CATransaction with no actions to prevent implicit // The text is truncated to be a maximum of half the width of the view.
// animations from occurring. CGSize boundingSize = self.bounds.size;
[CATransaction begin]; boundingSize.width /= 2.0;
[CATransaction setDisableActions:YES];
NSArray* labelLayers = @[ // The UILabels in |labels| are laid out according to the location of their
self.addTabLabel.layer, self.refreshLabel.layer, self.closeTabLabel.layer // corresponding UIImageView in |images|.
NSArray* labels =
@[ self.addTabLabel, self.refreshLabel, self.closeTabLabel ];
NSArray* images = @[
self.addTabActionImageView, self.refreshActionImageView,
self.closeTabActionImageView
]; ];
NSArray* imageLayers = @[
self.addTabActionImageView.layer, self.refreshActionImageView.layer,
self.closeTabActionImageView.layer
];
[labelLayers
enumerateObjectsUsingBlock:^(CALayer* label, NSUInteger idx, BOOL*) {
CALayer* image = imageLayers[idx];
label.position =
CGPointMake(image.position.x,
image.position.y + CGRectGetHeight(image.bounds) / 2.0 +
kActionLabelVerticalPadding);
[labels enumerateObjectsUsingBlock:^(UILabel* label, NSUInteger idx, BOOL*) {
UIImageView* image = images[idx];
CGRect frame = CGRectZero;
frame.size = [label sizeThatFits:boundingSize];
frame.origin.x = image.center.x - frame.size.width / 2.0;
frame.origin.x = fmaxf(
frame.origin.x, CGRectGetMinX(self.bounds) + kActionLabelSidePadding);
frame.origin.x = fminf(frame.origin.x, CGRectGetMaxX(self.bounds) -
kActionLabelSidePadding -
CGRectGetWidth(frame));
frame.origin.y = image.center.y + CGRectGetHeight(image.bounds) / 2.0 +
kActionLabelVerticalPadding;
label.frame = frame;
}]; }];
[CATransaction commit];
} }
- (CGFloat)absorbsHorizontalMovementAroundActions:(CGFloat)x { - (CGFloat)absorbsHorizontalMovementAroundActions:(CGFloat)x {
......
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