Various improvements

This commit is contained in:
Ilya Laktyushin 2023-07-20 01:08:04 +02:00
parent 6fdd2ebf0d
commit 2aeeaaee44
4 changed files with 61 additions and 47 deletions

View File

@ -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";

View File

@ -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

View File

@ -395,7 +395,7 @@ enum PremiumPerk: CaseIterable {
case .translation:
return strings.Premium_Translation
case .stories:
return strings.Premium_Stories
return ""
}
}

View File

@ -33,32 +33,51 @@ 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<Empty>, transition: Transition) -> CGSize {
let previousPrivacy = self.component?.privacy
self.component = component
self.state = state
let size = CGSize(width: component.isEditable ? 40.0 : 24.0, height: 24.0)
self.image = generateImage(size, contextGenerator: { size, context in
let bounds = CGRect(origin: .zero, size: size)
context.clear(bounds)
let path: CGPath
if size.width == size.height {
path = CGPath(ellipseIn: bounds, transform: nil)
} else {
path = CGPath(roundedRect: bounds, cornerWidth: size.height / 2.0, cornerHeight: size.height / 2.0, transform: nil)
}
context.addPath(path)
context.clip()
var locations: [CGFloat] = [1.0, 0.0]
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]
@ -74,14 +93,31 @@ final class StoryPrivacyIconComponent: Component {
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)
let path: CGPath
if size.width == size.height {
path = CGPath(ellipseIn: bounds, transform: nil)
} else {
path = CGPath(roundedRect: bounds, cornerWidth: size.height / 2.0, cornerHeight: size.height / 2.0, transform: nil)
}
context.addPath(path)
context.clip()
var locations: [CGFloat] = [1.0, 0.0]
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))