Adapt call view to RTL.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent e2125978de
commit d4e62efce5

@ -67,17 +67,17 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value);
// //
// NOTE: the margin values are inverted in RTL layouts. // NOTE: the margin values are inverted in RTL layouts.
- (BOOL)isRTL; - (BOOL)isRTL;
- (void)autoPinLeadingAndTrailingToSuperview; - (NSLayoutConstraint *)autoPinLeadingAndTrailingToSuperview;
- (void)autoPinLeadingToSuperView; - (NSLayoutConstraint *)autoPinLeadingToSuperView;
- (void)autoPinLeadingToSuperViewWithMargin:(CGFloat)margin; - (NSLayoutConstraint *)autoPinLeadingToSuperViewWithMargin:(CGFloat)margin;
- (void)autoPinTrailingToSuperView; - (NSLayoutConstraint *)autoPinTrailingToSuperView;
- (void)autoPinTrailingToSuperViewWithMargin:(CGFloat)margin; - (NSLayoutConstraint *)autoPinTrailingToSuperViewWithMargin:(CGFloat)margin;
- (void)autoPinLeadingToTrailingOfView:(UIView *)view; - (NSLayoutConstraint *)autoPinLeadingToTrailingOfView:(UIView *)view;
- (void)autoPinLeadingToTrailingOfView:(UIView *)view margin:(CGFloat)margin; - (NSLayoutConstraint *)autoPinLeadingToTrailingOfView:(UIView *)view margin:(CGFloat)margin;
- (void)autoPinLeadingToView:(UIView *)view; - (NSLayoutConstraint *)autoPinLeadingToView:(UIView *)view;
- (void)autoPinLeadingToView:(UIView *)view margin:(CGFloat)margin; - (NSLayoutConstraint *)autoPinLeadingToView:(UIView *)view margin:(CGFloat)margin;
- (void)autoPinTrailingToView:(UIView *)view; - (NSLayoutConstraint *)autoPinTrailingToView:(UIView *)view;
- (void)autoPinTrailingToView:(UIView *)view margin:(CGFloat)margin; - (NSLayoutConstraint *)autoPinTrailingToView:(UIView *)view margin:(CGFloat)margin;
// Return Right on LTR and Right on RTL. // Return Right on LTR and Right on RTL.
- (NSTextAlignment)textAlignmentUnnatural; - (NSTextAlignment)textAlignmentUnnatural;
// Leading and trailing anchors honor layout margins. // Leading and trailing anchors honor layout margins.

@ -224,73 +224,81 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value)
return (self.isRTL ? -value : value); 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 NSLayoutConstraint *constraint =
constant:[self rtlSafeConstant:margin]] [self.leadingAnchor constraintEqualToAnchor:self.superview.layoutMarginsGuide.leadingAnchor constant:margin];
.active constraint.active = YES;
= 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 NSLayoutConstraint *constraint =
constant:[self rtlSafeConstant:margin]] [self.trailingAnchor constraintEqualToAnchor:self.superview.layoutMarginsGuide.trailingAnchor
.active constant:[self rtlSafeConstant:margin]];
= YES; constraint.active = YES;
return constraint;
} }
- (void)autoPinLeadingToTrailingOfView:(UIView *)view - (NSLayoutConstraint *)autoPinLeadingToTrailingOfView:(UIView *)view
{ {
OWSAssert(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); 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); 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); 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); 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); OWSAssert(view);
[self.trailingAnchor constraintEqualToAnchor:view.trailingAnchor constant:[self rtlSafeConstant:margin]].active NSLayoutConstraint *constraint =
= YES; [self.trailingAnchor constraintEqualToAnchor:view.trailingAnchor constant:[self rtlSafeConstant:margin]];
constraint.active = YES;
return constraint;
} }
- (NSTextAlignment)textAlignmentUnnatural - (NSTextAlignment)textAlignmentUnnatural

