-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PM-15377: Rolled back review prompt legacy api #1218
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import StoreKit | ||
import SwiftUI | ||
|
||
/// A view modifier that requests a review when the view appears. | ||
@available(iOS 16.0, *) | ||
struct ReviewModifier: ViewModifier { | ||
/// The environment key for the request review function. | ||
@Environment(\.requestReview) var requestReview | ||
|
||
/// The eligibility for requesting a review. | ||
let isEligible: Bool | ||
|
||
/// The closure to execute after requesting a review. | ||
let afterClosure: () -> Void | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
.task(id: isEligible) { | ||
if isEligible { | ||
requestReview() | ||
afterClosure() | ||
} | ||
Check warning on line 22 in BitwardenShared/UI/Platform/Application/Appearance/Modifiers/ReviewModifier.swift Codecov / codecov/patchBitwardenShared/UI/Platform/Application/Appearance/Modifiers/ReviewModifier.swift#L20-L22
|
||
} | ||
} | ||
} | ||
|
||
/// A view modifier that requests a review via legacy API when the view appears. | ||
struct RequestReviewLegacyModifier: ViewModifier { | ||
/// The eligibility for requesting a review. | ||
let isEligible: Bool | ||
|
||
/// The window scene to request a review. | ||
let windowScene: UIWindowScene | ||
|
||
/// The closure to execute after requesting a review. | ||
let afterClosure: () -> Void | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
.task(id: isEligible) { | ||
if isEligible { | ||
SKStoreReviewController.requestReview(in: windowScene) | ||
afterClosure() | ||
} | ||
} | ||
} | ||
Check warning on line 46 in BitwardenShared/UI/Platform/Application/Appearance/Modifiers/ReviewModifier.swift Codecov / codecov/patchBitwardenShared/UI/Platform/Application/Appearance/Modifiers/ReviewModifier.swift#L38-L46
|
||
} | ||
|
||
/// A view extension that requests a review when the view appears. | ||
extension View { | ||
func requestReview(windowScene: UIWindowScene?, isEligible: Bool, afterClosure: @escaping () -> Void) -> some View { | ||
apply { view in | ||
if #available(iOS 16.0, *) { | ||
view.modifier( | ||
ReviewModifier( | ||
isEligible: isEligible, | ||
afterClosure: afterClosure | ||
) | ||
) | ||
} else { | ||
if let windowScene { | ||
view.modifier( | ||
RequestReviewLegacyModifier( | ||
isEligible: isEligible, | ||
windowScene: windowScene, | ||
afterClosure: afterClosure | ||
) | ||
) | ||
} | ||
Check warning on line 69 in BitwardenShared/UI/Platform/Application/Appearance/Modifiers/ReviewModifier.swift Codecov / codecov/patchBitwardenShared/UI/Platform/Application/Appearance/Modifiers/ReviewModifier.swift#L61-L69
|
||
} | ||
} | ||
} | ||
} | ||
|
||
/// An error that represents a window scene error. | ||
public enum WindowSceneError: Error, Equatable { | ||
/// The window scene is null. | ||
case nullWindowScene | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๐ค As stated in the previous PR, SKStoreReviewController has been deprecated in iOS 18. Ezimet had some problems with this so and we've also tried using a
ViewModifier
with.apply()
+#available
to include or not the view modifier but Ezimet said it was throwing some compiler issues.@matt-livefront @KatherineInCode do you know any workaround for this so we can use the new environment approach for iOS 16+ and use the old approach for the older iOS version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it'd work but I've thought something like:
And applying it like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And another similar way:
Applying like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second approach worked perfectly.
Thanks @fedemkr