Rewrite registration view.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-05-20 14:43:04 -04:00
parent 1f68f3af71
commit 070395e8b6
3 changed files with 196 additions and 334 deletions

View file

@ -6,9 +6,6 @@
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
@ -16,224 +13,9 @@
<scene sceneID="mx5-Ld-bVC">
<objects>
<viewController storyboardIdentifier="RegistrationViewController" id="nS2-Vr-sRt" userLabel="_1.0 Registration Screen" customClass="RegistrationViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="r20-Uu-fes"/>
<viewControllerLayoutGuide type="bottom" id="VXl-FQ-a8g"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="NJf-bg-N21" userLabel="_1.0 Registration Screen">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="xmu-A7-TNZ" userLabel="_1.0a Registration Screen Title">
<rect key="frame" x="0.0" y="0.0" width="320" height="225"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="top" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Your Phone Number" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="K0h-3v-ziO">
<rect key="frame" x="0.0" y="182" width="320" height="29"/>
<constraints>
<constraint firstAttribute="height" constant="29" id="kQ1-1j-ABF"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="20"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleAspectFit" image="logoSignal" translatesAutoresizingMaskIntoConstraints="NO" id="0de-rr-b5G">
<rect key="frame" x="96.5" y="40.5" width="127.5" height="127.5"/>
<constraints>
<constraint firstAttribute="width" secondItem="0de-rr-b5G" secondAttribute="height" multiplier="1:1" id="CcI-gL-h9H"/>
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" red="0.1135657504" green="0.4787300229" blue="0.89595204589999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" secondItem="K0h-3v-ziO" secondAttribute="width" id="4l7-4V-dIx"/>
<constraint firstItem="K0h-3v-ziO" firstAttribute="top" secondItem="0de-rr-b5G" secondAttribute="bottom" constant="14" id="AGh-EW-HI6"/>
<constraint firstAttribute="centerX" secondItem="K0h-3v-ziO" secondAttribute="centerX" id="AIL-Y4-wEG"/>
<constraint firstAttribute="height" constant="225" id="EX0-kF-4ZZ"/>
<constraint firstAttribute="bottom" secondItem="K0h-3v-ziO" secondAttribute="bottom" constant="14" id="GzS-Jj-DiU"/>
<constraint firstAttribute="centerX" secondItem="0de-rr-b5G" secondAttribute="centerX" id="d3o-xW-nyx"/>
<constraint firstItem="0de-rr-b5G" firstAttribute="height" secondItem="xmu-A7-TNZ" secondAttribute="height" multiplier="17:30" id="emL-3k-cN5"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ogW-8F-AvT" userLabel="_1.0b Registration Country Code Selection">
<rect key="frame" x="0.0" y="225" width="320" height="60"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Lch-qL-C1Y">
<rect key="frame" x="0.0" y="59" width="320" height="1"/>
<color key="backgroundColor" red="0.75549191240000002" green="0.75563699009999996" blue="0.75546777249999997" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="B7F-lc-fBJ"/>
</constraints>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="right" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="aSz-jb-g2o">
<rect key="frame" x="237" y="17" width="67" height="26"/>
<constraints>
<constraint firstAttribute="width" constant="67" id="2eK-uf-CSO"/>
<constraint firstAttribute="height" constant="26" id="XPQ-5W-mbO"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<state key="normal" title="+1">
<color key="titleColor" red="0.054103322330000002" green="0.45790460710000003" blue="0.9261735082" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="tailTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Pu7-Ia-adg">
<rect key="frame" x="20" y="0.0" width="195" height="60"/>
<rect key="contentStretch" x="1" y="0.0" width="1" height="1"/>
<constraints>
<constraint firstAttribute="height" constant="60" id="wO6-Jl-BdE"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="16"/>
<state key="normal" title="Country Code">
<color key="titleColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="Lch-qL-C1Y" secondAttribute="trailing" id="Gt8-RR-WBc"/>
<constraint firstAttribute="centerY" secondItem="aSz-jb-g2o" secondAttribute="centerY" id="HU4-qW-Gz8"/>
<constraint firstItem="Lch-qL-C1Y" firstAttribute="top" secondItem="ogW-8F-AvT" secondAttribute="top" constant="59" id="R4z-Zx-3tZ"/>
<constraint firstAttribute="trailing" secondItem="Pu7-Ia-adg" secondAttribute="trailing" constant="105" id="Y5T-N5-RQV"/>
<constraint firstItem="Pu7-Ia-adg" firstAttribute="top" secondItem="ogW-8F-AvT" secondAttribute="top" id="bGo-09-tC2"/>
<constraint firstAttribute="trailing" secondItem="aSz-jb-g2o" secondAttribute="trailing" constant="16" id="hlM-OC-LN6"/>
<constraint firstItem="Pu7-Ia-adg" firstAttribute="leading" secondItem="ogW-8F-AvT" secondAttribute="leading" constant="20" id="qu0-ZZ-p0W"/>
<constraint firstAttribute="height" constant="60" id="rfw-FH-ybj"/>
<constraint firstItem="Lch-qL-C1Y" firstAttribute="leading" secondItem="ogW-8F-AvT" secondAttribute="leading" id="s5Y-V5-Wab"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="rrP-cR-EdR" userLabel="_1.0c Registration Phone Number Input">
<rect key="frame" x="0.0" y="285" width="320" height="61"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Dl2-b7-xdO">
<rect key="frame" x="0.0" y="59" width="360" height="1"/>
<color key="backgroundColor" red="0.75559091570000003" green="0.75556838510000002" blue="0.75558114050000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="NYr-pV-kmN"/>
</constraints>
</view>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Enter Number" textAlignment="right" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="3dc-W2-Cct">
<rect key="frame" x="128" y="19" width="176" height="26"/>
<constraints>
<constraint firstAttribute="height" constant="26" id="lFp-Li-YIs"/>
<constraint firstAttribute="width" constant="176" id="saS-cJ-AqF"/>
</constraints>
<color key="textColor" red="0.23574128750000001" green="0.2357865572" blue="0.23573371770000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<textInputTraits key="textInputTraits" keyboardType="phonePad" keyboardAppearance="light"/>
</textField>
<button opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="OHo-Bz-J6X">
<rect key="frame" x="20" y="18" width="152" height="26"/>
<constraints>
<constraint firstAttribute="height" constant="26" id="FJs-Tn-tgw"/>
<constraint firstAttribute="width" constant="152" id="FXC-xX-QzS"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="15"/>
<state key="normal" title="Phone Number">
<color key="titleColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="OHo-Bz-J6X" firstAttribute="leading" secondItem="rrP-cR-EdR" secondAttribute="leading" constant="20" id="AYJ-bM-qNc"/>
<constraint firstItem="OHo-Bz-J6X" firstAttribute="top" secondItem="rrP-cR-EdR" secondAttribute="top" constant="18" id="CD4-Am-3dE"/>
<constraint firstAttribute="height" constant="61" id="JzF-Pn-EFj"/>
<constraint firstAttribute="trailing" secondItem="Dl2-b7-xdO" secondAttribute="trailing" constant="-40" id="Tec-mV-MQl"/>
<constraint firstItem="3dc-W2-Cct" firstAttribute="top" secondItem="rrP-cR-EdR" secondAttribute="top" constant="19" id="dRt-yw-0Td"/>
<constraint firstAttribute="trailing" secondItem="3dc-W2-Cct" secondAttribute="trailing" constant="16" id="jqT-TF-omH"/>
<constraint firstItem="Dl2-b7-xdO" firstAttribute="leading" secondItem="rrP-cR-EdR" secondAttribute="leading" id="nsi-Cg-As6"/>
<constraint firstItem="Dl2-b7-xdO" firstAttribute="top" secondItem="rrP-cR-EdR" secondAttribute="top" constant="59" id="xE3-Lu-01P"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="iDP-Me-eCf" userLabel="_1.0d Registration Verification Code Button">
<rect key="frame" x="0.0" y="355" width="320" height="47"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="mtj-nl-ohU">
<rect key="frame" x="30" y="1" width="260" height="47"/>
<color key="backgroundColor" red="0.08213712275" green="0.4684380293" blue="0.91112053390000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="47" id="Tgf-rp-YCy"/>
<constraint firstAttribute="height" constant="47" id="pNQ-IE-Fz9"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="14"/>
<state key="normal" title="Activate This Device">
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="sendCodeAction:" destination="nS2-Vr-sRt" eventType="touchUpInside" id="ATR-ZQ-ivB"/>
</connections>
</button>
<activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" style="white" translatesAutoresizingMaskIntoConstraints="NO" id="DBZ-d0-eAi">
<rect key="frame" x="250" y="15" width="20" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="wJ6-5U-WEn"/>
<constraint firstAttribute="width" constant="20" id="zIf-LA-Z5C"/>
</constraints>
</activityIndicatorView>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="mtj-nl-ohU" firstAttribute="top" secondItem="iDP-Me-eCf" secondAttribute="top" constant="1" id="Dff-xZ-xvv"/>
<constraint firstItem="mtj-nl-ohU" firstAttribute="leading" secondItem="iDP-Me-eCf" secondAttribute="leading" constant="30" id="aBh-6a-w1n"/>
<constraint firstItem="DBZ-d0-eAi" firstAttribute="top" secondItem="mtj-nl-ohU" secondAttribute="top" constant="14" id="hLQ-d0-2nv"/>
<constraint firstItem="DBZ-d0-eAi" firstAttribute="trailing" secondItem="mtj-nl-ohU" secondAttribute="trailing" constant="-20" id="kyH-um-7rx"/>
<constraint firstAttribute="height" constant="47" id="oYk-Aj-EDD"/>
<constraint firstAttribute="trailing" secondItem="mtj-nl-ohU" secondAttribute="trailing" constant="30" id="qWP-JR-pdn"/>
</constraints>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="AqN-gc-h3O">
<rect key="frame" x="46" y="412" width="228" height="36"/>
<constraints>
<constraint firstAttribute="height" constant="36" id="GhF-p5-pku"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="14"/>
<state key="normal" title="Already have a Signal account?">
<color key="titleColor" red="0.08235294118" green="0.47058823529999999" blue="0.90980392160000001" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" red="0.49803921568627452" green="0.49803921568627452" blue="0.49803921568627452" alpha="1" colorSpace="calibratedRGB"/>
</state>
<connections>
<action selector="didTapExistingUserButton:" destination="nS2-Vr-sRt" eventType="touchUpInside" id="NWf-jj-BWs"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailingMargin" secondItem="ogW-8F-AvT" secondAttribute="trailing" constant="-16" id="52r-uL-fTy"/>
<constraint firstItem="AqN-gc-h3O" firstAttribute="top" secondItem="iDP-Me-eCf" secondAttribute="bottom" constant="10" id="53V-8O-5jo"/>
<constraint firstAttribute="centerX" secondItem="xmu-A7-TNZ" secondAttribute="centerX" id="BqA-cq-dwf"/>
<constraint firstItem="ogW-8F-AvT" firstAttribute="leading" secondItem="NJf-bg-N21" secondAttribute="leadingMargin" constant="-16" id="EPx-WT-zWo"/>
<constraint firstItem="xmu-A7-TNZ" firstAttribute="width" secondItem="NJf-bg-N21" secondAttribute="width" id="FGC-aY-f9A"/>
<constraint firstItem="rrP-cR-EdR" firstAttribute="leading" secondItem="NJf-bg-N21" secondAttribute="leadingMargin" constant="-16" id="K4z-MB-kzs"/>
<constraint firstAttribute="trailingMargin" secondItem="rrP-cR-EdR" secondAttribute="trailing" constant="-16" id="Lwy-E4-8Ee"/>
<constraint firstItem="xmu-A7-TNZ" firstAttribute="top" secondItem="r20-Uu-fes" secondAttribute="bottom" constant="-20" id="Otb-w3-TYT"/>
<constraint firstItem="ogW-8F-AvT" firstAttribute="top" secondItem="xmu-A7-TNZ" secondAttribute="bottom" id="ZjB-A5-R0v"/>
<constraint firstItem="iDP-Me-eCf" firstAttribute="leading" secondItem="NJf-bg-N21" secondAttribute="leadingMargin" constant="-16" id="aa4-CR-ieG"/>
<constraint firstAttribute="trailingMargin" secondItem="AqN-gc-h3O" secondAttribute="trailing" constant="30" id="flY-3s-XAV"/>
<constraint firstItem="AqN-gc-h3O" firstAttribute="leading" secondItem="NJf-bg-N21" secondAttribute="leadingMargin" constant="30" id="ph5-vz-q6E"/>
<constraint firstItem="rrP-cR-EdR" firstAttribute="top" secondItem="ogW-8F-AvT" secondAttribute="bottom" id="srb-kk-5P5"/>
<constraint firstAttribute="trailingMargin" secondItem="iDP-Me-eCf" secondAttribute="trailing" constant="-16" id="syq-Ef-9Lq"/>
<constraint firstItem="iDP-Me-eCf" firstAttribute="top" secondItem="rrP-cR-EdR" secondAttribute="bottom" constant="9" id="uX8-hI-UyT"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="PhN-sR-LcA"/>
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics" statusBarStyle="lightContent"/>
<nil key="simulatedTopBarMetrics"/>
<connections>
<outlet property="countryCodeButton" destination="aSz-jb-g2o" id="HAe-2D-BxF"/>
<outlet property="countryCodeRow" destination="ogW-8F-AvT" id="5uE-tH-utQ"/>
<outlet property="countryNameButton" destination="Pu7-Ia-adg" id="PFU-m2-gzV"/>
<outlet property="existingUserButton" destination="AqN-gc-h3O" id="XQz-rJ-HOP"/>
<outlet property="headerHeightConstraint" destination="EX0-kF-4ZZ" id="e8J-On-rOg"/>
<outlet property="phoneNumberButton" destination="OHo-Bz-J6X" id="V1H-FP-hcY"/>
<outlet property="phoneNumberTextField" destination="3dc-W2-Cct" id="xWc-E5-zL3"/>
<outlet property="sendCodeButton" destination="mtj-nl-ohU" id="byR-sB-ZeM"/>
<outlet property="signalLogo" destination="0de-rr-b5G" id="3G1-Yh-gAM"/>
<outlet property="spinnerView" destination="DBZ-d0-eAi" id="rbd-C8-3t6"/>
<outlet property="titleLabel" destination="K0h-3v-ziO" id="xui-9i-8Sp"/>
<segue destination="vAf-74-zQH" kind="show" identifier="codeSent" id="Oue-D5-f7y"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="YTE-zH-eXO" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
@ -284,7 +66,4 @@
<point key="canvasLocation" x="-5502" y="-735"/>
</scene>
</scenes>
<resources>
<image name="logoSignal" width="138" height="139"/>
</resources>
</document>

