Update Ghostgram features

This commit is contained in:
ichmagmaus 812
2026-03-07 18:15:32 +01:00
parent 1a3303b059
commit 24a7ec39d9
902 changed files with 148302 additions and 62355 deletions
@@ -1,5 +1,11 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
sgDeps = [
"//Swiftgram/SGSimpleSettings:SGSimpleSettings",
"//Swiftgram/SGInputToolbar:SGInputToolbar"
]
swift_library(
name = "MessageInputPanelComponent",
module_name = "MessageInputPanelComponent",
@@ -9,7 +15,7 @@ swift_library(
copts = [
"-warnings-as-errors",
],
deps = [
deps = sgDeps + [
"//submodules/Display",
"//submodules/ComponentFlow",
"//submodules/AppBundle",
@@ -1,3 +1,8 @@
// MARK: Swiftgram
import class SwiftUI.UIHostingController
import SGSimpleSettings
import SGInputToolbar
import Foundation
import UIKit
import Display
@@ -603,6 +608,9 @@ public final class MessageInputPanelComponent: Component {
private let counter = ComponentView<Empty>()
private var header: ComponentView<Empty>?
// MARK: Swiftgram
private var toolbarView: UIView?
private var disabledPlaceholder: ComponentView<Empty>?
private var textClippingView = UIView()
private let textField = ComponentView<Empty>()
@@ -659,7 +667,7 @@ public final class MessageInputPanelComponent: Component {
return (self.likeButton.view as? MessageInputActionButtonComponent.View)?.likeIconView
}
override init(frame: CGRect) {
init(context: AccountContext, frame: CGRect) {
self.fieldBackgroundView = BlurredBackgroundView(color: nil, enableBlur: true)
self.fieldBackgroundTint = UIView()
self.fieldBackgroundTint.backgroundColor = UIColor(white: 1.0, alpha: 0.1)
@@ -706,6 +714,9 @@ public final class MessageInputPanelComponent: Component {
self.state?.updated()
}
)
// MARK: Swiftgram
self.initToolbarIfNeeded(context: context)
}
required init?(coder: NSCoder) {
@@ -914,6 +925,11 @@ public final class MessageInputPanelComponent: Component {
if result == nil, let contextQueryResultPanel = self.contextQueryResultPanel?.view, let panelResult = contextQueryResultPanel.hitTest(self.convert(point, to: contextQueryResultPanel), with: event), panelResult !== contextQueryResultPanel {
return panelResult
}
// MARK: Swiftgram
if result == nil, let toolbarView = self.toolbarView, let toolbarResult = toolbarView.hitTest(self.convert(point, to: toolbarView), with: event) {
return toolbarResult
}
return result
}
@@ -1508,7 +1524,7 @@ public final class MessageInputPanelComponent: Component {
self.fieldBackgroundTint.isHidden = true
}
if let fieldGlassBackgroundView = self.fieldGlassBackgroundView {
fieldGlassBackgroundView.update(size: fieldBackgroundFrame.size, cornerRadius: baseFieldHeight * 0.5, isDark: component.theme.overallDarkAppearance, tintColor: .init(kind: .panel, color: component.theme.chat.inputPanel.inputBackgroundColor.withMultipliedAlpha(0.7)), transition: transition)
fieldGlassBackgroundView.update(size: fieldBackgroundFrame.size, cornerRadius: baseFieldHeight * 0.5, isDark: component.theme.overallDarkAppearance, tintColor: .init(kind: .panel), transition: transition)
transition.setFrame(view: fieldGlassBackgroundView, frame: fieldBackgroundFrame)
}
case .videoChat:
@@ -2983,12 +2999,15 @@ public final class MessageInputPanelComponent: Component {
}
}
// MARK: Swiftgram
size = self.layoutToolbar(transition: transition, layoutFromTop: layoutFromTop, size: size, availableSize: availableSize, defaultInsets: defaultInsets, textFieldSize: textFieldSize, previousComponent: previousComponent)
return size
}
}
public func makeView() -> View {
return View(frame: CGRect())
return View(context: self.context, frame: CGRect())
}
public func update(view: View, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: ComponentTransition) -> CGSize {
@@ -3036,3 +3055,109 @@ final class ViewForOverlayContent: UIView {
return nil
}
}
extension MessageInputPanelComponent.View {
func initToolbarIfNeeded(context: AccountContext) {
guard #available(iOS 13.0, *) else { return }
guard SGSimpleSettings.shared.inputToolbar else { return }
guard context.sharedContext.immediateSGStatus.status > 1 else { return }
guard self.toolbarView == nil else { return }
let notificationName = Notification.Name("sgToolbarAction")
let toolbar = ChatToolbarView(
onQuote: { [weak self] in
guard let _ = self else { return }
NotificationCenter.default.post(name: notificationName, object: nil, userInfo: ["action": "quote"])
},
onSpoiler: { [weak self] in
guard let _ = self else { return }
NotificationCenter.default.post(name: notificationName, object: nil, userInfo: ["action": "spoiler"])
},
onBold: { [weak self] in
guard let _ = self else { return }
NotificationCenter.default.post(name: notificationName, object: nil, userInfo: ["action": "bold"])
},
onItalic: { [weak self] in
guard let _ = self else { return }
NotificationCenter.default.post(name: notificationName, object: nil, userInfo: ["action": "italic"])
},
onMonospace: { [weak self] in
guard let _ = self else { return }
NotificationCenter.default.post(name: notificationName, object: nil, userInfo: ["action": "monospace"])
},
onLink: { [weak self] in
guard let _ = self else { return }
NotificationCenter.default.post(name: notificationName, object: nil, userInfo: ["action": "link"])
},
onStrikethrough: { [weak self]
in guard let _ = self else { return }
NotificationCenter.default.post(name: notificationName, object: nil, userInfo: ["action": "strikethrough"])
},
onUnderline: { [weak self] in
guard let _ = self else { return }
NotificationCenter.default.post(name: notificationName, object: nil, userInfo: ["action": "underline"])
},
onCode: { [weak self] in
guard let _ = self else { return }
NotificationCenter.default.post(name: notificationName, object: nil, userInfo: ["action": "code"])
},
onNewLine: { [weak self] in
guard let _ = self else { return }
NotificationCenter.default.post(name: notificationName, object: nil, userInfo: ["action": "newline"])
},
// TODO(swiftgram): Binding
showNewLine: .constant(true), //.constant(self.sendWithReturnKey)
onClearFormatting: { [weak self] in
guard let _ = self else { return }
NotificationCenter.default.post(name: notificationName, object: nil, userInfo: ["action": "clearFormatting"])
}
).colorScheme(.dark)
let toolbarHostingController = UIHostingController(rootView: toolbar)
toolbarHostingController.view.backgroundColor = .clear
let toolbarView = toolbarHostingController.view
self.toolbarView = toolbarView
// assigning toolbarHostingController bugs responsivness and overrides layout
// self.toolbarHostingController = toolbarHostingController
// Disable "Swipe to go back" gesture when touching scrollview
self.interactiveTransitionGestureRecognizerTest = { [weak self] point in
if let self, let _ = self.toolbarView?.hitTest(point, with: nil) {
return false
}
return true
}
if let toolbarView = self.toolbarView {
self.addSubview(toolbarView)
}
}
func layoutToolbar(transition: ComponentTransition, layoutFromTop: Bool, size: CGSize, availableSize: CGSize, defaultInsets: UIEdgeInsets, textFieldSize: CGSize, previousComponent: MessageInputPanelComponent?) -> CGSize {
// TODO(swiftgram): Do not show if locked formatting
var transition = transition
if let previousComponent = previousComponent {
let previousLayoutFromTop = previousComponent.attachmentButtonMode == .captionDown
if previousLayoutFromTop != layoutFromTop {
// attachmentButtonMode changed
transition = .immediate
}
}
var size = size
if let toolbarView = self.toolbarView {
let toolbarHeight: CGFloat = 44.0
let toolbarSpacing: CGFloat = 1.0
let toolbarSize = CGSize(width: availableSize.width, height: toolbarHeight)
let hasFirstResponder = self.hasFirstResponder()
transition.setAlpha(view: toolbarView, alpha: hasFirstResponder ? 1.0 : 0.0)
if layoutFromTop {
transition.setFrame(view: toolbarView, frame: CGRect(origin: CGPoint(x: .zero, y: availableSize.height + toolbarSpacing), size: toolbarSize))
} else {
transition.setFrame(view: toolbarView, frame: CGRect(origin: CGPoint(x: .zero, y: textFieldSize.height + defaultInsets.top + toolbarSpacing), size: toolbarSize))
if hasFirstResponder {
size.height += toolbarHeight + toolbarSpacing
}
}
}
return size
}
}