@ -210,9 +210,10 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R
blurView.isUserInteractionEnabled = false blurView.isUserInteractionEnabled = false
self.view.addSubview(blurView) self.view.addSubview(blurView)
self.view.setHLayoutMargins(0)
// Create the video views first, as they are under the other views. // Create the video views first, as they are under the other views.
createVideoViews() createVideoViews()
createContactViews() createContactViews()
createOngoingCallControls() createOngoingCallControls()
createIncomingCallControls() createIncomingCallControls()
@ -510,7 +511,7 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R
hasConstraints = true hasConstraints = true
let topMargin = CGFloat(40) let topMargin = CGFloat(40)
let contactHMargin = CGFloat(30) let contactHMargin = CGFloat(0)
let contactVSpacing = CGFloat(3) let contactVSpacing = CGFloat(3)
let ongoingHMargin = ScaleFromIPhone5To7Plus(46, 72) let ongoingHMargin = ScaleFromIPhone5To7Plus(46, 72)
let incomingHMargin = ScaleFromIPhone5To7Plus(46, 72) let incomingHMargin = ScaleFromIPhone5To7Plus(46, 72)
@ -529,18 +530,18 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R
// Dark blurred background. // Dark blurred background.
blurView.autoPinEdgesToSuperviewEdges() blurView.autoPinEdgesToSuperviewEdges()
localVideoView.autoPinEdge(toSuperviewEdge:.right, withInset:videoPreviewHMargin) localVideoView.autoPinTrailingToSuperView(withMargin: videoPreviewHMargin)
localVideoView.autoPinEdge(toSuperviewEdge:.top, withInset:topMargin) localVideoView.autoPinEdge(toSuperviewEdge:.top, withInset:topMargin)
let localVideoSize = ScaleFromIPhone5To7Plus(80, 100) let localVideoSize = ScaleFromIPhone5To7Plus(80, 100)
localVideoView.autoSetDimension(.width, toSize:localVideoSize) localVideoView.autoSetDimension(.width, toSize:localVideoSize)
localVideoView.autoSetDimension(.height, toSize:localVideoSize) localVideoView.autoSetDimension(.height, toSize:localVideoSize)
contactNameLabel.autoPinEdge(toSuperviewEdge:.top, withInset:topMargin) contactNameLabel.autoPinEdge(toSuperviewEdge:.top, withInset:topMargin)
contactNameLabel.autoPinEdge(toSuperviewEdge:.left, withInset:contactHMargin) contactNameLabel.autoPinLeadingToSuperView(withMargin: contactHMargin)
contactNameLabel.setContentHuggingVerticalHigh() contactNameLabel.setContentHuggingVerticalHigh()
callStatusLabel.autoPinEdge(.top, to:.bottom, of:contactNameLabel, withOffset:contactVSpacing) callStatusLabel.autoPinEdge(.top, to:.bottom, of:contactNameLabel, withOffset:contactVSpacing)
callStatusLabel.autoPinEdge(toSuperviewEdge:.left, withInset:contactHMargin) callStatusLabel.autoPinLeadingToSuperView(withMargin: contactHMargin)
callStatusLabel.setContentHuggingVerticalHigh() callStatusLabel.setContentHuggingVerticalHigh()
contactAvatarView.autoPinEdge(.top, to:.bottom, of:callStatusLabel, withOffset:+avatarTopSpacing) contactAvatarView.autoPinEdge(.top, to:.bottom, of:callStatusLabel, withOffset:+avatarTopSpacing)
@ -631,13 +632,13 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R
var constraints: [NSLayoutConstraint] = [] var constraints: [NSLayoutConstraint] = []
if localVideoView.isHidden { if localVideoView.isHidden {
let contactHMargin = CGFloat(30) let contactHMargin = CGFloat(0)
constraints.append(contactNameLabel.autoPinEdge(toSuperviewEdge:.right, withInset:contactHMargin)) constraints.append(contactNameLabel.autoPinTrailingToSuperView())
constraints.append(callStatusLabel.autoPinEdge(toSuperviewEdge:.right, withInset:contactHMargin)) constraints.append(callStatusLabel.autoPinTrailingToSuperView())
} else { } else {
let spacing = CGFloat(10) let spacing = CGFloat(10)
constraints.append(contactNameLabel.autoPinEdge(.right, to:.left, of:localVideoView, withOffset:-spacing)) constraints.append(localVideoView.autoPinLeading(toTrailingOf: contactNameLabel, margin: spacing))
constraints.append(callStatusLabel.autoPinEdge(.right, to:.left, of:localVideoView, withOffset:-spacing)) constraints.append(localVideoView.autoPinLeading(toTrailingOf: callStatusLabel, margin: spacing))
} }
self.localVideoConstraints = constraints self.localVideoConstraints = constraints

Loading…
Cancel
Save