Skip to content

Commit 4b74d1c

Browse files
committed
Various fixes
1 parent 99746e7 commit 4b74d1c

File tree

14 files changed

+214
-31
lines changed

14 files changed

+214
-31
lines changed

submodules/AccountContext/Sources/AttachmentMainButtonState.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public struct AttachmentMainButtonState {
3333
}
3434

3535
public let text: String?
36+
public let badge: String?
3637
public let font: Font
3738
public let background: Background
3839
public let textColor: UIColor
@@ -44,6 +45,7 @@ public struct AttachmentMainButtonState {
4445

4546
public init(
4647
text: String?,
48+
badge: String? = nil,
4749
font: Font,
4850
background: Background,
4951
textColor: UIColor,
@@ -54,6 +56,7 @@ public struct AttachmentMainButtonState {
5456
position: Position? = nil
5557
) {
5658
self.text = text
59+
self.badge = badge
5760
self.font = font
5861
self.background = background
5962
self.textColor = textColor

submodules/AccountContext/Sources/ContactMultiselectionController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public enum ContactMultiselectionControllerMode {
7979
case channelCreation
8080
case chatSelection(ChatSelection)
8181
case premiumGifting(birthdays: [EnginePeer.Id: TelegramBirthday]?, selectToday: Bool, hasActions: Bool)
82-
case requestedUsersSelection
82+
case requestedUsersSelection(isBot: Bool?, isPremium: Bool?)
8383
}
8484

8585
public enum ContactListFilter {

submodules/AccountContext/Sources/PeerSelectionController.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public final class PeerSelectionControllerParams {
5959
public let createNewGroup: (() -> Void)?
6060
public let pretendPresentedInModal: Bool
6161
public let multipleSelection: Bool
62+
public let multipleSelectionLimit: Int32?
6263
public let forwardedMessageIds: [EngineMessage.Id]
6364
public let hasTypeHeaders: Bool
6465
public let selectForumThreads: Bool
@@ -80,6 +81,7 @@ public final class PeerSelectionControllerParams {
8081
createNewGroup: (() -> Void)? = nil,
8182
pretendPresentedInModal: Bool = false,
8283
multipleSelection: Bool = false,
84+
multipleSelectionLimit: Int32? = nil,
8385
forwardedMessageIds: [EngineMessage.Id] = [],
8486
hasTypeHeaders: Bool = false,
8587
selectForumThreads: Bool = false,
@@ -100,6 +102,7 @@ public final class PeerSelectionControllerParams {
100102
self.createNewGroup = createNewGroup
101103
self.pretendPresentedInModal = pretendPresentedInModal
102104
self.multipleSelection = multipleSelection
105+
self.multipleSelectionLimit = multipleSelectionLimit
103106
self.forwardedMessageIds = forwardedMessageIds
104107
self.hasTypeHeaders = hasTypeHeaders
105108
self.selectForumThreads = selectForumThreads

submodules/AttachmentUI/Sources/AttachmentPanel.swift

Lines changed: 126 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,102 @@ private final class LoadingProgressNode: ASDisplayNode {
382382
}
383383
}
384384

385+
private final class BadgeNode: ASDisplayNode {
386+
private var fillColor: UIColor
387+
private var strokeColor: UIColor
388+
private var textColor: UIColor
389+
390+
private let textNode: ImmediateTextNode
391+
private let backgroundNode: ASImageNode
392+
393+
private let font: UIFont = Font.with(size: 15.0, design: .round, weight: .bold)
394+
395+
var text: String = "" {
396+
didSet {
397+
self.textNode.attributedText = NSAttributedString(string: self.text, font: self.font, textColor: self.textColor)
398+
self.invalidateCalculatedLayout()
399+
}
400+
}
401+
402+
init(fillColor: UIColor, strokeColor: UIColor, textColor: UIColor) {
403+
self.fillColor = fillColor
404+
self.strokeColor = strokeColor
405+
self.textColor = textColor
406+
407+
self.textNode = ImmediateTextNode()
408+
self.textNode.isUserInteractionEnabled = false
409+
self.textNode.displaysAsynchronously = false
410+
411+
self.backgroundNode = ASImageNode()
412+
self.backgroundNode.isLayerBacked = true
413+
self.backgroundNode.displayWithoutProcessing = true
414+
self.backgroundNode.displaysAsynchronously = false
415+
self.backgroundNode.image = generateStretchableFilledCircleImage(diameter: 18.0, color: fillColor, strokeColor: nil, strokeWidth: 1.0)
416+
417+
super.init()
418+
419+
self.addSubnode(self.backgroundNode)
420+
self.addSubnode(self.textNode)
421+
422+
self.isUserInteractionEnabled = false
423+
}
424+
425+
func updateTheme(fillColor: UIColor, strokeColor: UIColor, textColor: UIColor) {
426+
self.fillColor = fillColor
427+
self.strokeColor = strokeColor
428+
self.textColor = textColor
429+
self.backgroundNode.image = generateStretchableFilledCircleImage(diameter: 18.0, color: fillColor, strokeColor: strokeColor, strokeWidth: 1.0)
430+
self.textNode.attributedText = NSAttributedString(string: self.text, font: self.font, textColor: self.textColor)
431+
}
432+
433+
func animateBump(incremented: Bool) {
434+
if incremented {
435+
let firstTransition = ContainedViewLayoutTransition.animated(duration: 0.1, curve: .easeInOut)
436+
firstTransition.updateTransformScale(layer: self.backgroundNode.layer, scale: 1.2)
437+
firstTransition.updateTransformScale(layer: self.textNode.layer, scale: 1.2, completion: { finished in
438+
if finished {
439+
let secondTransition = ContainedViewLayoutTransition.animated(duration: 0.1, curve: .easeInOut)
440+
secondTransition.updateTransformScale(layer: self.backgroundNode.layer, scale: 1.0)
441+
secondTransition.updateTransformScale(layer: self.textNode.layer, scale: 1.0)
442+
}
443+
})
444+
} else {
445+
let firstTransition = ContainedViewLayoutTransition.animated(duration: 0.1, curve: .easeInOut)
446+
firstTransition.updateTransformScale(layer: self.backgroundNode.layer, scale: 0.8)
447+
firstTransition.updateTransformScale(layer: self.textNode.layer, scale: 0.8, completion: { finished in
448+
if finished {
449+
let secondTransition = ContainedViewLayoutTransition.animated(duration: 0.1, curve: .easeInOut)
450+
secondTransition.updateTransformScale(layer: self.backgroundNode.layer, scale: 1.0)
451+
secondTransition.updateTransformScale(layer: self.textNode.layer, scale: 1.0)
452+
}
453+
})
454+
}
455+
}
456+
457+
func animateOut() {
458+
let timingFunction = CAMediaTimingFunctionName.easeInEaseOut.rawValue
459+
self.backgroundNode.layer.animateScale(from: 1.0, to: 0.1, duration: 0.3, delay: 0.0, timingFunction: timingFunction, removeOnCompletion: true, completion: nil)
460+
self.textNode.layer.animateScale(from: 1.0, to: 0.1, duration: 0.3, delay: 0.0, timingFunction: timingFunction, removeOnCompletion: true, completion: nil)
461+
}
462+
463+
func update(_ constrainedSize: CGSize) -> CGSize {
464+
let badgeSize = self.textNode.updateLayout(constrainedSize)
465+
let backgroundSize = CGSize(width: max(18.0, badgeSize.width + 8.0), height: 18.0)
466+
let backgroundFrame = CGRect(origin: CGPoint(), size: backgroundSize)
467+
self.backgroundNode.frame = backgroundFrame
468+
self.textNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels(backgroundFrame.midX - badgeSize.width / 2.0), y: floorToScreenPixels((backgroundFrame.size.height - badgeSize.height) / 2.0) - UIScreenPixel), size: badgeSize)
469+
470+
return backgroundSize
471+
}
472+
}
473+
385474
private final class MainButtonNode: HighlightTrackingButtonNode {
386475
private var state: AttachmentMainButtonState
387476
private var size: CGSize?
388477

389478
private let backgroundAnimationNode: ASImageNode
390479
fileprivate let textNode: ImmediateTextNode
480+
private var badgeNode: BadgeNode?
391481
private let statusNode: SemanticStatusNode
392482
private var progressNode: ASImageNode?
393483

@@ -616,6 +706,7 @@ private final class MainButtonNode: HighlightTrackingButtonNode {
616706
progressNode.image = generateIndefiniteActivityIndicatorImage(color: state.textColor, diameter: diameter, lineWidth: 3.0)
617707
}
618708

709+
var textFrame: CGRect = .zero
619710
if let text = state.text {
620711
let font: UIFont
621712
switch state.font {
@@ -627,13 +718,7 @@ private final class MainButtonNode: HighlightTrackingButtonNode {
627718
self.textNode.attributedText = NSAttributedString(string: text, font: font, textColor: state.textColor)
628719

629720
let textSize = self.textNode.updateLayout(size)
630-
let textFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - textSize.width) / 2.0), y: floorToScreenPixels((size.height - textSize.height) / 2.0)), size: textSize)
631-
if self.textNode.frame.width.isZero {
632-
self.textNode.frame = textFrame
633-
} else {
634-
self.textNode.bounds = CGRect(origin: .zero, size: textSize)
635-
transition.updatePosition(node: self.textNode, position: textFrame.center)
636-
}
721+
textFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - textSize.width) / 2.0), y: floorToScreenPixels((size.height - textSize.height) / 2.0)), size: textSize)
637722

