Various Improvements

This commit is contained in:
Ilya Laktyushin
2021-12-21 19:35:39 +04:00
parent d60d2beaa4
commit 52cfe331ac
2 changed files with 51 additions and 29 deletions

View File

@@ -698,7 +698,19 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState
resourceAvailable = false 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] let message = messages[0]
var isExpired = false var isExpired = false
for media in message.media { for media in message.media {
@@ -728,7 +740,7 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState
if let restrictedText = restrictedText { if let restrictedText = restrictedText {
storeMessageTextInPasteboard(restrictedText, entities: nil) storeMessageTextInPasteboard(restrictedText, entities: nil)
} else { } else {
storeMessageTextInPasteboard(message.text, entities: messageEntities) storeMessageTextInPasteboard(messageText, entities: messageEntities)
} }
Queue.mainQueue().after(0.2, { Queue.mainQueue().after(0.2, {
@@ -744,7 +756,7 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState
|> deliverOnMainQueue).start(next: { data in |> deliverOnMainQueue).start(next: { data in
if data.complete, let imageData = try? Data(contentsOf: URL(fileURLWithPath: data.path)) { if data.complete, let imageData = try? Data(contentsOf: URL(fileURLWithPath: data.path)) {
if let image = UIImage(data: imageData) { if let image = UIImage(data: imageData) {
if !message.text.isEmpty { if !messageText.isEmpty {
copyTextWithEntities() copyTextWithEntities()
} else { } else {
UIPasteboard.general.image = image UIPasteboard.general.image = image
@@ -770,20 +782,20 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState
f(.default) 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 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) return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Translate"), color: theme.actionSheet.primaryTextColor)
}, action: { _, f in }, action: { _, f in
controllerInteraction.performTextSelectionAction(0, NSAttributedString(string: message.text), .translate) controllerInteraction.performTextSelectionAction(0, NSAttributedString(string: messageText), .translate)
f(.default) f(.default)
}))) })))
} }
if isSpeakSelectionEnabled() && !message.text.isEmpty { if isSpeakSelectionEnabled() && !messageText.isEmpty {
actions.append(.action(ContextMenuActionItem(text: chatPresentationInterfaceState.strings.Conversation_ContextMenuSpeak, icon: { theme in 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) return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Message"), color: theme.actionSheet.primaryTextColor)
}, action: { _, f in }, action: { _, f in
controllerInteraction.performTextSelectionAction(0, NSAttributedString(string: message.text), .speak) controllerInteraction.performTextSelectionAction(0, NSAttributedString(string: messageText), .speak)
f(.default) f(.default)
}))) })))
} }

View File

@@ -352,10 +352,7 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
} }
} }
private var currentState: ChatTextInputState?
func updateInputTextState(_ state: ChatTextInputState, keepSendButtonEnabled: Bool, extendedSearchLayout: Bool, accessoryItems: [ChatTextInputAccessoryItem], animated: Bool) { func updateInputTextState(_ state: ChatTextInputState, keepSendButtonEnabled: Bool, extendedSearchLayout: Bool, accessoryItems: [ChatTextInputAccessoryItem], animated: Bool) {
self.currentState = state
if state.inputText.length != 0 && self.textInputNode == nil { if state.inputText.length != 0 && self.textInputNode == nil {
self.loadTextInputNode() 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 { guard let textInputNode = self.textInputNode else {
return return
} }
@@ -1894,15 +1891,15 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
self.spoilersRevealed = revealed self.spoilersRevealed = revealed
if revealed { if revealed {
self.updateInternalSpoilersRevealed(true) self.updateInternalSpoilersRevealed(true, animated: animated)
} else { } else {
Queue.mainQueue().after(1.5, { 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 { guard self.spoilersRevealed == revealed, let textInputNode = self.textInputNode, let presentationInterfaceState = self.presentationInterfaceState else {
return return
} }
@@ -1913,11 +1910,9 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
refreshChatTextInputAttributes(textInputNode, theme: presentationInterfaceState.theme, baseFontSize: baseFontSize, spoilersRevealed: self.spoilersRevealed) refreshChatTextInputAttributes(textInputNode, theme: presentationInterfaceState.theme, baseFontSize: baseFontSize, spoilersRevealed: self.spoilersRevealed)
if let state = self.currentState { textInputNode.attributedText = textAttributedStringForStateText(self.inputTextState.inputText, fontSize: baseFontSize, textColor: textColor, accentTextColor: accentTextColor, writingDirection: nil, spoilersRevealed: self.spoilersRevealed)
textInputNode.attributedText = textAttributedStringForStateText(state.inputText, fontSize: baseFontSize, textColor: textColor, accentTextColor: accentTextColor, writingDirection: nil, spoilersRevealed: self.spoilersRevealed)
}
if textInputNode.textView.subviews.count > 1 { if textInputNode.textView.subviews.count > 1, animated {
let containerView = textInputNode.textView.subviews[1] let containerView = textInputNode.textView.subviews[1]
if let canvasView = containerView.subviews.first { if let canvasView = containerView.subviews.first {
if let snapshotView = canvasView.snapshotView(afterScreenUpdates: false) { if let snapshotView = canvasView.snapshotView(afterScreenUpdates: false) {
@@ -1930,6 +1925,7 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
} }
} }
if animated {
if revealed { if revealed {
let transition = ContainedViewLayoutTransition.animated(duration: 0.3, curve: .linear) let transition = ContainedViewLayoutTransition.animated(duration: 0.3, curve: .linear)
if let dustNode = self.dustNode { if let dustNode = self.dustNode {
@@ -1941,6 +1937,9 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
transition.updateAlpha(node: dustNode, alpha: 1.0) transition.updateAlpha(node: dustNode, alpha: 1.0)
} }
} }
} else if let dustNode = self.dustNode {
dustNode.alpha = revealed ? 0.0 : 1.0
}
} }
private func updateCounterTextNode(transition: ContainedViewLayoutTransition) { private func updateCounterTextNode(transition: ContainedViewLayoutTransition) {
@@ -2336,10 +2335,21 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
@objc func formatAttributesSpoiler(_ sender: Any) { @objc func formatAttributesSpoiler(_ sender: Any) {
self.inputMenu.back() 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 self.interfaceInteraction?.updateTextInputStateAndMode { current, inputMode in
return (chatTextInputAddFormattingAttribute(current, attribute: ChatTextInputAttributes.spoiler), inputMode) 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 { @objc func editableTextNode(_ editableTextNode: ASEditableTextNode, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {