Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed retain issues between presenter and views #355

Merged
merged 2 commits into from
Dec 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lock/AuthStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import UIKit

/// Style for AuthButton
public class AuthStyle {
public struct AuthStyle {

/// Name that will be used for titles. e.g. 'Login with Auth0'
let name: String
Expand Down Expand Up @@ -52,7 +52,7 @@ public class AuthStyle {

- returns: a new style
*/
public convenience init(name: String, color: UIColor = UIColor.a0_orange, foregroundColor: UIColor = .white, withImage image: LazyImage = LazyImage(name: "ic_auth_auth0", bundle: bundleForLock())) {
public init(name: String, color: UIColor = UIColor.a0_orange, foregroundColor: UIColor = .white, withImage image: LazyImage = LazyImage(name: "ic_auth_auth0", bundle: bundleForLock())) {
self.init(name: name, normalColor: color, highlightedColor: color.a0_darker(0.3), foregroundColor: foregroundColor, withImage: image)
}

Expand Down
4 changes: 2 additions & 2 deletions Lock/DatabaseForgotPasswordPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class DatabaseForgotPasswordPresenter: Presentable, Loggable {
input.showError()
}
}
let action = { (button: PrimaryButton) in
let action = { [weak form] (button: PrimaryButton) in
self.messagePresenter?.hideCurrent()
self.logger.info("request forgot password for email \(self.interactor.email)")
let interactor = self.interactor
Expand All @@ -73,7 +73,7 @@ class DatabaseForgotPasswordPresenter: Presentable, Loggable {
}
}
view.primaryButton?.onPress = action
view.form?.onReturn = {_ in
view.form?.onReturn = { [unowned view] _ in
guard let button = view.primaryButton else { return }
action(button)
}
Expand Down
12 changes: 6 additions & 6 deletions Lock/DatabaseOnlyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,21 @@ class DatabaseOnlyView: UIView, DatabaseView {

passwordPolicyView.isHidden = true
form.passwordField.errorLabel?.removeFromSuperview()
form.passwordField.onBeginEditing = { [unowned passwordPolicyView] _ in
form.passwordField.onBeginEditing = { _ in
passwordPolicyView.isHidden = false
}
form.passwordField.onEndEditing = { [unowned passwordPolicyView] _ in
form.passwordField.onEndEditing = { _ in
passwordPolicyView.isHidden = true
}

form.emailField.onReturn = { [unowned form, unowned passwordPolicyView] _ in
if form.emailField.nextField == form.passwordField {
form.emailField.onReturn = { [weak form] _ in
if form?.emailField.nextField == form?.passwordField {
self.navigator?.scroll(toPosition: CGPoint(x: 0, y: passwordPolicyView.intrinsicContentSize.height), animated: true)
}
}

form.usernameField?.onReturn = { [unowned form, unowned passwordPolicyView] _ in
if form.usernameField?.nextField == form.passwordField {
form.usernameField?.onReturn = { [weak form] _ in
if form?.usernameField?.nextField == form?.passwordField {
self.navigator?.scroll(toPosition: CGPoint(x: 0, y: passwordPolicyView.intrinsicContentSize.height), animated: true)
}
}
Expand Down
7 changes: 4 additions & 3 deletions Lock/DatabasePresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class DatabasePresenter: Presentable, Loggable {
let allow = self.options.allow
let database = DatabaseOnlyView(allowedModes: allow)
database.navigator = self.navigator
database.switcher?.onSelectionChange = { [weak database] switcher in
database.switcher?.onSelectionChange = { [unowned self, weak database] switcher in
let selected = switcher.selected
guard let view = database else { return }
self.logger.debug("selected \(selected)")
Expand Down Expand Up @@ -130,8 +130,9 @@ class DatabasePresenter: Presentable, Loggable {

}

view.form?.onReturn = { field in
guard let button = view.primaryButton, field.returnKey == .done else { return } // FIXME: Log warn
let primaryButton = view.primaryButton
view.form?.onReturn = { [weak primaryButton] field in
guard let button = primaryButton, field.returnKey == .done else { return } // FIXME: Log warn
action(button)
}
view.primaryButton?.onPress = action
Expand Down
4 changes: 2 additions & 2 deletions Lock/EnterpriseActiveAuthPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class EnterpriseActiveAuthPresenter: Presentable, Loggable {
}
}

let action = { (button: PrimaryButton) in
let action = { [weak form] (button: PrimaryButton) in
self.messagePresenter?.hideCurrent()
self.logger.info("Enterprise password connection started: \(self.interactor.identifier), \(self.interactor.connection)")
let interactor = self.interactor
Expand All @@ -87,7 +87,7 @@ class EnterpriseActiveAuthPresenter: Presentable, Loggable {
}

view.primaryButton?.onPress = action
view.form?.onReturn = {_ in
view.form?.onReturn = { [unowned view] _ in
guard let button = view.primaryButton else { return }
action(button)
}
Expand Down
6 changes: 3 additions & 3 deletions Lock/EnterpriseDomainPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class EnterpriseDomainPresenter: Presentable, Loggable {
let form = view.form

view.ssoBar?.isHidden = self.interactor.connection == nil
view.form?.onValueChange = { input in
view.form?.onValueChange = { [unowned view ] input in
self.messagePresenter?.hideCurrent()
view.ssoBar?.isHidden = true

Expand All @@ -85,7 +85,7 @@ class EnterpriseDomainPresenter: Presentable, Loggable {
}
}

let action = { (button: PrimaryButton) in
let action = { [weak form] (button: PrimaryButton) in
// Check for credential auth
if let connection = self.interactor.connection, self.options.enterpriseConnectionUsingActiveAuth.contains(connection.name) {
guard self.navigator?.navigate(.enterpriseActiveAuth(connection: connection)) == nil else { return }
Expand All @@ -112,7 +112,7 @@ class EnterpriseDomainPresenter: Presentable, Loggable {
}

view.primaryButton?.onPress = action
view.form?.onReturn = {_ in
view.form?.onReturn = { [unowned view] _ in
guard let button = view.primaryButton else { return }
action(button)
}
Expand Down
4 changes: 2 additions & 2 deletions Lock/MultifactorPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MultifactorPresenter: Presentable, Loggable {
input.showError()
}
}
let action = { (button: PrimaryButton) in
let action = { [weak form] (button: PrimaryButton) in
self.messagePresenter?.hideCurrent()
self.logger.debug("resuming with mutifactor code \(self.interactor.code)")
let interactor = self.interactor
Expand All @@ -68,7 +68,7 @@ class MultifactorPresenter: Presentable, Loggable {
}
}
}
view.form?.onReturn = { _ in
view.form?.onReturn = { [unowned view]_ in
guard let button = view.primaryButton else { return }
action(button)
}
Expand Down