mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
Various Improvements
This commit is contained in:
parent
d60d2beaa4
commit
52cfe331ac
@ -698,7 +698,19 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState
|
||||
resourceAvailable = false
|
||||
}
|
||||
|
||||
if (!messages[0].text.isEmpty || resourceAvailable || diceEmoji != nil) && !chatPresentationInterfaceState.copyProtectionEnabled {
|
||||
var messageText: String = ""
|
||||
for message in messages {
|
||||
if !message.text.isEmpty {
|
||||
if messageText.isEmpty {
|
||||
messageText = message.text
|
||||
} else {
|
||||
messageText = ""
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!messageText.isEmpty || resourceAvailable || diceEmoji != nil) && !chatPresentationInterfaceState.copyProtectionEnabled {
|
||||
let message = messages[0]
|
||||
var isExpired = false
|
||||
for media in message.media {
|
||||
@ -728,7 +740,7 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState
|
||||
if let restrictedText = restrictedText {
|
||||
storeMessageTextInPasteboard(restrictedText, entities: nil)
|
||||
} else {
|
||||
storeMessageTextInPasteboard(message.text, entities: messageEntities)
|
||||
storeMessageTextInPasteboard(messageText, entities: messageEntities)
|
||||
}
|
||||
|
||||
Queue.mainQueue().after(0.2, {
|
||||
@ -744,7 +756,7 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState
|
||||
|> deliverOnMainQueue).start(next: { data in
|
||||
if data.complete, let imageData = try? Data(contentsOf: URL(fileURLWithPath: data.path)) {
|
||||
if let image = UIImage(data: imageData) {
|
||||
if !message.text.isEmpty {
|
||||
if !messageText.isEmpty {
|
||||
copyTextWithEntities()
|
||||
} else {
|
||||
UIPasteboard.general.image = image
|
||||
@ -770,20 +782,20 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState
|
||||
f(.default)
|
||||
})))
|
||||
|
||||
if canTranslateText(context: context, text: message.text, showTranslate: translationSettings.showTranslate, ignoredLanguages: translationSettings.ignoredLanguages) {
|
||||
if canTranslateText(context: context, text: messageText, showTranslate: translationSettings.showTranslate, ignoredLanguages: translationSettings.ignoredLanguages) {
|
||||
actions.append(.action(ContextMenuActionItem(text: chatPresentationInterfaceState.strings.Conversation_ContextMenuTranslate, icon: { theme in
|
||||
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Translate"), color: theme.actionSheet.primaryTextColor)
|
||||
}, action: { _, f in
|
||||
controllerInteraction.performTextSelectionAction(0, NSAttributedString(string: message.text), .translate)
|
||||
controllerInteraction.performTextSelectionAction(0, NSAttributedString(string: messageText), .translate)
|
||||
f(.default)
|
||||
})))
|
||||
}
|
||||
|
||||
if isSpeakSelectionEnabled() && !message.text.isEmpty {
|
||||
if isSpeakSelectionEnabled() && !messageText.isEmpty {
|
||||
actions.append(.action(ContextMenuActionItem(text: chatPresentationInterfaceState.strings.Conversation_ContextMenuSpeak, icon: { theme in
|
||||
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Message"), color: theme.actionSheet.primaryTextColor)
|
||||
}, action: { _, f in
|
||||
controllerInteraction.performTextSelectionAction(0, NSAttributedString(string: message.text), .speak)
|
||||
controllerInteraction.performTextSelectionAction(0, NSAttributedString(string: messageText), .speak)
|
||||
f(.default)
|
||||
})))
|
||||
}
|
||||
|
@ -352,10 +352,7 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
private var currentState: ChatTextInputState?
|
||||
func updateInputTextState(_ state: ChatTextInputState, keepSendButtonEnabled: Bool, extendedSearchLayout: Bool, accessoryItems: [ChatTextInputAccessoryItem], animated: Bool) {
|
||||
self.currentState = state
|
||||
|
||||
if state.inputText.length != 0 && self.textInputNode == nil {
|
||||
self.loadTextInputNode()
|
||||
}
|
||||
@ -1870,7 +1867,7 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
private func updateSpoilersRevealed() {
|
||||
private func updateSpoilersRevealed(animated: Bool = true) {
|
||||
guard let textInputNode = self.textInputNode else {
|
||||
return
|
||||
}
|
||||
@ -1894,15 +1891,15 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
|
||||
self.spoilersRevealed = revealed
|
||||
|
||||
if revealed {
|
||||
self.updateInternalSpoilersRevealed(true)
|
||||
self.updateInternalSpoilersRevealed(true, animated: animated)
|
||||
} else {
|
||||
Queue.mainQueue().after(1.5, {
|
||||
self.updateInternalSpoilersRevealed(false)
|
||||
self.updateInternalSpoilersRevealed(false, animated: true)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private func updateInternalSpoilersRevealed(_ revealed: Bool) {
|
||||
private func updateInternalSpoilersRevealed(_ revealed: Bool, animated: Bool) {
|
||||
guard self.spoilersRevealed == revealed, let textInputNode = self.textInputNode, let presentationInterfaceState = self.presentationInterfaceState else {
|
||||
return
|
||||
}
|
||||
@ -1913,11 +1910,9 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
|
||||
|
||||
refreshChatTextInputAttributes(textInputNode, theme: presentationInterfaceState.theme, baseFontSize: baseFontSize, spoilersRevealed: self.spoilersRevealed)
|
||||
|
||||
if let state = self.currentState {
|
||||
textInputNode.attributedText = textAttributedStringForStateText(state.inputText, fontSize: baseFontSize, textColor: textColor, accentTextColor: accentTextColor, writingDirection: nil, spoilersRevealed: self.spoilersRevealed)
|
||||
}
|
||||
|
||||
if textInputNode.textView.subviews.count > 1 {
|
||||
textInputNode.attributedText = textAttributedStringForStateText(self.inputTextState.inputText, fontSize: baseFontSize, textColor: textColor, accentTextColor: accentTextColor, writingDirection: nil, spoilersRevealed: self.spoilersRevealed)
|
||||
|
||||
if textInputNode.textView.subviews.count > 1, animated {
|
||||
let containerView = textInputNode.textView.subviews[1]
|
||||
if let canvasView = containerView.subviews.first {
|
||||
if let snapshotView = canvasView.snapshotView(afterScreenUpdates: false) {
|
||||
@ -1930,16 +1925,20 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
if revealed {
|
||||
let transition = ContainedViewLayoutTransition.animated(duration: 0.3, curve: .linear)
|
||||
if let dustNode = self.dustNode {
|
||||
transition.updateAlpha(node: dustNode, alpha: 0.0)
|
||||
}
|
||||
} else {
|
||||
let transition = ContainedViewLayoutTransition.animated(duration: 0.3, curve: .linear)
|
||||
if let dustNode = self.dustNode {
|
||||
transition.updateAlpha(node: dustNode, alpha: 1.0)
|
||||
if animated {
|
||||
if revealed {
|
||||
let transition = ContainedViewLayoutTransition.animated(duration: 0.3, curve: .linear)
|
||||
if let dustNode = self.dustNode {
|
||||
transition.updateAlpha(node: dustNode, alpha: 0.0)
|
||||
}
|
||||
} else {
|
||||
let transition = ContainedViewLayoutTransition.animated(duration: 0.3, curve: .linear)
|
||||
if let dustNode = self.dustNode {
|
||||
transition.updateAlpha(node: dustNode, alpha: 1.0)
|
||||
}
|
||||
}
|
||||
} else if let dustNode = self.dustNode {
|
||||
dustNode.alpha = revealed ? 0.0 : 1.0
|
||||
}
|
||||
}
|
||||
|
||||
@ -2336,10 +2335,21 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
|
||||
|
||||
@objc func formatAttributesSpoiler(_ sender: Any) {
|
||||
self.inputMenu.back()
|
||||
|
||||
var animated = false
|
||||
if let attributedText = self.textInputNode?.attributedText {
|
||||
attributedText.enumerateAttributes(in: NSMakeRange(0, attributedText.length), options: [], using: { attributes, _, _ in
|
||||
if let _ = attributes[ChatTextInputAttributes.spoiler] {
|
||||
animated = true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
self.interfaceInteraction?.updateTextInputStateAndMode { current, inputMode in
|
||||
return (chatTextInputAddFormattingAttribute(current, attribute: ChatTextInputAttributes.spoiler), inputMode)
|
||||
}
|
||||
self.updateSpoilersRevealed()
|
||||
|
||||
self.updateSpoilersRevealed(animated: animated)
|
||||
}
|
||||
|
||||
@objc func editableTextNode(_ editableTextNode: ASEditableTextNode, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
|
||||
|
Loading…
x
Reference in New Issue
Block a user