From eeb495d79b42fba2d5b580b59196c76f70e61364 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 20 Dec 2018 03:30:03 +0400 Subject: [PATCH] Fixed web search gallery selection --- TelegramUI/WebSearchGalleryController.swift | 28 ++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/TelegramUI/WebSearchGalleryController.swift b/TelegramUI/WebSearchGalleryController.swift index 9cd333cd03..3bf9fb8cbd 100644 --- a/TelegramUI/WebSearchGalleryController.swift +++ b/TelegramUI/WebSearchGalleryController.swift @@ -79,7 +79,8 @@ class WebSearchGalleryController: ViewController { private let centralItemNavigationStyle = Promise() private let centralItemFooterContentNode = Promise() private let centralItemAttributesDisposable = DisposableSet(); - + + private let checkedDisposable = MetaDisposable() private var checkNode: GalleryNavigationCheckNode? private let _hiddenMedia = Promise(nil) @@ -160,6 +161,7 @@ class WebSearchGalleryController: ViewController { deinit { self.disposable.dispose() + self.checkedDisposable.dispose() self.centralItemAttributesDisposable.dispose() } @@ -266,6 +268,30 @@ class WebSearchGalleryController: ViewController { } } + let selectionState = self.controllerInteraction?.selectionState + let selectionUpdated = Signal { subscriber in + if let selectionState = selectionState { + let disposable = selectionState.selectionChangedSignal()!.start(next: { _ in + subscriber.putNext(Void()) + }, error: { _ in }, completed: {})! + return ActionDisposable { + disposable.dispose() + } + } else { + subscriber.putCompletion() + return EmptyDisposable + } + } + self.checkedDisposable.set((selectionUpdated + |> deliverOnMainQueue).start(next: { [weak self] _ in + if let strongSelf = self, let centralItemNode = strongSelf.galleryNode.pager.centralItemNode() { + let item = strongSelf.entries[centralItemNode.index] + if let checkNode = strongSelf.checkNode, let controllerInteraction = strongSelf.controllerInteraction, let selectionState = controllerInteraction.selectionState { + checkNode.setIsChecked(selectionState.isIdentifierSelected(item.result.id), animated: true) + } + } + })) + let ready = self.galleryNode.pager.ready() |> timeout(2.0, queue: Queue.mainQueue(), alternate: .single(Void())) |> afterNext { [weak self] _ in self?.didSetReady = true }