Skip to content

Commit 4fa367c

Browse files
committed
Gift setup improvements
1 parent ec9d5fd commit 4fa367c

File tree

2 files changed

+63
-22
lines changed

2 files changed

+63
-22
lines changed

submodules/TelegramUI/Components/Gifts/GiftSetupScreen/Sources/GiftSetupScreen.swift

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,33 @@ final class GiftSetupScreenComponent: Component {
417417
}
418418
}
419419

420+
@objc private func previewTap() {
421+
func hasFirstResponder(_ view: UIView) -> Bool {
422+
if view.isFirstResponder {
423+
return true
424+
}
425+
for subview in view.subviews {
426+
if hasFirstResponder(subview) {
427+
return true
428+
}
429+
}
430+
return false
431+
}
432+
433+
self.currentInputMode = .keyboard
434+
if hasFirstResponder(self) {
435+
if let titleView = self.introSection.findTaggedView(tag: self.textInputTag) as? ListMultilineTextFieldItemComponent.View {
436+
if titleView.isActive {
437+
titleView.deactivateInput()
438+
} else {
439+
self.endEditing(true)
440+
}
441+
}
442+
} else {
443+
self.state?.updated(transition: .spring(duration: 0.4))
444+
}
445+
}
446+
420447
func update(component: GiftSetupScreenComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment<EnvironmentType>, transition: ComponentTransition) -> CGSize {
421448
self.isUpdating = true
422449
defer {
@@ -693,28 +720,7 @@ final class GiftSetupScreenComponent: Component {
693720
))))
694721
self.resetText = nil
695722

696-
697-
var inputHeight: CGFloat = 0.0
698-
inputHeight += self.updateInputMediaNode(
699-
component: component,
700-
availableSize: availableSize,
701-
bottomInset: environment.safeInsets.bottom,
702-
inputHeight: 0.0,
703-
effectiveInputHeight: environment.deviceMetrics.standardInputHeight(inLandscape: false),
704-
metrics: environment.metrics,
705-
deviceMetrics: environment.deviceMetrics,
706-
transition: transition
707-
)
708-
if self.inputMediaNode == nil {
709-
if environment.inputHeight.isZero && self.textInputState.isEditing, let previousInputHeight = self.previousInputHeight {
710-
inputHeight = previousInputHeight
711-
} else {
712-
inputHeight = environment.inputHeight
713-
}
714-
}
715-
716723
let peerName = self.peerMap[component.peerId]?.compactDisplayTitle ?? ""
717-
718724
let introFooter: AnyComponent<Empty>?
719725
switch component.subject {
720726
case .premium:
@@ -751,7 +757,26 @@ final class GiftSetupScreenComponent: Component {
751757
}
752758
contentHeight += introSectionSize.height
753759
contentHeight += sectionSpacing
754-
760+
761+
var inputHeight: CGFloat = 0.0
762+
inputHeight += self.updateInputMediaNode(
763+
component: component,
764+
availableSize: availableSize,
765+
bottomInset: environment.safeInsets.bottom,
766+
inputHeight: 0.0,
767+
effectiveInputHeight: environment.deviceMetrics.standardInputHeight(inLandscape: false),
768+
metrics: environment.metrics,
769+
deviceMetrics: environment.deviceMetrics,
770+
transition: transition
771+
)
772+
if self.inputMediaNode == nil {
773+
if environment.inputHeight.isZero && self.textInputState.isEditing, let previousInputHeight = self.previousInputHeight {
774+
inputHeight = previousInputHeight
775+
} else {
776+
inputHeight = environment.inputHeight
777+
}
778+
}
779+
755780
let listItemParams = ListViewItemLayoutParams(width: availableSize.width - sideInset * 2.0, leftInset: 0.0, rightInset: 0.0, availableHeight: 10000.0, isStandalone: true)
756781
if let accountPeer = self.peerMap[component.context.account.peerId] {
757782
let subject: ChatGiftPreviewItem.Subject
@@ -793,6 +818,8 @@ final class GiftSetupScreenComponent: Component {
793818
if introContentView.superview == nil {
794819
if let placeholderView = self.introSection.findTaggedView(tag: self.introPlaceholderTag) {
795820
placeholderView.addSubview(introContentView)
821+
822+
placeholderView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.previewTap)))
796823
}
797824
}
798825
transition.setFrame(view: introContentView, frame: CGRect(origin: CGPoint(), size: introContentSize))

submodules/TelegramUI/Components/ListMultilineTextFieldItemComponent/Sources/ListMultilineTextFieldItemComponent.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,26 @@ public final class ListMultilineTextFieldItemComponent: Component {
227227
return false
228228
}
229229

230+
public var isActive: Bool {
231+
if let textFieldView = self.textField.view as? TextFieldComponent.View {
232+
return textFieldView.isActive
233+
} else {
234+
return false
235+
}
236+
}
237+
230238
public func activateInput() {
231239
if let textFieldView = self.textField.view as? TextFieldComponent.View {
232240
textFieldView.activateInput()
233241
}
234242
}
235243

244+
public func deactivateInput() {
245+
if let textFieldView = self.textField.view as? TextFieldComponent.View {
246+
textFieldView.deactivateInput()
247+
}
248+
}
249+
236250
public func insertText(text: NSAttributedString) {
237251
if let textFieldView = self.textField.view as? TextFieldComponent.View {
238252
textFieldView.insertText(text)

0 commit comments

Comments
 (0)