Improve voice chat scrolling

This commit is contained in:
Ilya Laktyushin 2020-12-23 15:24:37 +04:00
parent dbf5a5691f
commit e46c8645eb
8 changed files with 44 additions and 18 deletions

View File

@ -38,6 +38,7 @@ typedef enum
@property (nonatomic, readonly) NSString *uniformTypeIdentifier;
@property (nonatomic, readonly) NSString *fileName;
@property (nonatomic, readonly) NSInteger fileSize;
@property (nonatomic, readonly) bool isFavorite;
@property (nonatomic, readonly) TGMediaAssetType type;
@property (nonatomic, readonly) TGMediaAssetSubtype subtypes;

View File

@ -9,6 +9,8 @@
@property (nonatomic, readonly) TGImageView *imageView;
@property (nonatomic, readonly) TGCheckButtonView *checkButton;
@property (nonatomic, readonly) UIImageView *typeIconView;
- (void)setHidden:(bool)hidden animated:(bool)animated;
@property (nonatomic, strong) TGMediaSelectionContext *selectionContext;

View File

@ -102,6 +102,11 @@
return [self.uniformTypeIdentifier isEqualToString:(NSString *)kUTTypeGIF];
}
- (bool)isFavorite
{
return _backingAsset.isFavorite;
}
- (TGMediaAssetType)type
{
if (_cachedType == nil)

View File

@ -1,5 +1,7 @@
#import "TGMediaAssetsPhotoCell.h"
#import <LegacyComponents/TGMediaAsset.h>
#import "LegacyComponentsInternal.h"
NSString *const TGMediaAssetsPhotoCellKind = @"TGMediaAssetsPhotoCellKind";
@ -14,4 +16,15 @@ NSString *const TGMediaAssetsPhotoCellKind = @"TGMediaAssetsPhotoCellKind";
return self;
}
- (void)setItem:(NSObject *)item signal:(SSignal *)signal
{
[super setItem:item signal:signal];
TGMediaAsset *asset = (TGMediaAsset *)item;
if (![asset isKindOfClass:[TGMediaAsset class]])
return;
self.typeIconView.image = asset.isFavorite ? TGComponentsImageNamed(@"MediaGroupFavorites") : nil;
}
@end

View File

@ -15,7 +15,6 @@ NSString *const TGMediaAssetsVideoCellKind = @"TGMediaAssetsVideoCellKind";
@interface TGMediaAssetsVideoCell ()
{
UIImageView *_shadowView;
UIImageView *_iconView;
UILabel *_durationLabel;
SMetaDisposable *_adjustmentsDisposable;
@ -65,9 +64,6 @@ NSString *const TGMediaAssetsVideoCellKind = @"TGMediaAssetsVideoCellKind";
_shadowView.image = shadowImage;
[self addSubview:_shadowView];
_iconView = [[UIImageView alloc] init];
_iconView.contentMode = UIViewContentModeCenter;
_durationLabel = [[UILabel alloc] init];
_durationLabel.textColor = [UIColor whiteColor];
_durationLabel.backgroundColor = [UIColor clearColor];
@ -81,7 +77,6 @@ NSString *const TGMediaAssetsVideoCellKind = @"TGMediaAssetsVideoCellKind";
if (iosMajorVersion() >= 11)
{
_shadowView.accessibilityIgnoresInvertColors = true;
_iconView.accessibilityIgnoresInvertColors = true;
_durationLabel.accessibilityIgnoresInvertColors = true;
}
@ -103,7 +98,6 @@ NSString *const TGMediaAssetsVideoCellKind = @"TGMediaAssetsVideoCellKind";
if (![asset isKindOfClass:[TGMediaAsset class]])
return;
NSString *durationString = nil;
int duration = (int)ceil(asset.videoDuration);
if (duration >= 3600)
@ -114,12 +108,7 @@ NSString *const TGMediaAssetsVideoCellKind = @"TGMediaAssetsVideoCellKind";
_durationLabel.text = durationString;
[_durationLabel sizeToFit];
if (asset.subtypes & TGMediaAssetSubtypeVideoTimelapse)
_iconView.image = TGComponentsImageNamed(@"ModernMediaItemTimelapseIcon");
else if (asset.subtypes & TGMediaAssetSubtypeVideoHighFrameRate)
_iconView.image = TGComponentsImageNamed(@"ModernMediaItemSloMoIcon");
else
_iconView.image = TGComponentsImageNamed(@"ModernMediaItemVideoIcon");
self.typeIconView.image = asset.isFavorite ? TGComponentsImageNamed(@"MediaGroupFavorites") : nil;
SSignal *adjustmentsSignal = [self.editingContext adjustmentsSignalForItem:(id<TGMediaEditableItem>)self.item];
@ -234,7 +223,6 @@ NSString *const TGMediaAssetsVideoCellKind = @"TGMediaAssetsVideoCellKind";
{
self.checkButton.frame = (CGRect){ { self.frame.size.width - self.checkButton.frame.size.width - 2, 2 }, self.checkButton.frame.size };
_shadowView.frame = (CGRect){ { 0, self.frame.size.height - _shadowView.frame.size.height }, {self.frame.size.width, _shadowView.frame.size.height } };
_iconView.frame = CGRectMake(0, self.frame.size.height - 19, 19, 19);
CGSize durationSize = _durationLabel.frame.size;
_durationLabel.frame = CGRectMake(self.frame.size.width - floor(durationSize.width) - 5.0, self.frame.size.height - floor(durationSize.height) - 4.0, durationSize.width, durationSize.height);

View File

@ -34,6 +34,10 @@
if (iosMajorVersion() >= 11)
_imageView.accessibilityIgnoresInvertColors = true;
_typeIconView = [[UIImageView alloc] init];
_typeIconView.contentMode = UIViewContentModeCenter;
[self addSubview:_typeIconView];
self.isAccessibilityElement = true;
}
return self;
@ -212,6 +216,8 @@
_imageView.frame = self.bounds;
_imageView.transform = transform;
_typeIconView.frame = CGRectMake(2.0, self.frame.size.height - 19 - 2, 19, 19);
_checkButton.frame = (CGRect){ { self.frame.size.width - _checkButton.frame.size.width - 2, 2 }, _checkButton.frame.size };
}

