cleanup constraint based layout

pull/1/head
Michael Kirk 8 years ago committed by sdkjfhsdkjhfsdlkjhfsdf
parent 3a078c831d
commit 26be69975a

@ -222,7 +222,7 @@ public class AttachmentApprovalViewController: OWSViewController, MessagingToolb
override public var inputAccessoryView: UIView? { override public var inputAccessoryView: UIView? {
self.bottomToolbar.layoutIfNeeded() self.bottomToolbar.layoutIfNeeded()
return self.bottomToolbarO return self.bottomToolbar
// let toolbar = UIView(frame: CGRect(origin: CGPoint.zero, size: CGSize(width: 50, height: 100))) // let toolbar = UIView(frame: CGRect(origin: CGPoint.zero, size: CGSize(width: 50, height: 100)))
// toolbar.backgroundColor = UIColor.purple // toolbar.backgroundColor = UIColor.purple
// return toolbar // return toolbar
@ -477,10 +477,12 @@ class MessagingToolbar: UIView, UITextViewDelegate {
// //
// // toolbar doesn't render without some minimum height set. // // toolbar doesn't render without some minimum height set.
// // self.heightConstraint = self.autoSetDimension(.height, // // self.heightConstraint = self.autoSetDimension(.height,
self.autoSetDimension(.height, // self.autoSetDimension(.height,
toSize: kMinTextViewHeight + kToolbarMargin * 2, // toSize: kMinTextViewHeight + kToolbarMargin * 2,
relation: .greaterThanOrEqual) // relation: .greaterThanOrEqual)
// //
self.autoMatch(.height, to: .height, of: textView, withMultiplier:1, relation: .greaterThanOrEqual)
// Adding textView to a toolbar item inserts it into a "hostView" // Adding textView to a toolbar item inserts it into a "hostView"
// This isn't really documentd, but I've verified it works on iOS9 and iOS10 // This isn't really documentd, but I've verified it works on iOS9 and iOS10
self.textViewHeightConstraint = textView.autoSetDimension(.height, toSize: kMinTextViewHeight) self.textViewHeightConstraint = textView.autoSetDimension(.height, toSize: kMinTextViewHeight)
@ -514,36 +516,36 @@ class MessagingToolbar: UIView, UITextViewDelegate {
let fixedWidth = textView.frame.size.width let fixedWidth = textView.frame.size.width
let newSize = textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude)) let newSize = textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude))
// let newToolbarHeight = Clamp(newSize.height, kMinTextViewHeight, kMaxTextViewHeight)
// let newHeight = newToolbarHeight + kTextViewPadding * 2
let newHeight = Clamp(newSize.height, kMinTextViewHeight, kMaxTextViewHeight) let newHeight = Clamp(newSize.height, kMinTextViewHeight, kMaxTextViewHeight)
if newHeight != self.textViewHeightConstraint.constant { if newHeight != self.textViewHeightConstraint.constant {
Logger.debug("\(self.logTag) oldHeight: \(self.textViewHeightConstraint.constant), newHeight: \(newHeight)") Logger.debug("\(self.logTag) oldHeight: \(self.textViewHeightConstraint.constant), newHeight: \(newHeight)")
self.textViewHeightConstraint.constant = newHeight self.textViewHeightConstraint.constant = newHeight
self.textView.frame = CGRect(x: 0, y: 0, width: self.textView.frame.size.width, height: newHeight)
// UIView.animate(withDuration: 0.1) { // UIView.animate(withDuration: 0.1) {
self.setNeedsLayout() self.setNeedsLayout()
self.layoutIfNeeded() self.layoutIfNeeded()
// } self.textView.reloadInputViews()
} else { } else {
Logger.debug("\(self.logTag) height unchanged: \(self.textViewHeightConstraint.constant)") Logger.debug("\(self.logTag) height unchanged: \(self.textViewHeightConstraint.constant)")
} }
// if newHeight < kMaxTextViewHeight {
// // Sometimes when growing the textView, content can be offset
// textView.contentOffset = CGPoint.zero
// textView.isScrollEnabled = false
// } else {
// textView.isScrollEnabled = true
// }
} }
override func layoutSubviews() { override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
Logger.info("\(self.logTag) in \(#function)") Logger.info("\(self.logTag) in \(#function)")
Logger.info("textView: \(self.textView.frame), sendButton:\(sendButton)") Logger.info("textView: \(self.textView.frame), sendButton:\(sendButton.frame)")
// Updating the autoLayout constraints was not sufficient to properly set the frame of the inputAccessoryView,
// so we manually update the relevant frames here.
let originalTextViewFrame = self.textView.frame
let newTextViewFrame = CGRect(x: originalTextViewFrame.origin.x, y: originalTextViewFrame.origin.y, width: originalTextViewFrame.width, height: self.textViewHeightConstraint.constant)
self.textView.frame = newTextViewFrame
let diffY = newTextViewFrame.height - originalTextViewFrame.height
let originalFrame = self.frame
let newFrame = CGRect(x: originalFrame.origin.x, y: originalFrame.origin.y - diffY, width: originalFrame.width, height: originalFrame.size.height + diffY)
self.frame = newFrame
// //
// let kMargin = 4 // let kMargin = 4

Loading…
Cancel
Save