-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathShareViewController.swift
39 lines (32 loc) · 1.48 KB
/
ShareViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// ShareViewController.swift
// ReaderTranslatorShare
//
// Created by Viktor Kushnerov on 18/1/20.
// Copyright © 2020 Viktor Kushnerov. All rights reserved.
//
import Social
import SwiftUI
import UIKit
class ShareViewController: UIViewController {
override func viewDidLoad() {
guard let inputItems = self.extensionContext?.inputItems else { return }
guard let itemProvider = inputItems.first as? NSExtensionItem else { return }
guard let attachment = itemProvider.attachments?.first else { return }
let controller = UIHostingController(rootView: PreviewView())
self.addChild(controller)
controller.view.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(controller.view)
controller.didMove(toParent: self)
controller.view.leadingAnchor.constraint(equalTo: self.view.leadingAnchor).isActive = true
controller.view.trailingAnchor.constraint(equalTo: self.view.trailingAnchor).isActive = true
controller.view.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
controller.view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
attachment.loadItem(forTypeIdentifier: "public.plain-text", options: nil) { item, _ in
guard let sentence = item as? String else { return }
RunLoop.main.perform {
Store.shared.sentence = sentence
}
}
}
}