From 1246fcd99d8137fb87938ad302684f3a49215aab Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Sun, 26 Mar 2017 15:56:17 -0400 Subject: [PATCH] Rework country views in registration view. // FREEBIE --- .../CountryCodeViewController.h | 5 ++ .../CountryCodeViewController.m | 1 + .../RegistrationViewController.m | 53 +++++++++++++++---- 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/Signal/src/view controllers/CountryCodeViewController.h b/Signal/src/view controllers/CountryCodeViewController.h index 1cf0d26a4..d92323b9f 100644 --- a/Signal/src/view controllers/CountryCodeViewController.h +++ b/Signal/src/view controllers/CountryCodeViewController.h @@ -1,3 +1,7 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + #import @class CountryCodeViewController; @@ -18,6 +22,7 @@ @property (nonatomic, strong) IBOutlet UITableView *countryCodeTableView; @property (nonatomic, strong) IBOutlet UISearchBar *searchBar; @property (nonatomic, assign) id delegate; +@property (nonatomic, strong) NSString *countryCodeSelected; @property (nonatomic, strong) NSString *callingCodeSelected; @property (nonatomic, strong) NSString *countryNameSelected; diff --git a/Signal/src/view controllers/CountryCodeViewController.m b/Signal/src/view controllers/CountryCodeViewController.m index 1c57d3cb2..e8c183108 100644 --- a/Signal/src/view controllers/CountryCodeViewController.m +++ b/Signal/src/view controllers/CountryCodeViewController.m @@ -56,6 +56,7 @@ static NSString *const kUnwindToCountryCodeWasSelectedSegue = @"UnwindToCountryC NSString *countryCode = _countryCodes[(NSUInteger)indexPath.row]; _callingCodeSelected = [PhoneNumberUtil callingCodeFromCountryCode:countryCode]; _countryNameSelected = [PhoneNumberUtil countryNameFromCountryCode:countryCode]; + _countryCodeSelected = countryCode; [self.searchBar resignFirstResponder]; [self performSegueWithIdentifier:kUnwindToCountryCodeWasSelectedSegue sender:self]; } diff --git a/Signal/src/view controllers/RegistrationViewController.m b/Signal/src/view controllers/RegistrationViewController.m index ee73da604..7218b068a 100644 --- a/Signal/src/view controllers/RegistrationViewController.m +++ b/Signal/src/view controllers/RegistrationViewController.m @@ -3,7 +3,6 @@ // #import "RegistrationViewController.h" - #import "CodeVerificationViewController.h" #import "Environment.h" #import "LocalizableText.h" @@ -12,6 +11,7 @@ #import "SignalKeyingStorage.h" #import "TSAccountManager.h" #import "Util.h" +#import "UIView+OWS.h" static NSString *const kCodeSentSegue = @"codeSent"; @@ -54,20 +54,54 @@ static NSString *const kCodeSentSegue = @"codeSent"; [_phoneNumberTextField becomeFirstResponder]; } -#pragma mark - Locale +#pragma mark - Country - (void)populateDefaultCountryNameAndCode { NSLocale *locale = NSLocale.currentLocale; NSString *countryCode = [locale objectForKey:NSLocaleCountryCode]; - NSNumber *cc = [[PhoneNumberUtil sharedUtil].nbPhoneNumberUtil getCountryCodeForRegion:countryCode]; + NSNumber *callingCode = [[PhoneNumberUtil sharedUtil].nbPhoneNumberUtil getCountryCodeForRegion:countryCode]; + NSString *countryName = [PhoneNumberUtil countryNameFromCountryCode:countryCode]; + [self updateCountryWithName:countryName + callingCode:[NSString stringWithFormat:@"%@%@", + COUNTRY_CODE_PREFIX, + callingCode] + countryCode:countryCode]; +} - [_countryCodeButton setTitle:[NSString stringWithFormat:@"%@%@", COUNTRY_CODE_PREFIX, cc] - forState:UIControlStateNormal]; - [_countryNameButton setTitle:[PhoneNumberUtil countryNameFromCountryCode:countryCode] +- (void)updateCountryWithName:(NSString *)countryName + callingCode:(NSString *)callingCode + countryCode:(NSString *)countryCode { + NSString *title = [NSString stringWithFormat:@"%@ (%@)", + callingCode, + countryCode.uppercaseString]; + [_countryCodeButton setTitle:title forState:UIControlStateNormal]; + + // In the absence of a rewrite to a programmatic layout, + // re-add the country code and name views in order to + // remove any layout constraints that apply to them. + UIView *superview = _countryCodeButton.superview; + [_countryNameButton removeFromSuperview]; + [_countryCodeButton removeFromSuperview]; + [_countryNameButton removeConstraints:_countryNameButton.constraints]; + [_countryCodeButton removeConstraints:_countryCodeButton.constraints]; + + [superview addSubview:_countryNameButton]; + [superview addSubview:_countryCodeButton]; + [_countryNameButton autoVCenterInSuperview]; + [_countryCodeButton autoVCenterInSuperview]; + [_countryNameButton autoSetDimension:ALDimensionHeight toSize:26]; + [_countryCodeButton autoSetDimension:ALDimensionHeight toSize:26]; + [_countryNameButton autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:20]; + [_countryCodeButton autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:16]; + [_countryNameButton autoSetDimension:ALDimensionWidth toSize:150]; + [_countryCodeButton autoSetDimension:ALDimensionWidth toSize:150]; + _countryNameButton.translatesAutoresizingMaskIntoConstraints = NO; + _countryCodeButton.translatesAutoresizingMaskIntoConstraints = NO; + + [superview layoutSubviews]; } - #pragma mark - Actions - (IBAction)didTapExistingUserButton:(id)sender @@ -213,8 +247,9 @@ static NSString *const kCodeSentSegue = @"codeSent"; - (IBAction)unwindToCountryCodeWasSelected:(UIStoryboardSegue *)segue { CountryCodeViewController *vc = [segue sourceViewController]; - [_countryCodeButton setTitle:vc.callingCodeSelected forState:UIControlStateNormal]; - [_countryNameButton setTitle:vc.countryNameSelected forState:UIControlStateNormal]; + [self updateCountryWithName:vc.countryNameSelected + callingCode:vc.callingCodeSelected + countryCode:vc.countryCodeSelected]; // Reformat phone number NSString *digits = _phoneNumberTextField.text.digitsOnly;