Skip to content

Commit 15fd6d7

Browse files
committed
Various fixes
1 parent 86e7238 commit 15fd6d7

File tree

8 files changed

+80
-27
lines changed

8 files changed

+80
-27
lines changed

submodules/LegacyMediaPickerUI/Sources/LegacyPaintStickersContext.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ private class SendStarsButtonView: HighlightTrackingButton, TGPhotoSendStarsButt
629629

630630
override init(frame: CGRect) {
631631
self.backgroundView = UIView()
632+
self.backgroundView.isUserInteractionEnabled = false
632633

633634
self.textNode = ImmediateAnimatedCountLabelNode()
634635
self.textNode.isUserInteractionEnabled = false
@@ -654,12 +655,22 @@ private class SendStarsButtonView: HighlightTrackingButton, TGPhotoSendStarsButt
654655
self.textNode.layer.animateAlpha(from: 0.4, to: 1.0, duration: 0.2)
655656
}
656657
}
658+
659+
self.addTarget(self, action: #selector(self.buttonPressed), for: .touchUpInside)
657660
}
658661

659662
required init?(coder: NSCoder) {
660663
preconditionFailure()
661664
}
662665

666+
deinit {
667+
print()
668+
}
669+
670+
@objc private func buttonPressed() {
671+
self.pressed?()
672+
}
673+
663674
func updateFrame(_ frame: CGRect) {
664675
let transition: ContainedViewLayoutTransition
665676
if self.frame.width.isZero {

submodules/MediaPickerUI/Sources/MediaPickerScreen.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
13221322
}
13231323
}
13241324

1325-
let proceed: (Bool) -> Void = { convertToJpeg in
1325+
let proceed: (Bool) -> Void = { [weak self] convertToJpeg in
13261326
let signals: [Any]!
13271327
switch controller.subject {
13281328
case .assets:
@@ -1340,6 +1340,11 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
13401340
completion()
13411341
self?.controller?.dismiss(animated: animated)
13421342
})
1343+
1344+
Queue.mainQueue().after(1.5) {
1345+
controller.isDismissing = false
1346+
controller.completed = false
1347+
}
13431348
}
13441349

