Adeel Yousaf
Adeel Yousaf

Reputation: 51

screenOptions:{{tabBarHideonKeyboard: true}} not Working

When I am using custom tab bar through tabBar function tabBarHideOnKeyboard does not work but without tabBar function it works fine, any ideas on how I can make it work using tabBar function as well.

Upvotes: 5

Views: 5290

Answers (5)

Free Palestine
Free Palestine

Reputation: 975

If you are not using a custom tab bar with v6 you can use

screenOptions={{
   tabBarHideOnKeyboard: true,
}}

But with a custom tab bar, you have to manage that yourself. The way I did it was to create a custom hook that tracks the keyboard's status and change the tabBarStyle according to that.

screenOptions={{
    tabBarStyle: { display: keyboardStatus ? 'none' : 'flex' },
  }}

where keyboardStatus is a hook that returns true or false using the useLayoutEffect hook from react and the Keyboard.addListener() from react-native.

Upvotes: 2

ExDet
ExDet

Reputation: 168

I was using my customTab as well. And after huge amount of search, solved the problem with the help of Keyboard event listeners.

This is the best solution, I've found so far.

Here's my solution:

import { useEffect, useState } from "react";
import { Keyboard, Text, TouchableOpacity, View } from "react-native"

export default function TabBar({ state, descriptors, navigation }) {
    // As default it should be visible
    const [visible, setVisible] = useState(true);

    useEffect(() => {
        const showSubscription = Keyboard.addListener("keyboardDidShow", () => {
            //Whenever keyboard did show make it don't visible
            setVisible(false);
        });
        const hideSubscription = Keyboard.addListener("keyboardDidHide", () => {
            setVisible(true);
        });

        return () => {
            showSubscription.remove();
            hideSubscription.remove();
        };
    }, []);

   //Return your whole container like so
   return visible && (
         <View>
             ...
         </View>
         )

tabBarHideOnKeyboard or keyboardHidesTabBar options didn't work for me.

Upvotes: 1

Zacquio
Zacquio

Reputation: 347

<Tab.Navigator
  tabBarOptions={{
    showLabel: false,
    keyboardHidesTabBar: true, // use this props to hide bottom tabs when keyboard shown
  }}

the docs says to use tabBarHideOnKeyboard, but not working at all. then i found keyboardHidesTabBar and works like a charm

Upvotes: 2

localhost_3000
localhost_3000

Reputation: 194

Add "softwareKeyboardLayoutMode": "pan" in app.json file under "android" key and then restart your expo server with expo start -c

Upvotes: 3

jted95
jted95

Reputation: 1144

You'll get the tabBarHideOnKeyboard from the props for the custom tabBar.

tabBar={(props) => {
  return (
    <View>
      {props.state.routes.map((route, index) => {
        // You can replace Pressable and View with anything you like
        return (
          props.descriptors[route.key].options.tabBarHideOnKeyboard && (
            <Pressable>
              <View
                style={{
                  width: 200,
                  height: 200,
                  backgroundColor: "green",
                }}
              />
            </Pressable>
          )
        );
      })}
    </View>
  );

You can read more here

Upvotes: 0

Related Questions