mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Update story reactions [skip ci]
This commit is contained in:
parent
89bddb319a
commit
db9e286857
@ -48,6 +48,7 @@ public final class DrawingStickerEntityView: DrawingEntityView {
|
|||||||
|
|
||||||
if case .file(_, .reaction) = entity.content {
|
if case .file(_, .reaction) = entity.content {
|
||||||
let backgroundNode = ASImageNode()
|
let backgroundNode = ASImageNode()
|
||||||
|
backgroundNode.layer.zPosition = -1000.0
|
||||||
backgroundNode.image = UIImage(bundleImageName: "Media Editor/ReactionBackground")
|
backgroundNode.image = UIImage(bundleImageName: "Media Editor/ReactionBackground")
|
||||||
backgroundNode.displaysAsynchronously = false
|
backgroundNode.displaysAsynchronously = false
|
||||||
self.addSubnode(backgroundNode)
|
self.addSubnode(backgroundNode)
|
||||||
@ -319,15 +320,13 @@ public final class DrawingStickerEntityView: DrawingEntityView {
|
|||||||
var boundingSize = CGSize(width: sideSize, height: sideSize)
|
var boundingSize = CGSize(width: sideSize, height: sideSize)
|
||||||
|
|
||||||
if let backgroundNode = self.backgroundNode {
|
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))
|
boundingSize = CGSize(width: floor(sideSize * 0.63), height: floor(sideSize * 0.63))
|
||||||
}
|
}
|
||||||
|
|
||||||
let imageSize = self.dimensions.aspectFitted(boundingSize)
|
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)
|
let 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)
|
|
||||||
}
|
|
||||||
self.imageNode.asyncLayout()(TransformImageArguments(corners: ImageCorners(), imageSize: imageSize, boundingSize: imageSize, intrinsicInsets: UIEdgeInsets()))()
|
self.imageNode.asyncLayout()(TransformImageArguments(corners: ImageCorners(), imageSize: imageSize, boundingSize: imageSize, intrinsicInsets: UIEdgeInsets()))()
|
||||||
self.imageNode.frame = imageFrame
|
self.imageNode.frame = imageFrame
|
||||||
if let animationNode = self.animationNode {
|
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() {
|
func onDeselection() {
|
||||||
let _ = self.dismissReactionSelection()
|
let _ = self.dismissReactionSelection()
|
||||||
}
|
}
|
||||||
@ -560,10 +577,14 @@ public final class DrawingStickerEntityView: DrawingEntityView {
|
|||||||
self.bounds = CGRect(origin: .zero, size: self.dimensions.aspectFitted(size))
|
self.bounds = CGRect(origin: .zero, size: self.dimensions.aspectFitted(size))
|
||||||
self.transform = CGAffineTransformScale(CGAffineTransformMakeRotation(self.stickerEntity.rotation), self.stickerEntity.scale, self.stickerEntity.scale)
|
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)
|
let staticTransform = CATransform3DMakeScale(self.stickerEntity.mirrored ? -1.0 : 1.0, 1.0, 1.0)
|
||||||
|
|
||||||
if animated {
|
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 animationSourceTransform = CATransform3DIdentity
|
||||||
var animationTargetTransform = CATransform3DIdentity
|
var animationTargetTransform = CATransform3DIdentity
|
||||||
if isCurrentlyMirrored {
|
if isCurrentlyMirrored {
|
||||||
@ -574,23 +595,44 @@ public final class DrawingStickerEntityView: DrawingEntityView {
|
|||||||
animationTargetTransform = CATransform3DRotate(animationTargetTransform, .pi, 0.0, 1.0, 0.0)
|
animationTargetTransform = CATransform3DRotate(animationTargetTransform, .pi, 0.0, 1.0, 0.0)
|
||||||
animationTargetTransform.m34 = -1.0 / self.imageNode.frame.width
|
animationTargetTransform.m34 = -1.0 / self.imageNode.frame.width
|
||||||
}
|
}
|
||||||
self.imageNode.transform = animationSourceTransform
|
if isReaction {
|
||||||
self.animationNode?.transform = animationSourceTransform
|
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: {
|
UIView.animate(withDuration: 0.25, animations: {
|
||||||
self.imageNode.transform = animationTargetTransform
|
if isReaction {
|
||||||
self.animationNode?.transform = animationTargetTransform
|
self.backgroundNode?.transform = animationTargetTransform
|
||||||
self.videoNode?.transform = animationTargetTransform
|
} else {
|
||||||
|
self.imageNode.transform = animationTargetTransform
|
||||||
|
self.animationNode?.transform = animationTargetTransform
|
||||||
|
self.videoNode?.transform = animationTargetTransform
|
||||||
|
}
|
||||||
}, completion: { finished in
|
}, completion: { finished in
|
||||||
self.imageNode.transform = staticTransform
|
if isReaction {
|
||||||
self.animationNode?.transform = staticTransform
|
self.backgroundNode?.transform = staticTransform
|
||||||
self.videoNode?.transform = staticTransform
|
} else {
|
||||||
|
self.imageNode.transform = staticTransform
|
||||||
|
self.animationNode?.transform = staticTransform
|
||||||
|
self.videoNode?.transform = staticTransform
|
||||||
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
CATransaction.begin()
|
CATransaction.begin()
|
||||||
CATransaction.setDisableActions(true)
|
CATransaction.setDisableActions(true)
|
||||||
self.imageNode.transform = staticTransform
|
if isReaction {
|
||||||
self.animationNode?.transform = staticTransform
|
self.backgroundNode?.transform = staticTransform
|
||||||
self.videoNode?.transform = staticTransform
|
} else {
|
||||||
|
self.imageNode.transform = staticTransform
|
||||||
|
self.animationNode?.transform = staticTransform
|
||||||
|
self.videoNode?.transform = staticTransform
|
||||||
|
}
|
||||||
CATransaction.commit()
|
CATransaction.commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,12 +649,9 @@ public final class DrawingStickerEntityView: DrawingEntityView {
|
|||||||
|
|
||||||
selectionView.transform = .identity
|
selectionView.transform = .identity
|
||||||
let maxSide = max(self.selectionBounds.width, self.selectionBounds.height)
|
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
|
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)
|
selectionView.center = self.convert(center, to: selectionView.superview)
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ public final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate
|
|||||||
return self.entity as! DrawingTextEntity
|
return self.entity as! DrawingTextEntity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let blurredBackgroundView: BlurredBackgroundView
|
||||||
let textView: DrawingTextView
|
let textView: DrawingTextView
|
||||||
var customEmojiContainerView: CustomEmojiContainerView?
|
var customEmojiContainerView: CustomEmojiContainerView?
|
||||||
var emojiViewProvider: ((ChatTextInputTextCustomEmojiAttribute) -> UIView)?
|
var emojiViewProvider: ((ChatTextInputTextCustomEmojiAttribute) -> UIView)?
|
||||||
@ -35,6 +36,10 @@ public final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate
|
|||||||
var replaceWithImage: (UIImage, Bool) -> Void = { _, _ in }
|
var replaceWithImage: (UIImage, Bool) -> Void = { _, _ in }
|
||||||
|
|
||||||
init(context: AccountContext, entity: DrawingTextEntity) {
|
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 = DrawingTextView(frame: .zero)
|
||||||
self.textView.clipsToBounds = false
|
self.textView.clipsToBounds = false
|
||||||
|
|
||||||
@ -56,6 +61,7 @@ public final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate
|
|||||||
super.init(context: context, entity: entity)
|
super.init(context: context, entity: entity)
|
||||||
|
|
||||||
self.textView.delegate = self
|
self.textView.delegate = self
|
||||||
|
self.addSubview(self.blurredBackgroundView)
|
||||||
self.addSubview(self.textView)
|
self.addSubview(self.textView)
|
||||||
|
|
||||||
self.emojiViewProvider = { emoji in
|
self.emojiViewProvider = { emoji in
|
||||||
@ -174,6 +180,8 @@ public final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate
|
|||||||
textColor = color
|
textColor = color
|
||||||
case .stroke:
|
case .stroke:
|
||||||
textColor = color.lightness > 0.99 ? UIColor.black : UIColor.white
|
textColor = color.lightness > 0.99 ? UIColor.black : UIColor.white
|
||||||
|
case .blur:
|
||||||
|
textColor = color
|
||||||
}
|
}
|
||||||
|
|
||||||
self.emojiRects = customEmojiRects
|
self.emojiRects = customEmojiRects
|
||||||
@ -466,6 +474,8 @@ public final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate
|
|||||||
textColor = color
|
textColor = color
|
||||||
case .stroke:
|
case .stroke:
|
||||||
textColor = color.lightness > 0.99 ? UIColor.black : UIColor.white
|
textColor = color.lightness > 0.99 ? UIColor.black : UIColor.white
|
||||||
|
case .blur:
|
||||||
|
textColor = color
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let visualText = text.mutableCopy() as? NSMutableAttributedString else {
|
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.textColor = color.lightness > 0.99 ? UIColor.black : UIColor.white
|
||||||
self.textView.strokeColor = color
|
self.textView.strokeColor = color
|
||||||
self.textView.frameColor = nil
|
self.textView.frameColor = nil
|
||||||
|
case .blur:
|
||||||
|
break
|
||||||
}
|
}
|
||||||
self.textView.tintColor = self.textView.text.isEmpty ? .white : cursorColor
|
self.textView.tintColor = self.textView.text.isEmpty ? .white : cursorColor
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ enum DrawingTextStyle: Equatable {
|
|||||||
case filled
|
case filled
|
||||||
case semi
|
case semi
|
||||||
case stroke
|
case stroke
|
||||||
|
case blur
|
||||||
|
|
||||||
init(style: DrawingTextEntity.Style) {
|
init(style: DrawingTextEntity.Style) {
|
||||||
switch style {
|
switch style {
|
||||||
@ -23,6 +24,8 @@ enum DrawingTextStyle: Equatable {
|
|||||||
self = .semi
|
self = .semi
|
||||||
case .stroke:
|
case .stroke:
|
||||||
self = .stroke
|
self = .stroke
|
||||||
|
case .blur:
|
||||||
|
self = .blur
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -502,6 +505,8 @@ final class TextSettingsComponent: CombinedComponent {
|
|||||||
styleImage = state.image(.semi)
|
styleImage = state.image(.semi)
|
||||||
case .stroke:
|
case .stroke:
|
||||||
styleImage = state.image(.stroke)
|
styleImage = state.image(.stroke)
|
||||||
|
case .blur:
|
||||||
|
styleImage = state.image(.stroke)
|
||||||
}
|
}
|
||||||
|
|
||||||
var fontAvailableWidth: CGFloat = context.availableSize.width
|
var fontAvailableWidth: CGFloat = context.availableSize.width
|
||||||
|
@ -80,7 +80,13 @@ public final class DrawingStickerEntity: DrawingEntity, Codable {
|
|||||||
|
|
||||||
public var referenceDrawingSize: CGSize
|
public var referenceDrawingSize: CGSize
|
||||||
public var position: CGPoint
|
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 rotation: CGFloat
|
||||||
public var mirrored: Bool
|
public var mirrored: Bool
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@ public final class DrawingTextEntity: DrawingEntity, Codable {
|
|||||||
case filled
|
case filled
|
||||||
case semi
|
case semi
|
||||||
case stroke
|
case stroke
|
||||||
|
case blur
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Animation: Codable, Equatable {
|
public enum Animation: Codable, Equatable {
|
||||||
|
@ -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] {
|
func composerEntitiesForDrawingEntity(postbox: Postbox, textScale: CGFloat, entity: DrawingEntity, colorSpace: CGColorSpace, tintColor: UIColor? = nil) -> [MediaEditorComposerEntity] {
|
||||||
if let entity = entity as? DrawingStickerEntity {
|
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]) {
|
if case let .file(_, type) = entity.content, case .reaction = type {
|
||||||
return [MediaEditorComposerStaticEntity(image: image, position: entity.position, scale: entity.scale, rotation: entity.rotation, baseSize: entity.baseSize, mirrored: false)]
|
return []
|
||||||
|
// return [MediaEditorComposerStaticEntity(image: image, position: entity.position, scale: entity.scale, rotation: entity.rotation, baseSize: entity.baseSize, mirrored: false)]
|
||||||
} else {
|
} else {
|
||||||
let content: MediaEditorComposerStickerEntity.Content
|
let content: MediaEditorComposerStickerEntity.Content
|
||||||
switch entity.content {
|
switch entity.content {
|
||||||
|
@ -2283,7 +2283,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
|
|||||||
}
|
}
|
||||||
if gestureRecognizer === self.dismissPanGestureRecognizer {
|
if gestureRecognizer === self.dismissPanGestureRecognizer {
|
||||||
let location = gestureRecognizer.location(in: self.entitiesView)
|
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 false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@ -3028,7 +3028,6 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
|
|||||||
if let self {
|
if let self {
|
||||||
self.mediaEditor?.setAudioTrack(nil)
|
self.mediaEditor?.setAudioTrack(nil)
|
||||||
self.requestUpdate(transition: .easeInOut(duration: 0.25))
|
self.requestUpdate(transition: .easeInOut(duration: 0.25))
|
||||||
// strongSelf.insertEntity.invoke(DrawingSimpleShapeEntity(shapeType: .rectangle, drawType: .stroke, color: strongSelf.currentColor, lineWidth: 0.15))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user