Skip to content

Commit bb824aa

Browse files
authored
Merge pull request #179 from firebase/swift-auth-customization
implement swift auth customization controllers
2 parents 7883877 + 294601f commit bb824aa

16 files changed

+1253
-48
lines changed

samples/swift/FirebaseUI-demo-swift.xcodeproj/project.pbxproj

Lines changed: 79 additions & 25 deletions
Large diffs are not rendered by default.

samples/swift/FirebaseUI-demo-swift/Base.lproj/Main.storyboard

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,6 @@
189189
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
190190
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
191191
<color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
192-
<toolbar key="tableFooterView" opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="jjI-5e-RC1">
193-
<rect key="frame" x="0.0" y="521" width="375" height="44"/>
194-
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
195-
<items>
196-
<barButtonItem style="plain" systemItem="flexibleSpace" id="K12-RU-Zfz"/>
197-
<barButtonItem title="Sign In" id="E21-cP-Dhb">
198-
<connections>
199-
<action selector="onAuthorize:" destination="wby-P6-pid" id="oxf-0Q-Hdd"/>
200-
</connections>
201-
</barButtonItem>
202-
<barButtonItem style="plain" systemItem="flexibleSpace" id="G4L-Vb-g3u"/>
203-
</items>
204-
</toolbar>
205192
<sections>
206193
<tableViewSection headerTitle="Is signed-in" id="0Pr-Kf-qkL">
207194
<cells>
@@ -213,12 +200,35 @@
213200
<autoresizingMask key="autoresizingMask"/>
214201
</tableViewCellContentView>
215202
</tableViewCell>
203+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="BRB-gO-zrn">
204+
<rect key="frame" x="0.0" y="100" width="375" height="44"/>
205+
<autoresizingMask key="autoresizingMask"/>
206+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="BRB-gO-zrn" id="TDE-FU-8Jx">
207+
<frame key="frameInset" width="375" height="43"/>
208+
<autoresizingMask key="autoresizingMask"/>
209+
<subviews>
210+
<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">
211+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
212+
<nil key="textColor"/>
213+
<nil key="highlightedColor"/>
214+
</label>
215+
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="VRw-wD-ISl"/>
216+
</subviews>
217+
<constraints>
218+
<constraint firstItem="VRw-wD-ISl" firstAttribute="trailing" secondItem="TDE-FU-8Jx" secondAttribute="trailingMargin" id="0Z0-vA-fKp"/>
219+
<constraint firstItem="gGt-QN-wFM" firstAttribute="centerY" secondItem="TDE-FU-8Jx" secondAttribute="centerY" id="2Zh-8c-ssE"/>
220+
<constraint firstItem="VRw-wD-ISl" firstAttribute="leading" secondItem="gGt-QN-wFM" secondAttribute="trailing" constant="8" symbolic="YES" id="CBU-uW-rUA"/>
221+
<constraint firstItem="gGt-QN-wFM" firstAttribute="centerY" secondItem="VRw-wD-ISl" secondAttribute="centerY" id="VaB-k3-6Gg"/>
222+
<constraint firstItem="gGt-QN-wFM" firstAttribute="leading" secondItem="TDE-FU-8Jx" secondAttribute="leadingMargin" id="dqn-H7-od1"/>
223+
</constraints>
224+
</tableViewCellContentView>
225+
</tableViewCell>
216226
</cells>
217227
</tableViewSection>
218228
<tableViewSection headerTitle="Name" id="Jho-f6-Urp">
219229
<cells>
220230
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="mXf-Qr-aGq">
221-
<rect key="frame" x="0.0" y="140" width="375" height="44"/>
231+
<rect key="frame" x="0.0" y="184" width="375" height="44"/>
222232
<autoresizingMask key="autoresizingMask"/>
223233
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="mXf-Qr-aGq" id="VWa-qt-FWa">
224234
<frame key="frameInset" width="375" height="43"/>
@@ -230,7 +240,7 @@
230240
<tableViewSection headerTitle="e-mail" id="Acz-Do-HDT">
231241
<cells>
232242
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="IjQ-eL-x0N">
233-
<rect key="frame" x="0.0" y="224" width="375" height="44"/>
243+
<rect key="frame" x="0.0" y="268" width="375" height="44"/>
234244
<autoresizingMask key="autoresizingMask"/>
235245
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="IjQ-eL-x0N" id="kVz-NE-XOf">
236246
<frame key="frameInset" width="375" height="43"/>
@@ -242,7 +252,7 @@
242252
<tableViewSection headerTitle="UID" id="kdc-iI-3Bd">
243253
<cells>
244254
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="S6s-Qd-Z3i">
245-
<rect key="frame" x="0.0" y="308" width="375" height="44"/>
255+
<rect key="frame" x="0.0" y="352" width="375" height="44"/>
246256
<autoresizingMask key="autoresizingMask"/>
247257
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="S6s-Qd-Z3i" id="3tB-Th-rk9">
248258
<frame key="frameInset" width="375" height="43"/>
@@ -254,7 +264,7 @@
254264
<tableViewSection headerTitle="Provider Access Token" id="TTf-7r-Kld">
255265
<cells>
256266
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="NKE-io-hSe" style="IBUITableViewCellStyleDefault" id="BZ9-c2-MUK">
257-
<rect key="frame" x="0.0" y="392" width="375" height="44"/>
267+
<rect key="frame" x="0.0" y="436" width="375" height="44"/>
258268
<autoresizingMask key="autoresizingMask"/>
259269
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="BZ9-c2-MUK" id="AuA-sR-YEx">
260270
<frame key="frameInset" width="375" height="43"/>
@@ -275,7 +285,7 @@
275285
<tableViewSection headerTitle="Provider Id Token" id="i6h-Na-zzy">
276286
<cells>
277287
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="RB6-Yv-KVG" style="IBUITableViewCellStyleDefault" id="LmG-vd-Xzu">
278-
<rect key="frame" x="0.0" y="476" width="375" height="44"/>
288+
<rect key="frame" x="0.0" y="520" width="375" height="44"/>
279289
<autoresizingMask key="autoresizingMask"/>
280290
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="LmG-vd-Xzu" id="b7z-I4-euc">
281291
<frame key="frameInset" width="375" height="43"/>
@@ -299,14 +309,25 @@
299309
<outlet property="delegate" destination="wby-P6-pid" id="mHK-Jc-sWw"/>
300310
</connections>
301311
</tableView>
312+
<toolbarItems>
313+
<barButtonItem style="plain" systemItem="flexibleSpace" id="K12-RU-Zfz"/>
314+
<barButtonItem title="Sign In" id="E21-cP-Dhb">
315+
<connections>
316+
<action selector="onAuthorize:" destination="wby-P6-pid" id="oxf-0Q-Hdd"/>
317+
</connections>
318+
</barButtonItem>
319+
<barButtonItem style="plain" systemItem="flexibleSpace" id="G4L-Vb-g3u"/>
320+
</toolbarItems>
321+
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
302322
<connections>
303-
<outlet property="btnAuthorization" destination="E21-cP-Dhb" id="kvE-qq-41P"/>
323+
<outlet property="authorizationButton" destination="E21-cP-Dhb" id="nfv-XO-h5O"/>
304324
<outlet property="cellAccessToken" destination="BZ9-c2-MUK" id="xAH-KT-gy8"/>
305325
<outlet property="cellEmail" destination="IjQ-eL-x0N" id="zbw-rM-wNs"/>
306326
<outlet property="cellIdToken" destination="LmG-vd-Xzu" id="JZp-g3-bNl"/>
307327
<outlet property="cellName" destination="mXf-Qr-aGq" id="2Xi-HM-i86"/>
308328
<outlet property="cellSignedIn" destination="6vu-5U-WfK" id="29e-eN-Uzk"/>
309329
<outlet property="cellUid" destination="S6s-Qd-Z3i" id="exG-YI-qfx"/>
330+
<outlet property="customAuthorizationSwitch" destination="VRw-wD-ISl" id="yWY-Tz-wLP"/>
310331
</connections>
311332
</tableViewController>
312333
<placeholder placeholderIdentifier="IBFirstResponder" id="24p-6G-GD4" userLabel="First Responder" sceneMemberID="firstResponder"/>
@@ -377,7 +398,7 @@
377398
<objects>
378399
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="jBB-7b-HHb" sceneMemberID="viewController">
379400
<toolbarItems/>
380-
<navigationBar key="navigationBar" contentMode="scaleToFill" misplaced="YES" id="bRD-Ca-0aK">
401+
<navigationBar key="navigationBar" contentMode="scaleToFill" id="bRD-Ca-0aK">
381402
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
382403
<autoresizingMask key="autoresizingMask"/>
383404
</navigationBar>

