From d4e62efce542d31ba5704596adb5ea431c92b005 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 11 Jul 2017 13:07:24 -0400 Subject: [PATCH] Adapt call view to RTL. // FREEBIE --- Signal/src/UIView+OWS.h | 22 +++---- Signal/src/UIView+OWS.m | 62 +++++++++++-------- .../ViewControllers/CallViewController.swift | 21 ++++--- 3 files changed, 57 insertions(+), 48 deletions(-) diff --git a/Signal/src/UIView+OWS.h b/Signal/src/UIView+OWS.h index 31f5ecea1..8a13c2b22 100644 --- a/Signal/src/UIView+OWS.h +++ b/Signal/src/UIView+OWS.h @@ -67,17 +67,17 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value); // // NOTE: the margin values are inverted in RTL layouts. - (BOOL)isRTL; -- (void)autoPinLeadingAndTrailingToSuperview; -- (void)autoPinLeadingToSuperView; -- (void)autoPinLeadingToSuperViewWithMargin:(CGFloat)margin; -- (void)autoPinTrailingToSuperView; -- (void)autoPinTrailingToSuperViewWithMargin:(CGFloat)margin; -- (void)autoPinLeadingToTrailingOfView:(UIView *)view; -- (void)autoPinLeadingToTrailingOfView:(UIView *)view margin:(CGFloat)margin; -- (void)autoPinLeadingToView:(UIView *)view; -- (void)autoPinLeadingToView:(UIView *)view margin:(CGFloat)margin; -- (void)autoPinTrailingToView:(UIView *)view; -- (void)autoPinTrailingToView:(UIView *)view margin:(CGFloat)margin; +- (NSLayoutConstraint *)autoPinLeadingAndTrailingToSuperview; +- (NSLayoutConstraint *)autoPinLeadingToSuperView; +- (NSLayoutConstraint *)autoPinLeadingToSuperViewWithMargin:(CGFloat)margin; +- (NSLayoutConstraint *)autoPinTrailingToSuperView; +- (NSLayoutConstraint *)autoPinTrailingToSuperViewWithMargin:(CGFloat)margin; +- (NSLayoutConstraint *)autoPinLeadingToTrailingOfView:(UIView *)view; +- (NSLayoutConstraint *)autoPinLeadingToTrailingOfView:(UIView *)view margin:(CGFloat)margin; +- (NSLayoutConstraint *)autoPinLeadingToView:(UIView *)view; +- (NSLayoutConstraint *)autoPinLeadingToView:(UIView *)view margin:(CGFloat)margin; +- (NSLayoutConstraint *)autoPinTrailingToView:(UIView *)view; +- (NSLayoutConstraint *)autoPinTrailingToView:(UIView *)view margin:(CGFloat)margin; // Return Right on LTR and Right on RTL. - (NSTextAlignment)textAlignmentUnnatural; // Leading and trailing anchors honor layout margins. diff --git a/Signal/src/UIView+OWS.m b/Signal/src/UIView+OWS.m index 7ddf42471..fded4f690 100644 --- a/Signal/src/UIView+OWS.m +++ b/Signal/src/UIView+OWS.m @@ -224,73 +224,81 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value) return (self.isRTL ? -value : value); } -- (void)autoPinLeadingToSuperView +- (NSLayoutConstraint *)autoPinLeadingToSuperView { - [self autoPinLeadingToSuperViewWithMargin:0]; + return [self autoPinLeadingToSuperViewWithMargin:0]; } -- (void)autoPinLeadingToSuperViewWithMargin:(CGFloat)margin +- (NSLayoutConstraint *)autoPinLeadingToSuperViewWithMargin:(CGFloat)margin { - [self.leadingAnchor constraintEqualToAnchor:self.superview.layoutMarginsGuide.leadingAnchor - constant:[self rtlSafeConstant:margin]] - .active - = YES; + NSLayoutConstraint *constraint = + [self.leadingAnchor constraintEqualToAnchor:self.superview.layoutMarginsGuide.leadingAnchor constant:margin]; + constraint.active = YES; + return constraint; } -- (void)autoPinTrailingToSuperView +- (NSLayoutConstraint *)autoPinTrailingToSuperView { - [self autoPinTrailingToSuperViewWithMargin:0]; + return [self autoPinTrailingToSuperViewWithMargin:0]; } -- (void)autoPinTrailingToSuperViewWithMargin:(CGFloat)margin +- (NSLayoutConstraint *)autoPinTrailingToSuperViewWithMargin:(CGFloat)margin { - [self.trailingAnchor constraintEqualToAnchor:self.superview.layoutMarginsGuide.trailingAnchor - constant:[self rtlSafeConstant:margin]] - .active - = YES; + NSLayoutConstraint *constraint = + [self.trailingAnchor constraintEqualToAnchor:self.superview.layoutMarginsGuide.trailingAnchor + constant:[self rtlSafeConstant:margin]]; + constraint.active = YES; + return constraint; } -- (void)autoPinLeadingToTrailingOfView:(UIView *)view +- (NSLayoutConstraint *)autoPinLeadingToTrailingOfView:(UIView *)view { OWSAssert(view); - [self autoPinLeadingToTrailingOfView:view margin:0]; + NSLayoutConstraint *constraint = [self autoPinLeadingToTrailingOfView:view margin:0]; } -- (void)autoPinLeadingToTrailingOfView:(UIView *)view margin:(CGFloat)margin +- (NSLayoutConstraint *)autoPinLeadingToTrailingOfView:(UIView *)view margin:(CGFloat)margin { OWSAssert(view); - [self.leadingAnchor constraintEqualToAnchor:view.trailingAnchor constant:margin].active = YES; + NSLayoutConstraint *constraint = [self.leadingAnchor constraintEqualToAnchor:view.trailingAnchor constant:margin]; + constraint.active = YES; + return constraint; } -- (void)autoPinLeadingToView:(UIView *)view +- (NSLayoutConstraint *)autoPinLeadingToView:(UIView *)view { OWSAssert(view); - [self autoPinLeadingToView:view margin:0]; + return [self autoPinLeadingToView:view margin:0]; } -- (void)autoPinLeadingToView:(UIView *)view margin:(CGFloat)margin +- (NSLayoutConstraint *)autoPinLeadingToView:(UIView *)view margin:(CGFloat)margin { OWSAssert(view); - [self.leadingAnchor constraintEqualToAnchor:view.leadingAnchor constant:[self rtlSafeConstant:margin]].active = YES; + NSLayoutConstraint *constraint = + [self.leadingAnchor constraintEqualToAnchor:view.leadingAnchor constant:[self rtlSafeConstant:margin]]; + constraint.active = YES; + return constraint; } -- (void)autoPinTrailingToView:(UIView *)view +- (NSLayoutConstraint *)autoPinTrailingToView:(UIView *)view { OWSAssert(view); - [self autoPinTrailingToView:view margin:0]; + return [self autoPinTrailingToView:view margin:0]; } -- (void)autoPinTrailingToView:(UIView *)view margin:(CGFloat)margin +- (NSLayoutConstraint *)autoPinTrailingToView:(UIView *)view margin:(CGFloat)margin { OWSAssert(view); - [self.trailingAnchor constraintEqualToAnchor:view.trailingAnchor constant:[self rtlSafeConstant:margin]].active - = YES; + NSLayoutConstraint *constraint = + [self.trailingAnchor constraintEqualToAnchor:view.trailingAnchor constant:[self rtlSafeConstant:margin]]; + constraint.active = YES; + return constraint; } - (NSTextAlignment)textAlignmentUnnatural diff --git a/Signal/src/ViewControllers/CallViewController.swift b/Signal/src/ViewControllers/CallViewController.swift index 2e528d586..4d391e15a 100644 --- a/Signal/src/ViewControllers/CallViewController.swift +++ b/Signal/src/ViewControllers/CallViewController.swift @@ -210,9 +210,10 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R blurView.isUserInteractionEnabled = false self.view.addSubview(blurView) + self.view.setHLayoutMargins(0) + // Create the video views first, as they are under the other views. createVideoViews() - createContactViews() createOngoingCallControls() createIncomingCallControls() @@ -510,7 +511,7 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R hasConstraints = true let topMargin = CGFloat(40) - let contactHMargin = CGFloat(30) + let contactHMargin = CGFloat(0) let contactVSpacing = CGFloat(3) let ongoingHMargin = ScaleFromIPhone5To7Plus(46, 72) let incomingHMargin = ScaleFromIPhone5To7Plus(46, 72) @@ -529,18 +530,18 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R // Dark blurred background. blurView.autoPinEdgesToSuperviewEdges() - localVideoView.autoPinEdge(toSuperviewEdge:.right, withInset:videoPreviewHMargin) + localVideoView.autoPinTrailingToSuperView(withMargin: videoPreviewHMargin) localVideoView.autoPinEdge(toSuperviewEdge:.top, withInset:topMargin) let localVideoSize = ScaleFromIPhone5To7Plus(80, 100) localVideoView.autoSetDimension(.width, toSize:localVideoSize) localVideoView.autoSetDimension(.height, toSize:localVideoSize) contactNameLabel.autoPinEdge(toSuperviewEdge:.top, withInset:topMargin) - contactNameLabel.autoPinEdge(toSuperviewEdge:.left, withInset:contactHMargin) + contactNameLabel.autoPinLeadingToSuperView(withMargin: contactHMargin) contactNameLabel.setContentHuggingVerticalHigh() callStatusLabel.autoPinEdge(.top, to:.bottom, of:contactNameLabel, withOffset:contactVSpacing) - callStatusLabel.autoPinEdge(toSuperviewEdge:.left, withInset:contactHMargin) + callStatusLabel.autoPinLeadingToSuperView(withMargin: contactHMargin) callStatusLabel.setContentHuggingVerticalHigh() contactAvatarView.autoPinEdge(.top, to:.bottom, of:callStatusLabel, withOffset:+avatarTopSpacing) @@ -631,13 +632,13 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R var constraints: [NSLayoutConstraint] = [] if localVideoView.isHidden { - let contactHMargin = CGFloat(30) - constraints.append(contactNameLabel.autoPinEdge(toSuperviewEdge:.right, withInset:contactHMargin)) - constraints.append(callStatusLabel.autoPinEdge(toSuperviewEdge:.right, withInset:contactHMargin)) + let contactHMargin = CGFloat(0) + constraints.append(contactNameLabel.autoPinTrailingToSuperView()) + constraints.append(callStatusLabel.autoPinTrailingToSuperView()) } else { let spacing = CGFloat(10) - constraints.append(contactNameLabel.autoPinEdge(.right, to:.left, of:localVideoView, withOffset:-spacing)) - constraints.append(callStatusLabel.autoPinEdge(.right, to:.left, of:localVideoView, withOffset:-spacing)) + constraints.append(localVideoView.autoPinLeading(toTrailingOf: contactNameLabel, margin: spacing)) + constraints.append(localVideoView.autoPinLeading(toTrailingOf: callStatusLabel, margin: spacing)) } self.localVideoConstraints = constraints