From 2aeeaaee445f98a39b1da203a266aec063cc02ae Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 20 Jul 2023 01:08:04 +0200 Subject: [PATCH] Various improvements --- .../Telegram-iOS/en.lproj/Localizable.strings | 4 - .../PremiumUI/Sources/PremiumDemoScreen.swift | 20 +---- .../Sources/PremiumIntroScreen.swift | 2 +- .../Sources/StoryPrivacyIconComponent.swift | 82 +++++++++++++------ 4 files changed, 61 insertions(+), 47 deletions(-) diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index 7be547efa2..f7e28535f6 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -9428,10 +9428,6 @@ Sorry for the inconvenience."; "MediaPicker.AddImage" = "Add Image"; -"Premium.Stories" = "Story Posting"; -"Premium.StoriesInfo" = "Be one of the first to share your stories with your contacts or an unlimited audience."; -"Premium.Stories.Proceed" = "Unlock Story Posting"; - "AutoDownloadSettings.OnForContacts" = "On for contacts"; "AutoDownloadSettings.StoriesSectionHeader" = "AUTO-DOWNLOAD STORIES"; diff --git a/submodules/PremiumUI/Sources/PremiumDemoScreen.swift b/submodules/PremiumUI/Sources/PremiumDemoScreen.swift index b2afa7ae51..8890b9e757 100644 --- a/submodules/PremiumUI/Sources/PremiumDemoScreen.swift +++ b/submodules/PremiumUI/Sources/PremiumDemoScreen.swift @@ -939,24 +939,6 @@ private final class DemoSheetContent: CombinedComponent { ) ) ) - availableItems[.stories] = DemoPagerComponent.Item( - AnyComponentWithIdentity( - id: PremiumDemoScreen.Subject.stories, - component: AnyComponent( - PageComponent( - content: AnyComponent(PhoneDemoComponent( - context: component.context, - position: .top, - videoFile: configuration.videos["voice_to_text"], - decoration: .badgeStars - )), - title: strings.Premium_Stories, - text: strings.Premium_StoriesInfo, - textColor: textColor - ) - ) - ) - ) var items: [DemoPagerComponent.Item] = component.order.compactMap { availableItems[$0] } let index: Int @@ -1048,7 +1030,7 @@ private final class DemoSheetContent: CombinedComponent { case .translation: buttonText = strings.Premium_Translation_Proceed case .stories: - buttonText = strings.Premium_Stories_Proceed + buttonText = strings.Common_OK buttonAnimationName = "premium_unlock" default: buttonText = strings.Common_OK diff --git a/submodules/PremiumUI/Sources/PremiumIntroScreen.swift b/submodules/PremiumUI/Sources/PremiumIntroScreen.swift index f3bd80a70a..5e66a39116 100644 --- a/submodules/PremiumUI/Sources/PremiumIntroScreen.swift +++ b/submodules/PremiumUI/Sources/PremiumIntroScreen.swift @@ -395,7 +395,7 @@ enum PremiumPerk: CaseIterable { case .translation: return strings.Premium_Translation case .stories: - return strings.Premium_Stories + return "" } } diff --git a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryPrivacyIconComponent.swift b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryPrivacyIconComponent.swift index fa886bfa5d..025e35588a 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryPrivacyIconComponent.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryPrivacyIconComponent.swift @@ -33,14 +33,72 @@ final class StoryPrivacyIconComponent: Component { } final class View: UIImageView { + private let iconView = UIImageView() + private var component: StoryPrivacyIconComponent? private weak var state: EmptyComponentState? - + + override init(frame: CGRect) { + super.init(frame: frame) + + self.addSubview(self.iconView) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + func update(component: StoryPrivacyIconComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment, transition: Transition) -> CGSize { + let previousPrivacy = self.component?.privacy self.component = component self.state = state + let colors: [CGColor] + var icon: UIImage? + + if let previousPrivacy, previousPrivacy != component.privacy { + let disappearingBackgroundView = UIImageView(image: self.image) + disappearingBackgroundView.frame = self.bounds + self.insertSubview(disappearingBackgroundView, at: 0) + + disappearingBackgroundView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak disappearingBackgroundView] _ in + disappearingBackgroundView?.removeFromSuperview() + }) + + let disappearingIconView = UIImageView(image: self.iconView.image) + disappearingIconView.frame = self.iconView.frame + self.insertSubview(disappearingIconView, belowSubview: self.iconView) + + disappearingIconView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak disappearingIconView] _ in + disappearingIconView?.removeFromSuperview() + }) + disappearingIconView.layer.animateScale(from: 1.0, to: 0.01, duration: 0.2, removeOnCompletion: false) + + self.iconView.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) + self.iconView.layer.animateScale(from: 0.01, to: 1.0, duration: 0.2) + } + + switch component.privacy { + case .everyone: + colors = [UIColor(rgb: 0x4faaff).cgColor, UIColor(rgb: 0x017aff).cgColor] + icon = UIImage(bundleImageName: "Stories/PrivacyEveryone") + case .closeFriends: + colors = [UIColor(rgb: 0x87d93a).cgColor, UIColor(rgb: 0x31b73b).cgColor] + icon = UIImage(bundleImageName: "Stories/PrivacyCloseFriends") + case .contacts: + colors = [UIColor(rgb: 0xc36eff).cgColor, UIColor(rgb: 0x8c61fa).cgColor] + icon = UIImage(bundleImageName: "Stories/PrivacyContacts") + case .selectedContacts: + colors = [UIColor(rgb: 0xffb643).cgColor, UIColor(rgb: 0xf69a36).cgColor] + icon = UIImage(bundleImageName: "Stories/PrivacySelectedContacts") + } + let size = CGSize(width: component.isEditable ? 40.0 : 24.0, height: 24.0) + let iconFrame = CGRect(origin: CGPoint(x: component.isEditable ? 1.0 : 0.0, y: 0.0), size: CGSize(width: size.height, height: size.height)) + self.iconView.image = icon + self.iconView.bounds = CGRect(origin: .zero, size: iconFrame.size) + self.iconView.center = iconFrame.center + self.image = generateImage(size, contextGenerator: { size, context in let bounds = CGRect(origin: .zero, size: size) context.clear(bounds) @@ -56,32 +114,10 @@ final class StoryPrivacyIconComponent: Component { context.clip() var locations: [CGFloat] = [1.0, 0.0] - let colors: [CGColor] - var icon: UIImage? - - switch component.privacy { - case .everyone: - colors = [UIColor(rgb: 0x4faaff).cgColor, UIColor(rgb: 0x017aff).cgColor] - icon = UIImage(bundleImageName: "Stories/PrivacyEveryone") - case .closeFriends: - colors = [UIColor(rgb: 0x87d93a).cgColor, UIColor(rgb: 0x31b73b).cgColor] - icon = UIImage(bundleImageName: "Stories/PrivacyCloseFriends") - case .contacts: - colors = [UIColor(rgb: 0xc36eff).cgColor, UIColor(rgb: 0x8c61fa).cgColor] - icon = UIImage(bundleImageName: "Stories/PrivacyContacts") - case .selectedContacts: - colors = [UIColor(rgb: 0xffb643).cgColor, UIColor(rgb: 0xf69a36).cgColor] - icon = UIImage(bundleImageName: "Stories/PrivacySelectedContacts") - } - let colorSpace = CGColorSpaceCreateDeviceRGB() let gradient = CGGradient(colorsSpace: colorSpace, colors: colors as CFArray, locations: &locations)! context.drawLinearGradient(gradient, start: CGPoint(x: 0.0, y: 0.0), end: CGPoint(x: 0.0, y: size.height), options: CGGradientDrawingOptions()) - if let icon, let cgImage = icon.cgImage { - context.draw(cgImage, in: CGRect(origin: CGPoint(x: component.isEditable ? 1.0 : 0.0, y: 0.0), size: icon.size)) - } - if component.isEditable { if let arrowIcon = UIImage(bundleImageName: "Stories/PrivacyDownArrow"), let cgImage = arrowIcon.cgImage { context.draw(cgImage, in: CGRect(origin: CGPoint(x: size.width - arrowIcon.size.width - 6.0, y: floorToScreenPixels((size.height - arrowIcon.size.height) / 2.0)), size: arrowIcon.size))