Skip to content

Commit

Permalink
Remove canBecomeFirstResponder on InputTextView to fix `UITextVie…
Browse files Browse the repository at this point in the history
…wDelegate` methods not being called
  • Loading branch information
Kaspik committed Oct 25, 2022
1 parent 0c4431a commit 039a9cb
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog
- Master:
- Nothing yet
- 6.2.0
- Remove `canBecomeFirstResponder` on `InputTextView` to fix `UITextViewDelegate` methods not being called
- 6.1.1
- Fixed warning for Xcode 14
- 6.1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,11 @@ final class AdditionalBottomSpaceExampleViewController: CommonTableViewControlle

/// This replicates instagram's behavior when commenting in a post. As of 2020-09, it appears like they have one of the best product experiences of this handling the keyboard when dismissing the UIViewController
self.inputBar.inputTextView.resignFirstResponder()
/// This is set because otherwise, if only partially dragging the left edge of the screen, and then cancelling the dismissal, on viewDidAppear UIKit appears to set the first responder back to the inputTextView (https://stackoverflow.com/a/41847448)
self.inputBar.inputTextView.canBecomeFirstResponder = false
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

/// The opposite of `viewWillDisappear(_:)`
self.inputBar.inputTextView.canBecomeFirstResponder = true
self.inputBar.inputTextView.becomeFirstResponder()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,12 @@ final class SubviewExampleViewController: CommonTableViewController {

/// This replicates instagram's behavior when commenting in a post. As of 2020-09, it appears like they have one of the best product experiences of this handling the keyboard when dismissing the UIViewController
self.inputBar.inputTextView.resignFirstResponder()
/// This is set because otherwise, if only partially dragging the left edge of the screen, and then cancelling the dismissal, on viewDidAppear UIKit appears to set the first responder back to the inputTextView (https://stackoverflow.com/a/41847448)
self.inputBar.inputTextView.canBecomeFirstResponder = false
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

/// The opposite of `viewWillDisappear(_:)`
self.inputBar.inputTextView.canBecomeFirstResponder = true
self.inputBar.inputTextView.becomeFirstResponder()
}

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ Add your app to the list of apps using this library and make a pull request.
iMessage style [TypingIndicator](https://github.com/nathantannar4/TypingIndicator) for chat apps

## Latest Releases
6.2.0
- Remove `canBecomeFirstResponder` on `InputTextView` to fix `UITextViewDelegate` methods not being called

6.1.1
- Fixed warning for Xcode 14

Expand Down
6 changes: 0 additions & 6 deletions Sources/Views/InputTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ open class InputTextView: UITextView {

open var isImagePasteEnabled: Bool = true

private var canBecomeFirstResponderStorage: Bool = true
open override var canBecomeFirstResponder: Bool {
get { canBecomeFirstResponderStorage }
set(newValue) { canBecomeFirstResponderStorage = newValue }
}

/// A UILabel that holds the InputTextView's placeholder text
public let placeholderLabel: UILabel = {
let label = UILabel()
Expand Down

0 comments on commit 039a9cb

Please sign in to comment.