Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 6 #error "This file requires ARC support." | |
| 7 #endif | |
| 8 | |
| 9 #import "remoting/ios/app/session_reconnect_view.h" | |
| 10 | |
| 11 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" | |
| 12 #import "remoting/ios/app/remoting_theme.h" | |
| 13 | |
| 14 static const CGFloat kReconnectButtonWidth = 120.f; | |
| 15 static const CGFloat kReconnectButtonHeight = 30.f; | |
| 16 | |
| 17 @interface SessionReconnectView () { | |
| 18 MDCRaisedButton* _reconnectButton; | |
| 19 } | |
| 20 @end | |
| 21 | |
| 22 @implementation SessionReconnectView | |
| 23 | |
| 24 @synthesize delegate = _delegate; | |
| 25 | |
| 26 - (id)initWithFrame:(CGRect)frame { | |
| 27 self = [super initWithFrame:frame]; | |
| 28 if (self) { | |
| 29 self.backgroundColor = [UIColor clearColor]; | |
| 30 | |
| 31 _reconnectButton = [[MDCRaisedButton alloc] init]; | |
| 32 [_reconnectButton setElevation:4.0f forState:UIControlStateNormal]; | |
| 33 [_reconnectButton setTitle:@"Reconnect" forState:UIControlStateNormal]; | |
| 34 [_reconnectButton addTarget:self | |
| 35 action:@selector(didTapReconnect:) | |
| 36 forControlEvents:UIControlEventTouchUpInside]; | |
| 37 _reconnectButton.translatesAutoresizingMaskIntoConstraints = NO; | |
| 38 [self addSubview:_reconnectButton]; | |
| 39 | |
| 40 [self initializeLayoutConstraintsWithViews:NSDictionaryOfVariableBindings( | |
| 41 _reconnectButton)]; | |
| 42 } | |
| 43 return self; | |
| 44 } | |
| 45 | |
| 46 - (void)initializeLayoutConstraintsWithViews:(NSDictionary*)views { | |
| 47 // Metrics to use in visual format strings. | |
| 48 NSDictionary* layoutMetrics = @{ | |
| 49 @"reconnectButtonWidth" : @(kReconnectButtonWidth), | |
| 50 @"reconnectButtonHeight" : @(kReconnectButtonHeight), | |
| 51 }; | |
| 52 | |
| 53 [_reconnectButton.centerYAnchor constraintEqualToAnchor:self.centerYAnchor] | |
| 54 .active = YES; | |
| 55 [_reconnectButton.centerXAnchor constraintEqualToAnchor:self.centerXAnchor] | |
| 56 .active = YES; | |
| 57 | |
| 58 [self addConstraints:[NSLayoutConstraint | |
|
Yuwei
2017/07/06 21:52:39
For simple constraints like this I would probably
nicholss
2017/07/06 22:15:06
Done.
Yuwei
2017/07/06 22:36:28
FYI you could simplify these with array literal if
| |
| 59 constraintsWithVisualFormat: | |
| 60 @"H:[_reconnectButton(reconnectButtonWidth)]" | |
| 61 options:0 | |
| 62 metrics:layoutMetrics | |
| 63 views:views]]; | |
| 64 | |
| 65 [self addConstraints:[NSLayoutConstraint | |
| 66 constraintsWithVisualFormat: | |
| 67 @"V:[_reconnectButton(reconnectButtonHeight)]" | |
| 68 options:0 | |
| 69 metrics:layoutMetrics | |
| 70 views:views]]; | |
| 71 [self setNeedsUpdateConstraints]; | |
| 72 } | |
| 73 | |
| 74 #pragma mark - Private | |
| 75 | |
| 76 - (void)didTapReconnect:(id)sender { | |
| 77 if ([_delegate respondsToSelector:@selector(didTapReconnect)]) { | |
| 78 [_delegate didTapReconnect]; | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 @end | |
| OLD | NEW |