Skip to content

Commit

Permalink
Migrate PurchaseMarketing to module
Browse files Browse the repository at this point in the history
  • Loading branch information
Arclite committed May 13, 2024
1 parent ae6731d commit 66e4bd8
Show file tree
Hide file tree
Showing 33 changed files with 94 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Created by Geoff Pado on 5/13/24.
// Copyright © 2024 Cocoatype, LLC. All rights reserved.

import Combine
import SwiftUI

public extension View {
func onAppReceive<P>(_ publisher: P, perform action: @escaping (P.Output) -> Void) -> some View where P: Publisher, P.Failure == Never {
let isPreview: Bool
#if DEBUG
isPreview = ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"
#else
isPreview = false
#endif

if isPreview {
return self.onReceive(publisher, perform: { _ in })
} else {
return self.onReceive(publisher, perform: action)
}
}

func fill() -> some View {
return self.modifier(FillViewModifier())
}
}

struct FillViewModifier: ViewModifier {
func body(content: Content) -> some View {
AnyView(content).frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
}
}
15 changes: 15 additions & 0 deletions Modules/Capabilities/DesignSystem/Sources/ReadableWidthKey.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Created by Geoff Pado on 5/13/24.
// Copyright © 2024 Cocoatype, LLC. All rights reserved.

import SwiftUI

struct ReadableWidthKey: EnvironmentKey {
static let defaultValue = CGFloat.zero
}