638723
switch state.background {
639724
case let .color(backgroundColor):
@@ -669,6 +754,40 @@ private final class MainButtonNode: HighlightTrackingButtonNode {
669754
}
670755
}
671756

757+
if let badge = state.badge {
758+
let badgeNode: BadgeNode
759+
var badgeTransition = transition
760+
if let current = self.badgeNode {
761+
badgeNode = current
762+
} else {
763+
badgeTransition = .immediate
764+
var textColor: UIColor
765+
switch state.background {
766+
case let .color(backgroundColor):
767+
textColor = backgroundColor
768+
case .premium:
769+
textColor = UIColor(rgb: 0x0077ff)
770+
}
771+
badgeNode = BadgeNode(fillColor: state.textColor, strokeColor: .clear, textColor: textColor)
772+
self.badgeNode = badgeNode
773+
self.addSubnode(badgeNode)
774+
}
775+
badgeNode.text = badge
776+
let badgeSize = badgeNode.update(CGSize(width: 100.0, height: 100.0))
777+
textFrame.origin.x -= badgeSize.width / 2.0
778+
badgeTransition.updateFrame(node: badgeNode, frame: CGRect(origin: CGPoint(x: textFrame.maxX + 6.0, y: textFrame.minY + floorToScreenPixels((textFrame.height - badgeSize.height) * 0.5)), size: badgeSize))
779+
} else if let badgeNode = self.badgeNode {
780+
self.badgeNode = nil
781+
badgeNode.removeFromSupernode()
782+
}
783+
784+
if self.textNode.frame.width.isZero {
785+
self.textNode.frame = textFrame
786+
} else {
787+
self.textNode.bounds = CGRect(origin: .zero, size: textFrame.size)
788+
transition.updatePosition(node: self.textNode, position: textFrame.center)
789+
}
790+
672791
if previousState.progress != state.progress {
673792
if state.progress == .center {
674793
self.transitionToProgress()

submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,6 +2477,9 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
24772477
case let .user(userType):
24782478
if case let .user(user) = peer {
24792479
match = true
2480+
if user.id.isVerificationCodes {
2481+
match = false
2482+
}
24802483
if let isBot = userType.isBot {
24812484
if isBot != (user.botInfo != nil) {
24822485
match = false

submodules/ChatListUI/Sources/Node/ChatListItem.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -878,14 +878,10 @@ private final class ChatListMediaPreviewNode: ASDisplayNode {
878878
if file.isInstantVideo {
879879
isRound = true
880880
}
881-
if file.isSticker || file.isAnimatedSticker {
882-
self.playIcon.isHidden = true
881+
if file.isVideo && !file.isAnimated {
882+
self.playIcon.isHidden = false
883883
} else {
884-
if file.isAnimated {
885-
self.playIcon.isHidden = true
886-
} else {
887-
self.playIcon.isHidden = false
888-
}
884+
self.playIcon.isHidden = true
889885
}
890886
if let mediaDimensions = file.dimensions {
891887
dimensions = mediaDimensions.cgSize
@@ -2646,6 +2642,9 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode {
26462642
} else if contentImageIsDisplayedAsAvatar && (file.isSticker || file.isVideoSticker) {
26472643
let fitSize = contentImageSize
26482644
contentImageSpecs.append(ContentImageSpec(message: message, media: .file(file), size: fitSize))
2645+
} else if !file.previewRepresentations.isEmpty, let _ = file.dimensions {
2646+
let fitSize = contentImageSize
2647+
contentImageSpecs.append(ContentImageSpec(message: message, media: .file(file), size: fitSize))
26492648
}
26502649
break inner
26512650
} else if let webpage = media as? TelegramMediaWebpage, case let .Loaded(content) = webpage.content {

submodules/ChatListUI/Sources/Node/ChatListNode.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,6 +2444,9 @@ public final class ChatListNode: ListView {
24442444
case let .user(userType):
24452445
if case let .user(user) = peer {
24462446
match = true
2447+
if user.id.isVerificationCodes {
2448+
match = false
2449+
}
24472450
if let isBot = userType.isBot {
24482451
if isBot != (user.botInfo != nil) {
24492452
match = false

submodules/CounterControllerTitleView/Sources/CounterControllerTitleView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public final class CounterControllerTitleView: UIView {
5959
let primaryTextColor = self.primaryTextColor ?? self.theme.rootController.navigationBar.primaryTextColor
6060
let secondaryTextColor = self.secondaryTextColor ?? self.theme.rootController.navigationBar.secondaryTextColor
6161
self.titleNode.attributedText = NSAttributedString(string: self.title.title, font: Font.semibold(17.0), textColor: primaryTextColor)
62-
self.subtitleNode.attributedText = NSAttributedString(string: self.title.counter, font: Font.regular(13.0), textColor: secondaryTextColor)
62+
self.subtitleNode.attributedText = NSAttributedString(string: self.title.counter, font: Font.with(size: 13.0, traits: .monospacedNumbers), textColor: secondaryTextColor)
6363

6464
self.accessibilityLabel = self.title.title
6565
self.accessibilityValue = self.title.counter

submodules/LegacyComponents/Sources/TGPhotoEditorSliderView.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,11 @@ - (void)setValue:(CGFloat)value
381381

382382
- (void)setValue:(CGFloat)value animated:(BOOL)__unused animated
383383
{
384-
_value = MIN(MAX(_lowerBoundValue, MAX(value, _minimumValue)), _maximumValue);
384+
if (_lowerBoundValue > FLT_EPSILON) {
385+
_value = MIN(MAX(_lowerBoundValue, MAX(value, _minimumValue)), _maximumValue);
386+
} else {
387+
_value = MIN(MAX(value, _minimumValue), _maximumValue);
388+
}
385389
[self setNeedsLayout];
386390
}
387391

submodules/StickerPackPreviewUI/Sources/StickerPackEmojisItem.swift

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,24 @@ final class StickerPackEmojisItemNode: GridItemNode {
297297

298298
self.setNeedsLayout()
299299
}
300+
301+
private var visibleRect: CGRect?
302+
override func updateAbsoluteRect(_ absoluteRect: CGRect, within containerSize: CGSize) {
303+
var y: CGFloat
304+
if absoluteRect.minY > 0.0 {
305+
y = 0.0
306+
} else {
307+
y = absoluteRect.minY * -1.0
308+
}
309+
var rect = CGRect(origin: CGPoint(x: 0.0, y: y), size: CGSize(width: containerSize.width, height: containerSize.height))
310+
rect.size.height += 96.0
311+
self.visibleRect = rect
312+
313+
self.updateVisibleItems(attemptSynchronousLoads: false, transition: .immediate)
314+
}
300315

301316
func updateVisibleItems(attemptSynchronousLoads: Bool, transition: ContainedViewLayoutTransition) {
302-
guard let item = self.item, !self.size.width.isZero else {
317+
guard let item = self.item, !self.size.width.isZero, let visibleRect = self.visibleRect else {
303318
return
304319
}
305320

@@ -321,17 +336,26 @@ final class StickerPackEmojisItemNode: GridItemNode {
321336
self.containerNode.frame = CGRect(origin: CGPoint(x: 0.0, y: item.title != nil ? 61.0 : 0.0), size: CGSize(width: itemLayout.width, height: itemLayout.height))
322337

323338
for index in 0 ..< items.count {
339+
var itemFrame = itemLayout.frame(itemIndex: index)
340+
if !visibleRect.intersects(itemFrame) {
341+
continue
342+
}
324343
let item = items[index]
325344
let itemId = EmojiKeyboardItemLayer.Key(
326345
groupId: 0,
327346
itemId: .animation(.file(item.file.fileId))
328347
)
329-
validIds.insert(itemId)
330348

331349
let itemDimensions = item.file.dimensions?.cgSize ?? CGSize(width: 512.0, height: 512.0)
332350
let itemNativeFitSize = itemDimensions.fitted(CGSize(width: nativeItemSize, height: nativeItemSize))
333351
let itemVisibleFitSize = itemDimensions.fitted(CGSize(width: itemLayout.visibleItemSize, height: itemLayout.visibleItemSize))
334352

353+
validIds.insert(itemId)
354+
355+
itemFrame.origin.x += floor((itemFrame.width - itemVisibleFitSize.width) / 2.0)
356+
itemFrame.origin.y += floor((itemFrame.height - itemVisibleFitSize.height) / 2.0)
357+
itemFrame.size = itemVisibleFitSize
358+
335359
var updateItemLayerPlaceholder = false
336360
var itemTransition = transition
337361
let itemLayer: EmojiKeyboardItemLayer
@@ -426,12 +450,6 @@ final class StickerPackEmojisItemNode: GridItemNode {
426450
itemLayer.layerTintColor = color.cgColor
427451
}
428452

429-
var itemFrame = itemLayout.frame(itemIndex: index)
430-
431-
itemFrame.origin.x += floor((itemFrame.width - itemVisibleFitSize.width) / 2.0)
432-
itemFrame.origin.y += floor((itemFrame.height - itemVisibleFitSize.height) / 2.0)
433-
itemFrame.size = itemVisibleFitSize
434-
435453
let itemPosition = CGPoint(x: itemFrame.midX, y: itemFrame.midY)
436454
let itemBounds = CGRect(origin: CGPoint(), size: itemFrame.size)
437455
itemTransition.updatePosition(layer: itemLayer, position: itemPosition)

0 commit comments

Comments
 (0)