diff --git a/submodules/Display/Source/TextNode.swift b/submodules/Display/Source/TextNode.swift index 16af2a2c07..c226bb6144 100644 --- a/submodules/Display/Source/TextNode.swift +++ b/submodules/Display/Source/TextNode.swift @@ -2019,7 +2019,7 @@ open class TextNode: ASDisplayNode { var descent: CGFloat = 0.0 CTLineGetTypographicBounds(coreTextLine, &ascent, &descent, nil) - addAttachment(attachment: attachment, line: coreTextLine, ascent: ascent, descent: descent, startIndex: range.location, endIndex: max(range.location, min(lineRange.location + lineRange.length - 1, range.location + range.length)), isAtEndOfTheLine: range.location + range.length >= lineRange.location + lineRange.length - 1) + addAttachment(attachment: attachment, line: coreTextLine, ascent: ascent, descent: descent, startIndex: range.location, endIndex: max(range.location, min(lineRange.location + lineRange.length, range.location + range.length)), isAtEndOfTheLine: range.location + range.length >= lineRange.location + lineRange.length - 1) } } } @@ -2134,7 +2134,7 @@ open class TextNode: ASDisplayNode { var descent: CGFloat = 0.0 CTLineGetTypographicBounds(coreTextLine, &ascent, &descent, nil) - addAttachment(attachment: attachment, line: coreTextLine, ascent: ascent, descent: descent, startIndex: range.location, endIndex: max(range.location, min(lineRange.location + lineRange.length - 1, range.location + range.length)), isAtEndOfTheLine: range.location + range.length >= lineRange.location + lineRange.length - 1) + addAttachment(attachment: attachment, line: coreTextLine, ascent: ascent, descent: descent, startIndex: range.location, endIndex: max(range.location, min(lineRange.location + lineRange.length, range.location + range.length)), isAtEndOfTheLine: range.location + range.length >= lineRange.location + lineRange.length - 1) } } diff --git a/submodules/TelegramUI/Components/ListMultilineTextFieldItemComponent/Sources/ListMultilineTextFieldItemComponent.swift b/submodules/TelegramUI/Components/ListMultilineTextFieldItemComponent/Sources/ListMultilineTextFieldItemComponent.swift index 9dadf28dc5..f4476df226 100644 --- a/submodules/TelegramUI/Components/ListMultilineTextFieldItemComponent/Sources/ListMultilineTextFieldItemComponent.swift +++ b/submodules/TelegramUI/Components/ListMultilineTextFieldItemComponent/Sources/ListMultilineTextFieldItemComponent.swift @@ -9,6 +9,13 @@ import TextFieldComponent import AccountContext public final class ListMultilineTextFieldItemComponent: Component { + public final class ExternalState { + public fileprivate(set) var hasText: Bool = false + + public init() { + } + } + public final class ResetText: Equatable { public let value: String @@ -21,6 +28,7 @@ public final class ListMultilineTextFieldItemComponent: Component { } } + public let externalState: ExternalState? public let context: AccountContext public let theme: PresentationTheme public let strings: PresentationStrings @@ -31,9 +39,11 @@ public final class ListMultilineTextFieldItemComponent: Component { public let autocorrectionType: UITextAutocorrectionType public let characterLimit: Int? public let updated: ((String) -> Void)? + public let textUpdateTransition: Transition public let tag: AnyObject? public init( + externalState: ExternalState? = nil, context: AccountContext, theme: PresentationTheme, strings: PresentationStrings, @@ -44,8 +54,10 @@ public final class ListMultilineTextFieldItemComponent: Component { autocorrectionType: UITextAutocorrectionType = .default, characterLimit: Int? = nil, updated: ((String) -> Void)?, + textUpdateTransition: Transition = .immediate, tag: AnyObject? = nil ) { + self.externalState = externalState self.context = context self.theme = theme self.strings = strings @@ -56,10 +68,14 @@ public final class ListMultilineTextFieldItemComponent: Component { self.autocorrectionType = autocorrectionType self.characterLimit = characterLimit self.updated = updated + self.textUpdateTransition = textUpdateTransition self.tag = tag } public static func ==(lhs: ListMultilineTextFieldItemComponent, rhs: ListMultilineTextFieldItemComponent) -> Bool { + if lhs.externalState !== rhs.externalState { + return false + } if lhs.context !== rhs.context { return false } @@ -140,7 +156,7 @@ public final class ListMultilineTextFieldItemComponent: Component { @objc private func textDidChange() { if !self.isUpdating { - self.state?.updated(transition: .immediate) + self.state?.updated(transition: self.component?.textUpdateTransition ?? .immediate) } self.component?.updated?(self.currentText) } @@ -242,6 +258,8 @@ public final class ListMultilineTextFieldItemComponent: Component { self.separatorInset = 16.0 + component.externalState?.hasText = self.textFieldExternalState.hasText + return size } } diff --git a/submodules/TelegramUI/Components/Settings/BusinessLocationSetupScreen/Sources/BusinessLocationSetupScreen.swift b/submodules/TelegramUI/Components/Settings/BusinessLocationSetupScreen/Sources/BusinessLocationSetupScreen.swift index fc7fadbadd..7754e8382b 100644 --- a/submodules/TelegramUI/Components/Settings/BusinessLocationSetupScreen/Sources/BusinessLocationSetupScreen.swift +++ b/submodules/TelegramUI/Components/Settings/BusinessLocationSetupScreen/Sources/BusinessLocationSetupScreen.swift @@ -66,6 +66,7 @@ final class BusinessLocationSetupScreenComponent: Component { private let subtitle = ComponentView() private let addressSection = ComponentView() private let mapSection = ComponentView() + private let deleteSection = ComponentView() private var isUpdating: Bool = false @@ -73,6 +74,7 @@ final class BusinessLocationSetupScreenComponent: Component { private(set) weak var state: EmptyComponentState? private var environment: EnvironmentType? + private let addressTextInputState = ListMultilineTextFieldItemComponent.ExternalState() private let textFieldTag = NSObject() private var resetAddressText: String? @@ -271,6 +273,13 @@ final class BusinessLocationSetupScreenComponent: Component { self.component = component self.state = state + let alphaTransition: Transition + if !transition.animation.isImmediate { + alphaTransition = .easeInOut(duration: 0.25) + } else { + alphaTransition = .immediate + } + if themeUpdated { self.backgroundColor = environment.theme.list.blocksBackgroundColor } @@ -376,6 +385,7 @@ final class BusinessLocationSetupScreenComponent: Component { //TODO:localize var addressSectionItems: [AnyComponentWithIdentity] = [] addressSectionItems.append(AnyComponentWithIdentity(id: 0, component: AnyComponent(ListMultilineTextFieldItemComponent( + externalState: self.addressTextInputState, context: component.context, theme: environment.theme, strings: environment.strings, @@ -389,6 +399,7 @@ final class BusinessLocationSetupScreenComponent: Component { characterLimit: 64, updated: { _ in }, + textUpdateTransition: .spring(duration: 0.4), tag: self.textFieldTag )))) self.resetAddressText = nil @@ -482,6 +493,66 @@ final class BusinessLocationSetupScreenComponent: Component { } contentHeight += mapSectionSize.height + var deleteSectionHeight: CGFloat = 0.0 + + deleteSectionHeight += sectionSpacing + //TODO:localize + let deleteSectionSize = self.deleteSection.update( + transition: transition, + component: AnyComponent(ListSectionComponent( + theme: environment.theme, + header: nil, + footer: nil, + items: [ + AnyComponentWithIdentity(id: 0, component: AnyComponent(ListActionItemComponent( + theme: environment.theme, + title: AnyComponent(VStack([ + AnyComponentWithIdentity(id: AnyHashable(0), component: AnyComponent(MultilineTextComponent( + text: .plain(NSAttributedString( + string: "Delete Location", + font: Font.regular(presentationData.listsFontSize.baseDisplaySize), + textColor: environment.theme.list.itemDestructiveColor + )), + maximumNumberOfLines: 1 + ))), + ], alignment: .left, spacing: 2.0)), + accessory: nil, + action: { [weak self] _ in + guard let self else { + return + } + + self.resetAddressText = "" + self.mapCoordinates = nil + self.mapCoordinatesManuallySet = false + self.state?.updated(transition: .spring(duration: 0.4)) + } + ))) + ], + displaySeparators: false + )), + environment: {}, + containerSize: CGSize(width: availableSize.width - sideInset * 2.0, height: 10000.0) + ) + let deleteSectionFrame = CGRect(origin: CGPoint(x: sideInset, y: contentHeight + deleteSectionHeight), size: deleteSectionSize) + if let deleteSectionView = self.deleteSection.view { + if deleteSectionView.superview == nil { + self.scrollView.addSubview(deleteSectionView) + } + transition.setFrame(view: deleteSectionView, frame: deleteSectionFrame) + + if self.mapCoordinates != nil || self.addressTextInputState.hasText { + alphaTransition.setAlpha(view: deleteSectionView, alpha: 1.0) + } else { + alphaTransition.setAlpha(view: deleteSectionView, alpha: 0.0) + } + } + deleteSectionHeight += deleteSectionSize.height + + if self.mapCoordinates != nil || self.addressTextInputState.hasText { + contentHeight += deleteSectionHeight + } + contentHeight += bottomContentInset contentHeight += environment.safeInsets.bottom diff --git a/submodules/TelegramUI/Components/Settings/ChatbotSetupScreen/Sources/ChatbotSetupScreen.swift b/submodules/TelegramUI/Components/Settings/ChatbotSetupScreen/Sources/ChatbotSetupScreen.swift index 4bce7091d0..8e6a60cab9 100644 --- a/submodules/TelegramUI/Components/Settings/ChatbotSetupScreen/Sources/ChatbotSetupScreen.swift +++ b/submodules/TelegramUI/Components/Settings/ChatbotSetupScreen/Sources/ChatbotSetupScreen.swift @@ -533,7 +533,7 @@ final class ChatbotSetupScreenComponent: Component { contentHeight += 129.0 //TODO:localize - let subtitleString = NSMutableAttributedString(attributedString: parseMarkdownIntoAttributedString("Add a bot to your account to help you automatically process and respond to the messages you receive. [Learn More]() >", attributes: MarkdownAttributes( + let subtitleString = NSMutableAttributedString(attributedString: parseMarkdownIntoAttributedString("Add a bot to your account to help you automatically process and respond to the messages you receive. [Learn More >]()", attributes: MarkdownAttributes( body: MarkdownAttributeSet(font: Font.regular(15.0), textColor: environment.theme.list.freeTextColor), bold: MarkdownAttributeSet(font: Font.semibold(15.0), textColor: environment.theme.list.freeTextColor), link: MarkdownAttributeSet(font: Font.regular(15.0), textColor: environment.theme.list.itemAccentColor), @@ -568,7 +568,8 @@ final class ChatbotSetupScreenComponent: Component { guard let self, let component = self.component else { return } - let _ = component + //TODO:localize + component.context.sharedContext.applicationBindings.openUrl("https://telegram.org") } )), environment: {}, diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index a5d4429d34..0ed8b8b15d 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -9493,8 +9493,12 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G guard let peerId = self.chatLocation.peerId else { return } - let _ = self - let _ = shortcutId + + if !self.presentationInterfaceState.isPremium { + let controller = PremiumIntroScreen(context: self.context, source: .settings) + self.push(controller) + return + } self.updateChatPresentationInterfaceState(animated: true, interactive: false, { $0.updatedInterfaceState { $0.withUpdatedReplyMessageSubject(nil).withUpdatedComposeInputState(ChatTextInputState(inputText: NSAttributedString(string: ""))).withUpdatedComposeDisableUrlPreviews([]) } diff --git a/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift b/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift index 31779ba481..018aebdd58 100644 --- a/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift +++ b/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift @@ -1937,7 +1937,7 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState } } - if message.timestamp >= 0 { + if message.id.id < Int32.max - 1000 { if !actions.isEmpty { actions.append(.separator) }