IceCubesApp/IceCubesShareExtension/ShareViewController.swift

80 lines
2.5 KiB
Swift
Raw Normal View History

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
2024-01-06 18:27:26 +00:00
import StatusKit
2023-01-17 10:36:01 +00:00
import SwiftUI
import UIKit
2024-01-07 11:52:45 +00:00
import Models
2023-01-15 15:39:08 +00:00
class ShareViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
2023-01-17 10:36:01 +00:00
let appAccountsManager = AppAccountsManager.shared
let client = appAccountsManager.currentClient
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-02-03 18:44:55 +00:00
Task {
await instance.fetchCurrentInstance()
}
let colorScheme = traitCollection.userInterfaceStyle
let theme = Theme.shared
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 {
2024-01-06 17:43:26 +00:00
let view = StatusEditor.MainView(mode: .shareExtension(items: attachments))
2023-09-19 07:18:20 +00:00
.environment(UserPreferences.shared)
.environment(appAccountsManager)
.environment(client)
.environment(account)
2023-09-18 19:03:52 +00:00
.environment(theme)
.environment(instance)
2024-01-07 11:52:45 +00:00
.modelContainer(for: [
Draft.self,
LocalTimeline.self,
TagGroup.self,
RecentTag.self,
])
2023-01-15 15:39:08 +00:00
.tint(theme.tintColor)
.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-30 06:27:06 +00:00
childView.view.translatesAutoresizingMaskIntoConstraints = false
2023-01-30 06:27:06 +00:00
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),
2023-01-30 06:27:06 +00:00
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-10-26 04:23:00 +00:00
NotificationCenter.default.addObserver(forName: .shareSheetClose,
2023-01-15 15:39:08 +00:00
object: nil,
2023-03-13 12:38:28 +00:00
queue: nil)
{ [weak self] _ in
self?.close()
2023-01-15 15:39:08 +00:00
}
}
2023-01-17 10:36:01 +00:00
nonisolated func close() {
Task { @MainActor in
extensionContext?.completeRequest(returningItems: [], completionHandler: nil)
}
2023-01-15 15:39:08 +00:00
}
2023-01-17 10:36:01 +00:00
2023-01-15 15:39:08 +00:00
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
}