Skip to content

Commit

Permalink
implement swift auth customization controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
yramanchuk committed Oct 20, 2016
1 parent b953da9 commit 294601f
Show file tree
Hide file tree
Showing 16 changed files with 1,253 additions and 48 deletions.
104 changes: 79 additions & 25 deletions samples/swift/FirebaseUI-demo-swift.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

61 changes: 41 additions & 20 deletions samples/swift/FirebaseUI-demo-swift/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,6 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<toolbar key="tableFooterView" opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="jjI-5e-RC1">
<rect key="frame" x="0.0" y="521" width="375" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<items>
<barButtonItem style="plain" systemItem="flexibleSpace" id="K12-RU-Zfz"/>
<barButtonItem title="Sign In" id="E21-cP-Dhb">
<connections>
<action selector="onAuthorize:" destination="wby-P6-pid" id="oxf-0Q-Hdd"/>
</connections>
</barButtonItem>
<barButtonItem style="plain" systemItem="flexibleSpace" id="G4L-Vb-g3u"/>
</items>
</toolbar>
<sections>
<tableViewSection headerTitle="Is signed-in" id="0Pr-Kf-qkL">
<cells>
Expand All @@ -213,12 +200,35 @@
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="BRB-gO-zrn">
<rect key="frame" x="0.0" y="100" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="BRB-gO-zrn" id="TDE-FU-8Jx">
<frame key="frameInset" width="375" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Custom Authorization" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gGt-QN-wFM">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="VRw-wD-ISl"/>
</subviews>
<constraints>
<constraint firstItem="VRw-wD-ISl" firstAttribute="trailing" secondItem="TDE-FU-8Jx" secondAttribute="trailingMargin" id="0Z0-vA-fKp"/>
<constraint firstItem="gGt-QN-wFM" firstAttribute="centerY" secondItem="TDE-FU-8Jx" secondAttribute="centerY" id="2Zh-8c-ssE"/>
<constraint firstItem="VRw-wD-ISl" firstAttribute="leading" secondItem="gGt-QN-wFM" secondAttribute="trailing" constant="8" symbolic="YES" id="CBU-uW-rUA"/>
<constraint firstItem="gGt-QN-wFM" firstAttribute="centerY" secondItem="VRw-wD-ISl" secondAttribute="centerY" id="VaB-k3-6Gg"/>
<constraint firstItem="gGt-QN-wFM" firstAttribute="leading" secondItem="TDE-FU-8Jx" secondAttribute="leadingMargin" id="dqn-H7-od1"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection headerTitle="Name" id="Jho-f6-Urp">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="mXf-Qr-aGq">
<rect key="frame" x="0.0" y="140" width="375" height="44"/>
<rect key="frame" x="0.0" y="184" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="mXf-Qr-aGq" id="VWa-qt-FWa">
<frame key="frameInset" width="375" height="43"/>
Expand All @@ -230,7 +240,7 @@
<tableViewSection headerTitle="e-mail" id="Acz-Do-HDT">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="IjQ-eL-x0N">
<rect key="frame" x="0.0" y="224" width="375" height="44"/>
<rect key="frame" x="0.0" y="268" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="IjQ-eL-x0N" id="kVz-NE-XOf">
<frame key="frameInset" width="375" height="43"/>
Expand All @@ -242,7 +252,7 @@
<tableViewSection headerTitle="UID" id="kdc-iI-3Bd">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="S6s-Qd-Z3i">
<rect key="frame" x="0.0" y="308" width="375" height="44"/>
<rect key="frame" x="0.0" y="352" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="S6s-Qd-Z3i" id="3tB-Th-rk9">
<frame key="frameInset" width="375" height="43"/>
Expand All @@ -254,7 +264,7 @@
<tableViewSection headerTitle="Provider Access Token" id="TTf-7r-Kld">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="NKE-io-hSe" style="IBUITableViewCellStyleDefault" id="BZ9-c2-MUK">
<rect key="frame" x="0.0" y="392" width="375" height="44"/>
<rect key="frame" x="0.0" y="436" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="BZ9-c2-MUK" id="AuA-sR-YEx">
<frame key="frameInset" width="375" height="43"/>
Expand All @@ -275,7 +285,7 @@
<tableViewSection headerTitle="Provider Id Token" id="i6h-Na-zzy">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="RB6-Yv-KVG" style="IBUITableViewCellStyleDefault" id="LmG-vd-Xzu">
<rect key="frame" x="0.0" y="476" width="375" height="44"/>
<rect key="frame" x="0.0" y="520" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="LmG-vd-Xzu" id="b7z-I4-euc">
<frame key="frameInset" width="375" height="43"/>
Expand All @@ -299,14 +309,25 @@
<outlet property="delegate" destination="wby-P6-pid" id="mHK-Jc-sWw"/>
</connections>
</tableView>
<toolbarItems>
<barButtonItem style="plain" systemItem="flexibleSpace" id="K12-RU-Zfz"/>
<barButtonItem title="Sign In" id="E21-cP-Dhb">
<connections>
<action selector="onAuthorize:" destination="wby-P6-pid" id="oxf-0Q-Hdd"/>
</connections>
</barButtonItem>
<barButtonItem style="plain" systemItem="flexibleSpace" id="G4L-Vb-g3u"/>
</toolbarItems>
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
<connections>
<outlet property="btnAuthorization" destination="E21-cP-Dhb" id="kvE-qq-41P"/>
<outlet property="authorizationButton" destination="E21-cP-Dhb" id="nfv-XO-h5O"/>
<outlet property="cellAccessToken" destination="BZ9-c2-MUK" id="xAH-KT-gy8"/>
<outlet property="cellEmail" destination="IjQ-eL-x0N" id="zbw-rM-wNs"/>
<outlet property="cellIdToken" destination="LmG-vd-Xzu" id="JZp-g3-bNl"/>
<outlet property="cellName" destination="mXf-Qr-aGq" id="2Xi-HM-i86"/>
<outlet property="cellSignedIn" destination="6vu-5U-WfK" id="29e-eN-Uzk"/>
<outlet property="cellUid" destination="S6s-Qd-Z3i" id="exG-YI-qfx"/>
<outlet property="customAuthorizationSwitch" destination="VRw-wD-ISl" id="yWY-Tz-wLP"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="24p-6G-GD4" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down Expand Up @@ -377,7 +398,7 @@
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="jBB-7b-HHb" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" misplaced="YES" id="bRD-Ca-0aK">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="bRD-Ca-0aK">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class FIRAuthViewController: UITableViewController {