samples/swift/FirebaseUI-demo-swift/Samples/Auth/FIRAuthViewController.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class FIRAuthViewController: UITableViewController {
3434

3535
fileprivate(set) var auth: FIRAuth? = FIRAuth.auth()
3636
fileprivate(set) var authUI: FIRAuthUI? = FIRAuthUI.default()
37+
fileprivate(set) var customAuthUIDelegate: FIRAuthUIDelegate = FIRCustomAuthUIDelegate()
3738

3839
@IBOutlet weak var cellSignedIn: UITableViewCell!
3940
@IBOutlet weak var cellName: UITableViewCell!
@@ -42,7 +43,8 @@ class FIRAuthViewController: UITableViewController {
4243
@IBOutlet weak var cellAccessToken: UITableViewCell!
4344
@IBOutlet weak var cellIdToken: UITableViewCell!
4445

45-
@IBOutlet weak var btnAuthorization: UIBarButtonItem!
46+
@IBOutlet weak var authorizationButton: UIBarButtonItem!
47+
@IBOutlet weak var customAuthorizationSwitch: UISwitch!
4648

4749

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

6567
self.authStateDidChangeHandle =
6668
self.auth?.addStateDidChangeListener(self.updateUI(auth:user:))
69+
70+
self.navigationController?.isToolbarHidden = false;
6771
}
6872

6973
override func viewWillDisappear(_ animated: Bool) {
7074
super.viewWillDisappear(animated)
7175
if let handle = self.authStateDidChangeHandle {
7276
self.auth?.removeStateDidChangeListener(handle)
7377
}
78+
79+
self.navigationController?.isToolbarHidden = true;
7480
}
7581

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

9197
} else {
98+
self.authUI?.delegate = self.customAuthorizationSwitch.isOn ? self.customAuthUIDelegate : nil;
99+
92100
let controller = self.authUI!.authViewController()
101+
controller.navigationBar.isHidden = self.customAuthorizationSwitch.isOn
93102
self.present(controller, animated: true, completion: nil)
94103
}
95104
}
@@ -102,14 +111,14 @@ class FIRAuthViewController: UITableViewController {
102111
self.cellEmail.textLabel?.text = user.email ?? "(null)"
103112
self.cellUid.textLabel?.text = user.uid
104113

105-
self.btnAuthorization.title = "Sign Out";
114+
self.authorizationButton.title = "Sign Out";
106115
} else {
107116
self.cellSignedIn.textLabel?.text = "Not signed in"
108117
self.cellName.textLabel?.text = "null"
109118
self.cellEmail.textLabel?.text = "null"
110119
self.cellUid.textLabel?.text = "null"
111120

112-
self.btnAuthorization.title = "Sign In";
121+
self.authorizationButton.title = "Sign In";
113122
}
114123

