mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-07 01:10:09 +00:00
Prevent media gallery from opening multiple times
This commit is contained in:
parent
99d210e364
commit
16768ffb10
@ -48,6 +48,7 @@ public final class OpenChatMessageParams {
|
|||||||
public let gallerySource: GalleryControllerItemSource?
|
public let gallerySource: GalleryControllerItemSource?
|
||||||
public let centralItemUpdated: ((MessageId) -> Void)?
|
public let centralItemUpdated: ((MessageId) -> Void)?
|
||||||
public let getSourceRect: (() -> CGRect?)?
|
public let getSourceRect: (() -> CGRect?)?
|
||||||
|
public let blockInteraction: Promise<Bool>
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
context: AccountContext,
|
context: AccountContext,
|
||||||
@ -109,5 +110,6 @@ public final class OpenChatMessageParams {
|
|||||||
self.gallerySource = gallerySource
|
self.gallerySource = gallerySource
|
||||||
self.centralItemUpdated = centralItemUpdated
|
self.centralItemUpdated = centralItemUpdated
|
||||||
self.getSourceRect = getSourceRect
|
self.getSourceRect = getSourceRect
|
||||||
|
self.blockInteraction = Promise()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1076,7 +1076,6 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode {
|
|||||||
|
|
||||||
private var customUnembedWhenPortrait: ((OverlayMediaItemNode) -> Bool)?
|
private var customUnembedWhenPortrait: ((OverlayMediaItemNode) -> Bool)?
|
||||||
|
|
||||||
private var pictureInPictureContent: AnyObject?
|
|
||||||
private var nativePictureInPictureContent: AnyObject?
|
private var nativePictureInPictureContent: AnyObject?
|
||||||
|
|
||||||
private var activePictureInPictureNavigationController: NavigationController?
|
private var activePictureInPictureNavigationController: NavigationController?
|
||||||
@ -1544,10 +1543,6 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode {
|
|||||||
strongSelf.videoNode?.setBaseRate(playbackRate)
|
strongSelf.videoNode?.setBaseRate(playbackRate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if strongSelf.nativePictureInPictureContent == nil {
|
|
||||||
strongSelf.setupNativePictureInPicture()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.videoNode = videoNode
|
self.videoNode = videoNode
|
||||||
@ -2963,19 +2958,29 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc func pictureInPictureButtonPressed() {
|
@objc func pictureInPictureButtonPressed() {
|
||||||
if let currentPictureInPictureNode = self.context.sharedContext.mediaManager.currentPictureInPictureNode as? UniversalVideoGalleryItemNode, let currentItem = currentPictureInPictureNode.item, case let .message(currentMessage, _) = currentItem.contentInfo, case let .message(message, _) = self.item?.contentInfo, currentMessage.id == message.id {
|
if self.nativePictureInPictureContent == nil {
|
||||||
if let controller = self.galleryController() as? GalleryController {
|
self.setupNativePictureInPicture()
|
||||||
controller.dismiss(forceAway: true)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if #available(iOS 15.0, *) {
|
DispatchQueue.main.async { [weak self] in
|
||||||
if let nativePictureInPictureContent = self.nativePictureInPictureContent as? NativePictureInPictureContentImpl {
|
guard let self else {
|
||||||
addAppLogEvent(postbox: self.context.account.postbox, type: "pip_btn", peerId: self.context.account.peerId)
|
|
||||||
nativePictureInPictureContent.beginPictureInPicture()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let currentPictureInPictureNode = self.context.sharedContext.mediaManager.currentPictureInPictureNode as? UniversalVideoGalleryItemNode, let currentItem = currentPictureInPictureNode.item, case let .message(currentMessage, _) = currentItem.contentInfo, case let .message(message, _) = self.item?.contentInfo, currentMessage.id == message.id {
|
||||||
|
if let controller = self.galleryController() as? GalleryController {
|
||||||
|
controller.dismiss(forceAway: true)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if #available(iOS 15.0, *) {
|
||||||
|
if let nativePictureInPictureContent = self.nativePictureInPictureContent as? NativePictureInPictureContentImpl {
|
||||||
|
addAppLogEvent(postbox: self.context.account.postbox, type: "pip_btn", peerId: self.context.account.peerId)
|
||||||
|
nativePictureInPictureContent.beginPictureInPicture()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -58,7 +58,10 @@ public class ChatMessageMediaBubbleContentNode: ChatMessageBubbleContentNode {
|
|||||||
openChatMessageMode = .automaticPlayback
|
openChatMessageMode = .automaticPlayback
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = item.controllerInteraction.openMessage(item.message, OpenMessageParams(mode: openChatMessageMode, mediaIndex: self.mediaIndex, progress: self.itemNode?.makeProgress()))
|
if !item.controllerInteraction.isOpeningMedia {
|
||||||
|
let params = OpenMessageParams(mode: openChatMessageMode, mediaIndex: self.mediaIndex, progress: self.itemNode?.makeProgress())
|
||||||
|
let _ = item.controllerInteraction.openMessage(item.message, params)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.interactiveImageNode.activateAgeRestrictedMedia = { [weak self] in
|
self.interactiveImageNode.activateAgeRestrictedMedia = { [weak self] in
|
||||||
|
|||||||
@ -303,6 +303,29 @@ public final class ChatControllerInteraction: ChatControllerInteractionProtocol
|
|||||||
public var chatIsRotated: Bool = true
|
public var chatIsRotated: Bool = true
|
||||||
public var canReadHistory: Bool = false
|
public var canReadHistory: Bool = false
|
||||||
|
|
||||||
|
private var isOpeningMediaValue: Bool = false
|
||||||
|
public var isOpeningMedia: Bool {
|
||||||
|
return self.isOpeningMediaValue
|
||||||
|
}
|
||||||
|
private var isOpeningMediaDisposable: Disposable?
|
||||||
|
public var isOpeningMediaSignal: Signal<Bool, NoError>? {
|
||||||
|
didSet {
|
||||||
|
self.isOpeningMediaDisposable?.dispose()
|
||||||
|
self.isOpeningMediaDisposable = nil
|
||||||
|
self.isOpeningMediaValue = false
|
||||||
|
|
||||||
|
if let isOpeningMediaSignal = self.isOpeningMediaSignal {
|
||||||
|
self.isOpeningMediaValue = true
|
||||||
|
self.isOpeningMediaDisposable = (isOpeningMediaSignal |> filter { !$0 } |> take(1) |> timeout(1.0, queue: .mainQueue(), alternate: .single(false)) |> deliverOnMainQueue).startStrict(next: { [weak self] _ in
|
||||||
|
guard let self else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
self.isOpeningMediaValue = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
openMessage: @escaping (Message, OpenMessageParams) -> Bool,
|
openMessage: @escaping (Message, OpenMessageParams) -> Bool,
|
||||||
openPeer: @escaping (EnginePeer, ChatControllerInteractionNavigateToPeer, MessageReference?, OpenPeerSource) -> Void,
|
openPeer: @escaping (EnginePeer, ChatControllerInteractionNavigateToPeer, MessageReference?, OpenPeerSource) -> Void,
|
||||||
@ -538,4 +561,8 @@ public final class ChatControllerInteraction: ChatControllerInteractionProtocol
|
|||||||
|
|
||||||
self.presentationContext = presentationContext
|
self.presentationContext = presentationContext
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
self.isOpeningMediaDisposable?.dispose()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -323,8 +323,12 @@ func openChatMessageImpl(_ params: OpenChatMessageParams) -> Bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
params.blockInteraction.set(.single(true))
|
||||||
|
|
||||||
let _ = (gallery
|
let _ = (gallery
|
||||||
|> deliverOnMainQueue).startStandalone(next: { gallery in
|
|> deliverOnMainQueue).startStandalone(next: { gallery in
|
||||||
|
params.blockInteraction.set(.single(false))
|
||||||
|
|
||||||
gallery.centralItemUpdated = { messageId in
|
gallery.centralItemUpdated = { messageId in
|
||||||
params.centralItemUpdated?(messageId)
|
params.centralItemUpdated?(messageId)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user