Skip to content

Commit

Permalink
Merge pull request #20 from JNDisrupter/inital-text-renders-with-plac…
Browse files Browse the repository at this point in the history
…eholder-fix

Initial text renders with placeholder (Bug fix):
  • Loading branch information
jayelzaghmoutt authored May 27, 2024
2 parents 7611cbb + f143249 commit d9aebd8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
4 changes: 2 additions & 2 deletions JNMentionTextView.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "JNMentionTextView"
s.version = "1.0.2"
s.version = "1.0.3"
s.summary = "JNMentionTextView is a UITextView replacement supporting the mention feature for iOS applications."
s.description = "A UITextView drop-in replacement supporting special characters such as [ #, @ ] and regex patterns, written in Swift."
s.homepage = "https://github.com/JNDisrupter"
Expand All @@ -10,7 +10,7 @@ Pod::Spec.new do |s|

s.platform = :ios
s.platform = :ios, "11.0"
s.swift_versions = ['5.8', '5.8.1']
s.swift_versions = ['5.10']
s.source = { :git => "https://github.com/JNDisrupter/JNMentionTextView.git", :tag => "#{s.version}" }
s.source_files = "JNMentionTextView/**/*.{swift}"
end
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ extension JNMentionTextView: UITextViewDelegate {
self.mentionDelegate?.textViewDidChange?(textView)

// Update placeholder label visibility
self.showPlaceholder(textView.text.isEmpty)
self.updatePlaceholderVisibility()
}

/**
Expand All @@ -195,7 +195,7 @@ extension JNMentionTextView: UITextViewDelegate {
self.mentionDelegate?.textViewDidBeginEditing?(textView)

// Update placeholder label visibility
self.showPlaceholder(textView.text.isEmpty)
self.updatePlaceholderVisibility()
}

/**
Expand All @@ -209,7 +209,7 @@ extension JNMentionTextView: UITextViewDelegate {
}

// Update placeholder label visibility
self.showPlaceholder(textView.text.isEmpty)
self.updatePlaceholderVisibility()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ public class JNMentionTextView: UITextView {
}
}

/// Text
override open var text: String! {
didSet {
self.updatePlaceholderVisibility()
}
}

/// Attributed text
override open var attributedText: NSAttributedString! {
didSet {
self.updatePlaceholderVisibility()
}
}

/// Font
public override var font: UIFont? {
didSet {
Expand Down Expand Up @@ -179,10 +193,26 @@ public class JNMentionTextView: UITextView {
}

/**
Update placeholder label visibility
Update placeholder visibility
*/
public func showPlaceholder(_ show: Bool) {
self.placeholderLabel?.isHidden = !show
func updatePlaceholderVisibility() {
guard self.placeholderLabel != nil else { return }

// Is placeholder hidden
var isPlaceholderLabelHidden = true

// Check if there's a placeholder
// AND value text is empty
if let placeholder = self.placeHolder,
!placeholder.isEmpty,
self.text.isEmpty,
self.attributedText.string.isEmpty {

isPlaceholderLabelHidden = false
}

// Update placeholder label visibility
self.placeholderLabel?.isHidden = isPlaceholderLabelHidden
}

/**
Expand Down Expand Up @@ -212,6 +242,9 @@ public class JNMentionTextView: UITextView {

// Add subview
self.addSubview(self.placeholderLabel!)

// Update placeholder label visibility
self.updatePlaceholderVisibility()
}

/**
Expand Down

0 comments on commit d9aebd8

Please sign in to comment.