IceCubes/IceCubesShareExtension/ShareViewController.swift

60 lines
1.9 KiB
Swift
Raw Normal View History

2023-01-15 16:39:08 +01:00
import SwiftUI
import UIKit
import Status
import DesignSystem
import Account
import Network
import Env
import AppAccount
class ShareViewController: UIViewController {
@IBOutlet var container: UIView!
override func viewDidLoad() {
super.viewDidLoad()
let appAccountsManager = AppAccountsManager.shared
let client = appAccountsManager.currentClient
let account = CurrentAccount.shared
let instance = CurrentInstance.shared
2023-01-15 16:39:08 +01:00
account.setClient(client: client)
instance.setClient(client: client)
let colorScheme = traitCollection.userInterfaceStyle
let theme = Theme.shared
theme.setColor(withName: colorScheme == .dark ? .iceCubeDark : .iceCubeLight)
2023-01-15 16:39:08 +01:00
if let item = extensionContext?.inputItems.first as? NSExtensionItem {
if let attachments = item.attachments {
let view = StatusEditorView(mode: .shareExtension(items: attachments))
.environmentObject(UserPreferences.shared)
.environmentObject(appAccountsManager)
2023-01-15 16:39:08 +01:00
.environmentObject(client)
.environmentObject(account)
.environmentObject(theme)
.environmentObject(instance)
.tint(theme.tintColor)
.preferredColorScheme(colorScheme == .light ? .light : .dark)
2023-01-15 16:39:08 +01:00
let childView = UIHostingController(rootView: view)
self.addChild(childView)
childView.view.frame = self.container.bounds
self.container.addSubview(childView.view)
childView.didMove(toParent: self)
}
}
NotificationCenter.default.addObserver(forName: NotificationsName.shareSheetClose,
object: nil,
queue: nil) { _ in
self.close()
}
}
func close() {
extensionContext?.completeRequest(returningItems: [], completionHandler: nil)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
}