Various improvements

This commit is contained in:
Ilya Laktyushin 2023-12-20 14:20:11 +04:00
parent e6ba681c03
commit 7c435bf03e
6 changed files with 62 additions and 50 deletions

View File

@ -368,8 +368,8 @@ public final class PrincipalThemeEssentialGraphics {
self.mediaSelfExpiringIcon = generateTintedImage(image: selfExpiringImage, color: .white)! self.mediaSelfExpiringIcon = generateTintedImage(image: selfExpiringImage, color: .white)!
self.freeSelfExpiringIcon = generateTintedImage(image: selfExpiringImage, color: serviceColor.primaryText)! self.freeSelfExpiringIcon = generateTintedImage(image: selfExpiringImage, color: serviceColor.primaryText)!
self.radialIndicatorFileIconIncoming = emptyImage self.radialIndicatorFileIconIncoming = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/RadialProgressIconDocument"), color: .black)!
self.radialIndicatorFileIconOutgoing = emptyImage self.radialIndicatorFileIconOutgoing = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/RadialProgressIconDocument"), color: .black)!
} else { } else {
self.chatMessageBackgroundIncomingMaskImage = messageBubbleImage(maxCornerRadius: maxCornerRadius, minCornerRadius: minCornerRadius, incoming: true, fillColor: .black, strokeColor: .clear, neighbors: .none, theme: theme, wallpaper: .color(0xffffff), knockout: true, mask: true, extendedEdges: true) self.chatMessageBackgroundIncomingMaskImage = messageBubbleImage(maxCornerRadius: maxCornerRadius, minCornerRadius: minCornerRadius, incoming: true, fillColor: .black, strokeColor: .clear, neighbors: .none, theme: theme, wallpaper: .color(0xffffff), knockout: true, mask: true, extendedEdges: true)
self.chatMessageBackgroundIncomingExtractedMaskImage = messageBubbleImage(maxCornerRadius: maxCornerRadius, minCornerRadius: minCornerRadius, incoming: true, fillColor: .black, strokeColor: .clear, neighbors: .extracted, theme: theme, wallpaper: .color(0xffffff), knockout: true, mask: true, extendedEdges: true) self.chatMessageBackgroundIncomingExtractedMaskImage = messageBubbleImage(maxCornerRadius: maxCornerRadius, minCornerRadius: minCornerRadius, incoming: true, fillColor: .black, strokeColor: .clear, neighbors: .extracted, theme: theme, wallpaper: .color(0xffffff), knockout: true, mask: true, extendedEdges: true)

View File

@ -86,7 +86,6 @@ public class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode {
private let textNode: TextNodeWithEntities private let textNode: TextNodeWithEntities
private var spoilerTextNode: TextNodeWithEntities? private var spoilerTextNode: TextNodeWithEntities?
private var dustNode: InvisibleInkDustNode? private var dustNode: InvisibleInkDustNode?
private var moreNode: TextNode?
private let textAccessibilityOverlayNode: TextAccessibilityOverlayNode private let textAccessibilityOverlayNode: TextAccessibilityOverlayNode
public var statusNode: ChatMessageDateAndStatusNode? public var statusNode: ChatMessageDateAndStatusNode?
@ -167,7 +166,6 @@ public class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode {
let textLayout = TextNodeWithEntities.asyncLayout(self.textNode) let textLayout = TextNodeWithEntities.asyncLayout(self.textNode)
let spoilerTextLayout = TextNodeWithEntities.asyncLayout(self.spoilerTextNode) let spoilerTextLayout = TextNodeWithEntities.asyncLayout(self.spoilerTextNode)
let statusLayout = ChatMessageDateAndStatusNode.asyncLayout(self.statusNode) let statusLayout = ChatMessageDateAndStatusNode.asyncLayout(self.statusNode)
let moreLayout = TextNode.asyncLayout(self.moreNode)
let currentCachedChatMessageText = self.cachedChatMessageText let currentCachedChatMessageText = self.cachedChatMessageText
@ -506,27 +504,39 @@ public class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode {
attributedText = updatedString attributedText = updatedString
} }
let hideAllAdditionalInfo = item.presentationData.isPreview var customTruncationToken: NSAttributedString?
var maximumNumberOfLines: Int = 0
var moreLayoutAndApply: (TextNodeLayout, () -> TextNode)?
var cutout: TextNodeCutout? = nil
if item.presentationData.isPreview { if item.presentationData.isPreview {
moreLayoutAndApply = moreLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: item.presentationData.strings.Conversation_ReadMore, font: textFont, textColor: messageTheme.accentTextColor), maximumNumberOfLines: 1, truncationType: .end, constrainedSize: textConstrainedSize)) if item.message.groupingKey != nil {
if let moreSize = moreLayoutAndApply?.0.size { maximumNumberOfLines = 6
cutout = TextNodeCutout(bottomRight: CGSize(width: moreSize.width + 8.0, height: moreSize.height)) } else if let image = item.message.media.first(where: { $0 is TelegramMediaImage }) as? TelegramMediaImage, let dimensions = image.representations.first?.dimensions {
if dimensions.width > dimensions.height {
maximumNumberOfLines = 9
} else {
maximumNumberOfLines = 6
} }
} else if let file = item.message.media.first(where: { $0 is TelegramMediaFile }) as? TelegramMediaFile, file.isVideo || file.isAnimated, let dimensions = file.dimensions {
if dimensions.width > dimensions.height {
maximumNumberOfLines = 9
} else {
maximumNumberOfLines = 6
}
} else {
maximumNumberOfLines = 12
}
let truncationToken = NSMutableAttributedString()
truncationToken.append(NSAttributedString(string: "\u{2026} ", font: textFont, textColor: messageTheme.primaryTextColor))
truncationToken.append(NSAttributedString(string: item.presentationData.strings.Conversation_ReadMore, font: textFont, textColor: messageTheme.accentTextColor))
customTruncationToken = truncationToken
} }
let textInsets = UIEdgeInsets(top: 2.0, left: 2.0, bottom: 5.0, right: 2.0) let textInsets = UIEdgeInsets(top: 2.0, left: 2.0, bottom: 5.0, right: 2.0)
let (textLayout, textApply) = textLayout(TextNodeLayoutArguments(attributedString: attributedText, backgroundColor: nil, maximumNumberOfLines: maximumNumberOfLines, truncationType: .end, constrainedSize: textConstrainedSize, alignment: .natural, cutout: nil, insets: textInsets, lineColor: messageTheme.accentControlColor, customTruncationToken: customTruncationToken))
let (textLayout, textApply) = textLayout(TextNodeLayoutArguments(attributedString: attributedText, backgroundColor: nil, maximumNumberOfLines: hideAllAdditionalInfo ? 12 : 0, truncationType: .end, constrainedSize: textConstrainedSize, alignment: .natural, cutout: cutout, insets: textInsets, lineColor: messageTheme.accentControlColor))
if !textLayout.truncated {
moreLayoutAndApply = nil
}
let spoilerTextLayoutAndApply: (TextNodeLayout, (TextNodeWithEntities.Arguments?) -> TextNodeWithEntities)? let spoilerTextLayoutAndApply: (TextNodeLayout, (TextNodeWithEntities.Arguments?) -> TextNodeWithEntities)?
if !textLayout.spoilers.isEmpty { if !textLayout.spoilers.isEmpty {
spoilerTextLayoutAndApply = spoilerTextLayout(TextNodeLayoutArguments(attributedString: attributedText, backgroundColor: nil, maximumNumberOfLines: hideAllAdditionalInfo ? 12 : 0, truncationType: .end, constrainedSize: textConstrainedSize, alignment: .natural, cutout: cutout, insets: textInsets, lineColor: messageTheme.accentControlColor, displaySpoilers: true, displayEmbeddedItemsUnderSpoilers: true)) spoilerTextLayoutAndApply = spoilerTextLayout(TextNodeLayoutArguments(attributedString: attributedText, backgroundColor: nil, maximumNumberOfLines: maximumNumberOfLines, truncationType: .end, constrainedSize: textConstrainedSize, alignment: .natural, cutout: nil, insets: textInsets, lineColor: messageTheme.accentControlColor, displaySpoilers: true, displayEmbeddedItemsUnderSpoilers: true))
} else { } else {
spoilerTextLayoutAndApply = nil spoilerTextLayoutAndApply = nil
} }
@ -546,12 +556,12 @@ public class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode {
} }
let dateLayoutInput: ChatMessageDateAndStatusNode.LayoutInput let dateLayoutInput: ChatMessageDateAndStatusNode.LayoutInput
dateLayoutInput = .trailingContent(contentWidth: trailingWidthToMeasure, reactionSettings: hideAllAdditionalInfo ? nil : ChatMessageDateAndStatusNode.TrailingReactionSettings(displayInline: shouldDisplayInlineDateReactions(message: item.message, isPremium: item.associatedData.isPremium, forceInline: item.associatedData.forceInlineReactions), preferAdditionalInset: false)) dateLayoutInput = .trailingContent(contentWidth: trailingWidthToMeasure, reactionSettings: item.presentationData.isPreview ? nil : ChatMessageDateAndStatusNode.TrailingReactionSettings(displayInline: shouldDisplayInlineDateReactions(message: item.message, isPremium: item.associatedData.isPremium, forceInline: item.associatedData.forceInlineReactions), preferAdditionalInset: false))
statusSuggestedWidthAndContinue = statusLayout(ChatMessageDateAndStatusNode.Arguments( statusSuggestedWidthAndContinue = statusLayout(ChatMessageDateAndStatusNode.Arguments(
context: item.context, context: item.context,
presentationData: item.presentationData, presentationData: item.presentationData,
edited: edited && !hideAllAdditionalInfo, edited: edited && !item.presentationData.isPreview,
impressionCount: viewCount, impressionCount: viewCount,
dateText: dateText, dateText: dateText,
type: statusType, type: statusType,
@ -576,14 +586,6 @@ public class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode {
textFrame = textFrame.offsetBy(dx: layoutConstants.text.bubbleInsets.left, dy: topInset) textFrame = textFrame.offsetBy(dx: layoutConstants.text.bubbleInsets.left, dy: topInset)
textFrameWithoutInsets = textFrameWithoutInsets.offsetBy(dx: layoutConstants.text.bubbleInsets.left, dy: topInset) textFrameWithoutInsets = textFrameWithoutInsets.offsetBy(dx: layoutConstants.text.bubbleInsets.left, dy: topInset)
var readMoreFrame: CGRect = .zero
if let (readMoreLayout, _ ) = moreLayoutAndApply {
let remainingLineWidth = textLayout.size.width - textLayout.trailingLineWidth
if readMoreLayout.size.width < remainingLineWidth {
readMoreFrame = CGRect(origin: CGPoint(x: textFrame.maxX - readMoreLayout.size.width - textInsets.right, y: textFrame.maxY - readMoreLayout.size.height - textInsets.bottom), size: readMoreLayout.size)
}
}
var suggestedBoundingWidth: CGFloat = textFrameWithoutInsets.width var suggestedBoundingWidth: CGFloat = textFrameWithoutInsets.width
if let statusSuggestedWidthAndContinue = statusSuggestedWidthAndContinue { if let statusSuggestedWidthAndContinue = statusSuggestedWidthAndContinue {
suggestedBoundingWidth = max(suggestedBoundingWidth, statusSuggestedWidthAndContinue.0) suggestedBoundingWidth = max(suggestedBoundingWidth, statusSuggestedWidthAndContinue.0)
@ -674,19 +676,6 @@ public class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode {
} }
} }
if let (_, moreApply) = moreLayoutAndApply {
let moreNode = moreApply()
if strongSelf.moreNode == nil {
moreNode.displaysAsynchronously = false
strongSelf.moreNode = moreNode
strongSelf.containerNode.insertSubnode(moreNode, aboveSubnode: strongSelf.textNode.textNode)
}
moreNode.frame = readMoreFrame
} else if let moreNode = strongSelf.moreNode {
strongSelf.moreNode = nil
moreNode.removeFromSupernode()
}
switch strongSelf.visibility { switch strongSelf.visibility {
case .none: case .none:
strongSelf.textNode.visibilityRect = nil strongSelf.textNode.visibilityRect = nil

View File

@ -109,7 +109,7 @@ public final class DrawingStickerEntity: DrawingEntity, Codable {
if case let .file(_, type) = self.content, case .reaction = type { if case let .file(_, type) = self.content, case .reaction = type {
self.scale = max(0.59, min(1.77, self.scale)) self.scale = max(0.59, min(1.77, self.scale))
} else if case .message = self.content { } else if case .message = self.content {
self.scale = max(1.0, min(4.0, self.scale)) self.scale = max(2.5, self.scale)
} }
} }
} }

View File

@ -2438,7 +2438,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
messageEntity.position = CGPoint(x: storyDimensions.width / 2.0, y: storyDimensions.height / 2.0) messageEntity.position = CGPoint(x: storyDimensions.width / 2.0, y: storyDimensions.height / 2.0)
let fraction = max(size.width, size.height) / 353.0 let fraction = max(size.width, size.height) / 353.0
messageEntity.scale = 3.3 * fraction messageEntity.scale = min(6.0, 3.3 * fraction)
self.entitiesView.add(messageEntity, announce: false) self.entitiesView.add(messageEntity, announce: false)
@ -2698,8 +2698,14 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
} }
} }
private var enhanceInitialTranslation: Float? private var canEnhance: Bool {
if case .message = self.subject {
return false
}
return true
}
private var enhanceInitialTranslation: Float?
@objc func handleDismissPan(_ gestureRecognizer: UIPanGestureRecognizer) { @objc func handleDismissPan(_ gestureRecognizer: UIPanGestureRecognizer) {
guard let controller = self.controller, let layout = self.validLayout, (layout.inputHeight ?? 0.0).isZero else { guard let controller = self.controller, let layout = self.validLayout, (layout.inputHeight ?? 0.0).isZero else {
return return
@ -2724,7 +2730,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
self.isDismissBySwipeSuppressed = controller.isEligibleForDraft() self.isDismissBySwipeSuppressed = controller.isEligibleForDraft()
controller.requestLayout(transition: .animated(duration: 0.25, curve: .easeInOut)) controller.requestLayout(transition: .animated(duration: 0.25, curve: .easeInOut))
} }
} else if abs(translation.x) > 10.0 && !self.isDismissing && !self.isEnhancing { } else if abs(translation.x) > 10.0 && !self.isDismissing && !self.isEnhancing && self.canEnhance {
self.isEnhancing = true self.isEnhancing = true
controller.requestLayout(transition: .animated(duration: 0.3, curve: .easeInOut)) controller.requestLayout(transition: .animated(duration: 0.3, curve: .easeInOut))
} }
@ -2770,7 +2776,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
self.isDismissing = false self.isDismissing = false
controller.requestLayout(transition: .animated(duration: 0.4, curve: .spring)) controller.requestLayout(transition: .animated(duration: 0.4, curve: .spring))
} }
} else { } else if self.isEnhancing {
self.isEnhancing = false self.isEnhancing = false
Queue.mainQueue().after(0.5) { Queue.mainQueue().after(0.5) {
controller.requestLayout(transition: .animated(duration: 0.3, curve: .easeInOut)) controller.requestLayout(transition: .animated(duration: 0.3, curve: .easeInOut))
@ -4008,7 +4014,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
if self.entitiesView.hasSelection { if self.entitiesView.hasSelection {
self.entitiesView.selectEntity(nil) self.entitiesView.selectEntity(nil)
} }
let controller = MediaToolsScreen(context: self.context, mediaEditor: mediaEditor) let controller = MediaToolsScreen(context: self.context, mediaEditor: mediaEditor, hiddenTools: !self.canEnhance ? [.enhance] : [])
controller.dismissed = { [weak self] in controller.dismissed = { [weak self] in
if let self { if let self {
self.animateInFromTool() self.animateInFromTool()

View File

@ -127,17 +127,20 @@ private final class MediaToolsScreenComponent: Component {
let context: AccountContext let context: AccountContext
let mediaEditor: MediaEditor let mediaEditor: MediaEditor
let section: MediaToolsSection let section: MediaToolsSection
let hiddenTools: [EditorToolKey]
let sectionUpdated: (MediaToolsSection) -> Void let sectionUpdated: (MediaToolsSection) -> Void
init( init(
context: AccountContext, context: AccountContext,
mediaEditor: MediaEditor, mediaEditor: MediaEditor,
section: MediaToolsSection, section: MediaToolsSection,
hiddenTools: [EditorToolKey],
sectionUpdated: @escaping (MediaToolsSection) -> Void sectionUpdated: @escaping (MediaToolsSection) -> Void
) { ) {
self.context = context self.context = context
self.mediaEditor = mediaEditor self.mediaEditor = mediaEditor
self.section = section self.section = section
self.hiddenTools = hiddenTools
self.sectionUpdated = sectionUpdated self.sectionUpdated = sectionUpdated
} }
@ -148,6 +151,9 @@ private final class MediaToolsScreenComponent: Component {
if lhs.section != rhs.section { if lhs.section != rhs.section {
return false return false
} }
if lhs.hiddenTools != rhs.hiddenTools {
return false
}
return true return true
} }
@ -362,7 +368,6 @@ private final class MediaToolsScreenComponent: Component {
if availableSize.height < previewSize.height + 30.0 { if availableSize.height < previewSize.height + 30.0 {
topInset = 0.0 topInset = 0.0
controlsBottomInset = -75.0 controlsBottomInset = -75.0
// self.buttonsBackgroundView.backgroundColor = .black
} else { } else {
self.buttonsBackgroundView.backgroundColor = .clear self.buttonsBackgroundView.backgroundColor = .clear
} }
@ -658,6 +663,8 @@ private final class MediaToolsScreenComponent: Component {
// ) // )
] ]
tools = tools.filter { !component.hiddenTools.contains($0.key) }
if !component.mediaEditor.sourceIsVideo { if !component.mediaEditor.sourceIsVideo {
tools.insert(AdjustmentTool( tools.insert(AdjustmentTool(
key: .grain, key: .grain,
@ -1044,6 +1051,7 @@ public final class MediaToolsScreen: ViewController {
context: self.context, context: self.context,
mediaEditor: controller.mediaEditor, mediaEditor: controller.mediaEditor,
section: self.currentSection, section: self.currentSection,
hiddenTools: controller.hiddenTools,
sectionUpdated: { [weak self] section in sectionUpdated: { [weak self] section in
if let self { if let self {
self.currentSection = section self.currentSection = section
@ -1087,15 +1095,17 @@ public final class MediaToolsScreen: ViewController {
} }
fileprivate let context: AccountContext fileprivate let context: AccountContext
fileprivate let hiddenTools: [EditorToolKey]
fileprivate let mediaEditor: MediaEditor fileprivate let mediaEditor: MediaEditor
public var dismissed: () -> Void = {} public var dismissed: () -> Void = {}
private var initialValues: MediaEditorValues private var initialValues: MediaEditorValues
public init(context: AccountContext, mediaEditor: MediaEditor) { public init(context: AccountContext, mediaEditor: MediaEditor, hiddenTools: [EditorToolKey]) {
self.context = context self.context = context
self.mediaEditor = mediaEditor self.mediaEditor = mediaEditor
self.hiddenTools = hiddenTools
self.initialValues = mediaEditor.values.makeCopy() self.initialValues = mediaEditor.values.makeCopy()
super.init(navigationBarPresentationData: nil) super.init(navigationBarPresentationData: nil)

View File

@ -2422,6 +2422,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
} }
let shareController = ShareController(context: strongSelf.context, subject: .messages(messages), updatedPresentationData: strongSelf.updatedPresentationData, shareAsLink: true) let shareController = ShareController(context: strongSelf.context, subject: .messages(messages), updatedPresentationData: strongSelf.updatedPresentationData, shareAsLink: true)
var canShareToStory = true
if let message = messages.first, message.media.contains(where: { media in if let message = messages.first, message.media.contains(where: { media in
if media is TelegramMediaContact || media is TelegramMediaPoll { if media is TelegramMediaContact || media is TelegramMediaPoll {
return true return true
@ -2431,7 +2432,13 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
return false return false
} }
}) { }) {
} else { canShareToStory = false
}
if message.text.containsOnlyEmoji {
canShareToStory = false
}
if canShareToStory {
shareController.shareStory = { [weak self] in shareController.shareStory = { [weak self] in
guard let self else { guard let self else {
return return