-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWelcomeScreenPresentOperation.swift
More file actions
53 lines (47 loc) · 1.85 KB
/
Copy pathWelcomeScreenPresentOperation.swift
File metadata and controls
53 lines (47 loc) · 1.85 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import UIKit
import RKWelcomeScreen
import RKOperations
/// Показывает привественный экран
final class WelcomeScreenPresentOperation: RKOperation, @unchecked Sendable {
private weak var controller: UIViewController?
private let model: RKWelcomeScreenViewController.Model
init(controller: UIViewController, model: RKWelcomeScreenViewController.Model) {
self.controller = controller
self.model = model
super.init()
}
override func execute() {
DispatchQueue.main.async { [weak self] in
self?.present()
}
}
}
// MARK: - Present
private extension WelcomeScreenPresentOperation {
func present() {
let buttonAction = self.model.button.action
let model = RKWelcomeScreenViewController.Model(
title: self.model.title,
items: self.model.items,
button: (self.model.button.title, { [weak self] in
guard let self = self else { return }
buttonAction()
self.controller?.presentedViewController?.dismiss(animated: true, completion: nil)
self.finish()
}),
appearance: self.model.appearance
)
let width = UIDevice.isIpad ? 375 : (controller?.view.frame.width ?? 375)
let welcome = RKWelcomeScreenViewController(model: model, width: width)
if UIDevice.isIpad {
welcome.modalPresentationStyle = .formSheet
welcome.isModalInPresentation = true
welcome.preferredContentSize = CGSize(
width: width,
height: min(min(UIScreen.main.bounds.width, UIScreen.main.bounds.height) * 0.9, 600))
} else {
welcome.modalPresentationStyle = .fullScreen
}
controller?.present(welcome, animated: true, completion: nil)
}
}