Skip to content

Commit b3aef93

Browse files
committed
Various improvements
1 parent ef5a5d2 commit b3aef93

8 files changed

Lines changed: 104 additions & 32 deletions

File tree

Telegram/Telegram-iOS/en.lproj/Localizable.strings

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15703,7 +15703,8 @@ Error: %8$@";
1570315703

1570415704
"Gift.Craft.Select.Title" = "Select Gifts";
1570515705
"Gift.Craft.Select.YourGifts" = "Your Gifts";
15706-
"Gift.Craft.Select.SaleGifts" = "Suitable Gifts On Sale";
15706+
"Gift.Craft.Select.SaleGiftsCount_1" = "%@ Suitable Gift On Sale";
15707+
"Gift.Craft.Select.SaleGiftsCount_any" = "%@ Suitable Gifts On Sale";
1570715708
"Gift.Craft.Select.NoGiftsFromCollection" = "You don't have other gifts\nfrom this collection";
1570815709

1570915710
"Gift.Attribute.Rare" = "rare";

submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGifts.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4241,11 +4241,15 @@ public final class ResaleGiftsContext {
42414241
}
42424242
}
42434243

4244+
public let forCrafting: Bool
4245+
42444246
public init(
42454247
account: Account,
42464248
giftId: Int64,
42474249
forCrafting: Bool
42484250
) {
4251+
self.forCrafting = forCrafting
4252+
42494253
let queue = self.queue
42504254
self.impl = QueueLocalObject(queue: queue, generate: {
42514255
return ResaleGiftsContextImpl(queue: queue, account: account, giftId: giftId, forCrafting: forCrafting)

submodules/TelegramUI/Components/Gifts/GiftCraftScreen/Sources/CraftTableComponent.swift

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,29 @@ final class CraftTableComponent: Component {
114114
}
115115
self.didSetupFinishAnimation = true
116116

117-
self.animationView.onFinishApproach = { [weak self] isUpsideDown in
118-
guard let self else {
117+
self.animationView.onFinishApproach = { [weak self] isUpsideDown, isClockwise in
118+
guard let self, let component = self.component else {
119119
return
120120
}
121121
self.isFailed = true
122122
self.animationView.setSticker(nil, face: 0, mirror: false)
123123

124124
var availableStickers: [ComponentView<Empty>] = []
125-
for gift in self.selectedGifts.values {
126-
availableStickers.append(gift)
125+
for (id, gift) in self.selectedGifts {
126+
if let id = id.base as? Int, component.gifts[Int32(id)] != nil {
127+
availableStickers.append(gift)
128+
}
127129
}
128-
for i in 0 ..< min(2, availableStickers.count) {
130+
let wrappingCount = min(2, availableStickers.count)
131+
for i in 0 ..< wrappingCount {
129132
if let sticker = availableStickers[i].view {
130133
let face: Int
131-
if isUpsideDown {
134+
if isClockwise {
132135
face = i + 1
133136
} else {
134137
face = 3 - i
135138
}
136-
self.animationView.setSticker(sticker, face: face, mirror: isUpsideDown)
139+
self.animationView.setSticker(sticker, face: face, mirror: isUpsideDown, animated: true)
137140
}
138141
}
139142

@@ -163,25 +166,28 @@ final class CraftTableComponent: Component {
163166

164167
self.animationView.isSuccess = true
165168

166-
self.animationView.onFinishApproach = { [weak self] isUpsideDown in
169+
self.animationView.onFinishApproach = { [weak self] isUpsideDown, isClockwise in
167170
guard let self else {
168171
return
169172
}
170173
self.isSuccess = true
171174

172175
var availableStickers: [ComponentView<Empty>] = []
173-
for gift in self.selectedGifts.values {
174-
availableStickers.append(gift)
176+
for (id, gift) in self.selectedGifts {
177+
if let id = id.base as? Int, component.gifts[Int32(id)] != nil {
178+
availableStickers.append(gift)
179+
}
175180
}
176-
for i in 0 ..< min(2, availableStickers.count) {
181+
let wrappingCount = min(2, availableStickers.count)
182+
for i in 0 ..< wrappingCount {
177183
if let sticker = availableStickers[i].view {
178184
let face: Int
179-
if isUpsideDown {
185+
if isClockwise {
180186
face = i + 1
181187
} else {
182188
face = 3 - i
183189
}
184-
self.animationView.setSticker(sticker, face: face, mirror: isUpsideDown)
190+
self.animationView.setSticker(sticker, face: face, mirror: isUpsideDown, animated: true)
185191
}
186192
}
187193

@@ -262,7 +268,7 @@ final class CraftTableComponent: Component {
262268
if index == 0 {
263269
faceItems.append(
264270
AnyComponentWithIdentity(id: "background", component: AnyComponent(
265-
FilledRoundedRectangleComponent(color: component.buttonColor, cornerRadius: .value(28.0), smoothCorners: true)
271+
CubeFaceComponent(color: component.buttonColor, cornerRadius: 28.0)
266272
))
267273
)
268274
if !component.isCrafting || self.isFailed {
@@ -328,12 +334,12 @@ final class CraftTableComponent: Component {
328334
} else {
329335
faceItems.append(
330336
AnyComponentWithIdentity(id: "background", component: AnyComponent(
331-
FilledRoundedRectangleComponent(color: component.buttonColor, cornerRadius: .value(28.0), smoothCorners: true)
337+
CubeFaceComponent(color: component.buttonColor, cornerRadius: 28.0)
332338
))
333339
)
334340
faceItems.append(
335341
AnyComponentWithIdentity(id: "icon", component: AnyComponent(
336-
BundleIconComponent(name: "Components/CubeSide", tintColor: nil, flipVertically: self.flipFaces)
342+
BundleIconComponent(name: "Components/CubeSide", tintColor: nil, flipVertically: index < 4 ? self.flipFaces : false)
337343
))
338344
)
339345
}
@@ -781,3 +787,47 @@ private func generateAddIcon(backgroundColor: UIColor) -> UIImage? {
781787
context.strokePath()
782788
})
783789
}
790+
791+
private final class CubeFaceComponent: Component {
792+
private let color: UIColor
793+
private let cornerRadius: CGFloat
794+
795+
public init(color: UIColor, cornerRadius: CGFloat) {
796+
self.color = color
797+
self.cornerRadius = cornerRadius
798+
}
799+
800+
public static func ==(lhs: CubeFaceComponent, rhs: CubeFaceComponent) -> Bool {
801+
if !lhs.color.isEqual(rhs.color) {
802+
return false
803+
}
804+
if lhs.cornerRadius != rhs.cornerRadius {
805+
return false
806+
}
807+
return true
808+
}
809+
810+
public final class View: UIView {
811+
override public init(frame: CGRect) {
812+
super.init(frame: frame)
813+
814+
self.clipsToBounds = true
815+
self.layer.cornerCurve = .continuous
816+
}
817+
818+
required public init?(coder: NSCoder) {
819+
fatalError("init(coder:) has not been implemented")
820+
}
821+
}
822+
823+
public func makeView() -> View {
824+
return View(frame: CGRect())
825+
}
826+
827+
public func update(view: View, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: ComponentTransition) -> CGSize {
828+
transition.setBackgroundColor(view: view, color: self.color)
829+
transition.setCornerRadius(layer: view.layer, cornerRadius: self.cornerRadius)
830+
831+
return availableSize
832+
}
833+
}

submodules/TelegramUI/Components/Gifts/GiftCraftScreen/Sources/CubeAnimationView.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ final class CubeAnimationView: UIView {
8383
var isSuccess = false
8484

8585
var onStickerLaunch: (() -> Void)?
86-
var onFinishApproach: ((Bool) -> Void)?
86+
var onFinishApproach: ((Bool, Bool) -> Void)?
8787

8888
private let defaultStickOrder: [Int] = [0, 5, 4, 3]
8989
private let sequenceStickOrders: [String: [Int]] = [
@@ -161,7 +161,7 @@ final class CubeAnimationView: UIView {
161161
self.layoutStickers()
162162
}
163163

164-
func setSticker(_ sticker: UIView?, face index: Int, mirror: Bool) {
164+
func setSticker(_ sticker: UIView?, face index: Int, mirror: Bool, animated: Bool = false) {
165165
guard self.faces.indices.contains(index) else {
166166
return
167167
}
@@ -178,6 +178,13 @@ final class CubeAnimationView: UIView {
178178
if let priorIndex = self.faceOccupants.first(where: { $0.value === sticker })?.key {
179179
self.faceOccupants[priorIndex] = nil
180180
}
181+
182+
if animated, let stickerSuperview = sticker.superview, let snapshotView = sticker.snapshotView(afterScreenUpdates: false) {
183+
stickerSuperview.addSubview(snapshotView)
184+
snapshotView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { _ in
185+
snapshotView.removeFromSuperview()
186+
})
187+
}
181188
sticker.removeFromSuperview()
182189

183190
let targetFace = self.faces[index]
@@ -201,6 +208,10 @@ final class CubeAnimationView: UIView {
201208
snappedAngle += .pi
202209
}
203210
sticker.transform = CGAffineTransform(rotationAngle: snappedAngle)
211+
212+
if animated {
213+
sticker.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
214+
}
204215
}
205216

206217
func startStickerSequence(indices: [Int]? = nil) {
@@ -700,7 +711,8 @@ final class CubeAnimationView: UIView {
700711
if !self.hasFiredFinishApproach && absRemaining <= self.finishApproachTriggerAngle {
701712
self.hasFiredFinishApproach = true
702713
let upsideDown = abs(shortestAngleDelta(from: self.rotation.x, to: Float.pi)) < (Float.pi / 2)
703-
self.onFinishApproach?(upsideDown)
714+
let isClockwise = self.finishDirectionY > 0
715+
self.onFinishApproach?(upsideDown, isClockwise)
704716
}
705717
if self.isSuccess, absRemaining <= self.finishSuccessScaleTriggerAngle {
706718
let raw = (self.finishSuccessScaleTriggerAngle - absRemaining) / self.finishSuccessScaleTriggerAngle

submodules/TelegramUI/Components/Gifts/GiftCraftScreen/Sources/SelectCraftGiftScreen.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,13 @@ final class SelectGiftPageContent: Component {
406406

407407
contentHeight = self.updateScrolling(interactive: false, transition: transition)
408408

409+
let resaleCount = component.genericGift.availability?.resale ?? 0
410+
let saleTitle = environment.strings.Gift_Craft_Select_SaleGiftsCount(Int32(clamping: resaleCount)).uppercased()
411+
409412
let storeGiftsTitleSize = self.storeGiftsTitle.update(
410413
transition: transition,
411414
component: AnyComponent(
412-
MultilineTextComponent(text: .plain(NSAttributedString(string: environment.strings.Gift_Craft_Select_SaleGifts.uppercased(), font: Font.semibold(14.0), textColor: environment.theme.actionSheet.secondaryTextColor)))
415+
MultilineTextComponent(text: .plain(NSAttributedString(string: saleTitle, font: Font.semibold(14.0), textColor: environment.theme.actionSheet.secondaryTextColor)))
413416
),
414417
environment: {},
415418
containerSize: CGSize(width: availableSize.width - sideInset * 2.0, height: 100.0)

submodules/TelegramUI/Components/Gifts/GiftStoreScreen/Sources/GiftStoreScreen.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,10 @@ public final class GiftStoreContentComponent: Component {
552552

553553
let attributes = self.starGiftsState?.attributes ?? []
554554
let modelAttributes = attributes.filter { attribute in
555-
if case .model = attribute {
555+
if case let .model(_, _, _, crafted) = attribute {
556+
if component.resaleGiftsContext.forCrafting && crafted {
557+
return false
558+
}
556559
return true
557560
} else {
558561
return false

submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,14 @@ private final class GiftViewSheetContent: CombinedComponent {
15361536
controller?.present(UndoOverlayController(presentationData: presentationData, content: .linkCopied(title: nil, text: presentationData.strings.Conversation_LinkCopied), elevatedLayout: false, animateInAsReplacement: false, action: { _ in return false }), in: .current)
15371537
})))
15381538

1539+
items.append(.action(ContextMenuActionItem(text: presentationData.strings.Gift_View_Context_Share, icon: { theme in
1540+
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Forward"), color: theme.contextMenu.primaryColor)
1541+
}, action: { [weak self] c, _ in
1542+
c?.dismiss(completion: nil)
1543+
1544+
self?.shareGift()
1545+
})))
1546+
15391547
var canCraft = false
15401548
if let data = self.context.currentAppConfiguration.with({ $0 }).data {
15411549
if let _ = data["ios_enable_crafting"] {
@@ -1555,14 +1563,6 @@ private final class GiftViewSheetContent: CombinedComponent {
15551563
})))
15561564
}
15571565

1558-
items.append(.action(ContextMenuActionItem(text: presentationData.strings.Gift_View_Context_Share, icon: { theme in
1559-
return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Forward"), color: theme.contextMenu.primaryColor)
1560-
}, action: { [weak self] c, _ in
1561-
c?.dismiss(completion: nil)
1562-
1563-
self?.shareGift()
1564-
})))
1565-
15661566
if case let .unique(uniqueGift) = arguments.gift, case let .peerId(ownerPeerId) = uniqueGift.owner, ownerPeerId != self.context.account.peerId, uniqueGift.minOfferStars != nil {
15671567
items.append(.action(ContextMenuActionItem(text: presentationData.strings.Gift_View_Context_BuyOffer, icon: { theme in
15681568
return generateTintedImage(image: UIImage(bundleImageName: "Media Grid/Paid"), color: theme.contextMenu.primaryColor)

submodules/TranslateUI/Sources/TranslateScreen.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,9 +626,8 @@ private final class TranslateSheetComponent: CombinedComponent {
626626
}
627627
)
628628
),
629-
hasTopEdgeEffect: false,
630629
bottomItem: nil,
631-
backgroundColor: .color(theme.actionSheet.opaqueItemBackgroundColor),
630+
backgroundColor: .color(theme.list.modalBlocksBackgroundColor),
632631
animateOut: animateOut
633632
),
634633
environment: {

0 commit comments

Comments
 (0)