Skip to content

Commit

Permalink
fix the keyboard in onboarding screens
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuatbrown committed Jan 31, 2025
1 parent 5d0ca91 commit af40ca3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
10 changes: 9 additions & 1 deletion Nos/Views/Onboarding/DisplayNameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ struct DisplayNameView: View {
@Environment(OnboardingState.self) private var state
@Environment(CurrentUser.self) private var currentUser
@Environment(\.managedObjectContext) private var viewContext
@FocusState private var isTextFieldFocused: Bool

@Dependency(\.crashReporting) private var crashReporting

Expand All @@ -16,7 +17,7 @@ struct DisplayNameView: View {
ZStack {
Color.appBg
.ignoresSafeArea()
ViewThatFits(in: .vertical) {
ViewThatFits {
displayNameStack

ScrollView {
Expand All @@ -25,6 +26,11 @@ struct DisplayNameView: View {
}
}
.navigationBarHidden(true)
.onAppear {
isTextFieldFocused = true
}
.ignoresSafeArea(.keyboard)
.interactiveDismissDisabled()
.alert("", isPresented: $showError) {
Button {
nextStep()
Expand Down Expand Up @@ -55,6 +61,7 @@ struct DisplayNameView: View {
.foregroundStyle(Color.primaryTxt)
.fontWeight(.bold)
.autocorrectionDisabled()
.focused($isTextFieldFocused)
.padding()
.withStyledBorder()
Spacer()
Expand All @@ -65,6 +72,7 @@ struct DisplayNameView: View {
}
.padding(40)
.readabilityPadding()
.frame(maxWidth: .infinity, maxHeight: .infinity)
}

func nextStep() {
Expand Down
18 changes: 13 additions & 5 deletions Nos/Views/Onboarding/UsernameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct UsernameView: View {
@Environment(OnboardingState.self) private var state
@Environment(CurrentUser.self) private var currentUser
@Environment(\.managedObjectContext) private var viewContext
@FocusState private var isTextFieldFocused: Bool

@Dependency(\.crashReporting) private var crashReporting
@Dependency(\.namesAPI) private var namesAPI
Expand Down Expand Up @@ -47,15 +48,20 @@ struct UsernameView: View {
ZStack {
Color.appBg
.ignoresSafeArea()
ViewThatFits(in: .vertical) {
displayNameStack

ViewThatFits {
usernameStack
ScrollView {
displayNameStack
usernameStack
}
}
}
.navigationBarHidden(true)
.onAppear {
isTextFieldFocused = true
}
.ignoresSafeArea(.keyboard)
.interactiveDismissDisabled()
.alert("", isPresented: showAlert) {
Button {
nextStep()
Expand All @@ -67,7 +73,7 @@ struct UsernameView: View {
}
}

var displayNameStack: some View {
var usernameStack: some View {
VStack(alignment: .leading, spacing: 20) {
LargeNumberView(4)
HStack(alignment: .firstTextBaseline) {
Expand All @@ -92,6 +98,7 @@ struct UsernameView: View {
.foregroundStyle(Color.primaryTxt)
.fontWeight(.bold)
.autocorrectionDisabled()
.focused($isTextFieldFocused)
.padding()
.withStyledBorder()

Expand All @@ -110,6 +117,7 @@ struct UsernameView: View {
}
.padding(40)
.readabilityPadding()
.frame(maxWidth: .infinity, maxHeight: .infinity)
}

var usernameAlreadyClaimedText: some View {
Expand Down

0 comments on commit af40ca3

Please sign in to comment.