-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathPurchaseBrowserFeature.swift
More file actions
64 lines (50 loc) · 2.38 KB
/
PurchaseBrowserFeature.swift
File metadata and controls
64 lines (50 loc) · 2.38 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
54
55
56
57
58
59
60
61
62
63
//
// PurchaseBrowserFeature.swift
// FlintUI-iOS
//
// Created by Marc Palmer on 20/02/2019.
// Copyright © 2019 Montana Floss Co. Ltd. All rights reserved.
//
import Foundation
import FlintCore
/// Use to show a purchase browser UI that displays the current purchase status
/// of all purchases required by Features currently declared with Flint.
///
/// Perform the `show` action to present the browser from a `UIViewController` or
/// `UINavigationController`.
final public class PurchaseBrowserFeature: ConditionalFeature {
public static var description: String = "UI for browsing the status of Purchases"
public static func constraints(requirements: FeatureConstraintsBuilder) {
requirements.iOSOnly = .any
requirements.runtimeEnabled()
}
public static var isEnabled: Bool?
public static let show = action(ShowPurchaseBrowserAction.self)
public static let hide = action(HidePurchaseBrowserAction.self)
public static func prepare(actions: FeatureActionsBuilder) {
isEnabled = Flint.purchaseTracker != nil
actions.declare(show)
actions.declare(hide)
}
}
final public class ShowPurchaseBrowserAction: FlintCore.UIAction {
public typealias InputType = NoInput
public typealias PresenterType = UIViewController
public static var description: String = "Shows a UI for browsing the status of Purchases"
public static var hideFromTimeline: Bool = true
public static func perform(context: ActionContext<InputType>, presenter: PresenterType, completion: Completion) -> Completion.Status {
let purchaseStatusViewController = PurchaseBrowserViewController.instantiate()
if let navigationController = presenter as? UINavigationController {
context.logs.development?.debug("Presenting Purchase Status VC on navigation controller")
navigationController.pushViewController(purchaseStatusViewController, animated: true)
} else {
context.logs.development?.debug("Presenting Purchase Status VC modally")
presenter.present(purchaseStatusViewController, animated: true)
}
return completion.completedSync(.successWithFeatureTermination)
}
}
final public class HidePurchaseBrowserAction: DismissingUIAction {
public static var description: String = "Dismisses a Purchase browser"
public static var hideFromTimeline: Bool = true
}