Various improvements

This commit is contained in:
Ilya Laktyushin 2024-06-15 23:37:21 +04:00
parent a2872a6189
commit 8304a9c0a0
2 changed files with 30 additions and 1 deletions

View File

@ -143,6 +143,7 @@ final class ContextMenuActionNode: ASDisplayNode {
override func calculateSizeThatFits(_ constrainedSize: CGSize) -> CGSize {
if let textNode = self.textNode {
let constrainedSize = CGSize(width: constrainedSize.width - 36.0 - 24.0, height: constrainedSize.height)
let textSize = textNode.updateLayout(constrainedSize)
self.textSize = textSize
@ -151,7 +152,7 @@ final class ContextMenuActionNode: ASDisplayNode {
totalWidth += textSize.width
if let subtitleNode = self.subtitleNode {
let subtitleSize = subtitleNode.updateLayout(constrainedSize)
let subtitleSize = subtitleNode.updateLayout(CGSize(width: constrainedSize.width * 0.75, height: constrainedSize.height))
self.subtitleSize = subtitleSize
totalWidth = max(totalWidth, subtitleSize.width)
totalHeight += 14.0

View File

@ -204,6 +204,14 @@ private final class SheetContent: CombinedComponent {
)
)
state.selectLink = {
if let controller = controller() as? CreateLinkScreen {
if let view = controller.node.hostView.findTaggedView(tag: linkTag) as? LinkFieldComponent.View {
view.selectAll()
}
}
}
let urlSection = urlSection.update(
component: ListSectionComponent(
theme: theme,
@ -325,6 +333,8 @@ private final class CreateLinkSheetComponent: CombinedComponent {
private let linkDisposable = MetaDisposable()
private let linkPromise = ValuePromise<String>()
var selectLink: () -> Void = {}
init(
context: AccountContext,
link: CreateLinkScreen.Link?
@ -340,6 +350,20 @@ private final class CreateLinkSheetComponent: CombinedComponent {
super.init()
if link == nil {
Queue.mainQueue().after(0.1, {
let pasteboard = UIPasteboard.general
if pasteboard.hasURLs {
if let url = pasteboard.url?.absoluteString, !url.isEmpty {
self.link = url
self.updated()
self.selectLink()
}
}
})
}
self.linkDisposable.set((self.linkPromise.get()
|> delay(1.5, queue: Queue.mainQueue())
|> deliverOnMainQueue).startStrict(next: { [weak self] link in
@ -707,6 +731,10 @@ private final class LinkFieldComponent: Component {
self.textField.becomeFirstResponder()
}
func selectAll() {
self.textField.selectAll(nil)
}
func update(component: LinkFieldComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment<EnvironmentType>, transition: ComponentTransition) -> CGSize {
self.textField.textColor = component.textColor
self.textField.text = component.text