mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-01 20:28:05 +00:00
Fix inconsistent iOS keyboard animation when switching from a text field with prediction enabled to one without autocorrection
This commit is contained in:
parent
7cb664eb14
commit
0c22b4b37c
@ -272,6 +272,8 @@ public class Window1 {
|
||||
public var previewThemeAccentColor: UIColor = .blue
|
||||
public var previewThemeDarkBlur: Bool = false
|
||||
|
||||
private var shouldNotAnimateLikelyKeyboardAutocorrectionSwitch: Bool = false
|
||||
|
||||
public private(set) var forceInCallStatusBarText: String? = nil
|
||||
public var inCallNavigate: (() -> Void)? {
|
||||
didSet {
|
||||
@ -522,7 +524,15 @@ public class Window1 {
|
||||
transitionCurve = .easeInOut
|
||||
}
|
||||
|
||||
strongSelf.updateLayout { $0.update(inputHeight: keyboardHeight.isLessThanOrEqualTo(0.0) ? nil : keyboardHeight, transition: .animated(duration: duration, curve: transitionCurve), overrideTransition: false) }
|
||||
var transition: ContainedViewLayoutTransition = .animated(duration: duration, curve: transitionCurve)
|
||||
|
||||
if strongSelf.shouldNotAnimateLikelyKeyboardAutocorrectionSwitch, let inputHeight = strongSelf.windowLayout.inputHeight {
|
||||
if abs(inputHeight - keyboardHeight) <= 44.1 {
|
||||
transition = .immediate
|
||||
}
|
||||
}
|
||||
|
||||
strongSelf.updateLayout { $0.update(inputHeight: keyboardHeight.isLessThanOrEqualTo(0.0) ? nil : keyboardHeight, transition: transition, overrideTransition: false) }
|
||||
}
|
||||
})
|
||||
|
||||
@ -1203,4 +1213,11 @@ public class Window1 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func doNotAnimateLikelyKeyboardAutocorrectionSwitch() {
|
||||
self.shouldNotAnimateLikelyKeyboardAutocorrectionSwitch = true
|
||||
DispatchQueue.main.async {
|
||||
self.shouldNotAnimateLikelyKeyboardAutocorrectionSwitch = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3222,27 +3222,34 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
}))
|
||||
}
|
||||
}, beginMessageSearch: { [weak self] domain, query in
|
||||
if let strongSelf = self {
|
||||
strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, { current in
|
||||
return current.updatedTitlePanelContext {
|
||||
if let index = $0.firstIndex(where: {
|
||||
switch $0 {
|
||||
case .chatInfo:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}) {
|
||||
var updatedContexts = $0
|
||||
updatedContexts.remove(at: index)
|
||||
return updatedContexts
|
||||
} else {
|
||||
return $0
|
||||
}
|
||||
}.updatedSearch(current.search == nil ? ChatSearchData(domain: domain).withUpdatedQuery(query) : current.search?.withUpdatedDomain(domain).withUpdatedQuery(query))
|
||||
})
|
||||
strongSelf.updateItemNodesSearchTextHighlightStates()
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
var interactive = true
|
||||
if strongSelf.chatDisplayNode.isInputViewFocused {
|
||||
interactive = false
|
||||
strongSelf.context.sharedContext.mainWindow?.doNotAnimateLikelyKeyboardAutocorrectionSwitch()
|
||||
}
|
||||
|
||||
strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: interactive, { current in
|
||||
return current.updatedTitlePanelContext {
|
||||
if let index = $0.firstIndex(where: {
|
||||
switch $0 {
|
||||
case .chatInfo:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}) {
|
||||
var updatedContexts = $0
|
||||
updatedContexts.remove(at: index)
|
||||
return updatedContexts
|
||||
} else {
|
||||
return $0
|
||||
}
|
||||
}.updatedSearch(current.search == nil ? ChatSearchData(domain: domain).withUpdatedQuery(query) : current.search?.withUpdatedDomain(domain).withUpdatedQuery(query))
|
||||
})
|
||||
strongSelf.updateItemNodesSearchTextHighlightStates()
|
||||
}, dismissMessageSearch: { [weak self] in
|
||||
if let strongSelf = self {
|
||||
strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, { current in
|
||||
@ -4384,7 +4391,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
return a && b
|
||||
})
|
||||
|
||||
self.chatDisplayNode.loadInputPanels(theme: self.presentationInterfaceState.theme, strings: self.presentationInterfaceState.strings)
|
||||
self.chatDisplayNode.loadInputPanels(theme: self.presentationInterfaceState.theme, strings: self.presentationInterfaceState.strings, fontSize: self.presentationInterfaceState.fontSize)
|
||||
|
||||
self.recentlyUsedInlineBotsDisposable = (recentlyUsedInlineBots(postbox: self.context.account.postbox) |> deliverOnMainQueue).start(next: { [weak self] peers in
|
||||
self?.recentlyUsedInlineBotsValue = peers.filter({ $0.1 >= 0.14 }).map({ $0.0 })
|
||||
|
||||
@ -97,6 +97,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
|
||||
private var titleAccessoryPanelNode: ChatTitleAccessoryPanelNode?
|
||||
|
||||
private var inputPanelNode: ChatInputPanelNode?
|
||||
private weak var currentDismissedInputPanelNode: ASDisplayNode?
|
||||
private var secondaryInputPanelNode: ChatInputPanelNode?
|
||||
private var accessoryPanelNode: AccessoryPanelNode?
|
||||
private var inputContextPanelNode: ChatInputContextPanelNode?
|
||||
@ -1105,7 +1106,12 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
|
||||
inputPanelNode.frame = apparentInputPanelFrame.offsetBy(dx: 0.0, dy: apparentInputPanelFrame.height + previousInputPanelBackgroundFrame.maxY - apparentInputBackgroundFrame.maxY)
|
||||
inputPanelNode.alpha = 0.0
|
||||
}
|
||||
|
||||
if !transition.isAnimated {
|
||||
inputPanelNode.layer.removeAllAnimations()
|
||||
if let currentDismissedInputPanelNode = self.currentDismissedInputPanelNode, inputPanelNode is ChatSearchInputPanelNode {
|
||||
currentDismissedInputPanelNode.layer.removeAllAnimations()
|
||||
}
|
||||
}
|
||||
transition.updateFrame(node: inputPanelNode, frame: apparentInputPanelFrame)
|
||||
transition.updateAlpha(node: inputPanelNode, alpha: 1.0)
|
||||
}
|
||||
@ -1197,12 +1203,19 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
|
||||
if let dismissedInputPanelNode = dismissedInputPanelNode, dismissedInputPanelNode !== self.secondaryInputPanelNode {
|
||||
var frameCompleted = false
|
||||
var alphaCompleted = false
|
||||
self.currentDismissedInputPanelNode = dismissedInputPanelNode
|
||||
let completed = { [weak self, weak dismissedInputPanelNode] in
|
||||
if let strongSelf = self, let dismissedInputPanelNode = dismissedInputPanelNode, strongSelf.inputPanelNode === dismissedInputPanelNode {
|
||||
guard let strongSelf = self, let dismissedInputPanelNode = dismissedInputPanelNode else {
|
||||
return
|
||||
}
|
||||
if strongSelf.currentDismissedInputPanelNode === dismissedInputPanelNode {
|
||||
strongSelf.currentDismissedInputPanelNode = nil
|
||||
}
|
||||
if strongSelf.inputPanelNode === dismissedInputPanelNode {
|
||||
return
|
||||
}
|
||||
if frameCompleted && alphaCompleted {
|
||||
dismissedInputPanelNode?.removeFromSupernode()
|
||||
dismissedInputPanelNode.removeFromSupernode()
|
||||
}
|
||||
}
|
||||
let transitionTargetY = layout.size.height - insets.bottom
|
||||
@ -2258,4 +2271,8 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
|
||||
completion?()
|
||||
})
|
||||
}
|
||||
|
||||
func setEnablePredictiveTextInput(_ value: Bool) {
|
||||
self.textInputPanelNode?.enablePredictiveInput = value
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user