View file

@ -3,28 +3,7 @@
//
#import <UIKit/UIKit.h>
#import "CountryCodeViewController.h"
@interface RegistrationViewController : UIViewController <UITextFieldDelegate>
// Country code
@property (nonatomic) IBOutlet UIButton *countryNameButton;
@property (nonatomic) IBOutlet UIButton *countryCodeButton;
@property (nonatomic) IBOutlet UIView *countryCodeRow;
// Phone number
@property (nonatomic) IBOutlet UITextField *phoneNumberTextField;
@property (nonatomic) IBOutlet UIButton *phoneNumberButton;
@property (nonatomic) IBOutlet UILabel *titleLabel;
// Button
@property (nonatomic) IBOutlet UIButton *sendCodeButton;
@property (nonatomic) IBOutlet UIButton *existingUserButton;
@property (nonatomic) IBOutlet UIActivityIndicatorView *spinnerView;
@property (nonatomic) IBOutlet UIImageView *signalLogo;
@property (nonatomic) IBOutlet UIView *registrationHeader;
@property (nonatomic) IBOutlet NSLayoutConstraint *headerHeightConstraint;
@end

View file

@ -4,72 +4,216 @@
#import "RegistrationViewController.h"
#import "CodeVerificationViewController.h"
#import "CountryCodeViewController.h"
#import "Environment.h"
#import "PhoneNumber.h"
#import "PhoneNumberUtil.h"
#import "Signal-Swift.h"
#import "SignalKeyingStorage.h"
#import "TSAccountManager.h"
#import "UIView+OWS.h"
#import "Util.h"
#import "ViewControllerUtils.h"
static NSString *const kCodeSentSegue = @"codeSent";
@interface RegistrationViewController () <CountryCodeViewControllerDelegate>
@property (nonatomic) NSString *callingCode;
@property (nonatomic) UILabel *countryCodeLabel;
@property (nonatomic) UITextField *phoneNumberTextField;
@property (nonatomic) UIButton *activateButton;
@property (nonatomic) UIActivityIndicatorView *spinnerView;
@end
#pragma mark -
@implementation RegistrationViewController
- (void)viewDidLoad {
[super viewDidLoad];
- (void)loadView
{
[super loadView];
[self createViews];
// Do any additional setup after loading the view.
_phoneNumberTextField.delegate = self;
_phoneNumberTextField.keyboardType = UIKeyboardTypeNumberPad;
[self populateDefaultCountryNameAndCode];
[[Environment getCurrent] setSignUpFlowNavigationController:self.navigationController];
_titleLabel.text = NSLocalizedString(@"REGISTRATION_TITLE_LABEL", @"");
[_countryNameButton
setTitle:NSLocalizedString(@"REGISTRATION_DEFAULT_COUNTRY_NAME", @"Label for the country code field")
forState:UIControlStateNormal];
_phoneNumberTextField.placeholder = NSLocalizedString(
@"REGISTRATION_ENTERNUMBER_DEFAULT_TEXT", @"Placeholder text for the phone number textfield");
[_phoneNumberButton
setTitle:NSLocalizedString(@"REGISTRATION_PHONENUMBER_BUTTON", @"Label for the phone number textfield")
forState:UIControlStateNormal];
[_phoneNumberButton.titleLabel setAdjustsFontSizeToFitWidth:YES];
[_sendCodeButton setTitle:NSLocalizedString(@"REGISTRATION_VERIFY_DEVICE", @"") forState:UIControlStateNormal];
[_existingUserButton setTitle:NSLocalizedString(@"ALREADY_HAVE_ACCOUNT_BUTTON", @"registration button text")
forState:UIControlStateNormal];
[self.countryNameButton addTarget:self
action:@selector(changeCountryCodeTapped)
forControlEvents:UIControlEventTouchUpInside];
[self.countryCodeButton addTarget:self
action:@selector(changeCountryCodeTapped)
forControlEvents:UIControlEventTouchUpInside];
[self.countryCodeRow
addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(countryCodeRowWasTapped:)]];
}
- (void)viewWillAppear:(BOOL)animated {
[self adjustScreenSizes];
- (void)createViews
{
// TODO:
for (UIView *subview in self.view.subviews) {
[subview removeFromSuperview];
}
self.view.backgroundColor = [UIColor ows_signalBrandBlueColor];
UIView *header = [UIView new];
header.backgroundColor = [UIColor ows_signalBrandBlueColor];
[self.view addSubview:header];
[header autoPinToTopLayoutGuideOfViewController:self withInset:0];
[header autoPinWidthToSuperview];
UILabel *headerLabel = [UILabel new];
headerLabel.text = NSLocalizedString(@"REGISTRATION_TITLE_LABEL", @"");
headerLabel.textColor = [UIColor whiteColor];
headerLabel.font = [UIFont ows_mediumFontWithSize:20.f];
[header addSubview:headerLabel];
[headerLabel autoHCenterInSuperview];
[headerLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:14.f];
CGFloat screenHeight = MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
if (screenHeight < 568) {
// iPhone 4s
[header autoSetDimension:ALDimensionHeight toSize:20];
} else if (screenHeight < 667) {
// iPhone 5
[header autoSetDimension:ALDimensionHeight toSize:120];
} else {
[header autoSetDimension:ALDimensionHeight toSize:225];
UIImage *logo = [UIImage imageNamed:@"logoSignal"];
OWSAssert(logo);
UIImageView *logoView = [UIImageView new];
logoView.image = logo;
[header addSubview:logoView];
[logoView autoHCenterInSuperview];
[logoView autoPinEdge:ALEdgeBottom toEdge:ALEdgeTop ofView:headerLabel withOffset:-14.f];
}
UIView *contentView = [UIView new];
contentView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:contentView];
[contentView autoPinToBottomLayoutGuideOfViewController:self withInset:0];
[contentView autoPinWidthToSuperview];
[contentView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:header];
const CGFloat kRowHeight = 60.f;
const CGFloat kRowLeftMargin = 20.f;
const CGFloat kRowRightMargin = 16.f;
const CGFloat kSeparatorHeight = 1.f;
const CGFloat kButtonHMargin = 30.f;
// Country
UIView *countryRow = [UIView new];
[contentView addSubview:countryRow];
[countryRow autoPinWidthToSuperview];
[countryRow autoPinEdgeToSuperviewEdge:ALEdgeTop];
[countryRow autoSetDimension:ALDimensionHeight toSize:kRowHeight];
[countryRow
addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(countryCodeRowWasTapped:)]];
UILabel *countryNameLabel = [UILabel new];
countryNameLabel.text
= NSLocalizedString(@"REGISTRATION_DEFAULT_COUNTRY_NAME", @"Label for the country code field");
countryNameLabel.textColor = [UIColor blackColor];
countryNameLabel.font = [UIFont ows_mediumFontWithSize:16.f];
[countryRow addSubview:countryNameLabel];
[countryNameLabel autoVCenterInSuperview];
[countryNameLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:kRowLeftMargin];
UILabel *countryCodeLabel = [UILabel new];
self.countryCodeLabel = countryCodeLabel;
countryCodeLabel.textColor = [UIColor ows_materialBlueColor];
countryCodeLabel.font = [UIFont ows_mediumFontWithSize:16.f];
[countryRow addSubview:countryCodeLabel];
[countryCodeLabel autoVCenterInSuperview];
[countryCodeLabel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:kRowRightMargin];
UIView *separatorView1 = [UIView new];
separatorView1.backgroundColor = [UIColor colorWithWhite:0.75f alpha:1.f];
[contentView addSubview:separatorView1];
[separatorView1 autoPinWidthToSuperview];
[separatorView1 autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:countryRow];
[separatorView1 autoSetDimension:ALDimensionHeight toSize:kSeparatorHeight];
// Phone Number
UIView *phoneNumberRow = [UIView new];
[contentView addSubview:phoneNumberRow];
[phoneNumberRow autoPinWidthToSuperview];
[phoneNumberRow autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:separatorView1];
[phoneNumberRow autoSetDimension:ALDimensionHeight toSize:kRowHeight];
UILabel *phoneNumberLabel = [UILabel new];
phoneNumberLabel.text
= NSLocalizedString(@"REGISTRATION_PHONENUMBER_BUTTON", @"Label for the phone number textfield");
phoneNumberLabel.textColor = [UIColor blackColor];
phoneNumberLabel.font = [UIFont ows_mediumFontWithSize:16.f];
[phoneNumberRow addSubview:phoneNumberLabel];
[phoneNumberLabel autoVCenterInSuperview];
[phoneNumberLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:kRowLeftMargin];
UITextField *phoneNumberTextField = [UITextField new];
phoneNumberTextField.textAlignment = NSTextAlignmentRight;
phoneNumberTextField.delegate = self;
phoneNumberTextField.keyboardType = UIKeyboardTypeNumberPad;
phoneNumberTextField.placeholder = NSLocalizedString(
@"REGISTRATION_ENTERNUMBER_DEFAULT_TEXT", @"Placeholder text for the phone number textfield");
self.phoneNumberTextField = phoneNumberTextField;
phoneNumberTextField.textColor = [UIColor ows_materialBlueColor];
phoneNumberTextField.font = [UIFont ows_mediumFontWithSize:16.f];
[phoneNumberRow addSubview:phoneNumberTextField];
[phoneNumberTextField autoVCenterInSuperview];
[phoneNumberTextField autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:kRowRightMargin];
UIView *separatorView2 = [UIView new];
separatorView2.backgroundColor = [UIColor colorWithWhite:0.75f alpha:1.f];
[contentView addSubview:separatorView2];
[separatorView2 autoPinWidthToSuperview];
[separatorView2 autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:phoneNumberRow];
[separatorView2 autoSetDimension:ALDimensionHeight toSize:kSeparatorHeight];
// Activate Button
UIButton *activateButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.activateButton = activateButton;
activateButton.backgroundColor = [UIColor ows_signalBrandBlueColor];
[activateButton setTitle:NSLocalizedString(@"REGISTRATION_VERIFY_DEVICE", @"") forState:UIControlStateNormal];
[activateButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
activateButton.titleLabel.font = [UIFont ows_mediumFontWithSize:16.f];
[activateButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[activateButton setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[contentView addSubview:activateButton];
[activateButton autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:kButtonHMargin];
[activateButton autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:kButtonHMargin];
[activateButton autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:separatorView2 withOffset:9.f];
[activateButton autoSetDimension:ALDimensionHeight toSize:47.f];
[activateButton addTarget:self action:@selector(sendCodeAction:) forControlEvents:UIControlEventTouchUpInside];
UIActivityIndicatorView *spinnerView =
[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
self.spinnerView = spinnerView;
[activateButton addSubview:spinnerView];
[spinnerView autoVCenterInSuperview];
[spinnerView autoSetDimension:ALDimensionWidth toSize:20.f];
[spinnerView autoSetDimension:ALDimensionHeight toSize:20.f];
[spinnerView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:20];
[spinnerView stopAnimating];
// Existing Account Button
UIButton *existingAccountButton = [UIButton buttonWithType:UIButtonTypeCustom];
[existingAccountButton setTitle:NSLocalizedString(@"ALREADY_HAVE_ACCOUNT_BUTTON", @"registration button text")
forState:UIControlStateNormal];
[existingAccountButton setTitleColor:[UIColor ows_materialBlueColor] forState:UIControlStateNormal];
existingAccountButton.titleLabel.font = [UIFont ows_mediumFontWithSize:16.f];
[existingAccountButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[existingAccountButton setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[contentView addSubview:existingAccountButton];
[existingAccountButton autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:kButtonHMargin];
[existingAccountButton autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:kButtonHMargin];
[existingAccountButton autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:activateButton withOffset:9.f];
[existingAccountButton autoSetDimension:ALDimensionHeight toSize:36.f];
[existingAccountButton addTarget:self
action:@selector(didTapExistingUserButton:)
forControlEvents:UIControlEventTouchUpInside];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[_sendCodeButton setEnabled:YES];
[_spinnerView stopAnimating];
[_phoneNumberTextField becomeFirstResponder];
[self.activateButton setEnabled:YES];
[self.spinnerView stopAnimating];
[self.phoneNumberTextField becomeFirstResponder];
}
#pragma mark - Country
@ -95,37 +239,13 @@ static NSString *const kCodeSentSegue = @"codeSent";
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];
self.countryCodeLabel.text = title;
[self.countryCodeLabel setNeedsLayout];
}
#pragma mark - Actions
- (IBAction)didTapExistingUserButton:(id)sender
- (void)didTapExistingUserButton:(id)sender
{
DDLogInfo(@"called %s", __PRETTY_FUNCTION__);
@ -137,7 +257,8 @@ static NSString *const kCodeSentSegue = @"codeSent";
message:NSLocalizedString(@"EXISTING_USER_REGISTRATION_ALERT_BODY", @"during registration")];
}
- (IBAction)sendCodeAction:(id)sender {
- (void)sendCodeAction:(id)sender
{
NSString *phoneNumberText =
[_phoneNumberTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (phoneNumberText.length < 1) {
@ -162,14 +283,17 @@ static NSString *const kCodeSentSegue = @"codeSent";
return;
}
[_sendCodeButton setEnabled:NO];
[_spinnerView startAnimating];
[_phoneNumberTextField resignFirstResponder];
[self.activateButton setEnabled:NO];
[self.spinnerView startAnimating];
[self.phoneNumberTextField resignFirstResponder];
__weak RegistrationViewController *weakSelf = self;
[TSAccountManager registerWithPhoneNumber:parsedPhoneNumber
success:^{
[self performSegueWithIdentifier:@"codeSent" sender:self];
[_spinnerView stopAnimating];
[weakSelf.spinnerView stopAnimating];
CodeVerificationViewController *vc = [CodeVerificationViewController new];
[self.navigationController pushViewController:vc animated:YES];
}
failure:^(NSError *error) {
if (error.code == 400) {
@ -179,8 +303,8 @@ static NSString *const kCodeSentSegue = @"codeSent";
[OWSAlerts showAlertWithTitle:error.localizedDescription message:error.localizedRecoverySuggestion];
}
[_sendCodeButton setEnabled:YES];
[_spinnerView stopAnimating];
[weakSelf.activateButton setEnabled:YES];
[weakSelf.spinnerView stopAnimating];
}
smsVerification:YES];
}
@ -257,24 +381,4 @@ static NSString *const kCodeSentSegue = @"codeSent";
return NO;
}
#pragma mark - Unwind segue
- (IBAction)unwindToChangeNumber:(UIStoryboardSegue *)sender {
}
#pragma mark iPhone 5s or shorter
- (void)adjustScreenSizes
{
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
if (screenHeight < 568) { // iphone 4s
self.signalLogo.hidden = YES;
_headerHeightConstraint.constant = 20;
} else if (screenHeight < 667) { // iphone 5
self.signalLogo.hidden = YES;
_headerHeightConstraint.constant = 120;
}
}
@end