2021-12-27 22:33:27 +08:00
|
|
|
//
|
|
|
|
// LoginView.swift
|
|
|
|
// PushDeer
|
|
|
|
//
|
|
|
|
// Created by HEXT on 2021/12/25.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
import AuthenticationServices
|
|
|
|
|
|
|
|
/// 登录界面
|
|
|
|
struct LoginView: View {
|
2022-01-10 00:26:29 +08:00
|
|
|
|
|
|
|
@EnvironmentObject private var store: AppState
|
|
|
|
@State private var showLoading = false
|
|
|
|
|
2021-12-27 22:33:27 +08:00
|
|
|
var body: some View {
|
|
|
|
VStack{
|
|
|
|
Spacer()
|
|
|
|
Image("logo.with.space")
|
|
|
|
.resizable()
|
|
|
|
.scaledToFit()
|
|
|
|
Spacer()
|
2022-01-10 00:26:29 +08:00
|
|
|
if showLoading {
|
|
|
|
ProgressView()
|
|
|
|
.scaleEffect(1.5)
|
|
|
|
.frame(height: 64)
|
|
|
|
} else {
|
|
|
|
AppleSignInButton(
|
|
|
|
onRequest: { request in
|
|
|
|
request.requestedScopes = [.fullName, .email]
|
|
|
|
},
|
|
|
|
onCompletion: { result in
|
|
|
|
do {
|
|
|
|
showLoading = true
|
|
|
|
store.token = try await store.appleIdLogin(result).token
|
|
|
|
// 获取成功去主页
|
|
|
|
} catch {
|
|
|
|
showLoading = false
|
2022-01-04 22:28:18 +08:00
|
|
|
}
|
|
|
|
}
|
2022-01-10 00:26:29 +08:00
|
|
|
)
|
|
|
|
.frame(maxWidth: 375, minHeight: 64, maxHeight: 64)
|
|
|
|
.padding()
|
|
|
|
}
|
2021-12-27 22:33:27 +08:00
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
.padding()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct LoginView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
LoginView()
|
|
|
|
}
|
|
|
|
}
|