Skip to content

Commit

Permalink
[Dialogs] Fix UITextView accessory view example
Browse files Browse the repository at this point in the history
Fixing incorrect sizing of accessoryView after returning from 3D Touch
Subclassing UITextView and implementing `systemLayoutSizeFittingSize:` so the alert's accessory view will be sized correctly during layout.

PiperOrigin-RevId: 310577286
  • Loading branch information
galiak11 authored and material-automation committed May 8, 2020
1 parent 4a13f42 commit e9802b3
Showing 1 changed file with 17 additions and 1 deletion.
Expand Up @@ -100,7 +100,7 @@ class DialogsAccessoryExampleViewController: MDCCollectionViewController {

func performTextView() -> MDCAlertController {
let alert = MDCAlertController()
let textView = UITextView()
let textView = DialogTextView()
textView.attributedText = attributedText
textView.font = MDCTypographyScheme().body1
textView.isEditable = false
Expand Down Expand Up @@ -311,3 +311,19 @@ extension DialogsAccessoryExampleViewController {
}

}

/// Custom subclass of UITextView - to avoid resizing issue after 3D touch (b/155127456).
private class DialogTextView: UITextView {

override func systemLayoutSizeFitting(
_ targetSize: CGSize,
withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority,
verticalFittingPriority: UILayoutPriority
) -> CGSize {
return self.sizeThatFits(targetSize)
}

override func systemLayoutSizeFitting(_ targetSize: CGSize) -> CGSize {
return self.sizeThatFits(targetSize)
}
}

0 comments on commit e9802b3

Please sign in to comment.