Martin
Martin

Reputation: 12215

SwiftUI disable keyboard avoidance for custom tabbar control

I made a custom tabbar because the system one is not customizable in pure swiftUI.

The custom tab view looks like this:

struct MainTabView: View {  
    var body: some View {
        VStack(spacing: 0) {
            switch router.currentTab {
            case .tab1:
                Tab1View()
            case .tab2:
                Tab2View()
            ...
            }
            Spacer()
            HStack(spacing: 0) {
                TabBarIconView(viewRouter: viewRouter, ...)
                TabBarIconView(viewRouter: viewRouter, ...)
                TabBarIconView(viewRouter: viewRouter, ...)
                TabBarIconView(viewRouter: viewRouter, ...)
                TabBarIconView(viewRouter: viewRouter, ...)
            }
          //.ignoresSafeArea(.keyboard) // second try
        }
    }
    //.ignoresSafeArea(.keyboard) // first try
}

When I use a textfied in one of the TabXViews, the bottom HStack stays above the keyboard.

A solution I found is to disable keyboard avoidance for the tabbar. I made this by uncommenting the above line .ignoresSafeArea(.keyboard) (first try)

But of course, this apply globaly, for each subview => If I declare a scrollview, the bottom won't be accessible when keyboard is open.

I tryed to set the .ignoresSafeArea(.keyboard) under the above HStack (second try), but this doesn't do anything (HStack stays above the keyboard)

Is there a solution to opt-in keyboard avoidance again in subviews?

Upvotes: 3

Views: 367

Answers (0)

Related Questions