Skip to content

Commit

Permalink
[Sources] [RSKGrowingTextView] Handle `UITextView.textDidChangeNotifi…
Browse files Browse the repository at this point in the history
…cation`.

Fixes #18.
  • Loading branch information
ruslanskorb committed Jul 18, 2019
1 parent 11d40da commit 86d60c1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions RSKGrowingTextView/RSKGrowingTextView.swift
Expand Up @@ -180,6 +180,11 @@ public typealias HeightChangeUserActionsBlockType = ((_ oldHeight: CGFloat, _ ne

// MARK: - Object Lifecycle

deinit {

NotificationCenter.default.removeObserver(self, name: UITextView.textDidChangeNotification, object: self)
}

required public init?(coder aDecoder: NSCoder) {
calculationLayoutManager.addTextContainer(calculationTextContainer)
super.init(coder: aDecoder)
Expand All @@ -192,6 +197,13 @@ public typealias HeightChangeUserActionsBlockType = ((_ oldHeight: CGFloat, _ ne
commonInitializer()
}

// MARK: - Actions

@objc private func handleRSKGrowingTextViewTextDidChangeNotification(_ notification: Notification) {

refreshHeightIfNeededAnimated(animateHeightChange)
}

// MARK: - Private API

private func commonInitializer() {
Expand All @@ -206,6 +218,8 @@ public typealias HeightChangeUserActionsBlockType = ((_ oldHeight: CGFloat, _ ne
break
}
}

NotificationCenter.default.addObserver(self, selector: #selector(RSKGrowingTextView.handleRSKGrowingTextViewTextDidChangeNotification(_:)), name: UITextView.textDidChangeNotification, object: self)
}

private func heightForNumberOfLines(_ numberOfLines: Int) -> CGFloat {
Expand Down

0 comments on commit 86d60c1

Please sign in to comment.