Skip to content

Commit 40b7fea

Browse files
laktyushinAli
authored andcommitted
Video Messages Improvements
(cherry picked from commit e614343)
1 parent 51b1f7a commit 40b7fea

File tree

6 files changed

+193
-12
lines changed

6 files changed

+193
-12
lines changed

submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGVideoMessageRingView.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#import <UIKit/UIKit.h>
22

3+
@interface TGVideoMessageShimmerView : UIView
4+
5+
- (void)updateAbsoluteRect:(CGRect)absoluteRect containerSize:(CGSize)containerSize;
6+
7+
@end
8+
9+
310
@interface TGVideoMessageRingView : UIView
411

512
@property (nonatomic, strong) UIColor *accentColor;

submodules/LegacyComponents/Sources/TGVideoMessageCaptureController.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ @interface TGVideoMessageCaptureController () <TGVideoCameraPipelineDelegate, TG
9696
UIView *_separatorView;
9797

9898
UIImageView *_placeholderView;
99+
TGVideoMessageShimmerView *_shimmerView;
99100

100101
bool _automaticDismiss;
101102
NSTimeInterval _startTimestamp;
@@ -329,6 +330,10 @@ - (void)loadView
329330
_placeholderView.image = [TGVideoMessageCaptureController startImage];
330331
[_circleView addSubview:_placeholderView];
331332

333+
_shimmerView = [[TGVideoMessageShimmerView alloc] initWithFrame:_circleView.bounds];
334+
[_shimmerView updateAbsoluteRect:_circleView.bounds containerSize:_circleView.bounds.size];
335+
[_circleView addSubview:_shimmerView];
336+
332337
if (iosMajorVersion() >= 11)
333338
{
334339
_shadowView.accessibilityIgnoresInvertColors = true;
@@ -1182,9 +1187,11 @@ - (void)captureStarted
11821187
[UIView animateWithDuration:0.3 delay:delay options:kNilOptions animations:^
11831188
{
11841189
_placeholderView.alpha = 0.0f;
1190+
_shimmerView.alpha = 0.0f;
11851191
_switchButton.alpha = 1.0f;
11861192
} completion:^(__unused BOOL finished)
11871193
{
1194+
_shimmerView.hidden = true;
11881195
_placeholderView.hidden = true;
11891196
_placeholderView.alpha = 1.0f;
11901197
}];

submodules/LegacyComponents/Sources/TGVideoMessageRingView.m

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,168 @@
22

33
#import "TGColor.h"
44

5+
#import "LegacyComponentsInternal.h"
6+
7+
@interface TGVideoMessageShimmerEffectForegroundView : UIView
8+
{
9+
UIView *_imageContainerView;
10+
UIView *_imageView;
11+
12+
CGFloat _size;
13+
bool _hasContainerSize;
14+
CGRect _absoluteRect;
15+
CGSize _containerSize;
16+
}
17+
18+
- (instancetype)initWithSize:(CGFloat)size alpha:(CGFloat)alpha;
19+
20+
@end
21+
22+
@implementation TGVideoMessageShimmerEffectForegroundView
23+
24+
- (instancetype)initWithSize:(CGFloat)size alpha:(CGFloat)alpha {
25+
self = [super initWithFrame:CGRectZero];
26+
if (self != nil) {
27+
_size = size;
28+
29+
_imageContainerView = [[UIView alloc] init];
30+
_imageView = [[UIView alloc] init];
31+
32+
self.clipsToBounds = true;
33+
34+
[_imageContainerView addSubview:_imageView];
35+
[self addSubview:_imageContainerView];
36+
37+
UIGraphicsBeginImageContextWithOptions(CGSizeMake(size, 16), false, 0.0f);
38+
CGContextRef context = UIGraphicsGetCurrentContext();
39+
40+
CGRect bounds = CGRectMake(0, 0, size, 16);
41+
CGContextClearRect(context, bounds);
42+
CGContextClipToRect(context, bounds);
43+
44+
UIColor *transparentColor = [UIColor colorWithWhite:1.0 alpha:0.0];
45+
UIColor *peakColor = [UIColor colorWithWhite:1.0 alpha:alpha];
46+
47+
CGColorRef colors[3] = {
48+
CGColorRetain(transparentColor.CGColor),
49+
CGColorRetain(peakColor.CGColor),
50+
CGColorRetain(transparentColor.CGColor)
51+
};
52+
53+
CFArrayRef colorsArray = CFArrayCreate(kCFAllocatorDefault, (const void **)&colors, 3, NULL);
54+
CGFloat locations[3] = {0.0f, 0.5, 1.0};
55+
56+
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
57+
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, colorsArray, (CGFloat const *)&locations);
58+
59+
CGContextDrawLinearGradient(context, gradient, CGPointMake(0, 0), CGPointMake(size, 0), kNilOptions);
60+
61+
CFRelease(colorsArray);
62+
CFRelease(colors[0]);
63+
CFRelease(colors[1]);
64+
65+
CGColorSpaceRelease(colorSpace);
66+
CFRelease(gradient);
67+
68+
UIImage *image = [UIGraphicsGetImageFromCurrentImageContext() stretchableImageWithLeftCapWidth:25 topCapHeight:25];
69+
UIGraphicsEndImageContext();
70+
71+
_imageView.backgroundColor = [UIColor colorWithPatternImage:image];
72+
}
73+
return self;
74+
}
75+
76+
- (void)updateAbsoluteRect:(CGRect)absoluteRect containerSize:(CGSize)containerSize {
77+
_hasContainerSize = true;
78+
79+
CGRect previousAbsoluteRect = _absoluteRect;
80+
CGSize previousContainerSize = _containerSize;
81+
_absoluteRect = absoluteRect;
82+
_containerSize = containerSize;
83+
84+
if (!CGSizeEqualToSize(previousContainerSize, containerSize)) {
85+
[self setupAnimation];
86+
}
87+
88+
if (!CGRectEqualToRect(previousAbsoluteRect, absoluteRect)) {
89+
_imageContainerView.frame = CGRectMake(-absoluteRect.origin.x, -absoluteRect.origin.y, containerSize.width, containerSize.height);
90+
}
91+
}
92+
93+
94+
- (void)setupAnimation {
95+
if (!_hasContainerSize) {
96+
return;
97+
}
98+
99+
CGFloat gradientHeight = _size;
100+
_imageView.frame = CGRectMake(-gradientHeight, 0, gradientHeight, _containerSize.height);
101+
102+
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position.x"];
103+
animation.fromValue = @(_imageView.center.x);
104+
animation.toValue = @(_imageView.center.x + _containerSize.width + gradientHeight);
105+
animation.duration = 1.3f;
106+
animation.repeatCount = INFINITY;
107+
animation.beginTime = 1.0;
108+
[_imageView.layer addAnimation:animation forKey:@"position"];
109+
}
110+
111+
@end
112+
113+
@interface TGVideoMessageShimmerView ()
114+
{
115+
TGVideoMessageShimmerEffectForegroundView *_effectView;
116+
UIImageView *_imageView;
117+
118+
UIView *_borderView;
119+
UIView *_borderMaskView;
120+
TGVideoMessageShimmerEffectForegroundView *_borderEffectView;
121+
}
122+
@end
123+
124+
@implementation TGVideoMessageShimmerView
125+
126+
- (instancetype)initWithFrame:(CGRect)frame {
127+
self = [super initWithFrame:frame];
128+
if (self != nil) {
129+
self.clipsToBounds = true;
130+
self.layer.cornerRadius = frame.size.width / 2.0f;
131+
if (iosMajorVersion() >= 13) {
132+
self.layer.cornerCurve = kCACornerCurveCircular;
133+
}
134+
135+
_effectView = [[TGVideoMessageShimmerEffectForegroundView alloc] initWithSize:320 alpha:0.3];
136+
_effectView.layer.compositingFilter = @"screenBlendMode";
137+
_effectView.frame = self.bounds;
138+
139+
_borderView = [[UIView alloc] initWithFrame:self.bounds];
140+
_borderMaskView = [[UIView alloc] initWithFrame:self.bounds];
141+
_borderMaskView.layer.borderWidth = 1.0;
142+
_borderMaskView.layer.borderColor = [UIColor whiteColor].CGColor;
143+
_borderMaskView.layer.cornerRadius = frame.size.width / 2.0f;
144+
if (iosMajorVersion() >= 13) {
145+
_borderMaskView.layer.cornerCurve = kCACornerCurveCircular;
146+
}
147+
_borderView.maskView = _borderMaskView;
148+
149+
_borderEffectView = [[TGVideoMessageShimmerEffectForegroundView alloc] initWithSize:400 alpha:0.45];
150+
_borderEffectView.layer.compositingFilter = @"screenBlendMode";
151+
_borderEffectView.frame = self.bounds;
152+
153+
[self addSubview:_effectView];
154+
[self addSubview:_borderView];
155+
[_borderView addSubview:_borderEffectView];
156+
}
157+
return self;
158+
}
159+
160+
- (void)updateAbsoluteRect:(CGRect)absoluteRect containerSize:(CGSize)containerSize {
161+
[_effectView updateAbsoluteRect:absoluteRect containerSize:containerSize];
162+
[_borderEffectView updateAbsoluteRect:absoluteRect containerSize:containerSize];
163+
}
164+
165+
@end
166+
5167
@interface TGVideoMessageRingView ()
6168
{
7169
CGFloat _value;

submodules/MediaPlayer/Sources/MediaPlayer.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ private final class MediaPlayerContext {
281281
CMTimebaseSetRate(loadedState.controlTimebase.timebase, rate: 0.0)
282282
}
283283
}
284-
let currentTimestamp = CMTimeGetSeconds(CMTimebaseGetTime(loadedState.controlTimebase.timebase))
285284
var duration: Double = 0.0
286285
if let videoTrackFrameBuffer = loadedState.mediaBuffers.videoBuffer {
287286
duration = max(duration, CMTimeGetSeconds(videoTrackFrameBuffer.duration))

submodules/TelegramUI/Sources/InstantVideoRadialStatusNode.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,12 @@ final class InstantVideoRadialStatusNode: ASDisplayNode, UIGestureRecognizerDele
200200
self.hapticFeedback.impact(.light)
201201
}
202202
}
203-
self.seekTo?(min(0.99, fraction), false)
204-
self.seekingProgress = CGFloat(fraction)
203+
let newProgress = min(0.99, fraction)
204+
if let seekingProgress = self.seekingProgress, abs(seekingProgress - CGFloat(newProgress)) < 0.005 {
205+
} else {
206+
self.seekTo?(newProgress, false)
207+
self.seekingProgress = CGFloat(fraction)
208+
}
205209
case .ended, .cancelled:
206210
self.seeking = false
207211
self.seekTo?(min(0.99, fraction), true)

submodules/TextFormat/Sources/ChatTextInputAttributes.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -720,21 +720,23 @@ public func convertMarkdownToAttributes(_ text: NSAttributedString) -> NSAttribu
720720
let entity = string.substring(with: match.range(at: 7))
721721
let substring = string.substring(with: match.range(at: 6)) + text + string.substring(with: match.range(at: 9))
722722

723+
let textInputAttribute: NSAttributedString.Key?
723724
switch entity {
724725
case "`":
725-
result.append(NSAttributedString(string: substring, attributes: [ChatTextInputAttributes.monospace: true as NSNumber]))
726-
offsetRanges.append((NSMakeRange(matchIndex + match.range(at: 6).length, text.count), match.range(at: 6).length * 2))
726+
textInputAttribute = ChatTextInputAttributes.monospace
727727
case "**":
728-
result.append(NSAttributedString(string: substring, attributes: [ChatTextInputAttributes.bold: true as NSNumber]))
729-
offsetRanges.append((NSMakeRange(matchIndex + match.range(at: 6).length, text.count), match.range(at: 6).length * 2))
728+
textInputAttribute = ChatTextInputAttributes.bold
730729
case "__":
731-
result.append(NSAttributedString(string: substring, attributes: [ChatTextInputAttributes.italic: true as NSNumber]))
732-
offsetRanges.append((NSMakeRange(matchIndex + match.range(at: 6).length, text.count), match.range(at: 6).length * 2))
730+
textInputAttribute = ChatTextInputAttributes.italic
733731
case "~~":
734-
result.append(NSAttributedString(string: substring, attributes: [ChatTextInputAttributes.strikethrough: true as NSNumber]))
735-
offsetRanges.append((NSMakeRange(matchIndex + match.range(at: 6).length, text.count), match.range(at: 6).length * 2))
732+
textInputAttribute = ChatTextInputAttributes.strikethrough
736733
default:
737-
break
734+
textInputAttribute = nil
735+
}
736+
737+
if let textInputAttribute = textInputAttribute {
738+
result.append(NSAttributedString(string: substring, attributes: [textInputAttribute: true as NSNumber]))
739+
offsetRanges.append((NSMakeRange(matchIndex + match.range(at: 6).length, text.count), match.range(at: 6).length * 2))
738740
}
739741

740742
stringOffset -= match.range(at: 7).length * 2

0 commit comments

Comments
 (0)