Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yusufonderd/75e5eab612620d950dbe072550babd54 to your computer and use it in GitHub Desktop.
Save yusufonderd/75e5eab612620d950dbe072550babd54 to your computer and use it in GitHub Desktop.
rating
.sheet(isPresented: self.$store.showRatingSheet, onDismiss: {
store.dismissRatingBottomSheet()
}) {
RatingSheet()
.interactiveDismissDisabled()
.modify { view in
if #available(iOS 16.0, *) {
view.presentationDetents([.large]) }
}
}
@Published var showRatingSheet: Bool = false
@Published var showRatingNotYetButton: Bool = AppUserDefaults.showRatingNotYetButton
func requestRating(force: Bool = false) {
// Early return if the rate strategy is not to be shown
guard AppUserDefaults.showRateStrategy else {
AppStoreReviewManager.writeReviewWithDelay()
return
}
// Show rating bottom sheet immediately if forced
if force {
showRatingBottomSheet()
return
}
// Check if the user has already rated the app
if AppUserDefaults.lastStarOfRatingSheet != nil {
debugPrint("requestRating: User has already reviewed the app.")
return
}
// Determine if the rating sheet was shown today
if let lastShowingDate = AppUserDefaults.lastShowingRatingSheet {
if lastShowingDate.isInToday {
debugPrint("requestRating: Rating sheet was already shown today: \(lastShowingDate)")
return
} else {
debugPrint("requestRating: Rating sheet was shown previously, but not today: \(lastShowingDate)")
}
} else {
debugPrint("requestRating: Rating sheet has not been shown before.")
}
// Show the rating bottom sheet
showRatingBottomSheet()
}
func dismissRatingBottomSheet(){
showRatingSheet = false
}
@UserDefault("lastShowingRatingSheet", defaultValue: nil)
static var lastShowingRatingSheet: Date?
@UserDefault("lastStarOfRatingSheet", defaultValue: nil)
static var lastStarOfRatingSheet: Int?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment