Skip to content

Commit 8e93744

Browse files
author
Isaac
committed
Input field improvements
1 parent 67ada2a commit 8e93744

File tree

7 files changed

+47
-32
lines changed

7 files changed

+47
-32
lines changed

submodules/TelegramUI/Components/Chat/ChatMessageBubbleItemNode/Sources/ChatMessageBubbleItemNode.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6883,11 +6883,11 @@ public class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewI
68836883
}
68846884

68856885
if item.message.adAttribute != nil {
6886-
let transition: ContainedViewLayoutTransition = isScroll ? .animated(duration: 0.4, curve: .spring) : .immediate
6886+
let transition: ContainedViewLayoutTransition = isScroll ? .animated(duration: 0.25, curve: .easeInOut) : .immediate
68876887
if case let .visible(_, rect) = self.visibility, rect.height >= 1.0 {
6888-
transition.updateSublayerTransformOffset(layer: self.layer, offset: CGPoint(x: 0.0, y: 0.0))
6888+
transition.updateAlpha(layer: self.layer, alpha: 1.0)
68896889
} else {
6890-
transition.updateSublayerTransformOffset(layer: self.layer, offset: CGPoint(x: 0.0, y: 200.0))
6890+
transition.updateAlpha(layer: self.layer, alpha: 0.0)
68916891
}
68926892
}
68936893
}

submodules/TelegramUI/Components/Chat/ChatTextInputPanelNode/Sources/ChatTextInputPanelNode.swift

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,13 +1857,15 @@ public class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDeleg
18571857
updatedButtons.append(itemAndButton!)
18581858
}
18591859
for (_, button) in self.accessoryItemButtons {
1860-
if animatedTransition {
1861-
if removeAccessoryButtons == nil {
1862-
removeAccessoryButtons = []
1860+
if !updatedButtons.contains(where: { $0.1 === button }) {
1861+
if animatedTransition {
1862+
if removeAccessoryButtons == nil {
1863+
removeAccessoryButtons = []
1864+
}
1865+
removeAccessoryButtons!.append(button)
1866+
} else {
1867+
button.removeFromSuperview()
18631868
}
1864-
removeAccessoryButtons!.append(button)
1865-
} else {
1866-
button.removeFromSuperview()
18671869
}
18681870
}
18691871
self.accessoryItemButtons = updatedButtons
@@ -2602,9 +2604,14 @@ public class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDeleg
26022604
for button in removeAccessoryButtons {
26032605
let buttonFrame = CGRect(origin: CGPoint(x: button.frame.origin.x + additionalOffset, y: textInputFrame.maxY - minimalInputHeight), size: button.frame.size)
26042606
transition.updateFrame(layer: button.layer, frame: buttonFrame)
2607+
let alphaTransition: ContainedViewLayoutTransition = .animated(duration: 0.25, curve: .easeInOut)
26052608
button.layer.animateScale(from: 1.0, to: 0.2, duration: 0.25, removeOnCompletion: false)
2606-
button.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.25, removeOnCompletion: false, completion: { [weak button] _ in
2607-
button?.removeFromSuperview()
2609+
alphaTransition.updateAlpha(layer: button.layer, alpha: 0.0)
2610+
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.25 * UIView.animationDurationFactor(), execute: { [weak button] in
2611+
if let button {
2612+
button.removeFromSuperview()
2613+
button.tintMask.removeFromSuperview()
2614+
}
26082615
})
26092616
}
26102617
}
@@ -3799,7 +3806,7 @@ public class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDeleg
37993806
if self.sendActionButtons.sendContainerNode.alpha.isZero && self.rightSlowModeInset.isZero {
38003807
alphaTransition.updateAlpha(node: self.sendActionButtons.sendContainerNode, alpha: 1.0)
38013808
blurTransitionIn.animateBlur(layer: self.sendActionButtons.sendContainerNode.layer, fromRadius: sendButtonBlurOut, toRadius: 0.0)
3802-
transition.animatePositionAdditive(layer: self.sendActionButtons.sendButton.imageNode.layer, offset: CGPoint(x: -14.0, y: 10.0))
3809+
transition.animatePositionAdditive(layer: self.sendActionButtons.sendButton.imageNode.layer, offset: CGPoint(x: -18.0, y: 14.0))
38033810
if let sendButtonRadialStatusNode = self.sendActionButtons.sendButtonRadialStatusNode {
38043811
alphaTransition.updateAlpha(node: sendButtonRadialStatusNode, alpha: 1.0)
38053812
}
@@ -3863,7 +3870,10 @@ public class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDeleg
38633870

38643871
if mediaInputIsActive && !hideExpandMediaInput {
38653872
if self.mediaActionButtons.expandMediaInputButton.alpha.isZero {
3866-
alphaTransition.updateAlpha(layer: self.mediaActionButtons.expandMediaInputButton.layer, alpha: 1.0)
3873+
self.mediaActionButtons.expandMediaInputButton.alpha = 1.0
3874+
if alphaTransition.isAnimated {
3875+
self.mediaActionButtons.expandMediaInputButton.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
3876+
}
38673877
}
38683878
} else {
38693879
if !self.mediaActionButtons.expandMediaInputButton.alpha.isZero {

submodules/TelegramUI/Sources/CommandChatInputContextPanelNode.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ final class CommandChatInputContextPanelNode: ChatInputContextPanelNode {
300300
self.backgroundView.layer.anchorPoint = CGPoint()
301301

302302
self.listView = ListView()
303+
self.listView.anchorPoint = CGPoint()
303304
self.listView.isOpaque = false
304305
self.listView.stackFromBottom = true
305306
self.listView.limitHitTestToNodes = true
@@ -515,10 +516,15 @@ final class CommandChatInputContextPanelNode: ChatInputContextPanelNode {
515516
insets.right = rightInset
516517
insets.bottom = bottomInset
517518

518-
transition.updateFrame(node: self.listView, frame: CGRect(x: 0.0, y: 0.0, width: size.width, height: size.height))
519+
transition.updateBounds(node: self.listView, bounds: CGRect(x: 0.0, y: 0.0, width: size.width, height: size.height))
520+
521+
var customListAnimationTransition: ControlledTransition?
522+
if case let .animated(duration, curve) = transition {
523+
customListAnimationTransition = ControlledTransition(duration: duration, curve: curve, interactive: false)
524+
}
519525

520526
let (duration, curve) = listViewAnimationDurationAndCurve(transition: transition)
521-
let updateSizeAndInsets = ListViewUpdateSizeAndInsets(size: size, insets: insets, duration: duration, curve: curve)
527+
let updateSizeAndInsets = ListViewUpdateSizeAndInsets(size: size, insets: insets, duration: duration, curve: curve, customAnimationTransition: customListAnimationTransition)
522528

523529
self.contentOffsetChangeTransition = ComponentTransition(transition)
524530

@@ -553,11 +559,10 @@ final class CommandChatInputContextPanelNode: ChatInputContextPanelNode {
553559
if let topItemOffset {
554560
let offset = (self.listView.bounds.size.height - topItemOffset)
555561

556-
let position = self.listView.layer.position
557-
self.listView.layer.animatePosition(from: position, to: CGPoint(x: position.x, y: position.y + offset), duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, completion: { _ in
562+
self.listView.layer.animatePosition(from: CGPoint(), to: CGPoint(x: 0.0, y: offset), duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, additive: true, completion: { _ in
558563
completion()
559564
})
560-
self.backgroundView.layer.animatePosition(from: self.backgroundView.layer.position, to: CGPoint(x: self.backgroundView.layer.position.x, y: self.backgroundView.layer.position.y + offset), duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false)
565+
self.backgroundView.layer.animatePosition(from: CGPoint(), to: CGPoint(x: 0.0, y: offset), duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, additive: true)
561566
} else {
562567
completion()
563568
}

submodules/TelegramUI/Sources/HashtagChatInputContextPanelNode.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,10 @@ final class HashtagChatInputContextPanelNode: ChatInputContextPanelNode {
370370
if let topItemOffset = topItemOffset {
371371
let offset = (self.listView.bounds.size.height - topItemOffset)
372372

373-
let position = self.listView.layer.position
374-
self.listView.layer.animatePosition(from: position, to: CGPoint(x: position.x, y: position.y + offset), duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, completion: { _ in
373+
self.listView.layer.animatePosition(from: CGPoint(), to: CGPoint(x: 0.0, y: offset), duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, additive: true, completion: { _ in
375374
completion()
376375
})
377-
self.backgroundView.layer.animatePosition(from: self.backgroundView.layer.position, to: CGPoint(x: self.backgroundView.layer.position.x, y: self.backgroundView.layer.position.y + offset), duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false)
376+
self.backgroundView.layer.animatePosition(from: CGPoint(), to: CGPoint(x: 0.0, y: offset), duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, additive: true)
378377
} else {
379378
completion()
380379
}

submodules/TelegramUI/Sources/MentionChatInputContextPanelNode.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ final class MentionChatInputContextPanelNode: ChatInputContextPanelNode {
272272
}
273273
}
274274

275-
self.backgroundView.bounds = CGRect(origin: CGPoint(), size: CGSize(width: size.width, height: size.height + 32.0))
275+
transition.updateBounds(layer: self.backgroundView.layer, bounds: CGRect(origin: CGPoint(), size: CGSize(width: size.width, height: size.height + 32.0)))
276276
self.backgroundView.update(
277277
size: self.backgroundView.bounds.size,
278278
cornerRadius: 20.0,
@@ -290,7 +290,7 @@ final class MentionChatInputContextPanelNode: ChatInputContextPanelNode {
290290
transition.updateFrame(node: self.listView, frame: CGRect(x: 0.0, y: 0.0, width: size.width, height: size.height))
291291

292292
let (duration, curve) = listViewAnimationDurationAndCurve(transition: transition)
293-
let updateSizeAndInsets = ListViewUpdateSizeAndInsets(size: size, insets: insets, duration: duration, curve: curve)
293+
let updateSizeAndInsets = ListViewUpdateSizeAndInsets(size: size, insets: insets, duration: duration, curve: curve, customAnimationTransition: nil)
294294

295295
self.listView.transaction(deleteIndices: [], insertIndicesAndItems: [], updateIndicesAndItems: [], options: [.Synchronous, .LowLatency], scrollToItem: nil, updateSizeAndInsets: updateSizeAndInsets, stationaryItemRange: nil, updateOpaqueState: nil, completion: { _ in })
296296

@@ -312,11 +312,10 @@ final class MentionChatInputContextPanelNode: ChatInputContextPanelNode {
312312
if let topItemOffset {
313313
let offset = (self.listView.bounds.size.height - topItemOffset)
314314

315-
let position = self.listView.layer.position
316-
self.listView.layer.animatePosition(from: position, to: CGPoint(x: position.x, y: position.y + offset), duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, completion: { _ in
315+
self.listView.layer.animatePosition(from: CGPoint(), to: CGPoint(x: 0.0, y: offset), duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, additive: true, completion: { _ in
317316
completion()
318317
})
319-
self.backgroundView.layer.animatePosition(from: self.backgroundView.layer.position, to: CGPoint(x: self.backgroundView.layer.position.x, y: self.backgroundView.layer.position.y + offset), duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false)
318+
self.backgroundView.layer.animatePosition(from: CGPoint(), to: CGPoint(x: 0.0, y: offset), duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, additive: true)
320319
} else {
321320
completion()
322321
}

submodules/TelegramUI/Sources/VerticalListContextResultsChatInputPanelButtonItem.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ final class VerticalListContextResultsChatInputPanelButtonItemNode: ListViewItem
146146

147147
let nodeLayout = ListViewItemNodeLayout(contentSize: CGSize(width: params.width, height: VerticalListContextResultsChatInputPanelButtonItemNode.itemHeight(style: item.style)), insets: UIEdgeInsets())
148148

149-
return (nodeLayout, { _ in
149+
return (nodeLayout, { animation in
150150
if let strongSelf = self {
151151
strongSelf.item = item
152152

@@ -164,11 +164,13 @@ final class VerticalListContextResultsChatInputPanelButtonItemNode: ListViewItem
164164

165165
let _ = titleApply()
166166

167-
strongSelf.titleNode.frame = CGRect(origin: CGPoint(x: floor((params.width - titleLayout.size.width) / 2.0), y: floor((nodeLayout.contentSize.height - titleLayout.size.height) / 2.0) + titleOffsetY), size: titleLayout.size)
167+
let titleFrame = CGRect(origin: CGPoint(x: floor((params.width - titleLayout.size.width) / 2.0), y: floor((nodeLayout.contentSize.height - titleLayout.size.height) / 2.0) + titleOffsetY), size: titleLayout.size)
168+
animation.animator.updatePosition(layer: strongSelf.titleNode.layer, position: titleFrame.center, completion: nil)
169+
strongSelf.titleNode.bounds = CGRect(origin: CGPoint(), size: titleFrame.size)
168170

169-
strongSelf.separatorNode.frame = CGRect(origin: CGPoint(x: 0.0, y: nodeLayout.contentSize.height - UIScreenPixel), size: CGSize(width: params.width, height: UIScreenPixel))
171+
animation.animator.updateFrame(layer: strongSelf.separatorNode.layer, frame: CGRect(origin: CGPoint(x: 0.0, y: nodeLayout.contentSize.height - UIScreenPixel), size: CGSize(width: params.width, height: UIScreenPixel)), completion: nil)
170172

171-
strongSelf.buttonNode.frame = CGRect(origin: CGPoint(), size: nodeLayout.contentSize)
173+
animation.animator.updateFrame(layer: strongSelf.buttonNode.layer, frame: CGRect(origin: CGPoint(), size: nodeLayout.contentSize), completion: nil)
172174
}
173175
})
174176
}

submodules/TelegramUI/Sources/VerticalListContextResultsChatInputPanelItem.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ final class VerticalListContextResultsChatInputPanelItemNode: ListViewItemNode {
275275

276276
let nodeLayout = ListViewItemNodeLayout(contentSize: CGSize(width: params.width, height: VerticalListContextResultsChatInputPanelItemNode.itemHeight), insets: UIEdgeInsets())
277277

278-
return (nodeLayout, { _ in
278+
return (nodeLayout, { animation in
279279
if let strongSelf = self {
280280
strongSelf.item = item
281281

@@ -333,7 +333,7 @@ final class VerticalListContextResultsChatInputPanelItemNode: ListViewItemNode {
333333

334334
strongSelf.separatorNode.isHidden = !mergedBottom
335335

336-
strongSelf.separatorNode.frame = CGRect(origin: CGPoint(x: leftInset, y: nodeLayout.contentSize.height - UIScreenPixel), size: CGSize(width: params.width - leftInset, height: UIScreenPixel))
336+
animation.animator.updateFrame(layer: strongSelf.separatorNode.layer, frame: CGRect(origin: CGPoint(x: leftInset, y: nodeLayout.contentSize.height - UIScreenPixel), size: CGSize(width: params.width - leftInset, height: UIScreenPixel)), completion: nil)
337337

338338
strongSelf.highlightedBackgroundNode.frame = CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: CGSize(width: params.width, height: nodeLayout.size.height + UIScreenPixel))
339339

0 commit comments

Comments
 (0)