Skip to content

Commit

Permalink
Merge pull request #2 from shakurocom/II-16-add_accessibility
Browse files Browse the repository at this point in the history
Ii 16 add accessibility
  • Loading branch information
EugenDevIOS authored Jan 24, 2023
2 parents 3012c68 + 29abaaa commit 2b659a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Shakuro.PlaceholderTextView.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = 'Shakuro.PlaceholderTextView'
s.version = '1.0.0'
s.version = '1.0.1'
s.summary = 'PlaceholderTextView'
s.homepage = 'https://github.com/shakurocom/PlaceholderTextView'
s.license = { :type => "MIT", :file => "LICENSE.md" }
Expand Down
16 changes: 16 additions & 0 deletions Source/PlaceholderTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class PlaceholderTextView: UITextView {
placeholderTextView.text = newValue
invalidateIntrinsicContentSize()
updatePlaceholder()
setupAccessibility()
}
}

Expand All @@ -66,6 +67,7 @@ public class PlaceholderTextView: UITextView {
placeholderTextView.attributedText = newValue
invalidateIntrinsicContentSize()
updatePlaceholder()
setupAccessibility()
}
}

Expand All @@ -83,12 +85,14 @@ public class PlaceholderTextView: UITextView {
override public var text: String! {
didSet {
updatePlaceholder()
setupAccessibility()
}
}

override public var attributedText: NSAttributedString! {
didSet {
updatePlaceholder()
setupAccessibility()
}
}

Expand Down Expand Up @@ -207,6 +211,17 @@ public class PlaceholderTextView: UITextView {
return placeholder
}()

private func setupAccessibility() {
placeholderTextView.isAccessibilityElement = false
placeholderTextView.accessibilityElementsHidden = true
if placeholderTextView.alpha > 0 && placeholderTextView.superview != nil,
let text = placeholderTextView.text, !text.isEmpty {
accessibilityLabel = text
} else {
accessibilityLabel = nil
}
}

}

private extension PlaceholderTextView {
Expand All @@ -227,6 +242,7 @@ private extension PlaceholderTextView {
})
}
updatePlaceholder()
setupAccessibility()
updateTextWithLimit()
textDidChange?(text)
}
Expand Down

0 comments on commit 2b659a7

Please sign in to comment.