r/reactnative • Android • Sep 20 '20

Programmatically Hide Bottom tab when keyboard open.

Post image
198 Upvotes

32 comments sorted by

129

u/frankielyonshaha Sep 20 '20

Why not use:

  <BottomTab.Navigator
    tabBarOptions={{
      keyboardHidesTabBar: true,
    }}
  >

6

u/[deleted] Sep 20 '20

I was like, I use this option always with tabBarOptions prop. Why the code is so long? Maybe question is different.

1

u/archcorsair Sep 21 '20

I think the example still applies when you implement your own tab bar, where you don't have access to these properties.

1

u/VivekNeel55 Sep 21 '20

The real MVP

-7

u/Hotgeart Sep 20 '20

We don't all use react navigation...

12

u/I_know_HTML Sep 20 '20

This code implies react navigation doesn't it? navigation.setOptions right in the code

1

u/JackSparrah Sep 20 '20

Username checks out! :D

1

u/Hotgeart Sep 21 '20

Yes my bad read it too fast

0

u/[deleted] Sep 20 '20

[deleted]

1

u/Hotgeart Sep 21 '20

I find it too much complex when you want the drawer and bottomNav everywhere. But not display a link in it. So you've to rely on hacky solution.

Example:

BottomNav :

  • Profil

  • Message

  • Notification

Drawer :

  • Home

  • Forum

  • Settings

If I want the bottomNav and Drawer everywhere I would have to add homestack, forum and settings in the bottomnav but hide them.

4

u/andordavoti Sep 20 '20

nice, I've done something similar in the past, but I added an if check to only do this for android, since the iOS keyboard acts as an overlay and doesn't push the tabbar up

4

u/Veranova Sep 20 '20

You can change that behaviour in the android manifest, there are a few behaviours available.

I haven’t done it in a while but I think it’s this: https://developer.android.com/training/keyboard-input/visibility

3

u/andordavoti Sep 20 '20

yeah I know, but that isn't available for expo users:))

3

u/Veranova Sep 20 '20

Oh that makes sense!

3

u/[deleted] Sep 20 '20

Yeah which color scheme is that?

3

u/[deleted] Sep 20 '20

You should use will show and will hide on iOS, makes it much smoother

6

u/KajiTetsushi Sep 20 '20

The Platform.OS property can take care of that.

import { Platform } from 'react-native;'

const showEventType = Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow';
const hideEventType = Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide';

Then use them in the Keyboard.addListener() method.

2

u/[deleted] Sep 20 '20

Yup

2

u/himynameismile Sep 20 '20

Have you tried community hooks package? They have a keyboard listener hook, which cuts this code down to at least half.

1

u/matt_hammond iOS & Android Sep 20 '20

I think you should destructure setOptions before using it in the useCallback function.

The reason is - when you navigate to another screen the navigation state changes, and with it the navigation object, in order not to mutate the navigation object.

This behavior could have changed since react navigation 5 came out, but I haven't checked.

Either way, using setOptions in the useCallback function and listing it as a dependency is the correct way to do it.

1

u/ldf1111 Sep 20 '20

What program is this, so minimal

0

u/[deleted] Sep 20 '20

[deleted]

2

u/Shumuu Sep 20 '20

Yes you can

7

u/[deleted] Sep 20 '20

[removed] — view removed comment

5

u/DoctorCube Sep 20 '20

Looks like it might be Dracula at any rate its really close.
https://marketplace.visualstudio.com/items?itemName=dracula-theme.theme-dracula

1

u/anions Sep 20 '20

thanks mate.

1

u/OnlySeesLastSentence Sep 20 '20

Oh fuck. Mancala intentionaljoke effect there. I always thought it was called Darkula as a pun on dark and dracula.

2

u/DoctorCube Sep 20 '20

Don't get your Mandelas in a twist Darkula is another theme.

1

u/anions Sep 20 '20

thats what i came here for too lol. need a new theme long overdue