Files
simplex-chat/apps/ios/Shared/Views/Badges/BadgesView.swift
T
Evgeny @ SimpleX Chat 53d7e8c6ca ui: what's new in v7.1, supporter badge links and benefits (#7982)
* android, desktop: what's new in v7.1, get a supporter badge, Flat layout

* android, desktop: what's new image opens Wefunder, sections get icons

* android, desktop: crowdfunding image without the stripe at its left edge

* android, desktop: Support SimpleX in settings, badge benefits shown

* android, desktop: more space under the what's new crowdfunding image

* ci: desktop references of v7.1 what's new and the settings badge row

* android, desktop: crowdfunding page without contact button, badge texts

* ci: desktop references of what's new with one rocket

* ui: what's new in v7.1, badge links and benefits, investor offer in store

* ui: localized crowdfunding texts on iOS, badge button kept in place

* ci: iOS references of v7.1 what's new, badge row and store screens

* ui: badge instead of the phone picture in what's new

* ui: what's new crowdfunding section without the investor count

* ui: what's new badges section without a picture

* ci: what's new references without the picture and investor count

* ui: investor offer on badge store screens in every country

* ui: shorter subscription terms and store notes on badge screens

* ios: subscription terms without the cancellation window

* ios: subscription terms worded as on Google Play

* ui: shorter badge errors and subscription notes

* ui: translations of the shorter badge texts; shorter purchases alert on iOS

* ui: shorter link, channel signing and badge texts, with translations

* ui: Your badge for every badge except legend in settings

* android, desktop: badge button at one height on the store screens; crowdfunding texts translatable

* android, desktop: smaller crowdfunding image

* android, desktop: what's new references with the smaller crowdfunding image
2026-11-01 23:33:11 +00:00

74 lines
2.6 KiB
Swift

//
// BadgesView.swift
// SimpleX (iOS)
//
// Created by spaced4ndy on 11.09.2026.
// Copyright © 2026 SimpleX Chat. All rights reserved.
//
import SwiftUI
import SimpleXChat
struct BadgesView: View {
@EnvironmentObject var chatModel: ChatModel
@ObservedObject private var badgeModel = BadgeModel.shared
@ObservedObject private var store = BadgeStore.shared
var showsAsSheet: Bool = false
private var shownBadge: BadgeState? {
currentShownBadge()
}
var body: some View {
Group {
if let badgeState = shownBadge {
BadgesYourBadgeView(badgeState: badgeState, showsAsSheet: showsAsSheet)
.transition(.opacity)
} else if let purchaseState = store.purchaseState(chatModel.currentUser?.userId) {
// holds the purchase screens' slot, so a consumable cannot be bought twice
BadgesPurchaseStateView(title: purchaseState.title, message: purchaseState.message, failure: store.creditError(chatModel.currentUser?.userId), showsAsSheet: showsAsSheet)
.transition(.opacity)
} else if store.checkingPurchases {
BadgesPurchaseStateView(title: "Checking your purchases", showsAsSheet: showsAsSheet)
.transition(.opacity)
} else {
BadgesSupportSimplexView(showsAsSheet: showsAsSheet)
.transition(.opacity)
}
}
.animation(.default, value: shownBadge != nil)
.animation(.default, value: store.purchaseState(chatModel.currentUser?.userId))
.animation(.default, value: store.checkingPurchases)
.onAppear { badgesViewShown = true }
.onDisappear { badgesViewShown = false }
}
}
private(set) var badgesViewShown = false
var supportSimpleXAlertAction: UIAlertAction {
UIAlertAction(title: NSLocalizedString("Support SimpleX", comment: "alert button"), style: .default) { _ in
openBadgesView()
}
}
func openBadgesView() {
showAppSheet {
NavigationView {
BadgesView(showsAsSheet: true)
.modifier(ThemedBackground())
}
}
}
func currentShownBadge() -> BadgeState? {
guard BadgeModel.shared.userId == ChatModel.shared.currentUser?.userId else { return nil }
if let badgeState = BadgeModel.shared.badgeState, badgeState.shown { return badgeState }
return nil
}
// false until the badge state is loaded for the current profile, so a supporter is never pitched to
func noShownBadge() -> Bool {
BadgeModel.shared.badgeState?.shown != true && BadgeModel.shared.userId == ChatModel.shared.currentUser?.userId
}