feat: 固定按钮
This commit is contained in:
parent
c069f0f205
commit
6bc0648fc7
@ -81,60 +81,64 @@ struct UserInfo: View {
|
|||||||
|
|
||||||
// 可滚动的内容区域
|
// 可滚动的内容区域
|
||||||
GeometryReader { geometry in
|
GeometryReader { geometry in
|
||||||
ScrollView {
|
ZStack(alignment: .bottom) {
|
||||||
VStack(spacing: 0) {
|
ScrollView {
|
||||||
// 顶部Spacer - 只在非键盘状态下生效
|
VStack(spacing: 0) {
|
||||||
if !isKeyboardVisible {
|
// 顶部Spacer - 只在非键盘状态下生效
|
||||||
Spacer(minLength: 0)
|
if !isKeyboardVisible {
|
||||||
.frame(height: geometry.size.height * 0.1) // 10% of available height
|
Spacer(minLength: 0)
|
||||||
}
|
.frame(height: geometry.size.height * 0.1) // 10% of available height
|
||||||
|
|
||||||
// Content VStack
|
|
||||||
VStack(spacing: 20) {
|
|
||||||
// Title
|
|
||||||
Text(showUsername ? "Add Your Avatar" : "What's Your Name?")
|
|
||||||
.font(Typography.font(for: .body, family: .quicksandBold))
|
|
||||||
.frame(maxWidth: .infinity, alignment: .center)
|
|
||||||
|
|
||||||
// Avatar
|
|
||||||
AvatarPicker(
|
|
||||||
selectedImage: $avatarImage,
|
|
||||||
showUsername: $showUsername,
|
|
||||||
isKeyboardVisible: $isKeyboardVisible,
|
|
||||||
uploadedFileId: $uploadedFileId
|
|
||||||
)
|
|
||||||
.padding(.top, isKeyboardVisible ? 0 : 20)
|
|
||||||
|
|
||||||
if showUsername {
|
|
||||||
TextField("Username", text: $userName)
|
|
||||||
.font(Typography.font(for: .subtitle, family: .inter))
|
|
||||||
.multilineTextAlignment(.center)
|
|
||||||
.frame(maxWidth: .infinity)
|
|
||||||
.padding()
|
|
||||||
.foregroundColor(.black)
|
|
||||||
.background(
|
|
||||||
RoundedRectangle(cornerRadius: 16)
|
|
||||||
.fill(Color.themePrimaryLight)
|
|
||||||
)
|
|
||||||
.focused($isTextFieldFocused)
|
|
||||||
.submitLabel(.done)
|
|
||||||
.onSubmit {
|
|
||||||
isTextFieldFocused = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Content VStack
|
||||||
|
VStack(spacing: 20) {
|
||||||
|
// Title
|
||||||
|
Text(showUsername ? "Add Your Avatar" : "What's Your Name?")
|
||||||
|
.font(Typography.font(for: .body, family: .quicksandBold))
|
||||||
|
.frame(maxWidth: .infinity, alignment: .center)
|
||||||
|
|
||||||
|
// Avatar
|
||||||
|
AvatarPicker(
|
||||||
|
selectedImage: $avatarImage,
|
||||||
|
showUsername: $showUsername,
|
||||||
|
isKeyboardVisible: $isKeyboardVisible,
|
||||||
|
uploadedFileId: $uploadedFileId
|
||||||
|
)
|
||||||
|
.padding(.top, isKeyboardVisible ? 0 : 20)
|
||||||
|
|
||||||
|
if showUsername {
|
||||||
|
TextField("Username", text: $userName)
|
||||||
|
.font(Typography.font(for: .subtitle, family: .inter))
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.padding()
|
||||||
|
.foregroundColor(.black)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: 16)
|
||||||
|
.fill(Color.themePrimaryLight)
|
||||||
|
)
|
||||||
|
.focused($isTextFieldFocused)
|
||||||
|
.submitLabel(.done)
|
||||||
|
.onSubmit {
|
||||||
|
isTextFieldFocused = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
.background(Color(.white))
|
||||||
|
.cornerRadius(20)
|
||||||
|
.padding(.horizontal)
|
||||||
|
|
||||||
|
// 添加底部间距,为固定按钮留出空间
|
||||||
|
Spacer(minLength: 40) // 按钮高度 + 底部间距
|
||||||
}
|
}
|
||||||
.padding()
|
.frame(minHeight: geometry.size.height) // 确保内容至少填满可用高度
|
||||||
.background(Color(.white))
|
.padding(.bottom, isKeyboardVisible ? 300 : 0) // 为键盘留出空间
|
||||||
.cornerRadius(20)
|
}
|
||||||
.padding(.horizontal)
|
|
||||||
|
// Fixed Button at bottom
|
||||||
// 底部Spacer - 只在非键盘状态下生效
|
VStack {
|
||||||
if !isKeyboardVisible {
|
Spacer()
|
||||||
Spacer(minLength: 0)
|
|
||||||
.frame(height: geometry.size.height * 0.1) // 10% of available height
|
|
||||||
}
|
|
||||||
|
|
||||||
// Continue Button
|
|
||||||
Button(action: {
|
Button(action: {
|
||||||
if showUsername {
|
if showUsername {
|
||||||
let parameters: [String: Any] = [
|
let parameters: [String: Any] = [
|
||||||
@ -150,11 +154,9 @@ struct UserInfo: View {
|
|||||||
switch result {
|
switch result {
|
||||||
case .success(let response):
|
case .success(let response):
|
||||||
print("✅ 用户信息更新成功")
|
print("✅ 用户信息更新成功")
|
||||||
// Update local state with the new user info
|
|
||||||
if let userData = response.data {
|
if let userData = response.data {
|
||||||
self.userName = userData.username
|
self.userName = userData.username
|
||||||
}
|
}
|
||||||
// Navigate using router
|
|
||||||
Router.shared.navigate(to: .blindBox(mediaType: .image))
|
Router.shared.navigate(to: .blindBox(mediaType: .image))
|
||||||
|
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
@ -181,18 +183,10 @@ struct UserInfo: View {
|
|||||||
.fill(Color.themePrimary)
|
.fill(Color.themePrimary)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.padding(.horizontal, 32) // 添加上下边距,与上方按钮保持一致
|
.padding(.horizontal, 32)
|
||||||
.padding(.bottom, isKeyboardVisible ? 20 : 40)
|
.padding(.bottom, isKeyboardVisible ? 20 : 40)
|
||||||
.animation(.easeInOut, value: showUsername)
|
.animation(.easeInOut, value: showUsername)
|
||||||
.frame(maxWidth: .infinity)
|
|
||||||
|
|
||||||
// 底部安全区域占位
|
|
||||||
if isKeyboardVisible {
|
|
||||||
Spacer(minLength: 0)
|
|
||||||
.frame(height: 20) // 添加一些底部间距当键盘显示时
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.frame(minHeight: geometry.size.height) // 确保内容至少填满可用高度
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.background(Color.themeTextWhiteSecondary)
|
.background(Color.themeTextWhiteSecondary)
|
||||||
|
|||||||
@ -46,7 +46,7 @@ struct WakeApp: App {
|
|||||||
if authState.isAuthenticated {
|
if authState.isAuthenticated {
|
||||||
// 已登录:显示主页面
|
// 已登录:显示主页面
|
||||||
NavigationStack(path: $router.path) {
|
NavigationStack(path: $router.path) {
|
||||||
BlindBoxView(mediaType: .all)
|
UserInfo()
|
||||||
.navigationDestination(for: AppRoute.self) { route in
|
.navigationDestination(for: AppRoute.self) { route in
|
||||||
route.view
|
route.view
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user