mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-02-11 05:20:37 +00:00
83 lines
2.6 KiB
Swift
83 lines
2.6 KiB
Swift
import Foundation
|
|
import UIKit
|
|
import SwiftSignalKit
|
|
import AsyncDisplayKit
|
|
import Display
|
|
import Postbox
|
|
import TelegramCore
|
|
import TelegramPresentationData
|
|
import AccountContext
|
|
import ComponentFlow
|
|
import MultilineTextComponent
|
|
import BalancedTextComponent
|
|
import AlertComponent
|
|
import AlertInputFieldComponent
|
|
|
|
public func businessLinkNameAlertController(
|
|
context: AccountContext,
|
|
updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)? = nil,
|
|
value: String?,
|
|
apply: @escaping (String?) -> Void
|
|
) -> ViewController {
|
|
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
|
let strings = presentationData.strings
|
|
|
|
let inputState = AlertInputFieldComponent.ExternalState()
|
|
|
|
var content: [AnyComponentWithIdentity<AlertComponentEnvironment>] = []
|
|
content.append(AnyComponentWithIdentity(
|
|
id: "title",
|
|
component: AnyComponent(
|
|
AlertTitleComponent(title: strings.Business_Links_LinkNameTitle)
|
|
)
|
|
))
|
|
content.append(AnyComponentWithIdentity(
|
|
id: "text",
|
|
component: AnyComponent(
|
|
AlertTextComponent(content: .plain(strings.Business_Links_LinkNameText))
|
|
)
|
|
))
|
|
|
|
var applyImpl: (() -> Void)?
|
|
content.append(AnyComponentWithIdentity(
|
|
id: "input",
|
|
component: AnyComponent(
|
|
AlertInputFieldComponent(
|
|
context: context,
|
|
initialValue: value,
|
|
placeholder: strings.Business_Links_LinkNameInputPlaceholder,
|
|
characterLimit: 32,
|
|
hasClearButton: false,
|
|
isInitiallyFocused: true,
|
|
externalState: inputState,
|
|
returnKeyAction: {
|
|
applyImpl?()
|
|
}
|
|
)
|
|
)
|
|
))
|
|
|
|
var effectiveUpdatedPresentationData: (PresentationData, Signal<PresentationData, NoError>)
|
|
if let updatedPresentationData {
|
|
effectiveUpdatedPresentationData = updatedPresentationData
|
|
} else {
|
|
effectiveUpdatedPresentationData = (presentationData, context.sharedContext.presentationData)
|
|
}
|
|
|
|
let alertController = AlertScreen(
|
|
configuration: AlertScreen.Configuration(allowInputInset: true),
|
|
content: content,
|
|
actions: [
|
|
.init(title: strings.Common_Cancel),
|
|
.init(title: strings.Common_Done, type: .default, action: {
|
|
applyImpl?()
|
|
})
|
|
],
|
|
updatedPresentationData: effectiveUpdatedPresentationData
|
|
)
|
|
applyImpl = {
|
|
apply(inputState.value)
|
|
}
|
|
return alertController
|
|
}
|