Various fixes

This commit is contained in:
Ilya Laktyushin 2022-06-06 16:57:25 +04:00
parent 9ad1b7bf86
commit dd20006e40
4 changed files with 43 additions and 3 deletions

View File

@ -127,6 +127,8 @@ public class ItemListMultilineInputItemNode: ListViewItemNode, ASEditableTextNod
return self.item?.tag
}
private var exceededLimit = false
public init() {
self.backgroundNode = ASDisplayNode()
self.backgroundNode.isLayerBacked = true
@ -197,6 +199,7 @@ public class ItemListMultilineInputItemNode: ListViewItemNode, ASEditableTextNod
var limitTextString: NSAttributedString?
var rightInset: CGFloat = params.rightInset
var exceededLimit = false
if let maxLength = item.maxLength, maxLength.display {
let textLength: Int
switch maxLength.mode {
@ -210,6 +213,7 @@ public class ItemListMultilineInputItemNode: ListViewItemNode, ASEditableTextNod
if displayTextLimit {
limitTextString = NSAttributedString(string: "\(remainingCount)", font: Font.regular(13.0), textColor: remainingCount < 0 ? item.presentationData.theme.list.itemDestructiveColor : item.presentationData.theme.list.itemSecondaryTextColor)
}
exceededLimit = remainingCount < 0
rightInset += 30.0 + 4.0
}
@ -254,6 +258,7 @@ public class ItemListMultilineInputItemNode: ListViewItemNode, ASEditableTextNod
if let strongSelf = self {
strongSelf.item = item
strongSelf.layoutParams = params
strongSelf.exceededLimit = exceededLimit
if let _ = updatedTheme {
strongSelf.topStripeNode.backgroundColor = itemSeparatorColor
@ -470,6 +475,12 @@ public class ItemListMultilineInputItemNode: ListViewItemNode, ASEditableTextNod
self.textNode.layer.addShakeAnimation()
}
public func animateErrorIfNeeded() {
if self.exceededLimit {
self.animateError()
}
}
@objc private func inlineActionPressed() {
if let action = self.item?.inlineAction?.action {
action()

View File

@ -286,7 +286,14 @@ public final class AccountContextImpl: AccountContext {
strongSelf.animatedEmojiStickers = stickers
})
self.userLimitsConfigurationDisposable = (self.engine.data.subscribe(TelegramEngine.EngineData.Item.Configuration.UserLimits(isPremium: false))
self.userLimitsConfigurationDisposable = (self.account.postbox.peerView(id: self.account.peerId)
|> mapToSignal { peerView -> Signal<EngineConfiguration.UserLimits, NoError> in
if let peer = peerView.peers[peerView.peerId] {
return self.engine.data.subscribe(TelegramEngine.EngineData.Item.Configuration.UserLimits(isPremium: peer.isPremium))
} else {
return .complete()
}
}
|> deliverOnMainQueue).start(next: { [weak self] value in
guard let strongSelf = self else {
return

View File

@ -219,6 +219,14 @@ private final class PeerInfoScreenItemSectionContainerNode: ASDisplayNode {
return contentHeight
}
func animateErrorIfNeeded() {
for (_, itemNode) in self.itemNodes {
if let itemNode = itemNode as? PeerInfoScreenMultilineInputItemNode {
itemNode.animateErrorIfNeeded()
}
}
}
}
final class PeerInfoSelectionPanelNode: ASDisplayNode {
@ -2636,7 +2644,6 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate
})
strongSelf.controller?.navigationItem.setLeftBarButton(UIBarButtonItem(title: strongSelf.presentationData.strings.Common_Cancel, style: .plain, target: strongSelf, action: #selector(strongSelf.editingCancelPressed)), animated: true)
case .done, .cancel:
(strongSelf.controller?.parent as? TabBarController)?.updateIsTabBarHidden(false, transition: .animated(duration: 0.3, curve: .linear))
strongSelf.view.endEditing(true)
if case .done = key {
guard let data = strongSelf.data else {
@ -2649,6 +2656,16 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate
let lastName = strongSelf.headerNode.editingContentNode.editingTextForKey(.lastName) ?? ""
let bio = strongSelf.state.updatingBio
if let bio = bio {
if Int32(bio.count) > strongSelf.context.userLimits.maxAboutLength {
for (_, section) in strongSelf.editingSections {
section.animateErrorIfNeeded()
}
strongSelf.hapticFeedback?.error()
return
}
}
if peer.firstName != firstName || peer.lastName != lastName || (bio != nil && bio != cachedData.about) {
var updateNameSignal: Signal<Void, NoError> = .complete()
var hasProgress = false
@ -2889,6 +2906,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate
}, completion: nil)
strongSelf.controller?.navigationItem.setLeftBarButton(nil, animated: true)
}
(strongSelf.controller?.parent as? TabBarController)?.updateIsTabBarHidden(false, transition: .animated(duration: 0.3, curve: .linear))
case .select:
strongSelf.state = strongSelf.state.withSelectedMessageIds(Set())
if let (layout, navigationHeight) = strongSelf.validLayout {

View File

@ -29,7 +29,7 @@ final class PeerInfoScreenMultilineInputItem: PeerInfoScreenItem {
}
}
private final class PeerInfoScreenMultilineInputItemNode: PeerInfoScreenItemNode {
final class PeerInfoScreenMultilineInputItemNode: PeerInfoScreenItemNode {
private let bottomSeparatorNode: ASDisplayNode
private let maskNode: ASImageNode
@ -118,4 +118,8 @@ private final class PeerInfoScreenMultilineInputItemNode: PeerInfoScreenItemNode
return height
}
func animateErrorIfNeeded() {
self.itemNode?.animateErrorIfNeeded()
}
}