From 9978ef672578b5b67d1cd3991763a3f102db1708 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Sat, 2 Nov 2019 22:59:49 +0400 Subject: [PATCH] Fix disabled check button glitches --- .../LegacyComponents/TGAttachmentAssetCell.m | 9 ++++++--- .../LegacyComponents/TGCheckButtonView.m | 2 +- .../LegacyComponents/TGMediaPickerCell.m | 3 +-- .../TGMediaPickerGalleryInterfaceView.m | 17 +++++++++++------ 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/submodules/LegacyComponents/LegacyComponents/TGAttachmentAssetCell.m b/submodules/LegacyComponents/LegacyComponents/TGAttachmentAssetCell.m index 4aa30205a7..51b23a8596 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGAttachmentAssetCell.m +++ b/submodules/LegacyComponents/LegacyComponents/TGAttachmentAssetCell.m @@ -6,6 +6,7 @@ @interface TGAttachmentAssetCell () { SMetaDisposable *_itemSelectedDisposable; + bool _ignoreSetSelected; } @end @@ -126,14 +127,16 @@ - (void)checkButtonPressed { - [_checkButton setSelected:!_checkButton.selected animated:true]; + _ignoreSetSelected = true; - [self.selectionContext setItem:(id)self.asset selected:_checkButton.selected animated:false sender:_checkButton]; + [self.selectionContext setItem:(id)self.asset selected:!_checkButton.selected animated:true sender:_checkButton]; bool value = [self.selectionContext isItemSelected:(id)self.asset]; if (value != _checkButton.selected) { - [_checkButton setSelected:value animated:false]; + [_checkButton setSelected:value animated:true]; } + + _ignoreSetSelected = false; } - (void)setChecked:(bool)checked animated:(bool)animated diff --git a/submodules/LegacyComponents/LegacyComponents/TGCheckButtonView.m b/submodules/LegacyComponents/LegacyComponents/TGCheckButtonView.m index 8bf2270aa4..8aa9440404 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGCheckButtonView.m +++ b/submodules/LegacyComponents/LegacyComponents/TGCheckButtonView.m @@ -483,7 +483,7 @@ static CGAffineTransform TGCheckButtonDefaultTransform; { _numberLabel = [[UILabel alloc] init]; _numberLabel.backgroundColor = [UIColor clearColor]; - _numberLabel.frame = CGRectMake(0.0f, -TGScreenPixel, _wrapperView.frame.size.width, _wrapperView.frame.size.height); + _numberLabel.frame = CGRectMake(0.0f, -TGScreenPixel, _wrapperView.bounds.size.width, _wrapperView.bounds.size.height); _numberLabel.textColor = _checkColor; _numberLabel.textAlignment = NSTextAlignmentCenter; _numberLabel.userInteractionEnabled = false; diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerCell.m b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerCell.m index 993848100d..263eb2aa9c 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerCell.m +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerCell.m @@ -96,8 +96,7 @@ - (void)checkButtonPressed { - [_checkButton setSelected:!_checkButton.selected animated:true]; - [self.selectionContext setItem:(id)self.item selected:_checkButton.selected animated:false sender:_checkButton]; + [self.selectionContext setItem:(id)self.item selected:!_checkButton.selected animated:false sender:_checkButton]; bool value = [self.selectionContext isItemSelected:(id)self.item]; if (value != _checkButton.selected) { [_checkButton setSelected:value animated:true]; diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.m b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.m index d3d5f3a38b..c94f055775 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.m +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.m @@ -64,6 +64,7 @@ TGModernButton *_muteButton; TGCheckButtonView *_checkButton; + bool _ignoreSetSelected; TGMediaPickerPhotoCounterButton *_photoCounterButton; TGMediaPickerGroupButton *_groupButton; TGMediaPickerCameraButton *_cameraButton; @@ -531,7 +532,9 @@ if ([_currentItem conformsToProtocol:@protocol(TGModernGallerySelectableItem)]) selectableItem = ((id)_currentItem).selectableMediaItem; - [_checkButton setSelected:[_selectionContext isItemSelected:selectableItem] animated:false]; + if (!_ignoreSetSelected) { + [_checkButton setSelected:[_selectionContext isItemSelected:selectableItem] animated:false]; + } [_checkButton setNumber:[_selectionContext indexOfItem:selectableItem]]; signal = [_selectionContext itemInformativeSelectedSignal:selectableItem]; [_itemSelectedDisposable setDisposable:[signal startWithNext:^(TGMediaSelectionChange *next) @@ -669,15 +672,17 @@ if ([_currentItem conformsToProtocol:@protocol(TGModernGallerySelectableItem)]) selectableItem = ((id)_currentItem).selectableMediaItem; - [_checkButton setSelected:!_checkButton.selected animated:true]; + _ignoreSetSelected = true; if (selectableItem != nil) { - [_selectionContext setItem:selectableItem selected:_checkButton.selected animated:animated sender:_checkButton]; + [_selectionContext setItem:selectableItem selected:!_checkButton.selected animated:animated sender:_checkButton]; bool value = [_selectionContext isItemSelected:selectableItem]; - if (value != _checkButton.selected) { - [_checkButton setSelected:value animated:true]; - } + [_checkButton setSelected:value animated:true]; + } else { + [_checkButton setSelected:!_checkButton.selected animated:true]; } + + _ignoreSetSelected = false; } - (void)photoCounterButtonPressed