115124
self.cellAccessToken.textLabel?.text = getAllAccessTokens()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// Copyright (c) 2016 Google Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
import UIKit
18+
import FirebaseAuthUI
19+
20+
@objc(FIRCustomAuthPickerViewController)
21+
22+
class FIRCustomAuthPickerViewController: FIRAuthPickerViewController {
23+
24+
@IBAction func onClose(_ sender: AnyObject) {
25+
self.cancelAuthorization()
26+
}
27+
28+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<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">
3+
<dependencies>
4+
<deployment identifier="iOS"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
6+
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
7+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
8+
</dependencies>
9+
<objects>
10+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="FIRCustomAuthPickerViewController" customModule="FirebaseUI_demo_swift" customModuleProvider="target">
11+
<connections>
12+
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
13+
</connections>
14+
</placeholder>
15+
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
16+
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
17+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
18+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19+
<subviews>
20+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="VxO-Mp-NxI">
21+
<color key="backgroundColor" name="selectedKnobColor" catalog="System" colorSpace="catalog"/>
22+
<state key="normal" title="Cancel">
23+
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
24+
</state>
25+
<connections>
26+
<action selector="onClose:" destination="-1" eventType="touchUpInside" id="oXy-b9-wIa"/>
27+
</connections>
28+
</button>
29+
</subviews>
30+
<color key="backgroundColor" name="knobColor" catalog="System" colorSpace="catalog"/>
31+
<constraints>
32+
<constraint firstItem="VxO-Mp-NxI" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leadingMargin" id="0gC-XW-7T5"/>
33+
<constraint firstItem="VxO-Mp-NxI" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" constant="109" id="Sej-IC-Sc9"/>
34+
<constraint firstAttribute="trailing" secondItem="VxO-Mp-NxI" secondAttribute="trailing" constant="16" id="cqe-Rw-f8d"/>
35+
</constraints>
36+
<point key="canvasLocation" x="25.5" y="-79.5"/>
37+
</view>
38+
</objects>
39+
</document>

0 commit comments

Comments
 (0)