mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-02 00:17:02 +00:00
Reaction effect in own stories
This commit is contained in:
parent
8130d9e937
commit
d5c1f37878
@ -3308,97 +3308,100 @@ final class StoryItemSetContainerSendMessage {
|
||||
return
|
||||
}
|
||||
|
||||
if component.slice.peer.id != component.context.account.peerId {
|
||||
let animateWithReactionItem: (ReactionItem) -> Void = { [weak self, weak view] reactionItem in
|
||||
guard let self, let view else {
|
||||
return
|
||||
}
|
||||
|
||||
self.performWithPossibleStealthModeConfirmation(view: view, action: { [weak view] in
|
||||
guard let view, let component = view.component else {
|
||||
return
|
||||
}
|
||||
if case .channel = component.slice.peer {
|
||||
} else {
|
||||
let _ = component.context.engine.messages.setStoryReaction(peerId: component.slice.peer.id, id: component.slice.item.storyItem.id, reaction: reaction).start()
|
||||
}
|
||||
|
||||
let targetFrame = reactionView.convert(reactionView.bounds, to: view)
|
||||
|
||||
let targetView = UIView(frame: targetFrame)
|
||||
targetView.isUserInteractionEnabled = false
|
||||
view.addSubview(targetView)
|
||||
|
||||
let standaloneReactionAnimation = StandaloneReactionAnimation(genericReactionEffect: nil, useDirectRendering: false)
|
||||
view.componentContainerView.addSubview(standaloneReactionAnimation.view)
|
||||
|
||||
if let standaloneReactionAnimation = view.standaloneReactionAnimation {
|
||||
view.standaloneReactionAnimation = nil
|
||||
standaloneReactionAnimation.view.removeFromSuperview()
|
||||
}
|
||||
view.standaloneReactionAnimation = standaloneReactionAnimation
|
||||
|
||||
standaloneReactionAnimation.frame = view.bounds
|
||||
standaloneReactionAnimation.animateReactionSelection(
|
||||
context: component.context,
|
||||
theme: component.theme,
|
||||
animationCache: component.context.animationCache,
|
||||
reaction: reactionItem,
|
||||
avatarPeers: [],
|
||||
playHaptic: true,
|
||||
isLarge: false,
|
||||
hideCenterAnimation: true,
|
||||
targetView: targetView,
|
||||
addStandaloneReactionAnimation: { [weak view] standaloneReactionAnimation in
|
||||
guard let view else {
|
||||
return
|
||||
}
|
||||
|
||||
if let standaloneReactionAnimation = view.standaloneReactionAnimation {
|
||||
view.standaloneReactionAnimation = nil
|
||||
standaloneReactionAnimation.view.removeFromSuperview()
|
||||
}
|
||||
view.standaloneReactionAnimation = standaloneReactionAnimation
|
||||
|
||||
standaloneReactionAnimation.frame = view.bounds
|
||||
view.componentContainerView.addSubview(standaloneReactionAnimation.view)
|
||||
},
|
||||
completion: { [weak targetView, weak standaloneReactionAnimation] in
|
||||
targetView?.removeFromSuperview()
|
||||
standaloneReactionAnimation?.view.removeFromSuperview()
|
||||
}
|
||||
)
|
||||
})
|
||||
let animateWithReactionItem: (ReactionItem) -> Void = { [weak self, weak view] reactionItem in
|
||||
guard let self, let view else {
|
||||
return
|
||||
}
|
||||
|
||||
switch reaction {
|
||||
case .builtin:
|
||||
if let availableReactions = component.availableReactions {
|
||||
for reactionItem in availableReactions.reactionItems {
|
||||
if reactionItem.reaction.rawValue == reaction {
|
||||
animateWithReactionItem(reactionItem)
|
||||
break
|
||||
self.performWithPossibleStealthModeConfirmation(view: view, action: { [weak view] in
|
||||
guard let view, let component = view.component else {
|
||||
return
|
||||
}
|
||||
if component.slice.peer.id != component.context.account.peerId {
|
||||
} else if case .channel = component.slice.peer {
|
||||
} else {
|
||||
let _ = component.context.engine.messages.setStoryReaction(peerId: component.slice.peer.id, id: component.slice.item.storyItem.id, reaction: reaction).start()
|
||||
}
|
||||
|
||||
let targetFrame = reactionView.convert(reactionView.bounds, to: view)
|
||||
|
||||
let targetView = UIView(frame: targetFrame)
|
||||
targetView.isUserInteractionEnabled = false
|
||||
view.addSubview(targetView)
|
||||
|
||||
let standaloneReactionAnimation = StandaloneReactionAnimation(genericReactionEffect: nil, useDirectRendering: false)
|
||||
view.componentContainerView.addSubview(standaloneReactionAnimation.view)
|
||||
|
||||
if let standaloneReactionAnimation = view.standaloneReactionAnimation {
|
||||
view.standaloneReactionAnimation = nil
|
||||
|
||||
let standaloneReactionAnimationView = standaloneReactionAnimation.view
|
||||
standaloneReactionAnimation.view.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.1, removeOnCompletion: false, completion: { [weak standaloneReactionAnimationView] _ in
|
||||
standaloneReactionAnimationView?.removeFromSuperview()
|
||||
})
|
||||
}
|
||||
view.standaloneReactionAnimation = standaloneReactionAnimation
|
||||
|
||||
standaloneReactionAnimation.frame = view.bounds
|
||||
standaloneReactionAnimation.animateReactionSelection(
|
||||
context: component.context,
|
||||
theme: component.theme,
|
||||
animationCache: component.context.animationCache,
|
||||
reaction: reactionItem,
|
||||
avatarPeers: [],
|
||||
playHaptic: true,
|
||||
isLarge: false,
|
||||
hideCenterAnimation: true,
|
||||
targetView: targetView,
|
||||
addStandaloneReactionAnimation: { [weak view] standaloneReactionAnimation in
|
||||
guard let view else {
|
||||
return
|
||||
}
|
||||
|
||||
if let standaloneReactionAnimation = view.standaloneReactionAnimation {
|
||||
view.standaloneReactionAnimation = nil
|
||||
standaloneReactionAnimation.view.removeFromSuperview()
|
||||
}
|
||||
view.standaloneReactionAnimation = standaloneReactionAnimation
|
||||
|
||||
standaloneReactionAnimation.frame = view.bounds
|
||||
view.componentContainerView.addSubview(standaloneReactionAnimation.view)
|
||||
},
|
||||
completion: { [weak targetView, weak standaloneReactionAnimation] in
|
||||
targetView?.removeFromSuperview()
|
||||
standaloneReactionAnimation?.view.removeFromSuperview()
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
switch reaction {
|
||||
case .builtin:
|
||||
if let availableReactions = component.availableReactions {
|
||||
for reactionItem in availableReactions.reactionItems {
|
||||
if reactionItem.reaction.rawValue == reaction {
|
||||
animateWithReactionItem(reactionItem)
|
||||
break
|
||||
}
|
||||
}
|
||||
case let .custom(fileId):
|
||||
let _ = (component.context.engine.stickers.resolveInlineStickers(fileIds: [fileId])
|
||||
|> deliverOnMainQueue).start(next: { files in
|
||||
if let itemFile = files[fileId] {
|
||||
let reactionItem = ReactionItem(
|
||||
reaction: ReactionItem.Reaction(rawValue: .custom(itemFile.fileId.id)),
|
||||
appearAnimation: itemFile,
|
||||
stillAnimation: itemFile,
|
||||
listAnimation: itemFile,
|
||||
largeListAnimation: itemFile,
|
||||
applicationAnimation: nil,
|
||||
largeApplicationAnimation: nil,
|
||||
isCustom: true
|
||||
)
|
||||
animateWithReactionItem(reactionItem)
|
||||
}
|
||||
})
|
||||
}
|
||||
case let .custom(fileId):
|
||||
let _ = (component.context.engine.stickers.resolveInlineStickers(fileIds: [fileId])
|
||||
|> deliverOnMainQueue).start(next: { files in
|
||||
if let itemFile = files[fileId] {
|
||||
let reactionItem = ReactionItem(
|
||||
reaction: ReactionItem.Reaction(rawValue: .custom(itemFile.fileId.id)),
|
||||
appearAnimation: itemFile,
|
||||
stillAnimation: itemFile,
|
||||
listAnimation: itemFile,
|
||||
largeListAnimation: itemFile,
|
||||
applicationAnimation: nil,
|
||||
largeApplicationAnimation: nil,
|
||||
isCustom: true
|
||||
)
|
||||
animateWithReactionItem(reactionItem)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user