Various fixes

This commit is contained in:
Ilya Laktyushin 2023-10-30 01:35:38 +04:00
parent 785e92c565
commit 22449d49e2
3 changed files with 127 additions and 41 deletions

View File

@ -666,6 +666,7 @@ private final class DemoSheetContent: CombinedComponent {
let background = Child(GradientBackgroundComponent.self) let background = Child(GradientBackgroundComponent.self)
let pager = Child(DemoPagerComponent.self) let pager = Child(DemoPagerComponent.self)
let button = Child(SolidRoundedButtonComponent.self) let button = Child(SolidRoundedButtonComponent.self)
let measureText = Child(MultilineTextComponent.self)
return { context in return { context in
let environment = context.environment[ViewControllerComponentContainer.Environment.self].value let environment = context.environment[ViewControllerComponentContainer.Environment.self].value
@ -703,7 +704,7 @@ private final class DemoSheetContent: CombinedComponent {
if case .other = component.source { if case .other = component.source {
isStandalone = true isStandalone = true
} }
if let stickers = state.stickers, let appIcons = state.appIcons, let configuration = state.promoConfiguration { if let stickers = state.stickers, let appIcons = state.appIcons, let configuration = state.promoConfiguration {
let textColor = theme.actionSheet.primaryTextColor let textColor = theme.actionSheet.primaryTextColor
@ -971,7 +972,7 @@ private final class DemoSheetContent: CombinedComponent {
.position(CGPoint(x: context.availableSize.width / 2.0, y: pager.size.height / 2.0)) .position(CGPoint(x: context.availableSize.width / 2.0, y: pager.size.height / 2.0))
) )
} }
let closeButton = closeButton.update( let closeButton = closeButton.update(
component: Button( component: Button(
content: AnyComponent(ZStack([ content: AnyComponent(ZStack([
@ -1003,44 +1004,108 @@ private final class DemoSheetContent: CombinedComponent {
.cornerRadius(15.0) .cornerRadius(15.0)
) )
var measuredTextHeight: CGFloat?
let buttonText: String let buttonText: String
var buttonAnimationName: String? var buttonAnimationName: String?
if state.isPremium == true { if state.isPremium == true {
buttonText = strings.Common_OK buttonText = strings.Common_OK
} else { } else {
switch component.source { switch component.source {
case let .intro(price): case let .intro(price):
buttonText = strings.Premium_SubscribeFor(price ?? "").string buttonText = strings.Premium_SubscribeFor(price ?? "").string
case let .gift(price): case let .gift(price):
buttonText = strings.Premium_Gift_GiftSubscription(price ?? "").string buttonText = strings.Premium_Gift_GiftSubscription(price ?? "").string
case .other: case .other:
switch component.subject { var text: String
case .fasterDownload: switch component.subject {
buttonText = strings.Premium_FasterSpeed_Proceed case .fasterDownload:
case .advancedChatManagement: buttonText = strings.Premium_FasterSpeed_Proceed
buttonText = strings.Premium_ChatManagement_Proceed case .advancedChatManagement:
case .uniqueReactions: buttonText = strings.Premium_ChatManagement_Proceed
buttonText = strings.Premium_Reactions_Proceed case .uniqueReactions:
buttonAnimationName = "premium_unlock" buttonText = strings.Premium_Reactions_Proceed
case .premiumStickers: buttonAnimationName = "premium_unlock"
buttonText = strings.Premium_Stickers_Proceed case .premiumStickers:
buttonAnimationName = "premium_unlock" buttonText = strings.Premium_Stickers_Proceed
case .appIcons: buttonAnimationName = "premium_unlock"
buttonText = strings.Premium_AppIcons_Proceed case .appIcons:
buttonAnimationName = "premium_unlock" buttonText = strings.Premium_AppIcons_Proceed
case .noAds: buttonAnimationName = "premium_unlock"
buttonText = strings.Premium_NoAds_Proceed case .noAds:
case .animatedEmoji: buttonText = strings.Premium_NoAds_Proceed
buttonText = strings.Premium_AnimatedEmoji_Proceed case .animatedEmoji:
buttonAnimationName = "premium_unlock" buttonText = strings.Premium_AnimatedEmoji_Proceed
case .translation: buttonAnimationName = "premium_unlock"
buttonText = strings.Premium_Translation_Proceed case .translation:
case .stories: buttonText = strings.Premium_Translation_Proceed
buttonText = strings.Common_OK case .stories:
buttonAnimationName = "premium_unlock" buttonText = strings.Common_OK
default: buttonAnimationName = "premium_unlock"
buttonText = strings.Common_OK default:
buttonText = strings.Common_OK
}
switch component.subject {
case .moreUpload:
text = strings.Premium_UploadSizeInfo
case .fasterDownload:
text = strings.Premium_FasterSpeedStandaloneInfo
case .voiceToText:
text = strings.Premium_VoiceToTextStandaloneInfo
case .noAds:
text = strings.Premium_NoAdsStandaloneInfo
case .uniqueReactions:
text = strings.Premium_InfiniteReactionsInfo
case .premiumStickers:
text = strings.Premium_StickersInfo
case .emojiStatus:
text = strings.Premium_EmojiStatusInfo
case .advancedChatManagement:
text = strings.Premium_ChatManagementStandaloneInfo
case .profileBadge:
text = strings.Premium_BadgeInfo
case .animatedUserpics:
text = strings.Premium_AvatarInfo
case .appIcons:
text = strings.Premium_AppIconStandaloneInfo
case .animatedEmoji:
text = strings.Premium_AnimatedEmojiStandaloneInfo
case .translation:
text = strings.Premium_TranslationStandaloneInfo
case .doubleLimits:
text = ""
case .stories:
text = ""
}
let textSideInset: CGFloat = 24.0
let textColor = UIColor.black
let textFont = Font.regular(17.0)
let boldTextFont = Font.semibold(17.0)
let markdownAttributes = MarkdownAttributes(
body: MarkdownAttributeSet(font: textFont, textColor: textColor),
bold: MarkdownAttributeSet(font: boldTextFont, textColor: textColor),
link: MarkdownAttributeSet(font: textFont, textColor: textColor),
linkAttribute: { _ in
return nil
} }
)
let measureText = measureText.update(
component: MultilineTextComponent(
text: .markdown(text: text, attributes: markdownAttributes),
horizontalAlignment: .center,
maximumNumberOfLines: 0,
lineSpacing: 0.0
),
availableSize: CGSize(width: context.availableSize.width - textSideInset * 2.0, height: context.availableSize.height),
transition: .immediate
)
context.add(measureText
.position(CGPoint(x: 0.0, y: 1000.0))
)
measuredTextHeight = measureText.size.height
} }
} }
@ -1079,12 +1144,17 @@ private final class DemoSheetContent: CombinedComponent {
transition: context.transition transition: context.transition
) )
var contentHeight: CGFloat = context.availableSize.width + 146.0 var contentHeight: CGFloat = context.availableSize.width
if case .other = component.source { if let measuredTextHeight {
contentHeight -= 40.0 contentHeight += measuredTextHeight + 66.0
} else {
if [.advancedChatManagement, .fasterDownload].contains(component.subject) { contentHeight += 146.0
contentHeight += 20.0 if case .other = component.source {
contentHeight -= 40.0
if [.advancedChatManagement, .fasterDownload].contains(component.subject) {
contentHeight += 20.0
}
} }
} }
@ -1166,6 +1236,7 @@ private final class DemoSheetComponent: CombinedComponent {
} }
)), )),
backgroundColor: .color(environment.theme.actionSheet.opaqueItemBackgroundColor), backgroundColor: .color(environment.theme.actionSheet.opaqueItemBackgroundColor),
followContentSizeChanges: context.component.source == .other,
animateOut: animateOut animateOut: animateOut
), ),
environment: { environment: {

View File

@ -817,7 +817,7 @@ public class PremiumLimitsListScreen: ViewController {
additionalInset = 20.0 additionalInset = 20.0
} }
return layout.size.height - layout.size.width - 178.0 - panelHeight + additionalInset return layout.size.height - layout.size.width - 181.0 - panelHeight + additionalInset
} else { } else {
return 210.0 return 210.0
} }

View File

@ -184,6 +184,7 @@ private struct PeerNameColorScreenState: Equatable {
var updatedNameColor: PeerNameColor? var updatedNameColor: PeerNameColor?
var updatedBackgroundEmojiId: Int64? var updatedBackgroundEmojiId: Int64?
var inProgress: Bool = false var inProgress: Bool = false
var needsBoosts: Bool = false
} }
private func peerNameColorScreenEntries( private func peerNameColorScreenEntries(
@ -253,7 +254,11 @@ private func peerNameColorScreenEntries(
colors: nameColors, colors: nameColors,
currentColor: nameColor currentColor: nameColor
)) ))
entries.append(.colorDescription(presentationData.strings.NameColor_ChatPreview_Description_Account)) if case .channel = peer {
entries.append(.colorDescription(presentationData.strings.NameColor_ChatPreview_Description_Channel))
} else {
entries.append(.colorDescription(presentationData.strings.NameColor_ChatPreview_Description_Account))
}
if let emojiContent { if let emojiContent {
entries.append(.backgroundEmojiHeader(presentationData.strings.NameColor_BackgroundEmoji_Title, backgroundEmojiId != nil ? presentationData.strings.NameColor_BackgroundEmoji_Remove : nil)) entries.append(.backgroundEmojiHeader(presentationData.strings.NameColor_BackgroundEmoji_Title, backgroundEmojiId != nil ? presentationData.strings.NameColor_BackgroundEmoji_Remove : nil))
@ -561,6 +566,10 @@ public func PeerNameColorScreen(
return true return true
} }
let state = stateValue.with({ $0 }) let state = stateValue.with({ $0 })
if case .channel = subject, state.needsBoosts {
f()
return true
}
var hasChanges = false var hasChanges = false
if state.updatedNameColor != nil || state.updatedBackgroundEmojiId != nil { if state.updatedNameColor != nil || state.updatedBackgroundEmojiId != nil {
hasChanges = true hasChanges = true
@ -624,6 +633,12 @@ public func PeerNameColorScreen(
|> deliverOnMainQueue).startStandalone(next: { |> deliverOnMainQueue).startStandalone(next: {
}, error: { error in }, error: { error in
if case .channelBoostRequired = error { if case .channelBoostRequired = error {
updateState { state in
var updatedState = state
updatedState.needsBoosts = true
return updatedState
}
let _ = combineLatest( let _ = combineLatest(
queue: Queue.mainQueue(), queue: Queue.mainQueue(),
context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)), context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)),