From 01378dcb7eb412a0a6855376e63a8831aa1b6419 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 27 Jan 2023 14:54:40 +0400 Subject: [PATCH] Various fixes --- ...SendMessageActionSheetControllerNode.swift | 11 +++++-- .../Navigation/NavigationModalContainer.swift | 5 +++- .../Sources/AvatarEditorScreen.swift | 30 ++++++++++++++----- .../Sources/ColorPickerComponent.swift | 8 ++++- .../Sources/ChatControllerNode.swift | 4 +-- .../ChatReportPeerTitlePanelNode.swift | 14 +++++---- .../Sources/EditableTokenListNode.swift | 5 ++-- 7 files changed, 55 insertions(+), 22 deletions(-) diff --git a/submodules/ChatSendMessageActionUI/Sources/ChatSendMessageActionSheetControllerNode.swift b/submodules/ChatSendMessageActionUI/Sources/ChatSendMessageActionSheetControllerNode.swift index e12f9abe9a..e90286ade0 100644 --- a/submodules/ChatSendMessageActionUI/Sources/ChatSendMessageActionSheetControllerNode.swift +++ b/submodules/ChatSendMessageActionUI/Sources/ChatSendMessageActionSheetControllerNode.swift @@ -663,7 +663,7 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode, contentSize.width = min(layout.size.width - 40.0, 250.0) var applyNodes: [(ASDisplayNode, CGFloat, (CGFloat) -> Void)] = [] for itemNode in self.contentNodes { - let (width, height, apply) = itemNode.updateLayout(maxWidth: layout.size.width - sideInset * 2.0) + let (width, height, apply) = itemNode.updateLayout(maxWidth: layout.size.width - 16.0 * 2.0) applyNodes.append((itemNode, height, apply)) contentSize.width = max(contentSize.width, width) contentSize.height += height @@ -679,8 +679,14 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode, } let contentOffset = self.scrollNode.view.contentOffset.y + let initialSendButtonFrame = self.sendButtonFrame - var contentOrigin = CGPoint(x: layout.size.width - sideInset - contentSize.width - layout.safeInsets.right, y: layout.size.height - 6.0 - insets.bottom - contentSize.height) + var contentOrigin: CGPoint + if initialSendButtonFrame.width > initialSendButtonFrame.height * 1.2 { + contentOrigin = CGPoint(x: layout.size.width - contentSize.width - layout.safeInsets.right - 5.0, y: initialSendButtonFrame.minY - contentSize.height) + } else { + contentOrigin = CGPoint(x: layout.size.width - sideInset - contentSize.width - layout.safeInsets.right, y: layout.size.height - 6.0 - insets.bottom - contentSize.height) + } if inputHeight > 0.0 && !layout.isNonExclusive && self.animateInputField { contentOrigin.y += menuHeightWithInset } @@ -694,7 +700,6 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode, nextY += height } - let initialSendButtonFrame = self.sendButtonFrame var sendButtonFrame = CGRect(origin: CGPoint(x: layout.size.width - initialSendButtonFrame.width + 1.0 - UIScreenPixel - layout.safeInsets.right, y: layout.size.height - insets.bottom - initialSendButtonFrame.height), size: initialSendButtonFrame.size) if (inputHeight.isZero || layout.isNonExclusive) && self.animateInputField { sendButtonFrame.origin.y -= menuHeightWithInset diff --git a/submodules/Display/Source/Navigation/NavigationModalContainer.swift b/submodules/Display/Source/Navigation/NavigationModalContainer.swift index 42354f8ec4..0c2ec4473c 100644 --- a/submodules/Display/Source/Navigation/NavigationModalContainer.swift +++ b/submodules/Display/Source/Navigation/NavigationModalContainer.swift @@ -429,7 +429,10 @@ final class NavigationModalContainer: ASDisplayNode, UIScrollViewDelegate, UIGes let maxSide = max(layout.size.width, layout.size.height) let minSide = min(layout.size.width, layout.size.height) - let containerSize = CGSize(width: min(layout.size.width - 20.0, floor(maxSide / 2.0)), height: min(layout.size.height, minSide) - verticalInset * 2.0) + var containerSize = CGSize(width: min(layout.size.width - 20.0, floor(maxSide / 2.0)), height: min(layout.size.height, minSide) - verticalInset * 2.0) + if let preferredSize = controllers.last?.preferredContentSizeForLayout(layout) { + containerSize = preferredSize + } containerFrame = CGRect(origin: CGPoint(x: floor((layout.size.width - containerSize.width) / 2.0), y: floor((layout.size.height - containerSize.height) / 2.0)), size: containerSize) containerScale = 1.0 diff --git a/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/AvatarEditorScreen.swift b/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/AvatarEditorScreen.swift index dfb972e806..00bec289d1 100644 --- a/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/AvatarEditorScreen.swift +++ b/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/AvatarEditorScreen.swift @@ -652,9 +652,12 @@ final class AvatarEditorScreenComponent: Component { updateScrollingToItemGroup: { }, onScroll: { [weak self] in - if let self, let state = self.state, state.expanded { - state.expanded = false - state.updated(transition: Transition(animation: .curve(duration: 0.45, curve: .spring))) + if let self { + self.endEditing(true) + if let state = self.state, state.expanded { + state.expanded = false + state.updated(transition: Transition(animation: .curve(duration: 0.45, curve: .spring))) + } } }, chatPeerId: nil, @@ -776,9 +779,12 @@ final class AvatarEditorScreenComponent: Component { updateScrollingToItemGroup: { }, onScroll: { [weak self] in - if let self, let state = self.state, state.expanded { - state.expanded = false - state.updated(transition: Transition(animation: .curve(duration: 0.45, curve: .spring))) + if let self { + self.endEditing(true) + if let state = self.state, state.expanded { + state.expanded = false + state.updated(transition: Transition(animation: .curve(duration: 0.45, curve: .spring))) + } } }, chatPeerId: nil, @@ -1033,6 +1039,11 @@ final class AvatarEditorScreenComponent: Component { transition.setAlpha(view: backgroundView, alpha: state.editingColor ? 0.0 : 1.0) } + var colorPickerBottomInset: CGFloat = 0.0 + if environment.deviceMetrics.type != .tablet { + colorPickerBottomInset = environment.safeInsets.bottom + } + let colorPickerSize = self.colorPickerView.update( transition: transition, component: AnyComponent( @@ -1040,6 +1051,7 @@ final class AvatarEditorScreenComponent: Component { theme: environment.theme, strings: environment.strings, isVisible: state.editingColor, + bottomInset: colorPickerBottomInset, colors: state.selectedBackground.colors, colorsChanged: { [weak state] colors in if let state { @@ -1066,7 +1078,7 @@ final class AvatarEditorScreenComponent: Component { ) ), environment: {}, - containerSize: CGSize(width: availableSize.width - sideInset * 2.0, height: .greatestFiniteMagnitude) + containerSize: CGSize(width: availableSize.width - sideInset * 2.0, height: availableSize.height) ) let colorPickerFrame = CGRect(origin: .zero, size: colorPickerSize) if let colorPickerView = self.colorPickerView.view { @@ -1535,4 +1547,8 @@ public final class AvatarEditorScreen: ViewControllerComponentContainer { override public func viewDidLoad() { super.viewDidLoad() } + + public override func preferredContentSizeForLayout(_ layout: ContainerViewLayout) -> CGSize? { + return CGSize(width: 390.0, height: 730.0) + } } diff --git a/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/ColorPickerComponent.swift b/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/ColorPickerComponent.swift index 0d61a2f55b..73de5e8819 100644 --- a/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/ColorPickerComponent.swift +++ b/submodules/TelegramUI/Components/AvatarEditorScreen/Sources/ColorPickerComponent.swift @@ -21,6 +21,7 @@ final class ColorPickerComponent: Component { let theme: PresentationTheme let strings: PresentationStrings let isVisible: Bool + let bottomInset: CGFloat let colors: [UInt32] let colorsChanged: ([UInt32]) -> Void let cancel: () -> Void @@ -30,6 +31,7 @@ final class ColorPickerComponent: Component { theme: PresentationTheme, strings: PresentationStrings, isVisible: Bool, + bottomInset: CGFloat, colors: [UInt32], colorsChanged: @escaping ([UInt32]) -> Void, cancel: @escaping () -> Void, @@ -38,6 +40,7 @@ final class ColorPickerComponent: Component { self.theme = theme self.strings = strings self.isVisible = isVisible + self.bottomInset = bottomInset self.colors = colors self.colorsChanged = colorsChanged self.cancel = cancel @@ -54,6 +57,9 @@ final class ColorPickerComponent: Component { if lhs.isVisible != rhs.isVisible { return false } + if lhs.bottomInset != rhs.bottomInset { + return false + } if lhs.colors != rhs.colors { return false } @@ -395,7 +401,7 @@ final class ColorPickerComponent: Component { self.component = component let buttonHeight: CGFloat = 44.0 - let size = CGSize(width: availableSize.width, height: 264.0) + let size = CGSize(width: availableSize.width, height: availableSize.height - availableSize.width - 32.0 - buttonHeight - 56.0 - component.bottomInset) let panelSize = CGSize(width: availableSize.width, height: size.height + buttonHeight) if themeChanged { diff --git a/submodules/TelegramUI/Sources/ChatControllerNode.swift b/submodules/TelegramUI/Sources/ChatControllerNode.swift index eddab96fbc..8c0a70d353 100644 --- a/submodules/TelegramUI/Sources/ChatControllerNode.swift +++ b/submodules/TelegramUI/Sources/ChatControllerNode.swift @@ -1098,7 +1098,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { var translationPanelHeight: CGFloat? var hasTranslationPanel = false - if let _ = self.chatPresentationInterfaceState.translationState { + if let _ = self.chatPresentationInterfaceState.translationState, self.emptyType == nil { if case .overlay = self.chatPresentationInterfaceState.mode { } else if self.chatPresentationInterfaceState.renderedPeer?.peer?.restrictionText(platform: "ios", contentSettings: self.context.currentContentSettings.with { $0 }) != nil { } else if self.chatPresentationInterfaceState.search != nil { @@ -1452,7 +1452,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { let _ = inputMediaNode.updateLayout(width: layout.size.width, leftInset: layout.safeInsets.left, rightInset: layout.safeInsets.right, bottomInset: cleanInsets.bottom, standardInputHeight: layout.standardInputHeight, inputHeight: layout.inputHeight ?? 0.0, maximumHeight: maximumInputNodeHeight, inputPanelHeight: inputPanelSize?.height ?? 0.0, transition: .immediate, interfaceState: self.chatPresentationInterfaceState, deviceMetrics: layout.deviceMetrics, isVisible: false, isExpanded: self.inputPanelContainerNode.stableIsExpanded) } - transition.updateFrame(node: self.titleAccessoryPanelContainer, frame: CGRect(origin: CGPoint(x: 0.0, y: insets.top), size: CGSize(width: layout.size.width, height: 100.0))) + transition.updateFrame(node: self.titleAccessoryPanelContainer, frame: CGRect(origin: CGPoint(x: 0.0, y: insets.top), size: CGSize(width: layout.size.width, height: 116.0))) transition.updateFrame(node: self.inputContextPanelContainer, frame: CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: CGSize(width: layout.size.width, height: layout.size.height))) transition.updateFrame(node: self.inputContextOverTextPanelContainer, frame: CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: CGSize(width: layout.size.width, height: layout.size.height))) diff --git a/submodules/TelegramUI/Sources/ChatReportPeerTitlePanelNode.swift b/submodules/TelegramUI/Sources/ChatReportPeerTitlePanelNode.swift index d9d2d80352..89b0544ab0 100644 --- a/submodules/TelegramUI/Sources/ChatReportPeerTitlePanelNode.swift +++ b/submodules/TelegramUI/Sources/ChatReportPeerTitlePanelNode.swift @@ -403,7 +403,7 @@ final class ChatReportPeerTitlePanelNode: ChatTitleAccessoryPanelNode { } else { updatedButtons = [] } - + var buttonsUpdated = false if self.buttons.count != updatedButtons.count { buttonsUpdated = true @@ -594,6 +594,11 @@ final class ChatReportPeerTitlePanelNode: ChatTitleAccessoryPanelNode { let initialPanelHeight = panelHeight transition.updateFrame(node: self.separatorNode, frame: CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: CGSize(width: width, height: UIScreenPixel))) + var panelInset: CGFloat = 0.0 + if let _ = interfaceState.translationState { + panelInset += 40.0 + } + var chatPeer: Peer? if let renderedPeer = interfaceState.renderedPeer { chatPeer = renderedPeer.peers[renderedPeer.peerId] @@ -616,7 +621,7 @@ final class ChatReportPeerTitlePanelNode: ChatTitleAccessoryPanelNode { if let inviteInfoNode = self.inviteInfoNode { let inviteHeight = inviteInfoNode.update(width: width, theme: interfaceState.theme, strings: interfaceState.strings, wallpaper: interfaceState.chatWallpaper, chatPeer: chatPeer, invitedBy: invitedBy, transition: inviteInfoTransition) - inviteInfoTransition.updateFrame(node: inviteInfoNode, frame: CGRect(origin: CGPoint(x: 0.0, y: panelHeight), size: CGSize(width: width, height: inviteHeight))) + inviteInfoTransition.updateFrame(node: inviteInfoNode, frame: CGRect(origin: CGPoint(x: 0.0, y: panelHeight + panelInset), size: CGSize(width: width, height: inviteHeight))) panelHeight += inviteHeight } } else if let inviteInfoNode = self.inviteInfoNode { @@ -644,7 +649,7 @@ final class ChatReportPeerTitlePanelNode: ChatTitleAccessoryPanelNode { if let peerNearbyInfoNode = self.peerNearbyInfoNode { let peerNearbyHeight = peerNearbyInfoNode.update(width: width, theme: interfaceState.theme, strings: interfaceState.strings, wallpaper: interfaceState.chatWallpaper, chatPeer: chatPeer, distance: distance, transition: peerNearbyInfoTransition) - peerNearbyInfoTransition.updateFrame(node: peerNearbyInfoNode, frame: CGRect(origin: CGPoint(x: 0.0, y: panelHeight), size: CGSize(width: width, height: peerNearbyHeight))) + peerNearbyInfoTransition.updateFrame(node: peerNearbyInfoNode, frame: CGRect(origin: CGPoint(x: 0.0, y: panelHeight + panelInset), size: CGSize(width: width, height: peerNearbyHeight))) panelHeight += peerNearbyHeight } } else if let peerNearbyInfoNode = self.peerNearbyInfoNode { @@ -653,8 +658,7 @@ final class ChatReportPeerTitlePanelNode: ChatTitleAccessoryPanelNode { peerNearbyInfoNode?.removeFromSupernode() }) } - - return LayoutResult(backgroundHeight: initialPanelHeight, insetHeight: panelHeight) + return LayoutResult(backgroundHeight: initialPanelHeight, insetHeight: panelHeight + panelInset) } @objc func buttonPressed(_ view: UIButton) { diff --git a/submodules/TelegramUI/Sources/EditableTokenListNode.swift b/submodules/TelegramUI/Sources/EditableTokenListNode.swift index 6f72701385..dd74061201 100644 --- a/submodules/TelegramUI/Sources/EditableTokenListNode.swift +++ b/submodules/TelegramUI/Sources/EditableTokenListNode.swift @@ -418,12 +418,11 @@ final class EditableTokenListNode: ASDisplayNode, UITextFieldDelegate { } } - if width - currentOffset.x < 90.0 { + let placeholderSize = self.placeholderNode.measure(CGSize(width: max(1.0, width - sideInset - sideInset), height: CGFloat.greatestFiniteMagnitude)) + if width - currentOffset.x < placeholderSize.width { currentOffset.y += 28.0 currentOffset.x = sideInset } - - let placeholderSize = self.placeholderNode.measure(CGSize(width: max(1.0, width - sideInset - sideInset), height: CGFloat.greatestFiniteMagnitude)) transition.updateFrame(node: self.placeholderNode, frame: CGRect(origin: CGPoint(x: currentOffset.x + 4.0, y: currentOffset.y + floor((28.0 - placeholderSize.height) / 2.0)), size: placeholderSize)) let textNodeFrame = CGRect(origin: CGPoint(x: currentOffset.x + 4.0, y: currentOffset.y + UIScreenPixel), size: CGSize(width: width - currentOffset.x - sideInset - 8.0, height: 28.0))