Я изо всех сил пытаюсь не перемещать панель вкладок, когда появляется клавиатура.
Вот код моего основного экрана панели вкладок
var body: some View {
VStack(spacing: 0) {
pomeHeader
switch viewModel.selectedTab {
case .activities:
ActivityView()
case .emotions:
EmotionsView()
.ignoresSafeArea(.all)
case .journal:
JournalView()
case .insights:
InsightsView()
}
customTabBar
}
.onAppear {
dataService.startListening()
}
.onDisappear {
dataService.stopListening()
}
}
.ignoresSafeArea(.keyboard, Edges: .bottom) для панели вкладок не помогает
var body: some View {
ZStack(alignment: .bottom) {
mainContent
searchBar
}
}
вот мои эмоции, где панель поиска находится внизу
Моя панель вкладок находится внутри этого представления
struct MainView: View {
@StateObject private var routerService = AppRouterService.shared
var body: some View {
ZStack {
switch routerService.currentRoute {
case .onboarding:
OnboardingView()
case .userAuth:
UserAuthView()
case .questionire:
QuestionireView()
case .tabBar:
TabBarView()
}
}
.transition(.opacity)
.animation(.easeInOut(duration: 0.5), value: routerService.currentRoute)
}
}
Я пробовал разные решения (также наблюдатель за клавиатурой)
Но я просто хочу, чтобы моя панель вкладок всегда была внизу и поднимала поисковик над клавиатурой
private var searchBar: some View {
HStack {
emotionSearchBar
.opacity(viewModel.searchbarOpened ? 1 : 0)
.animation(.easeInOut(duration: 0.25), value: viewModel.searchbarOpened)
ZStack {
Circle()
.fill(Color.white)
.stroke(Color.borderLight, lineWidth: 2)
Image(.searchIcon)
.resizable()
.frame(width: 24, height: 24)
}
.frame(width: 40, height: 40)
.onTapGesture {
withAnimation(.easeInOut) {
viewModel.searchbarOpened.toggle()
}
searchFocused.toggle()
}
}
.padding([.horizontal, .bottom], 20)
.frame(height: 40)
}
private var emotionSearchBar: some View {
TextField("Enter your emotion", text: $viewModel.searchText)
.focused($searchFocused)
.padding()
.frame(height: 40)
.background {
RoundedRectangle(cornerRadius: 20)
.fill(Color.white)
.stroke(Color.borderLight, lineWidth: 2)
}
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... h-keyboard