fileprivate(set) var auth: FIRAuth? = FIRAuth.auth()
fileprivate(set) var authUI: FIRAuthUI? = FIRAuthUI.default()
fileprivate(set) var customAuthUIDelegate: FIRAuthUIDelegate = FIRCustomAuthUIDelegate()

@IBOutlet weak var cellSignedIn: UITableViewCell!
@IBOutlet weak var cellName: UITableViewCell!
Expand All @@ -42,7 +43,8 @@ class FIRAuthViewController: UITableViewController {
@IBOutlet weak var cellAccessToken: UITableViewCell!
@IBOutlet weak var cellIdToken: UITableViewCell!

@IBOutlet weak var btnAuthorization: UIBarButtonItem!
@IBOutlet weak var authorizationButton: UIBarButtonItem!
@IBOutlet weak var customAuthorizationSwitch: UISwitch!


override func viewWillAppear(_ animated: Bool) {
Expand All @@ -64,13 +66,17 @@ class FIRAuthViewController: UITableViewController {

self.authStateDidChangeHandle =
self.auth?.addStateDidChangeListener(self.updateUI(auth:user:))

self.navigationController?.isToolbarHidden = false;
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
if let handle = self.authStateDidChangeHandle {
self.auth?.removeStateDidChangeListener(handle)
}

self.navigationController?.isToolbarHidden = true;
}

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
Expand All @@ -89,7 +95,10 @@ class FIRAuthViewController: UITableViewController {
}

} else {
self.authUI?.delegate = self.customAuthorizationSwitch.isOn ? self.customAuthUIDelegate : nil;

let controller = self.authUI!.authViewController()
controller.navigationBar.isHidden = self.customAuthorizationSwitch.isOn
self.present(controller, animated: true, completion: nil)
}
}
Expand All @@ -102,14 +111,14 @@ class FIRAuthViewController: UITableViewController {
self.cellEmail.textLabel?.text = user.email ?? "(null)"
self.cellUid.textLabel?.text = user.uid

self.btnAuthorization.title = "Sign Out";
self.authorizationButton.title = "Sign Out";
} else {
self.cellSignedIn.textLabel?.text = "Not signed in"
self.cellName.textLabel?.text = "null"
self.cellEmail.textLabel?.text = "null"
self.cellUid.textLabel?.text = "null"

self.btnAuthorization.title = "Sign In";
self.authorizationButton.title = "Sign In";
}

self.cellAccessToken.textLabel?.text = getAllAccessTokens()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Copyright (c) 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import UIKit
import FirebaseAuthUI

@objc(FIRCustomAuthPickerViewController)

class FIRCustomAuthPickerViewController: FIRAuthPickerViewController {

@IBAction func onClose(_ sender: AnyObject) {
self.cancelAuthorization()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="FIRCustomAuthPickerViewController" customModule="FirebaseUI_demo_swift" customModuleProvider="target">
<connections>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="VxO-Mp-NxI">
<color key="backgroundColor" name="selectedKnobColor" catalog="System" colorSpace="catalog"/>
<state key="normal" title="Cancel">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="onClose:" destination="-1" eventType="touchUpInside" id="oXy-b9-wIa"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" name="knobColor" catalog="System" colorSpace="catalog"/>
<constraints>
<constraint firstItem="VxO-Mp-NxI" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leadingMargin" id="0gC-XW-7T5"/>
<constraint firstItem="VxO-Mp-NxI" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" constant="109" id="Sej-IC-Sc9"/>
<constraint firstAttribute="trailing" secondItem="VxO-Mp-NxI" secondAttribute="trailing" constant="16" id="cqe-Rw-f8d"/>
</constraints>
<point key="canvasLocation" x="25.5" y="-79.5"/>
</view>
</objects>
</document>
Loading

0 comments on commit 294601f

Please sign in to comment.