基于 Lottie 在关键流程中新增全局 Loading 遮罩
引入带引用计数的 GlobalLoadingCenter,通过 RootView 及主要登录/订单/个人中心页面接入,并添加 Loading 动画资源与单元测试。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -15,6 +15,7 @@ struct RootView: View {
|
||||
@State private var scenicSpotContext = ScenicSpotContext()
|
||||
@State private var appRouter = AppRouter()
|
||||
@State private var toastCenter = ToastCenter()
|
||||
@State private var globalLoading = GlobalLoadingCenter()
|
||||
@State private var snapshotStore: AccountSnapshotStore
|
||||
@State private var apiClient: APIClient
|
||||
@State private var authAPI: AuthAPI
|
||||
@ -66,12 +67,14 @@ struct RootView: View {
|
||||
var body: some View {
|
||||
rootContent
|
||||
.globalToastOverlay()
|
||||
.globalLoadingOverlay(loadingCenter: globalLoading)
|
||||
.environment(appSession)
|
||||
.environment(accountContext)
|
||||
.environment(permissionContext)
|
||||
.environment(scenicSpotContext)
|
||||
.environment(appRouter)
|
||||
.environment(toastCenter)
|
||||
.environment(\.globalLoading, globalLoading)
|
||||
.environment(snapshotStore)
|
||||
.environment(apiClient)
|
||||
.environment(authAPI)
|
||||
@ -87,14 +90,16 @@ struct RootView: View {
|
||||
.environment(authSessionCoordinator)
|
||||
.task {
|
||||
apiClient.bindAuthTokenProvider { appSession.token }
|
||||
await sessionBootstrapper.restore(
|
||||
appSession: appSession,
|
||||
accountContext: accountContext,
|
||||
permissionContext: permissionContext,
|
||||
profileAPI: profileAPI,
|
||||
accountContextAPI: accountContextAPI,
|
||||
toastCenter: toastCenter
|
||||
)
|
||||
await globalLoading.withLoading {
|
||||
await sessionBootstrapper.restore(
|
||||
appSession: appSession,
|
||||
accountContext: accountContext,
|
||||
permissionContext: permissionContext,
|
||||
profileAPI: profileAPI,
|
||||
accountContextAPI: accountContextAPI,
|
||||
toastCenter: toastCenter
|
||||
)
|
||||
}
|
||||
}
|
||||
.task(id: scenicSpotTaskID) {
|
||||
guard appSession.isLoggedIn else {
|
||||
@ -122,9 +127,8 @@ struct RootView: View {
|
||||
case .loggedOut:
|
||||
LoginView()
|
||||
case .restoring:
|
||||
ProgressView()
|
||||
Color(.systemBackground)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.background(Color(.systemBackground))
|
||||
case .loggedIn:
|
||||
MainTabsView()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user