Код: Выделить всё
import SwiftUI
struct ContentView: View {
@State private var userCountry: String? = nil
@State private var isTrackingInProgress: Bool = false
var trackLocationButtonView: some View {
HStack(spacing: 20) {
Text("Track Location")
.font(.headline)
.foregroundStyle(Color.white)
if isTrackingInProgress {
ProgressView()
}
}
.compositingGroup()
.padding(EdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 16))
.background {
RoundedRectangle(cornerRadius: 8.0)
.fill(Color.blue.opacity(isTrackingInProgress ? 0.7: 1))
}
}
var body: some View {
VStack {
if let userCountry, !isTrackingInProgress {
Text("Current Location: \(userCountry)")
.font(.headline)
.foregroundColor(Color.blue)
.padding(.vertical, 150)
}
trackLocationButtonView
.onTapGesture {
print("Track Location button tapped")
print("Retrieving location")
isTrackingInProgress = true
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
userCountry = "XYZ"
isTrackingInProgress = false
}
}
}
.animation(.easeInOut, value: isTrackingInProgress)
}
}
#Preview {
ContentView()
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... not-synced