@@ -528,29 +528,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
528528 if case let . assets( _, mode) = controller. subject, [ . wallpaper, . story, . addImage, . cover, . createSticker, . createAvatar] . contains ( mode) {
529529
530530 } else {
531- let selectionGesture = MediaPickerGridSelectionGesture < TGMediaSelectableItem > ( )
532- selectionGesture. delegate = self . wrappedGestureRecognizerDelegate
533- selectionGesture. began = { [ weak self] in
534- self ? . controller? . cancelPanGesture ( )
535- }
536- selectionGesture. updateIsScrollEnabled = { [ weak self] isEnabled in
537- self ? . gridNode. scrollView. isScrollEnabled = isEnabled
538- }
539- selectionGesture. itemAt = { [ weak self] point in
540- if let self, let itemNode = self . gridNode. itemNodeAtPoint ( point) as? MediaPickerGridItemNode , let selectableItem = itemNode. selectableItem {
541- return ( selectableItem, self . controller? . interaction? . selectionState? . isIdentifierSelected ( selectableItem. uniqueIdentifier) ?? false )
542- } else {
543- return nil
544- }
545- }
546- selectionGesture. updateSelection = { [ weak self] asset, selected in
547- if let strongSelf = self {
548- strongSelf. controller? . interaction? . selectionState? . setItem ( asset, selected: selected, animated: true , sender: nil )
549- }
550- }
551- selectionGesture. sideInset = 44.0
552- self . gridNode. view. addGestureRecognizer ( selectionGesture)
553- self . selectionGesture = selectionGesture
531+ self . setupSelectionGesture ( )
554532 }
555533
556534 if let controller = self . controller, case let . assets( collection, _) = controller. subject, collection != nil {
@@ -713,6 +691,35 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
713691 }
714692 }
715693
694+ func setupSelectionGesture( ) {
695+ guard self . selectionGesture == nil else {
696+ return
697+ }
698+ let selectionGesture = MediaPickerGridSelectionGesture < TGMediaSelectableItem > ( )
699+ selectionGesture. delegate = self . wrappedGestureRecognizerDelegate
700+ selectionGesture. began = { [ weak self] in
701+ self ? . controller? . cancelPanGesture ( )
702+ }
703+ selectionGesture. updateIsScrollEnabled = { [ weak self] isEnabled in
704+ self ? . gridNode. scrollView. isScrollEnabled = isEnabled
705+ }
706+ selectionGesture. itemAt = { [ weak self] point in
707+ if let self, let itemNode = self . gridNode. itemNodeAtPoint ( point) as? MediaPickerGridItemNode , let selectableItem = itemNode. selectableItem {
708+ return ( selectableItem, self . controller? . interaction? . selectionState? . isIdentifierSelected ( selectableItem. uniqueIdentifier) ?? false )
709+ } else {
710+ return nil
711+ }
712+ }
713+ selectionGesture. updateSelection = { [ weak self] asset, selected in
714+ if let strongSelf = self {
715+ strongSelf. controller? . interaction? . selectionState? . setItem ( asset, selected: selected, animated: true , sender: nil )
716+ }
717+ }
718+ selectionGesture. sideInset = 44.0
719+ self . gridNode. view. addGestureRecognizer ( selectionGesture)
720+ self . selectionGesture = selectionGesture
721+ }
722+
716723 @objc private func cameraTapped( ) {
717724 guard let camera = self . modernCamera, let previewView = self . modernCameraView else {
718725 return
@@ -2352,9 +2359,6 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
23522359 let transition = ContainedViewLayoutTransition . animated ( duration: 0.25 , curve: . easeInOut)
23532360 var moreIsVisible = false
23542361 if case let . assets( _, mode) = self . subject, [ . story, . createSticker] . contains ( mode) {
2355- if count == 1 {
2356- self . requestAttachmentMenuExpansion ( )
2357- }
23582362 moreIsVisible = true
23592363 } else if case let . media( media) = self . subject {
23602364 self . titleView. title = media. count == 1 ? self . presentationData. strings. Attachment_Pasteboard : self . presentationData. strings. Attachment_SelectedMedia ( count)
@@ -2618,6 +2622,8 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
26182622
26192623 self . navigationItem. setRightBarButton ( nil , animated: true )
26202624 self . explicitMultipleSelection = true
2625+ self . controllerNode. setupSelectionGesture ( )
2626+ self . requestAttachmentMenuExpansion ( )
26212627
26222628 if let state = self . controllerNode. state {
26232629 self . controllerNode. updateState ( state)
0 commit comments