Apply Voice Chat UI fixes

This commit is contained in:
Ilya Laktyushin 2020-12-23 21:11:56 +04:00
parent 3d062fff78
commit a9d42fd5c8
11 changed files with 50 additions and 34 deletions

View File

@ -422,7 +422,7 @@ open class ListViewItemNode: ASDisplayNode, AccessibilityFocusableNode {
} }
public func addInsetsAnimationToValue(_ value: UIEdgeInsets, duration: Double, beginAt: Double) { public func addInsetsAnimationToValue(_ value: UIEdgeInsets, duration: Double, beginAt: Double) {
let animation = ListViewAnimation(from: self.insets, to: value, duration: duration, curve: listViewAnimationCurveSystem, beginAt: beginAt, update: { [weak self] _, currentValue in let animation = ListViewAnimation(from: self.insets, to: value, duration: duration, curve: self.preferredAnimationCurve, beginAt: beginAt, update: { [weak self] _, currentValue in
if let strongSelf = self { if let strongSelf = self {
strongSelf.insets = currentValue strongSelf.insets = currentValue
} }
@ -483,7 +483,7 @@ open class ListViewItemNode: ASDisplayNode, AccessibilityFocusableNode {
duration = 0.0 duration = 0.0
} }
let animation = ListViewAnimation(from: self.apparentHeight, to: value, duration: duration, curve: listViewAnimationCurveSystem, beginAt: beginAt, update: { [weak self] _, currentValue in let animation = ListViewAnimation(from: self.apparentHeight, to: value, duration: duration, curve: self.preferredAnimationCurve, beginAt: beginAt, update: { [weak self] _, currentValue in
if let strongSelf = self { if let strongSelf = self {
strongSelf.apparentHeight = currentValue strongSelf.apparentHeight = currentValue
} }

View File

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

View File

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

View File

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

View File

@ -1,5 +1,7 @@
#import "TGMediaAssetsPhotoCell.h" #import "TGMediaAssetsPhotoCell.h"
#import <LegacyComponents/TGMediaAsset.h>
#import "LegacyComponentsInternal.h" #import "LegacyComponentsInternal.h"
NSString *const TGMediaAssetsPhotoCellKind = @"TGMediaAssetsPhotoCellKind"; NSString *const TGMediaAssetsPhotoCellKind = @"TGMediaAssetsPhotoCellKind";
@ -14,4 +16,15 @@ NSString *const TGMediaAssetsPhotoCellKind = @"TGMediaAssetsPhotoCellKind";
return self; 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 @end

View File

@ -15,7 +15,6 @@ NSString *const TGMediaAssetsVideoCellKind = @"TGMediaAssetsVideoCellKind";
@interface TGMediaAssetsVideoCell () @interface TGMediaAssetsVideoCell ()
{ {
UIImageView *_shadowView; UIImageView *_shadowView;
UIImageView *_iconView;
UILabel *_durationLabel; UILabel *_durationLabel;
SMetaDisposable *_adjustmentsDisposable; SMetaDisposable *_adjustmentsDisposable;
@ -64,10 +63,7 @@ NSString *const TGMediaAssetsVideoCellKind = @"TGMediaAssetsVideoCellKind";
_shadowView = [[UIImageView alloc] initWithFrame:CGRectMake(0, frame.size.height - 20, frame.size.width, 20)]; _shadowView = [[UIImageView alloc] initWithFrame:CGRectMake(0, frame.size.height - 20, frame.size.width, 20)];
_shadowView.image = shadowImage; _shadowView.image = shadowImage;
[self addSubview:_shadowView]; [self addSubview:_shadowView];
_iconView = [[UIImageView alloc] init];
_iconView.contentMode = UIViewContentModeCenter;
_durationLabel = [[UILabel alloc] init]; _durationLabel = [[UILabel alloc] init];
_durationLabel.textColor = [UIColor whiteColor]; _durationLabel.textColor = [UIColor whiteColor];
_durationLabel.backgroundColor = [UIColor clearColor]; _durationLabel.backgroundColor = [UIColor clearColor];
@ -81,7 +77,6 @@ NSString *const TGMediaAssetsVideoCellKind = @"TGMediaAssetsVideoCellKind";
if (iosMajorVersion() >= 11) if (iosMajorVersion() >= 11)
{ {
_shadowView.accessibilityIgnoresInvertColors = true; _shadowView.accessibilityIgnoresInvertColors = true;
_iconView.accessibilityIgnoresInvertColors = true;
_durationLabel.accessibilityIgnoresInvertColors = true; _durationLabel.accessibilityIgnoresInvertColors = true;
} }
@ -103,7 +98,6 @@ NSString *const TGMediaAssetsVideoCellKind = @"TGMediaAssetsVideoCellKind";
if (![asset isKindOfClass:[TGMediaAsset class]]) if (![asset isKindOfClass:[TGMediaAsset class]])
return; return;
NSString *durationString = nil; NSString *durationString = nil;
int duration = (int)ceil(asset.videoDuration); int duration = (int)ceil(asset.videoDuration);
if (duration >= 3600) if (duration >= 3600)
@ -114,12 +108,7 @@ NSString *const TGMediaAssetsVideoCellKind = @"TGMediaAssetsVideoCellKind";
_durationLabel.text = durationString; _durationLabel.text = durationString;
[_durationLabel sizeToFit]; [_durationLabel sizeToFit];
if (asset.subtypes & TGMediaAssetSubtypeVideoTimelapse) self.typeIconView.image = asset.isFavorite ? TGComponentsImageNamed(@"MediaGroupFavorites") : nil;
_iconView.image = TGComponentsImageNamed(@"ModernMediaItemTimelapseIcon");
else if (asset.subtypes & TGMediaAssetSubtypeVideoHighFrameRate)
_iconView.image = TGComponentsImageNamed(@"ModernMediaItemSloMoIcon");
else
_iconView.image = TGComponentsImageNamed(@"ModernMediaItemVideoIcon");
SSignal *adjustmentsSignal = [self.editingContext adjustmentsSignalForItem:(id<TGMediaEditableItem>)self.item]; 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 }; 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 } }; _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; 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); _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) if (iosMajorVersion() >= 11)
_imageView.accessibilityIgnoresInvertColors = true; _imageView.accessibilityIgnoresInvertColors = true;
_typeIconView = [[UIImageView alloc] init];
_typeIconView.contentMode = UIViewContentModeCenter;
[self addSubview:_typeIconView];
self.isAccessibilityElement = true; self.isAccessibilityElement = true;
} }
return self; return self;
@ -212,6 +216,8 @@
_imageView.frame = self.bounds; _imageView.frame = self.bounds;
_imageView.transform = transform; _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 }; _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 + (UIEdgeInsets)safeAreaInsetForOrientation:(UIInterfaceOrientation)orientation hasOnScreenNavigation:(bool)hasOnScreenNavigation
{ {
int height = (int)TGScreenSize().height; 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; return UIEdgeInsetsZero;
if (TGIsPad()) { if (TGIsPad()) {

View File

@ -257,8 +257,4 @@ class VoiceChatActionItemNode: ListViewItemNode {
override public func header() -> ListViewItemHeader? { override public func header() -> ListViewItemHeader? {
return nil return nil
} }
override var preferredAnimationCurve: (CGFloat) -> CGFloat {
return listViewAnimationCurveEaseInOut
}
} }

View File

@ -940,9 +940,9 @@ public final class VoiceChatController: ViewController {
self.call.members, self.call.members,
invitedPeers invitedPeers
) )
|> mapToSignal { values in |> mapToThrottled { values in
return .single(values) return .single(values)
|> delay(0.0, queue: .mainQueue()) |> then(.complete() |> delay(0.1, queue: Queue.mainQueue()))
}).start(next: { [weak self] state, callMembers, invitedPeers in }).start(next: { [weak self] state, callMembers, invitedPeers in
guard let strongSelf = self else { guard let strongSelf = self else {
return return
@ -1826,8 +1826,6 @@ public final class VoiceChatController: ViewController {
} }
let topPanelFrame = self.topPanelNode.view.convert(self.topPanelNode.bounds, to: self.view) let topPanelFrame = self.topPanelNode.view.convert(self.topPanelNode.bounds, to: self.view)
let offset: CGFloat = self.contentContainer.bounds.minY
self.contentContainer.layer.animateBoundsOriginYAdditive(from: self.contentContainer.bounds.origin.y, to: -(layout.size.height - topPanelFrame.minY) - 44.0, duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, completion: { _ in self.contentContainer.layer.animateBoundsOriginYAdditive(from: self.contentContainer.bounds.origin.y, to: -(layout.size.height - topPanelFrame.minY) - 44.0, duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, completion: { _ in
offsetCompleted = true offsetCompleted = true
internalCompletion() internalCompletion()
@ -1861,7 +1859,7 @@ public final class VoiceChatController: ViewController {
if transition.crossFade { if transition.crossFade {
options.insert(.AnimateCrossfade) options.insert(.AnimateCrossfade)
} }
if transition.animated { if transition.animated && self.animation == nil {
options.insert(.AnimateInsertion) options.insert(.AnimateInsertion)
} }
} }
@ -1897,7 +1895,7 @@ public final class VoiceChatController: ViewController {
self.listNode.frame = frame self.listNode.frame = frame
} else if !self.isExpanded { } else if !self.isExpanded {
if self.listNode.frame.minY != targetY && !self.animatingExpansion && self.panGestureArguments == nil { if self.listNode.frame.minY != targetY && !self.animatingExpansion && self.panGestureArguments == nil {
self.animation = ListViewAnimation(from: self.listNode.frame.minY, to: targetY, duration: 0.4, curve: listViewAnimationCurveEaseInOut, beginAt: CACurrentMediaTime(), update: { [weak self] _, currentValue in self.animation = ListViewAnimation(from: self.listNode.frame.minY, to: targetY, duration: 0.4, curve: listViewAnimationCurveSystem, beginAt: CACurrentMediaTime(), update: { [weak self] _, currentValue in
if let strongSelf = self { if let strongSelf = self {
var frame = strongSelf.listNode.frame var frame = strongSelf.listNode.frame
frame.origin.y = currentValue frame.origin.y = currentValue
@ -2055,6 +2053,7 @@ public final class VoiceChatController: ViewController {
private var panGestureArguments: (topInset: CGFloat, offset: CGFloat)? private var panGestureArguments: (topInset: CGFloat, offset: CGFloat)?
@objc func panGesture(_ recognizer: UIPanGestureRecognizer) { @objc func panGesture(_ recognizer: UIPanGestureRecognizer) {
let contentOffset = self.listNode.visibleContentOffset()
switch recognizer.state { switch recognizer.state {
case .began: case .began:
let topInset: CGFloat let topInset: CGFloat
@ -2072,7 +2071,8 @@ public final class VoiceChatController: ViewController {
if let (currentTopInset, currentPanOffset) = self.panGestureArguments { if let (currentTopInset, currentPanOffset) = self.panGestureArguments {
topInset = currentTopInset topInset = currentTopInset
if case let .known(value) = self.listNode.visibleContentOffset(), value > 0 { if case let .known(value) = contentOffset, value <= 0.5 {
} else {
translation = currentPanOffset translation = currentPanOffset
if self.isExpanded { if self.isExpanded {
recognizer.setTranslation(CGPoint(), in: self.contentContainer.view) recognizer.setTranslation(CGPoint(), in: self.contentContainer.view)
@ -2090,7 +2090,6 @@ public final class VoiceChatController: ViewController {
} }
if self.isExpanded { if self.isExpanded {
} else { } else {
if currentOffset > 0.0 { if currentOffset > 0.0 {
self.listNode.scroller.panGestureRecognizer.setTranslation(CGPoint(), in: self.listNode.scroller) self.listNode.scroller.panGestureRecognizer.setTranslation(CGPoint(), in: self.listNode.scroller)
@ -2112,7 +2111,9 @@ public final class VoiceChatController: ViewController {
let translation = recognizer.translation(in: self.contentContainer.view) let translation = recognizer.translation(in: self.contentContainer.view)
var velocity = recognizer.velocity(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() velocity = CGPoint()
} }
@ -2140,6 +2141,7 @@ public final class VoiceChatController: ViewController {
self.isExpanded = false self.isExpanded = false
self.updateIsFullscreen(false) self.updateIsFullscreen(false)
self.animatingExpansion = true self.animatingExpansion = true
self.listNode.scroller.setContentOffset(CGPoint(), animated: false)
if let (layout, navigationHeight) = self.validLayout { if let (layout, navigationHeight) = self.validLayout {
self.containerLayoutUpdated(layout, navigationHeight: navigationHeight, transition: .animated(duration: 0.3, curve: .easeInOut)) self.containerLayoutUpdated(layout, navigationHeight: navigationHeight, transition: .animated(duration: 0.3, curve: .easeInOut))
@ -2165,6 +2167,12 @@ public final class VoiceChatController: ViewController {
self.controller?.dismiss(closing: false, manual: true) self.controller?.dismiss(closing: false, manual: true)
dismissing = true dismissing = true
} else if velocity.y < -300.0 || offset < topInset / 2.0 { } else if velocity.y < -300.0 || offset < topInset / 2.0 {
if velocity.y > -1500.0 && !self.isFullscreen {
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 })
}
}
self.isExpanded = true self.isExpanded = true
self.updateIsFullscreen(true) self.updateIsFullscreen(true)
self.animatingExpansion = true self.animatingExpansion = true
@ -2178,6 +2186,7 @@ public final class VoiceChatController: ViewController {
} else { } else {
self.updateIsFullscreen(false) self.updateIsFullscreen(false)
self.animatingExpansion = true self.animatingExpansion = true
self.listNode.scroller.setContentOffset(CGPoint(), animated: false)
if let (layout, navigationHeight) = self.validLayout { if let (layout, navigationHeight) = self.validLayout {
self.containerLayoutUpdated(layout, navigationHeight: navigationHeight, transition: .animated(duration: 0.3, curve: .easeInOut)) self.containerLayoutUpdated(layout, navigationHeight: navigationHeight, transition: .animated(duration: 0.3, curve: .easeInOut))

View File

@ -787,8 +787,4 @@ class VoiceChatParticipantItemNode: ItemListRevealOptionsItemNode {
self.setRevealOptionsOpened(false, animated: true) self.setRevealOptionsOpened(false, animated: true)
self.revealOptionsInteractivelyClosed() self.revealOptionsInteractivelyClosed()
} }
override var preferredAnimationCurve: (CGFloat) -> CGFloat {
return listViewAnimationCurveEaseInOut
}
} }