View File

@ -1072,7 +1072,7 @@ static id<LegacyComponentsContext> _defaultContext = nil;
+ (UIEdgeInsets)safeAreaInsetForOrientation:(UIInterfaceOrientation)orientation hasOnScreenNavigation:(bool)hasOnScreenNavigation
{
int height = (int)TGScreenSize().height;
if (!TGIsPad() && (height != 812 && height != 896 && height != 780 && height != 844 && height != 926))
if (!TGIsPad() && (height != 812 && height != 896 && height != 780 && height != 844 && height != 926) && !hasOnScreenNavigation)
return UIEdgeInsetsZero;
if (TGIsPad()) {

View File

@ -2079,6 +2079,7 @@ public final class VoiceChatController: ViewController {
private var panGestureArguments: (topInset: CGFloat, offset: CGFloat)?
@objc func panGesture(_ recognizer: UIPanGestureRecognizer) {
let contentOffset = self.listNode.visibleContentOffset()
switch recognizer.state {
case .began:
let topInset: CGFloat
@ -2096,7 +2097,8 @@ public final class VoiceChatController: ViewController {
if let (currentTopInset, currentPanOffset) = self.panGestureArguments {
topInset = currentTopInset
if case let .known(value) = self.listNode.visibleContentOffset(), value > 0 {
if case let .known(value) = contentOffset, value <= 0.5 {
} else {
translation = currentPanOffset
if self.isExpanded {
recognizer.setTranslation(CGPoint(), in: self.contentContainer.view)
@ -2114,7 +2116,6 @@ public final class VoiceChatController: ViewController {
}
if self.isExpanded {
} else {
if currentOffset > 0.0 {
self.listNode.scroller.panGestureRecognizer.setTranslation(CGPoint(), in: self.listNode.scroller)
@ -2136,7 +2137,9 @@ public final class VoiceChatController: ViewController {
let translation = recognizer.translation(in: self.contentContainer.view)
var velocity = recognizer.velocity(in: self.contentContainer.view)
if case let .known(value) = self.listNode.visibleContentOffset(), value > 0 {
if case let .known(value) = contentOffset, value > 0.0 {
velocity = CGPoint()
} else if case .unknown = contentOffset {
velocity = CGPoint()
}
@ -2164,6 +2167,7 @@ public final class VoiceChatController: ViewController {
self.isExpanded = false
self.updateIsFullscreen(false)
self.animatingExpansion = true
self.listNode.scroller.setContentOffset(CGPoint(), animated: false)
if let (layout, navigationHeight) = self.validLayout {
self.containerLayoutUpdated(layout, navigationHeight: navigationHeight, transition: .animated(duration: 0.3, curve: .easeInOut))
@ -2193,6 +2197,12 @@ public final class VoiceChatController: ViewController {
self.updateIsFullscreen(true)
self.animatingExpansion = true
if velocity.y > -1500.0 {
DispatchQueue.main.async {
self.listNode.transaction(deleteIndices: [], insertIndicesAndItems: [], updateIndicesAndItems: [], options: [.Synchronous, .LowLatency], scrollToItem: ListViewScrollToItem(index: 0, position: .top(0.0), animated: true, curve: .Default(duration: nil), directionHint: .Up), updateSizeAndInsets: nil, stationaryItemRange: nil, updateOpaqueState: nil, completion: { _ in })
}
}
if let (layout, navigationHeight) = self.validLayout {
self.containerLayoutUpdated(layout, navigationHeight: navigationHeight, transition: .animated(duration: 0.3, curve: .easeInOut))
}
@ -2202,6 +2212,7 @@ public final class VoiceChatController: ViewController {
} else {
self.updateIsFullscreen(false)
self.animatingExpansion = true
self.listNode.scroller.setContentOffset(CGPoint(), animated: false)
if let (layout, navigationHeight) = self.validLayout {
self.containerLayoutUpdated(layout, navigationHeight: navigationHeight, transition: .animated(duration: 0.3, curve: .easeInOut))