diff --git a/submodules/DrawingUI/Sources/DrawingStickerEntity.swift b/submodules/DrawingUI/Sources/DrawingStickerEntity.swift index acd9bc753b..2841e1ddeb 100644 --- a/submodules/DrawingUI/Sources/DrawingStickerEntity.swift +++ b/submodules/DrawingUI/Sources/DrawingStickerEntity.swift @@ -48,6 +48,7 @@ public final class DrawingStickerEntityView: DrawingEntityView { if case .file(_, .reaction) = entity.content { let backgroundNode = ASImageNode() + backgroundNode.layer.zPosition = -1000.0 backgroundNode.image = UIImage(bundleImageName: "Media Editor/ReactionBackground") backgroundNode.displaysAsynchronously = false self.addSubnode(backgroundNode) @@ -319,15 +320,13 @@ public final class DrawingStickerEntityView: DrawingEntityView { var boundingSize = CGSize(width: sideSize, height: sideSize) if let backgroundNode = self.backgroundNode { - backgroundNode.frame = CGRect(origin: .zero, size: boundingSize) + backgroundNode.frame = CGRect(origin: .zero, size: boundingSize).insetBy(dx: -5.0, dy: -5.0) boundingSize = CGSize(width: floor(sideSize * 0.63), height: floor(sideSize * 0.63)) } let imageSize = self.dimensions.aspectFitted(boundingSize) - var imageFrame = CGRect(origin: CGPoint(x: floor((size.width - imageSize.width) / 2.0), y: (size.height - imageSize.height) / 2.0), size: imageSize) - if case let .file(_, type) = self.stickerEntity.content, case .reaction = type { - imageFrame = imageFrame.offsetBy(dx: -3.0, dy: -9.0) - } + let imageFrame = CGRect(origin: CGPoint(x: floor((size.width - imageSize.width) / 2.0), y: (size.height - imageSize.height) / 2.0), size: imageSize) + self.imageNode.asyncLayout()(TransformImageArguments(corners: ImageCorners(), imageSize: imageSize, boundingSize: imageSize, intrinsicInsets: UIEdgeInsets()))() self.imageNode.frame = imageFrame if let animationNode = self.animationNode { @@ -351,6 +350,24 @@ public final class DrawingStickerEntityView: DrawingEntityView { } } + private var isReaction: Bool { + if case let .file(_, type) = self.stickerEntity.content, case .reaction = type { + return true + } else { + return false + } + } + + override func animateInsertion() { + super.animateInsertion() + + if self.isReaction { + Queue.mainQueue().after(0.2) { + let _ = self.selectedTapAction() + } + } + } + func onDeselection() { let _ = self.dismissReactionSelection() } @@ -560,10 +577,14 @@ public final class DrawingStickerEntityView: DrawingEntityView { self.bounds = CGRect(origin: .zero, size: self.dimensions.aspectFitted(size)) self.transform = CGAffineTransformScale(CGAffineTransformMakeRotation(self.stickerEntity.rotation), self.stickerEntity.scale, self.stickerEntity.scale) + let isReaction = self.isReaction let staticTransform = CATransform3DMakeScale(self.stickerEntity.mirrored ? -1.0 : 1.0, 1.0, 1.0) - + if animated { - let isCurrentlyMirrored = ((self.imageNode.layer.value(forKeyPath: "transform.scale.y") as? NSNumber)?.floatValue ?? 1.0) < 0.0 + var isCurrentlyMirrored = ((self.imageNode.layer.value(forKeyPath: "transform.scale.y") as? NSNumber)?.floatValue ?? 1.0) < 0.0 + if isReaction { + isCurrentlyMirrored = ((self.backgroundNode?.layer.value(forKeyPath: "transform.scale.y") as? NSNumber)?.floatValue ?? 1.0) < 0.0 + } var animationSourceTransform = CATransform3DIdentity var animationTargetTransform = CATransform3DIdentity if isCurrentlyMirrored { @@ -574,23 +595,44 @@ public final class DrawingStickerEntityView: DrawingEntityView { animationTargetTransform = CATransform3DRotate(animationTargetTransform, .pi, 0.0, 1.0, 0.0) animationTargetTransform.m34 = -1.0 / self.imageNode.frame.width } - self.imageNode.transform = animationSourceTransform - self.animationNode?.transform = animationSourceTransform + if isReaction { + self.backgroundNode?.transform = animationSourceTransform + + let values = [1.0, 0.01, 1.0] + let keyTimes = [0.0, 0.5, 1.0] + self.animationNode?.layer.animateKeyframes(values: values as [NSNumber], keyTimes: keyTimes as [NSNumber], duration: 0.25, keyPath: "transform.scale.x", timingFunction: CAMediaTimingFunctionName.linear.rawValue) + } else { + self.imageNode.transform = animationSourceTransform + self.animationNode?.transform = animationSourceTransform + self.videoNode?.transform = animationSourceTransform + } UIView.animate(withDuration: 0.25, animations: { - self.imageNode.transform = animationTargetTransform - self.animationNode?.transform = animationTargetTransform - self.videoNode?.transform = animationTargetTransform + if isReaction { + self.backgroundNode?.transform = animationTargetTransform + } else { + self.imageNode.transform = animationTargetTransform + self.animationNode?.transform = animationTargetTransform + self.videoNode?.transform = animationTargetTransform + } }, completion: { finished in - self.imageNode.transform = staticTransform - self.animationNode?.transform = staticTransform - self.videoNode?.transform = staticTransform + if isReaction { + self.backgroundNode?.transform = staticTransform + } else { + self.imageNode.transform = staticTransform + self.animationNode?.transform = staticTransform + self.videoNode?.transform = staticTransform + } }) } else { CATransaction.begin() CATransaction.setDisableActions(true) - self.imageNode.transform = staticTransform - self.animationNode?.transform = staticTransform - self.videoNode?.transform = staticTransform + if isReaction { + self.backgroundNode?.transform = staticTransform + } else { + self.imageNode.transform = staticTransform + self.animationNode?.transform = staticTransform + self.videoNode?.transform = staticTransform + } CATransaction.commit() } @@ -607,12 +649,9 @@ public final class DrawingStickerEntityView: DrawingEntityView { selectionView.transform = .identity let maxSide = max(self.selectionBounds.width, self.selectionBounds.height) - var center = self.selectionBounds.center + let center = self.selectionBounds.center let scale = self.superview?.superview?.layer.value(forKeyPath: "transform.scale.x") as? CGFloat ?? 1.0 - if case let .file(_, type) = self.stickerEntity.content, case .reaction = type { - center = center.offsetBy(dx: -8.0 * scale, dy: -18.0 * scale) - } selectionView.center = self.convert(center, to: selectionView.superview) diff --git a/submodules/DrawingUI/Sources/DrawingTextEntity.swift b/submodules/DrawingUI/Sources/DrawingTextEntity.swift index b9ffc1ba1f..20cde13ec5 100644 --- a/submodules/DrawingUI/Sources/DrawingTextEntity.swift +++ b/submodules/DrawingUI/Sources/DrawingTextEntity.swift @@ -27,6 +27,7 @@ public final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate return self.entity as! DrawingTextEntity } + let blurredBackgroundView: BlurredBackgroundView let textView: DrawingTextView var customEmojiContainerView: CustomEmojiContainerView? var emojiViewProvider: ((ChatTextInputTextCustomEmojiAttribute) -> UIView)? @@ -35,6 +36,10 @@ public final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate var replaceWithImage: (UIImage, Bool) -> Void = { _, _ in } init(context: AccountContext, entity: DrawingTextEntity) { + self.blurredBackgroundView = BlurredBackgroundView(color: UIColor(white: 0.0, alpha: 0.25), enableBlur: true) + self.blurredBackgroundView.clipsToBounds = true + self.blurredBackgroundView.isHidden = true + self.textView = DrawingTextView(frame: .zero) self.textView.clipsToBounds = false @@ -56,6 +61,7 @@ public final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate super.init(context: context, entity: entity) self.textView.delegate = self + self.addSubview(self.blurredBackgroundView) self.addSubview(self.textView) self.emojiViewProvider = { emoji in @@ -174,6 +180,8 @@ public final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate textColor = color case .stroke: textColor = color.lightness > 0.99 ? UIColor.black : UIColor.white + case .blur: + textColor = color } self.emojiRects = customEmojiRects @@ -466,6 +474,8 @@ public final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate textColor = color case .stroke: textColor = color.lightness > 0.99 ? UIColor.black : UIColor.white + case .blur: + textColor = color } guard let visualText = text.mutableCopy() as? NSMutableAttributedString else { @@ -629,6 +639,8 @@ public final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate self.textView.textColor = color.lightness > 0.99 ? UIColor.black : UIColor.white self.textView.strokeColor = color self.textView.frameColor = nil + case .blur: + break } self.textView.tintColor = self.textView.text.isEmpty ? .white : cursorColor diff --git a/submodules/DrawingUI/Sources/TextSettingsComponent.swift b/submodules/DrawingUI/Sources/TextSettingsComponent.swift index 5702b3b372..099be3521e 100644 --- a/submodules/DrawingUI/Sources/TextSettingsComponent.swift +++ b/submodules/DrawingUI/Sources/TextSettingsComponent.swift @@ -12,6 +12,7 @@ enum DrawingTextStyle: Equatable { case filled case semi case stroke + case blur init(style: DrawingTextEntity.Style) { switch style { @@ -23,6 +24,8 @@ enum DrawingTextStyle: Equatable { self = .semi case .stroke: self = .stroke + case .blur: + self = .blur } } } @@ -502,6 +505,8 @@ final class TextSettingsComponent: CombinedComponent { styleImage = state.image(.semi) case .stroke: styleImage = state.image(.stroke) + case .blur: + styleImage = state.image(.stroke) } var fontAvailableWidth: CGFloat = context.availableSize.width diff --git a/submodules/TelegramUI/Components/MediaEditor/Sources/Drawing/DrawingStickerEntity.swift b/submodules/TelegramUI/Components/MediaEditor/Sources/Drawing/DrawingStickerEntity.swift index c1c9ec38b5..206d176115 100644 --- a/submodules/TelegramUI/Components/MediaEditor/Sources/Drawing/DrawingStickerEntity.swift +++ b/submodules/TelegramUI/Components/MediaEditor/Sources/Drawing/DrawingStickerEntity.swift @@ -80,7 +80,13 @@ public final class DrawingStickerEntity: DrawingEntity, Codable { public var referenceDrawingSize: CGSize public var position: CGPoint - public var scale: CGFloat + public var scale: CGFloat { + didSet { + if case let .file(_, type) = self.content, case .reaction = type { + self.scale = max(0.75, min(2.0, self.scale)) + } + } + } public var rotation: CGFloat public var mirrored: Bool diff --git a/submodules/TelegramUI/Components/MediaEditor/Sources/Drawing/DrawingTextEntity.swift b/submodules/TelegramUI/Components/MediaEditor/Sources/Drawing/DrawingTextEntity.swift index deecc1193a..9eac4874ef 100644 --- a/submodules/TelegramUI/Components/MediaEditor/Sources/Drawing/DrawingTextEntity.swift +++ b/submodules/TelegramUI/Components/MediaEditor/Sources/Drawing/DrawingTextEntity.swift @@ -61,6 +61,7 @@ public final class DrawingTextEntity: DrawingEntity, Codable { case filled case semi case stroke + case blur } public enum Animation: Codable, Equatable { diff --git a/submodules/TelegramUI/Components/MediaEditor/Sources/MediaEditorComposerEntity.swift b/submodules/TelegramUI/Components/MediaEditor/Sources/MediaEditorComposerEntity.swift index b5c0caa4b0..a6d865c56a 100644 --- a/submodules/TelegramUI/Components/MediaEditor/Sources/MediaEditorComposerEntity.swift +++ b/submodules/TelegramUI/Components/MediaEditor/Sources/MediaEditorComposerEntity.swift @@ -63,8 +63,9 @@ private func prerenderTextTransformations(entity: DrawingEntity, image: UIImage, func composerEntitiesForDrawingEntity(postbox: Postbox, textScale: CGFloat, entity: DrawingEntity, colorSpace: CGColorSpace, tintColor: UIColor? = nil) -> [MediaEditorComposerEntity] { if let entity = entity as? DrawingStickerEntity { - if case let .file(_, type) = entity.content, case .reaction = type, let renderImage = entity.renderImage, let image = CIImage(image: renderImage, options: [.colorSpace: colorSpace]) { - return [MediaEditorComposerStaticEntity(image: image, position: entity.position, scale: entity.scale, rotation: entity.rotation, baseSize: entity.baseSize, mirrored: false)] + if case let .file(_, type) = entity.content, case .reaction = type { + return [] +// return [MediaEditorComposerStaticEntity(image: image, position: entity.position, scale: entity.scale, rotation: entity.rotation, baseSize: entity.baseSize, mirrored: false)] } else { let content: MediaEditorComposerStickerEntity.Content switch entity.content { diff --git a/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaEditorScreen.swift b/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaEditorScreen.swift index 688a4d5567..40833120f8 100644 --- a/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaEditorScreen.swift +++ b/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaEditorScreen.swift @@ -2283,7 +2283,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate } if gestureRecognizer === self.dismissPanGestureRecognizer { let location = gestureRecognizer.location(in: self.entitiesView) - if self.isDisplayingTool || self.entitiesView.hasSelection || self.entitiesView.getView(at: location) != nil { + if self.controller?.isEditingStory == true || self.isDisplayingTool || self.entitiesView.hasSelection || self.entitiesView.getView(at: location) != nil { return false } return true @@ -3028,7 +3028,6 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate if let self { self.mediaEditor?.setAudioTrack(nil) self.requestUpdate(transition: .easeInOut(duration: 0.25)) -// strongSelf.insertEntity.invoke(DrawingSimpleShapeEntity(shapeType: .rectangle, drawType: .stroke, color: strongSelf.currentColor, lineWidth: 0.15)) } } ) diff --git a/submodules/TelegramUI/Images.xcassets/Media Editor/ReactionBackground.imageset/Reaction Sticker.pdf b/submodules/TelegramUI/Images.xcassets/Media Editor/ReactionBackground.imageset/Reaction Sticker.pdf index 569452cbad..80a343fff4 100644 Binary files a/submodules/TelegramUI/Images.xcassets/Media Editor/ReactionBackground.imageset/Reaction Sticker.pdf and b/submodules/TelegramUI/Images.xcassets/Media Editor/ReactionBackground.imageset/Reaction Sticker.pdf differ