Skip to content

Commit 4bb6fc2

Browse files
authored
Lay out a short Article draft like a line of text in the composer (#187)
* Lay out a short Article draft like a line of text in the composer A one-line draft made the input field about 8 pt taller than a line of text, so the send button was no longer centered, and the expand button sat under the send button until the draft reached four lines. The field now keeps the one-line height while the draft fits it, and the expand button takes the emoji button's slot next to the send button when there is no room above it. * Keep plain text layout and grow a short draft's field smoothly Move the expand button next to the send button only while an Article draft is shown, so it can't cover the visible emoji button of a 4-line text input at small font sizes, and shrink the draft's empty insets gradually instead of jumping from the one-line height to the full measured height.
1 parent 6591a1b commit 4bb6fc2

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

‎packages/ChatUI/Sources/ChatUI/ChatInputView.swift‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,17 @@ public final class ChatInputContainerView: FlippableView {
211211
accessory.isVisibility() ? 10 + accessory.size.height : 0
212212
}
213213

214+
fileprivate var richDraftSlotHeight: CGFloat {
215+
let minHeight = CGFloat(textView.min_height)
216+
let draftHeight = richDraftPreviewHeight - RichTextDraftPreviewView.vInset * 2
217+
return max(minHeight, min(richDraftPreviewHeight, draftHeight * 2 - minHeight))
218+
}
219+
214220
public func contentHeight(for width: CGFloat) -> CGFloat {
215221
// A rich draft stands IN PLACE of the text (it looks like the entered content), so it replaces the
216222
// text's base height rather than stacking above an empty field.
217223
if richDraftPreviewHeight > 0 {
218-
return max(richDraftPreviewHeight, CGFloat(textView.min_height)) + accessoryHeight
224+
return richDraftSlotHeight + accessoryHeight
219225
}
220226
let base = (chatState == .normal || chatState == .editing) ? textViewSize(width).0.height : CGFloat(textView.min_height)
221227
return base + accessoryHeight
@@ -269,8 +275,7 @@ public final class ChatInputContainerView: FlippableView {
269275
// doesn't flash at the origin before the next layout pass.
270276
let sendAsInset: CGFloat = sendAsView != nil ? 34 + 3 : 0
271277
let textLeftInset: CGFloat = 12 + sendAsInset
272-
let slot = max(richDraftPreviewHeight, CGFloat(textView.min_height))
273-
let previewY = accessoryHeight + (slot - richDraftPreviewHeight) / 2
278+
let previewY = accessoryHeight + (richDraftSlotHeight - richDraftPreviewHeight) / 2
274279
current.frame = NSMakeRect(textLeftInset, previewY, width, richDraftPreviewHeight)
275280
}
276281
} else if let view = richDraftPreview {
@@ -490,8 +495,7 @@ public final class ChatInputContainerView: FlippableView {
490495
}
491496
}
492497
textView.isHidden = true
493-
let slot = max(richDraftPreviewHeight, CGFloat(textView.min_height))
494-
let previewY = textY + (slot - richDraftPreviewHeight) / 2
498+
let previewY = textY + (richDraftSlotHeight - richDraftPreviewHeight) / 2
495499
transition.updateFrame(view: preview, frame: NSMakeRect(textLeftInset, previewY, textSize.width, richDraftPreviewHeight))
496500
} else {
497501
textView.isHidden = false
@@ -519,7 +523,14 @@ public final class ChatInputContainerView: FlippableView {
519523
}
520524
let bs = current.frame.size
521525
let sendColumnMidX = containerWidth - ChatInputSendButton.fieldInset - sendWidth / 2
522-
let frame = NSMakeRect(sendColumnMidX - bs.width / 2, accessoryHeight + 8, bs.width, bs.height)
526+
let stackedY = accessoryHeight + 8
527+
let frame: NSRect
528+
if richDraftPreview != nil, sendButton.isInField, stackedY + bs.height > contentHeight - sendSize.height {
529+
let slot = actionsView.entertaiments.frame.size
530+
frame = NSMakeRect(fieldContentWidth - (slot.width + bs.width) / 2, contentHeight - (slot.height + bs.height) / 2, bs.width, bs.height)
531+
} else {
532+
frame = NSMakeRect(sendColumnMidX - bs.width / 2, stackedY, bs.width, bs.height)
533+
}
523534
if isNew {
524535
current.frame = frame
525536
} else {

0 commit comments

Comments
 (0)