Skip to content

Commit

Permalink
Added property to enable/disable text input in MessageForm (#451)
Browse files Browse the repository at this point in the history
* Added property to enable/disable text input in MessageForm

* Disabling user interaction when 'inputEnabled' is false

* Bumped version to 1.4.2

* PR comment

* PR comment
  • Loading branch information
pimms authored Jul 9, 2019
1 parent a52d919 commit 5150814
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion FinniversKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'FinniversKit'
s.version = '1.4.1'
s.version = '1.4.2'
s.summary = "FINN's iOS Components"
s.author = 'FINN.no'
s.homepage = 'https://schibsted.frontify.com/d/oCLrx0cypXJM/design-system'
Expand Down
5 changes: 5 additions & 0 deletions Sources/Fullscreen/MessageForm/MessageFormBottomSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public class MessageFormBottomSheet: BottomSheet {

public weak var messageFormDelegate: MessageFormBottomSheetDelegate?

public var inputEnabled: Bool {
get { return messageFormViewController.inputEnabled }
set { messageFormViewController.inputEnabled = newValue }
}

/// This view should be used if you wish to present a toast inside this view controller.
public var toastPresenterView: UIView {
return messageFormViewController.toastPresenterView
Expand Down
17 changes: 17 additions & 0 deletions Sources/Fullscreen/MessageForm/MessageFormView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ class MessageFormView: UIView {
}
}

var inputEnabled: Bool = true {
didSet {
textView.isUserInteractionEnabled = inputEnabled
if inputEnabled {
becomeFirstResponder()
} else {
resignFirstResponder()
}
}
}

// MARK: - Private properties

private let viewModel: MessageFormViewModel
Expand Down Expand Up @@ -75,9 +86,15 @@ class MessageFormView: UIView {

// MARK: - Overrides

@discardableResult
public override func becomeFirstResponder() -> Bool {
return textView.becomeFirstResponder()
}

@discardableResult
public override func resignFirstResponder() -> Bool {
return textView.resignFirstResponder()
}
}

extension MessageFormView: TextViewDelegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class MessageFormViewController: UIViewController {
return messageFormView
}

var inputEnabled: Bool {
get { return messageFormView.inputEnabled }
set { messageFormView.inputEnabled = newValue }
}

// MARK: - Private properties

private let viewModel: MessageFormViewModel
Expand Down

0 comments on commit 5150814

Please sign in to comment.