-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement passing parameters to a view
- Implement `onInAppPurchaseCompletion` to handle the completion of a purchase. - Implement `inAppPurchaseOptions` to pass additional parameters for a purchase.
- Loading branch information
1 parent
4b4d141
commit d38ffbf
Showing
24 changed files
with
223 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
Sources/FlareUI/Classes/Core/EnvironmentKey/PurchaseCompletionKey.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// Flare | ||
// Copyright © 2024 Space Code. All rights reserved. | ||
// | ||
|
||
import Flare | ||
import SwiftUI | ||
|
||
// MARK: - PurchaseCompletionKey | ||
|
||
struct PurchaseCompletionKey: EnvironmentKey { | ||
static var defaultValue: ((StoreProduct, Result<Void, Error>) -> Void)? | ||
} | ||
|
||
extension EnvironmentValues { | ||
var purchaseCompletion: ((StoreProduct, Result<Void, Error>) -> Void)? { | ||
get { self[PurchaseCompletionKey.self] } | ||
set { self[PurchaseCompletionKey.self] = newValue } | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Sources/FlareUI/Classes/Core/EnvironmentKey/PurchaseOptionKey.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// Flare | ||
// Copyright © 2024 Space Code. All rights reserved. | ||
// | ||
|
||
import Flare | ||
import StoreKit | ||
import SwiftUI | ||
|
||
// MARK: - PurchaseOptionKey | ||
|
||
struct PurchaseOptionKey: EnvironmentKey { | ||
static var defaultValue: ((StoreProduct) -> PurchaseOptions)? | ||
} | ||
|
||
extension EnvironmentValues { | ||
var purchaseOptions: ((StoreProduct) -> PurchaseOptions)? { | ||
get { self[PurchaseOptionKey.self] } | ||
set { self[PurchaseOptionKey.self] = newValue } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// Flare | ||
// Copyright © 2024 Space Code. All rights reserved. | ||
// | ||
|
||
import StoreKit | ||
|
||
struct PurchaseOptions { | ||
// MARK: Properties | ||
|
||
private var _options: Any? | ||
|
||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, visionOS 1.0, *) | ||
var options: Set<Product.PurchaseOption>? { | ||
_options as? Set<Product.PurchaseOption> | ||
} | ||
|
||
// MARK: Initialization | ||
|
||
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, visionOS 1.0, *) | ||
init(options: Set<Product.PurchaseOption>) { | ||
self._options = options | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
Sources/FlareUI/Classes/Presentation/Components/Helpers/View+PurchaseCompletion.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// Flare | ||
// Copyright © 2024 Space Code. All rights reserved. | ||
// | ||
|
||
import Flare | ||
import SwiftUI | ||
|
||
public extension View { | ||
func onInAppPurchaseCompletion(completion: ((StoreProduct, Result<Void, Error>) -> Void)?) -> some View { | ||
environment(\.purchaseCompletion, completion) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Sources/FlareUI/Classes/Presentation/Components/Helpers/View+PurchaseOption.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// Flare | ||
// Copyright © 2024 Space Code. All rights reserved. | ||
// | ||
|
||
import Flare | ||
import StoreKit | ||
import SwiftUI | ||
|
||
public extension View { | ||
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) | ||
func inAppPurchaseOptions(_ options: ((StoreProduct) -> Set<Product.PurchaseOption>)?) -> some View { | ||
environment(\.purchaseOptions) { PurchaseOptions(options: options?($0) ?? []) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...s/FlareUI/Resources/Assets/Media.xcassets/Colors/system_background.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"color" : { | ||
"color-space" : "display-p3", | ||
"components" : { | ||
"alpha" : "1.000", | ||
"blue" : "255", | ||
"green" : "255", | ||
"red" : "255" | ||
} | ||
}, | ||
"idiom" : "universal" | ||
}, | ||
{ | ||
"appearances" : [ | ||
{ | ||
"appearance" : "luminosity", | ||
"value" : "dark" | ||
} | ||
], | ||
"color" : { | ||
"color-space" : "display-p3", | ||
"components" : { | ||
"alpha" : "1.000", | ||
"blue" : "0", | ||
"green" : "0", | ||
"red" : "0" | ||
} | ||
}, | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file modified
BIN
-1.1 KB
(98%)
...ts/__Snapshots__/ProductsViewSnapshotTests/test_productsView_products-iOS.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-81 Bytes
(100%)
.../__Snapshots__/ProductsViewSnapshotTests/test_productsView_products-macOS.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-118 Bytes
(100%)
...s/__Snapshots__/ProductsViewSnapshotTests/test_productsView_products-tvOS.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-1.27 KB
(98%)
...oductsViewSnapshotTests/test_productsView_products_withRestoreButtons-iOS.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-246 Bytes
(100%)
...uctsViewSnapshotTests/test_productsView_products_withRestoreButtons-macOS.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-24 Bytes
(100%)
...ductsViewSnapshotTests/test_productsView_products_withRestoreButtons-tvOS.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.