Commit 68b0d770 authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Chromium LUCI CQ

[iOS][QRScanner] Fix text animation

Worked on this doing pair programming with Sébastien today, and after
debugging we found out that the change in the width of the text is what
causes the animation to appear like it "jumps". Having the text width
to be constant fixes that, and looks good on normal dynamic size fonts.
However it does needs scrolling on the bigger a11y fonts. Would like to
get your input in the way i'm fixing the bug, as this will decrease the
horizontal space for text on iPads.

Another issue we found was that on compact height the text is cropped
into <1 line, and looks bad. Hiding it fixes that.

Fixed: 1005249
Change-Id: I0651ec85ddbb5bbbf30f50518bbb9c6be7f9392a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2595857Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Javier Flores <javierrobles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#838126}
parent 04bea55f
...@@ -37,6 +37,8 @@ const CGFloat kFlashDuration = 0.5; ...@@ -37,6 +37,8 @@ const CGFloat kFlashDuration = 0.5;
} // namespace } // namespace
@interface ScannerView () { @interface ScannerView () {
// A scrollview containing the viewport's caption.
UIScrollView* _captionContainer;
// A button to toggle the torch. // A button to toggle the torch.
UIBarButtonItem* _torchButton; UIBarButtonItem* _torchButton;
// A view containing the preview layer for camera input. // A view containing the preview layer for camera input.
...@@ -181,6 +183,12 @@ const CGFloat kFlashDuration = 0.5; ...@@ -181,6 +183,12 @@ const CGFloat kFlashDuration = 0.5;
return @""; return @"";
} }
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
_captionContainer.hidden =
UIUserInterfaceSizeClassCompact == self.traitCollection.verticalSizeClass;
}
#pragma mark - private methods #pragma mark - private methods
// Creates an image with template rendering mode for use in icons. // Creates an image with template rendering mode for use in icons.
...@@ -263,35 +271,39 @@ const CGFloat kFlashDuration = 0.5; ...@@ -263,35 +271,39 @@ const CGFloat kFlashDuration = 0.5;
[viewportCaption.layer setMasksToBounds:NO]; [viewportCaption.layer setMasksToBounds:NO];
[viewportCaption.layer setShouldRasterize:YES]; [viewportCaption.layer setShouldRasterize:YES];
UIScrollView* scrollView = [[UIScrollView alloc] init]; _captionContainer = [[UIScrollView alloc] init];
scrollView.showsVerticalScrollIndicator = NO; _captionContainer.showsVerticalScrollIndicator = NO;
[self addSubview:scrollView]; [self addSubview:_captionContainer];
[scrollView addSubview:viewportCaption]; [_captionContainer addSubview:viewportCaption];
// Constraints for viewportCaption. // Constraints for viewportCaption.
scrollView.translatesAutoresizingMaskIntoConstraints = NO; _captionContainer.translatesAutoresizingMaskIntoConstraints = NO;
viewportCaption.translatesAutoresizingMaskIntoConstraints = NO; viewportCaption.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[scrollView.topAnchor [_captionContainer.topAnchor
constraintEqualToAnchor:self.centerYAnchor constraintEqualToAnchor:self.centerYAnchor
constant:[self viewportSize].height / 2 + constant:self.viewportSize.height / 2 +
kViewportCaptionVerticalPadding], kViewportCaptionVerticalPadding],
[scrollView.bottomAnchor constraintEqualToAnchor:toolbar.topAnchor], [_captionContainer.bottomAnchor constraintEqualToAnchor:toolbar.topAnchor],
[scrollView.leadingAnchor [_captionContainer.centerXAnchor
constraintEqualToAnchor:self.leadingAnchor constraintEqualToAnchor:_previewOverlay.centerXAnchor],
constant:kViewportCaptionHorizontalPadding], [_captionContainer.contentLayoutGuide.widthAnchor
[viewportCaption.leadingAnchor constraintEqualToAnchor:_captionContainer.widthAnchor],
constraintEqualToAnchor:self.leadingAnchor [_captionContainer.widthAnchor
constant:kViewportCaptionHorizontalPadding], constraintLessThanOrEqualToAnchor:self.widthAnchor
[scrollView.trailingAnchor constant:-2 *
constraintEqualToAnchor:self.trailingAnchor kViewportCaptionHorizontalPadding],
constant:-kViewportCaptionHorizontalPadding], [_captionContainer.widthAnchor
[viewportCaption.trailingAnchor constraintLessThanOrEqualToAnchor:self.heightAnchor
constraintEqualToAnchor:self.trailingAnchor constant:-2 *
constant:-kViewportCaptionHorizontalPadding], kViewportCaptionHorizontalPadding],
]]; ]];
AddSameConstraints(scrollView, viewportCaption); AddSameConstraints(_captionContainer, viewportCaption);
// There is no space for at least 1 line of text in compact height.
_captionContainer.hidden =
UIUserInterfaceSizeClassCompact == self.traitCollection.verticalSizeClass;
} }
// Adds a preview view to |self| and configures its layout constraints. // Adds a preview view to |self| and configures its layout constraints.
......
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