13451350
if asFile && hasHeic {

submodules/TelegramUI/Components/MessageInputPanelComponent/Sources/MessageInputPanelComponent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ public final class MessageInputPanelComponent: Component {
14521452
inputActionButtonMode = .send
14531453
} else {
14541454
if self.textFieldExternalState.hasText {
1455-
if let sendPaidMessageStars = component.sendPaidMessageStars {
1455+
if let sendPaidMessageStars = component.sendPaidMessageStars, "".isEmpty {
14561456
inputActionButtonMode = .stars(sendPaidMessageStars.value)
14571457
} else {
14581458
inputActionButtonMode = .send

submodules/TelegramUI/Components/PeerInfo/PeerInfoCoverComponent/Sources/PeerInfoGiftsCoverComponent.swift

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ public final class PeerInfoGiftsCoverComponent: Component {
138138

139139
private var giftsDisposable: Disposable?
140140
private var gifts: [ProfileGiftsContext.State.StarGift] = []
141+
private var appliedGiftIds: [Int64] = []
141142

142143
private var iconLayers: [AnyHashable: GiftIconLayer] = [:]
143144

144145
private var iconPositions: [PositionGenerator.Position] = []
145-
private let seed = UInt(Date().timeIntervalSince1970)
146146

147147
override public init(frame: CGRect) {
148148
self.avatarBackgroundGradientLayer = SimpleGradientLayer()
@@ -185,6 +185,7 @@ public final class PeerInfoGiftsCoverComponent: Component {
185185
self.isUpdating = false
186186
}
187187

188+
let previousComponent = self.component
188189
self.component = component
189190
self.state = state
190191

@@ -193,7 +194,15 @@ public final class PeerInfoGiftsCoverComponent: Component {
193194

194195
let iconSize = CGSize(width: 32.0, height: 32.0)
195196

196-
if previousCurrentSize?.width != availableSize.width {
197+
let giftIds = self.gifts.map { gift in
198+
if case let .unique(gift) = gift.gift {
199+
return gift.id
200+
} else {
201+
return 0
202+
}
203+
}
204+
205+
if previousCurrentSize?.width != availableSize.width || (previousComponent != nil && previousComponent?.hasBackground != component.hasBackground) || self.appliedGiftIds != giftIds {
197206
var excludeRects: [CGRect] = []
198207
excludeRects.append(CGRect(origin: .zero, size: CGSize(width: 50.0, height: 90.0)))
199208
excludeRects.append(CGRect(origin: CGPoint(x: availableSize.width - 105.0, y: 0.0), size: CGSize(width: 105.0, height: 90.0)))
@@ -209,11 +218,12 @@ public final class PeerInfoGiftsCoverComponent: Component {
209218
minDistance: 75.0,
210219
maxDistance: availableSize.width / 2.0,
211220
padding: 12.0,
212-
seed: self.seed,
221+
seed: UInt(Date().timeIntervalSince1970),
213222
excludeRects: excludeRects
214223
)
215224
self.iconPositions = positionGenerator.generatePositions(count: 9, viewSize: iconSize)
216225
}
226+
self.appliedGiftIds = giftIds
217227

218228
if self.giftsDisposable == nil {
219229
self.giftsDisposable = combineLatest(
@@ -243,7 +253,7 @@ public final class PeerInfoGiftsCoverComponent: Component {
243253
self.gifts = pinnedGifts
244254

245255
if !self.isUpdating {
246-
self.state?.updated(transition: .immediate)
256+
self.state?.updated(transition: .spring(duration: 0.4))
247257
}
248258
})
249259
}
@@ -271,11 +281,13 @@ public final class PeerInfoGiftsCoverComponent: Component {
271281
}
272282
validIds.insert(id)
273283

284+
var iconTransition = transition
274285
let iconPosition = self.iconPositions[index]
275286
let iconLayer: GiftIconLayer
276287
if let current = self.iconLayers[id] {
277288
iconLayer = current
278289
} else {
290+
iconTransition = .immediate
279291
iconLayer = GiftIconLayer(context: component.context, gift: gift, size: iconSize, glowing: component.hasBackground)
280292
iconLayer.startHovering()
281293
self.iconLayers[id] = iconLayer
@@ -284,6 +296,7 @@ public final class PeerInfoGiftsCoverComponent: Component {
284296
iconLayer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
285297
iconLayer.animateScale(from: 0.01, to: 1.0, duration: 0.2)
286298
}
299+
iconLayer.glowing = component.hasBackground
287300

288301
let centerPosition = component.avatarCenter
289302
let finalPosition = iconPosition.center.offsetBy(dx: component.avatarCenter.x, dy: component.avatarCenter.y)
@@ -303,10 +316,10 @@ public final class PeerInfoGiftsCoverComponent: Component {
303316

304317
let effectivePosition = interpolateRect(from: finalPosition, to: centerPosition, t: itemScaleFraction)
305318

306-
transition.setBounds(layer: iconLayer, bounds: CGRect(origin: .zero, size: iconSize))
307-
transition.setPosition(layer: iconLayer, position: effectivePosition)
308-
transition.setScale(layer: iconLayer, scale: iconPosition.scale * (1.0 - itemScaleFraction))
309-
transition.setAlpha(layer: iconLayer, alpha: 1.0 - itemScaleFraction)
319+
iconTransition.setBounds(layer: iconLayer, bounds: CGRect(origin: .zero, size: iconSize))
320+
iconTransition.setPosition(layer: iconLayer, position: effectivePosition)
321+
iconTransition.setScale(layer: iconLayer, scale: iconPosition.scale * (1.0 - itemScaleFraction))
322+
iconTransition.setAlpha(layer: iconLayer, alpha: 1.0 - itemScaleFraction)
310323

311324
index += 1
312325
}
@@ -434,7 +447,7 @@ private class PositionGenerator {
434447
let distance = hypot(result.x - self.avatarFrame.center.x, result.y - self.avatarFrame.center.y)
435448
let baseScale = min(1.0, max(0.77, 1.0 - (distance - 75.0) / 75.0))
436449

437-
let randomFactor = 0.05 + (1.0 - baseScale) * 0.1
450+
let randomFactor = 0.14 + (1.0 - baseScale) * 0.2
438451
let randomValue = -randomFactor + CGFloat(self.rng.next()) * 2.0 * randomFactor
439452

440453
let finalScale = min(1.2, max(baseScale * 0.65, baseScale + randomValue))
@@ -563,6 +576,8 @@ private final class StarsEffectLayer: SimpleLayer {
563576
}
564577

565578
func setup(color: UIColor, size: CGSize) {
579+
self.color = color
580+
566581
let emitter = CAEmitterCell()
567582
emitter.name = "emitter"
568583
emitter.contents = UIImage(bundleImageName: "Premium/Stars/Particle")?.cgImage
@@ -586,8 +601,10 @@ private final class StarsEffectLayer: SimpleLayer {
586601
self.emitterLayer.emitterCells = [emitter]
587602
}
588603

604+
private var color: UIColor?
605+
589606
func update(color: UIColor, size: CGSize) {
590-
if self.emitterLayer.emitterCells == nil {
607+
if self.color != color {
591608
self.setup(color: color, size: size)
592609
}
593610
self.emitterLayer.seed = UInt32.random(in: .min ..< .max)
@@ -604,7 +621,25 @@ private class GiftIconLayer: SimpleLayer {
604621
private let context: AccountContext
605622
private let gift: ProfileGiftsContext.State.StarGift
606623
private let size: CGSize
607-
private let glowing: Bool
624+
var glowing: Bool {
625+
didSet {
626+
self.shadowLayer.opacity = self.glowing ? 1.0 : 0.0
627+
628+
let color: UIColor
629+
if self.glowing {
630+
color = .white
631+
} else if let layerTintColor = self.shadowLayer.layerTintColor {
632+
color = UIColor(cgColor: layerTintColor)
633+
} else {
634+
color = .white
635+
}
636+
637+
let side = floor(self.size.width * 1.25)
638+
let starsFrame = CGSize(width: side, height: side).centered(in: CGRect(origin: .zero, size: self.size))
639+
self.starsLayer.frame = starsFrame
640+
self.starsLayer.update(color: color, size: starsFrame.size)
641+
}
642+
}
608643

609644
let shadowLayer = SimpleLayer()
610645
let starsLayer = StarsEffectLayer()
@@ -656,6 +691,7 @@ private class GiftIconLayer: SimpleLayer {
656691

657692
self.shadowLayer.contents = shadowImage?.cgImage
658693
self.shadowLayer.layerTintColor = color.cgColor
694+
self.shadowLayer.opacity = glowing ? 1.0 : 0.0
659695

660696
self.context = context
661697
self.gift = gift
@@ -669,9 +705,7 @@ private class GiftIconLayer: SimpleLayer {
669705
self.starsLayer.frame = starsFrame
670706
self.starsLayer.update(color: glowing ? .white : color, size: starsFrame.size)
671707

672-
if glowing {
673-
self.addSublayer(self.shadowLayer)
674-
}
708+
self.addSublayer(self.shadowLayer)
675709
self.addSublayer(self.starsLayer)
676710
self.addSublayer(self.animationLayer)
677711
}
@@ -723,6 +757,7 @@ private class GiftIconLayer: SimpleLayer {
723757

724758
self.shadowLayer.contents = shadowImage?.cgImage
725759
self.shadowLayer.layerTintColor = color.cgColor
760+
self.shadowLayer.opacity = glowing ? 1.0 : 0.0
726761

727762
super.init()
728763

@@ -731,9 +766,7 @@ private class GiftIconLayer: SimpleLayer {
731766
self.starsLayer.frame = starsFrame
732767
self.starsLayer.update(color: glowing ? .white : color, size: starsFrame.size)
733768

734-
if glowing {
735-
self.addSublayer(self.shadowLayer)
736-
}
769+
self.addSublayer(self.shadowLayer)
737770
self.addSublayer(self.starsLayer)
738771
self.addSublayer(self.animationLayer)
739772
}

submodules/TelegramUI/Sources/Chat/ChatControllerPaidMessage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extension ChatControllerImpl {
2020
completion(false)
2121
return
2222
}
23-
if let sendPaidMessageStars = self.presentationInterfaceState.sendPaidMessageStars {
23+
if let sendPaidMessageStars = self.presentationInterfaceState.sendPaidMessageStars, self.presentationInterfaceState.interfaceState.editMessage == nil {
2424
let totalAmount = sendPaidMessageStars.value * Int64(count)
2525

2626
let _ = (ApplicationSpecificNotice.dismissedPaidMessageWarningNamespace(accountManager: self.context.sharedContext.accountManager, peerId: peer.id)

submodules/TelegramUI/Sources/ChatController.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,11 +2067,15 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
20672067
})
20682068
}
20692069
}, sendCurrentMessage: { [weak self] silentPosting, messageEffect in
2070-
if let strongSelf = self {
2071-
if let _ = strongSelf.presentationInterfaceState.interfaceState.mediaDraftState {
2072-
strongSelf.sendMediaRecording(silentPosting: silentPosting, messageEffect: messageEffect)
2070+
if let self {
2071+
if let _ = self.presentationInterfaceState.interfaceState.mediaDraftState {
2072+
self.sendMediaRecording(silentPosting: silentPosting, messageEffect: messageEffect)
20732073
} else {
2074-
strongSelf.chatDisplayNode.sendCurrentMessage(silentPosting: silentPosting, messageEffect: messageEffect)
2074+
self.presentPaidMessageAlertIfNeeded(count: 1, completion: { [weak self] postpone in
2075+
if let self {
2076+
self.chatDisplayNode.sendCurrentMessage(silentPosting: silentPosting, postpone: postpone, messageEffect: messageEffect)
2077+
}
2078+
})
20752079
}
20762080
}
20772081
}, sendMessage: { [weak self] text in

submodules/TelegramUI/Sources/ChatTextInputActionButtonsNode.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ final class ChatTextInputActionButtonsNode: ASDisplayNode, ChatSendMessageAction
272272
self.validLayout = size
273273

274274
var innerSize = size
275-
if let sendPaidMessageStars = interfaceState.sendPaidMessageStars {
275+
if let sendPaidMessageStars = interfaceState.sendPaidMessageStars, interfaceState.interfaceState.editMessage == nil {
276276
self.sendButton.imageNode.alpha = 0.0
277277
self.textNode.isHidden = false
278278

submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,7 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate, Ch
19151915
placeholder = interfaceState.strings.Conversation_InputTextAnonymousPlaceholder
19161916
} else if case let .replyThread(replyThreadMessage) = interfaceState.chatLocation, !replyThreadMessage.isForumPost, replyThreadMessage.peerId != self.context?.account.peerId {
19171917
if replyThreadMessage.isChannelPost {
1918-
if let sendPaidMessageStars = interfaceState.sendPaidMessageStars {
1918+
if let sendPaidMessageStars = interfaceState.sendPaidMessageStars, interfaceState.interfaceState.editMessage == nil {
19191919
placeholder = interfaceState.strings.Chat_InputTextPaidCommentPlaceholder(" # \(presentationStringsFormattedNumber(Int32(sendPaidMessageStars.value), interfaceState.dateTimeFormat.groupingSeparator))").string
19201920
placeholderHasStar = true
19211921
} else {
@@ -1931,7 +1931,7 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate, Ch
19311931
placeholder = interfaceState.strings.Chat_InputPlaceholderMessageInTopic(forumTopicData.title).string
19321932
}
19331933
} else {
1934-
if let sendPaidMessageStars = interfaceState.sendPaidMessageStars {
1934+
if let sendPaidMessageStars = interfaceState.sendPaidMessageStars, interfaceState.interfaceState.editMessage == nil {
19351935
placeholder = interfaceState.strings.Chat_InputTextPaidMessagePlaceholder(" # \(presentationStringsFormattedNumber(Int32(sendPaidMessageStars.value), interfaceState.dateTimeFormat.groupingSeparator))").string
19361936
placeholderHasStar = true
19371937
} else {

0 commit comments

Comments
 (0)