public extension EnvironmentValues {
var readableWidth: CGFloat {
get { self[ReadableWidthKey.self] }
set { self[ReadableWidthKey.self] = newValue }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import SwiftUI
import UIKit

class PurchaseMarketingHostingController: UIHostingController<PurchaseMarketingView> {
init() {
public class PurchaseMarketingHostingController: UIHostingController<PurchaseMarketingView> {
public init() {
super.init(rootView: PurchaseMarketingView())
modalPresentationStyle = .formSheet
preferredContentSize = CGSize(width: 640, height: 640)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// Created by Geoff Pado on 5/18/21.
// Copyright © 2021 Cocoatype, LLC. All rights reserved.

import DesignSystem
import SwiftUI

struct PurchaseMarketingView: View {
public struct PurchaseMarketingView: View {
@Environment(\.horizontalSizeClass) var horizontalSizeClass

var body: some View {
public init() {}

public var body: some View {
GeometryReader { proxy in
VStack(spacing: 0) {
Color.primaryDark
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import StoreKit

enum ProductPriceFormatter {
static func formattedPrice(for product: SKProduct) -> String? {
public enum ProductPriceFormatter {
public static func formattedPrice(for product: SKProduct) -> String? {
if product.priceLocale != Self.priceFormatter.locale {
Self.priceFormatter.locale = product.priceLocale
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Created by Geoff Pado on 1/29/22.
// Copyright © 2022 Cocoatype, LLC. All rights reserved.

import DesignSystem
import SwiftUI

struct PurchaseMarketingTopBarSubheadline: View {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// blank
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
// Created by Geoff Pado on 4/24/24.
// Created by Geoff Pado on 5/13/24.
// Copyright © 2024 Cocoatype, LLC. All rights reserved.

import Purchasing
import SwiftUI

struct ReadableWidthKey: EnvironmentKey {
static let defaultValue = CGFloat.zero
}

struct PurchaseStatePublisherKey: EnvironmentKey {
static let defaultValue = PurchaseStatePublisher()
}

extension EnvironmentValues {
var readableWidth: CGFloat {
get { self[ReadableWidthKey.self] }
set { self[ReadableWidthKey.self] = newValue }
}

public extension EnvironmentValues {
var purchaseStatePublisher: PurchaseStatePublisher {
get { self[PurchaseStatePublisherKey.self] }
set { self[PurchaseStatePublisherKey.self] = newValue }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public struct UnpurchasedFeature {
public static func autoRedactions(learnMoreAction: LearnMoreAction? = nil) -> UnpurchasedFeature {
UnpurchasedFeature(
message: Strings.AutoRedactions.message,
learnMoreAction: nil,
learnMoreAction: learnMoreAction,
hideFeatureKey: .hideAutoRedactions
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import AppRatings
import Editing
import ErrorHandling
import Photos
import PurchaseMarketing
import Redactions
import UIKit
import VisionKit
Expand Down
25 changes: 0 additions & 25 deletions Modules/Legacy/Core/Sources/Extensions/ViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,11 @@ import Combine
import SwiftUI

extension View {
public func onAppReceive<P>(_ publisher: P, perform action: @escaping (P.Output) -> Void) -> some View where P: Publisher, P.Failure == Never {
let isPreview: Bool
#if DEBUG
isPreview = ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"
#else
isPreview = false
#endif

if isPreview {
return self.onReceive(publisher, perform: { _ in })
} else {
return self.onReceive(publisher, perform: action)
}
}

public func fill() -> some View {
return self.modifier(FillViewModifier())
}

public func continuousCornerRadius(_ radius: CGFloat) -> some View {
return self.modifier(ContinuousCornerRadiusViewModifier(radius))
}
}

struct FillViewModifier: ViewModifier {
func body(content: Content) -> some View {
AnyView(content).frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
}
}

struct ContinuousCornerRadiusViewModifier: ViewModifier {
private let radius: CGFloat
init(_ radius: CGFloat) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Created by Geoff Pado on 9/27/20.
// Copyright © 2020 Cocoatype, LLC. All rights reserved.

import PurchaseMarketing
import Purchasing
import SwiftUI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import AutoRedactionsUI
import Defaults
import PurchaseMarketing
import Purchasing
import SafariServices
import SwiftUI
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Created by Geoff Pado on 5/19/21.
// Copyright © 2021 Cocoatype, LLC. All rights reserved.

import PurchaseMarketing
import Purchasing
import StoreKit
import SwiftUI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import UIKit
import Unpurchased

class PhotoEditingAutoRedactionsAccessProvider: NSObject {
func autoRedactionsAccessViewController(learnMoreAction: UnpurchasedFeature.LearnMoreAction) -> UIViewController {
func autoRedactionsAccessViewController(learnMoreAction: @escaping UnpurchasedFeature.LearnMoreAction) -> UIViewController {
if purchased {
return AutoRedactionsAccessViewController()
} else {
return UnpurchasedAlertControllerFactory()
.alertController(for: .autoRedactions(learnMoreAction: nil))
.alertController(for: .autoRedactions(learnMoreAction: learnMoreAction))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import AutoRedactionsUI
import Defaults
import Observations
import Photos
import PurchaseMarketing
import Redactions
import UIKit

Expand Down Expand Up @@ -292,8 +293,7 @@ public class PhotoEditingViewController: UIViewController, UIScrollViewDelegate,
present(
PhotoEditingAutoRedactionsAccessProvider()
.autoRedactionsAccessViewController { [weak self] in
// TODO: present purchase marketing view
// self?.present(PurchaseMarketingHostingController(), animated: true)
self?.present(PurchaseMarketingHostingController(), animated: true)
},
animated: true)
}
Expand Down
14 changes: 13 additions & 1 deletion Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ let project = Project(
ErrorHandling.target,
Logging.target,
Observations.target,
PurchaseMarketing.target,
Purchasing.target,
Receipts.target,
Redacting.target,
Expand All @@ -58,6 +59,7 @@ let project = Project(
ErrorHandling.testTarget,
Logging.testTarget,
Observations.testTarget,
PurchaseMarketing.testTarget,
Purchasing.testTarget,
Redactions.testTarget,
Unpurchased.testTarget,
Expand All @@ -71,7 +73,17 @@ let project = Project(
testAction: .testPlans([
"Highlighter.xctestplan",
]),
runAction: .runAction()
runAction: .runAction(
arguments: .arguments(
environmentVariables: [
"OVERRIDE_PURCHASE": .environmentVariable(value: "", isEnabled: false),
"SHOW_DEBUG_OVERLAY": .environmentVariable(value: "", isEnabled: false),
],
launchArguments: [
.launchArgument(name: "-FeatureFlag.autoRedactInEdit YES", isEnabled: false),
]
)
)
),
]
)
1 change: 1 addition & 0 deletions Tuist/ProjectDescriptionHelpers/Targets/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum Core {
.target(Defaults.target),
.target(DesignSystem.target),
.target(Editing.target),
.target(PurchaseMarketing.target),
.target(Purchasing.target),
.target(Receipts.target),
.target(Unpurchased.target),
Expand Down
1 change: 1 addition & 0 deletions Tuist/ProjectDescriptionHelpers/Targets/Editing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum Editing {
.target(AutoRedactionsUI.target),
.target(ErrorHandling.target),
.target(Observations.target),
.target(PurchaseMarketing.target),
.target(Redactions.target),
.package(product: "ClippingBezier", type: .runtime),
.package(product: "Introspect", type: .runtime),
Expand Down
10 changes: 10 additions & 0 deletions Tuist/ProjectDescriptionHelpers/Targets/PurchaseMarketing.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ProjectDescription

public enum PurchaseMarketing {
public static let target = Target.capabilitiesTarget(name: "PurchaseMarketing", dependencies: [
.target(DesignSystem.target),
.target(Purchasing.target),
])

public static let testTarget = Target.capabilitiesTestTarget(name: "PurchaseMarketing")
}

0 comments on commit 66e4bd8

Please sign in to comment.