react native Bottom Tabs Navigator ref - react-native

is there a way to add ref for each tab in the Bottom Tabs Navigator ?
like
<View ref={component => this.childComponent = component} />

Related

Animate bottom navigation bar with Animated.View

Attempting to hide/show the bottom navigation bar on React-Native app
When wrapping the navigation tab With <Animated.view> the navigation styling collapses and the bottom tab bar jumps to the top of the screen and requires much styling to put it back to to place.
Using React-Native-Reanimated is there a way to animate the bottom tab appearance?
Working example:
import { createBottomTabNavigator } from '#react-navigation/bottom-tabs';
...
const Tab = createBottomTabNavigator();
...
<Tab.Navigator tabBarStyle: {
display: tabBarVisability,>
...
</Tab.Navigator>
Desired:
<Animated.View>
<Tab.Navigator>
</Tab.Navigator>
</Animated.View>
As suggested by Abe, the solution was to add the tabBar prop, wrapping the BottomTabBar with Animated.View
This is a working example:
import Animated, { FadeInUp, FadeOutDown, Layout } from 'react-native-reanimated';
import { BottomTabBar, createBottomTabNavigator } from '#react-navigation/bottom-tabs';
...
<Tab.Navigator
...props
tabBar={(props) => (
<Animated.View
entering={FadeInUp}
exiting={FadeOutDown}
layout={Layout.duration(100)}
style={{
height: tabBarVisible ? 80 : 0,
}}
>
<BottomTabBar {...props} />
</Animated.View>
)}
...Screens
</Tab.Navigator>

How to use stack navigation in side drawer navigation with header in react navigation v6

i am using the React navigation version 6 and i want to header of navigation
with drawer and Stack
but when i use stack in drawer navigation then shows to two header
the below is code which i write
const StockStack = createNativeStackNavigator();
const StockScreen = ({ navigation }) => (
<StockStack.Navigator>
<StockStack.Screen name="StockList" component={StockList} />
<StockStack.Screen name="StockItemDetail" component={StockItemDetail}/>
</StockStack.Navigator>
)
and this the drawer navigation
return (
<Drawer.Navigator drawerContent={ props => <SideMenu {...props} /> }>
<Drawer.Screen name="StockScreenList" component={StockScreen} />
</Drawer.Navigator>
);
any can help you can i remove the drawer header

Use props in pressable in react native for navigation

I am new to react native. What I want to achieve is that I want to navigate between screen while using pressable. What i have done is I have already created pressable button components inside buttons.js file what I want right now is that when I call that component inside of a file I want to pass screen name as a prop to that button component and navigate between screen using that main component. In short what i mean is whenever a screen name is passed from different file it act according to that and instead I don`t have to create multiple navigation inside each file.
E.g
Inside Home file
<ButtonXsPrimary
title='Login'
/>
Inside Buttons.js file
const ButtonXsPrimary = (prop) => {
const navigation = useNavigation();
return (
<>
<Pressable style={[style.buttonXs, Color.bgSecondry]} onPress={() => navigation.navigate(prop)} >
<Text style={[Color.White, style.buttonsTextSm]}>{prop.title}</Text>
</Pressable>
</>
);
};
The same title prop is used for navigation
As I understand you can do this way,
You need to pass navigation and route name as a prop inside your ButtonXsPrimary like
<ButtonXsPrimary
title="Login"
navigation={navigation}
routeName={'YourRouteName'}
/>
Access the props
onPress={() => prop.navigation.navigate(prop.routeName)}

react navigation v5 #react-navigation/drawer check drawer open

so in react navigation v5 how to check if drawer open or not
not that i use custom drawer
drawerContent={(props) => <DrawerComponent {...props} />}
const isDrawerOpen = useIsDrawerOpen() i can not use this from
useIsDrawerOpen() is a Hook to detect if the drawer is open in a parent navigator.
For exemple in your view you can test if your drawer is open or not directly using this approach :
import { useIsDrawerOpen } from '#react-navigation/drawer';
const MainContainer = () => {
return (
<View style={(useIsDrawerOpen()) ? styles.conatinerOpenStyle : styles.containerClosedStyle}>
<Text>{console.log("Test drawer "+useIsDrawerOpen())}</Text>
</View>
);}
And it will indicate to you the state of your drawer.

How to persist stacked screens when switching between tabs in React Native Navigation

I am using a bottom tab navigator created with createBottomTabNavigator() and passing it several screens, each of which contain their own stack navigation:
const tabNavigator = createBottomTabNavigator({
TradingStack,
LendingStack,
FinanceStack,
AccountBalancesStack,
OtherStack,
},
{
tabBarComponent: props => (
<NavigationFooter />
)
}
);
I am passing it my own custom bottom navigator component called <NavigationFooter />. When tabBarComponent is omitted, a built-in bottom tab navigator is used, however I need more functionality than this built-in solution offers. The issue is, when using my custom tab bar, I lose stack persistence in the individual screens. To clarify, let's say my TradingStack screen has several screens that stack on top of it, and I open one of those. When using the default tab bar, if I switch to the LendingStack screen and then back to TradingStack, I will still be on the stacked screen that was pushed on top of the root TradingStack screen.
However, when using my custom tab bar component, moving between these tabs/screens will always bring me to the root of each one instead of bringing me back to the stacked screen that the tab was on before switching away from it. Here's my custom Footer component:
function Footer({navigation}) {
return(
<View style={styles.tabBarStyle}>
<TouchableOpacity style={styles.tabStyle} onPress={() => navigation.navigate('Trading')} />
<TouchableOpacity style={styles.tabStyle} onPress={() => navigation.navigate('Lending')} />
<TouchableOpacity style={styles.tabStyle} onPress={() => navigation.navigate('Finance')} />
<TouchableOpacity style={styles.tabStyle} onPress={() => navigation.navigate('AccountBalances')} />
<TouchableOpacity style={styles.tabStyle} onPress={() => navigation.navigate('TabScreen')} />
</View>
);
}
const NavigationFooter = withNavigation(Footer);
As you can see, when one of the TouchableOpacity elements is pressed, I use navigation.navigate() to go to the desired screen, but, as mentioned, this brings me to the root of the screen. I understand that this is basically explicitly telling the app to navigate to a root screen of a tab, but I don't know how to make the tab "remember" the stacked screen it was on before I move away, as is the behavior of the default tab bar.
You can pass the name of the actual stack to navigation.navigate instead of the name of the starting screen on that specific tab, and the stacked screens should persist. So, instead of, for example
<TouchableOpacity style={styles.tabStyle} onPress={() => navigation.navigate('Trading')}/> //name of the screen
you should pass it
<TouchableOpacity style={styles.tabStyle} onPress={() => navigation.navigate('TradingStack')}/> //name of the stack
assuming Trading is the starting screen within the TradingStack.