2023-01-15 15:39:08 +00:00
|
|
|
import Account
|
|
|
|
import AppAccount
|
2023-01-17 10:36:01 +00:00
|
|
|
import DesignSystem
|
|
|
|
import Env
|
|
|
|
import Network
|
|
|
|
import Status
|
|
|
|
import SwiftUI
|
|
|
|
import UIKit
|
2023-01-15 15:39:08 +00:00
|
|
|
|
|
|
|
class ShareViewController: UIViewController {
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-17 08:09:46 +00:00
|
|
|
let appAccountsManager = AppAccountsManager.shared
|
|
|
|
let client = appAccountsManager.currentClient
|
2023-01-17 06:39:13 +00:00
|
|
|
let account = CurrentAccount.shared
|
|
|
|
let instance = CurrentInstance.shared
|
2023-01-15 15:39:08 +00:00
|
|
|
account.setClient(client: client)
|
|
|
|
instance.setClient(client: client)
|
2023-01-15 16:05:22 +00:00
|
|
|
let colorScheme = traitCollection.userInterfaceStyle
|
2023-01-17 06:39:13 +00:00
|
|
|
let theme = Theme.shared
|
2023-01-15 16:05:22 +00:00
|
|
|
theme.setColor(withName: colorScheme == .dark ? .iceCubeDark : .iceCubeLight)
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-15 15:39:08 +00:00
|
|
|
if let item = extensionContext?.inputItems.first as? NSExtensionItem {
|
|
|
|
if let attachments = item.attachments {
|
|
|
|
let view = StatusEditorView(mode: .shareExtension(items: attachments))
|
2023-01-17 06:39:13 +00:00
|
|
|
.environmentObject(UserPreferences.shared)
|
2023-01-17 08:09:46 +00:00
|
|
|
.environmentObject(appAccountsManager)
|
2023-01-15 15:39:08 +00:00
|
|
|
.environmentObject(client)
|
|
|
|
.environmentObject(account)
|
|
|
|
.environmentObject(theme)
|
|
|
|
.environmentObject(instance)
|
|
|
|
.tint(theme.tintColor)
|
2023-01-15 16:05:22 +00:00
|
|
|
.preferredColorScheme(colorScheme == .light ? .light : .dark)
|
2023-01-15 15:39:08 +00:00
|
|
|
let childView = UIHostingController(rootView: view)
|
2023-01-17 10:36:01 +00:00
|
|
|
addChild(childView)
|
2023-01-19 17:33:22 +00:00
|
|
|
childView.view.frame = self.view.bounds
|
|
|
|
self.view.addSubview(childView.view)
|
2023-01-15 15:39:08 +00:00
|
|
|
childView.didMove(toParent: self)
|
2023-01-29 13:48:32 +00:00
|
|
|
|
|
|
|
childView.view.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
childView.view.topAnchor.constraint(equalTo: self.view.topAnchor),
|
|
|
|
childView.view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),
|
|
|
|
childView.view.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
|
|
|
|
childView.view.trailingAnchor.constraint(equalTo: self.view.trailingAnchor)
|
|
|
|
])
|
2023-01-15 15:39:08 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-15 15:39:08 +00:00
|
|
|
NotificationCenter.default.addObserver(forName: NotificationsName.shareSheetClose,
|
|
|
|
object: nil,
|
|
|
|
queue: nil) { _ in
|
2023-01-17 10:36:01 +00:00
|
|
|
self.close()
|
2023-01-15 15:39:08 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-15 15:39:08 +00:00
|
|
|
func close() {
|
|
|
|
extensionContext?.completeRequest(returningItems: [], completionHandler: nil)
|
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-15 15:39:08 +00:00
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
|
|
super.viewDidAppear(animated)
|
|
|
|
}
|
|
|
|
}
|