How do I remove the shadow on header for React Native on Android, React Navigation v6? - react-native

The shadow looks like this.
I've tried using
headerStyle: {
elevation: 0,
shadowOpacity: 0,
borderBottomWidth: 0,
}
but according to this link
https://reactnavigation.org/docs/native-stack-navigator#options
in React Navigation v6, the only property supported in headerStyle is backgroundColor only.

For react-navigation v6 you can use headerShadowVisible to hide or show the header's shadow.
<Stack.Navigator screenOptions={{headerShadowVisible: false}}>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Notifications" component {NotificationsScreen} />
<Stack.Screen name="Profile" component={ProfileScreen} />
<Stack.Screen name="Settings" component={SettingsScreen} />
</Stack.Navigator>

Related

How to implement Mini View like PipView in mobile app with React-Native

I want to implement a Mini View or Floating View (for WebRTC calling) in React-Native that should be persist or opened until we close it and it should be remain opened if we navigate to other screen any idea about this?
You can create a component and add it along with the navigation. It will appear on all the screens. You can absolutely position and apply animation as per your requirement.
<SafeAreaProvider>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="login"
component={Login}
options={{
headerShown: false
}} />
<Stack.Screen name="home" component={Home} />
<Stack.Screen name="screen2" component={Screen2} />
<Stack.Screen name="screen3" component={Screen3} />
</Stack.Navigator>
<IncomingCall /> // component that is floating and shared between screens
</NavigationContainer>
</SafeAreaProvider>

Right-to-left screen animation in React Native navigation

I'd like to have screen animations from right to left in React Native. I checked a lot in the internet but most of the examples are old and they are using StackNavigator differently and the configurations are also different. I think they are using an old version of React Navigation. I use version 6. I also tried as explained here in docs https://reactnavigation.org/docs/stack-navigator/#animations but it didn't worked in any way.
Could you please help? Here is my code:
const Tab = createBottomTabNavigator();
const Stack = createNativeStackNavigator();
function MainScreen() {
return (
<Tab.Navigator>
<Tab.Screen name="Home" component={HomeScreen} />
<Tab.Screen name="To Read" component={ToReadScreen} />
<Tab.Screen name="Have Read" component={HaveReadScreen} />
</Tab.Navigator>
);
}
export default function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="ReadX"
component={MainScreen}
/>
<Stack.Screen
name="Settings"
component={SettingsScreen}
/>
</Stack.Navigator>
</NavigationContainer>
);
}
So I am trying to configure the screen animation between main screen and setting screen.
Any help would be appreaciated. Thanks.
Assuming this is a recent react-navigation v6 version, use the animationTypeForReplace option:
<Stack.Screen
name="Settings"
component={SettingsScreen}
options={{
animationTypeForReplace: 'pop',
}}
/>
https://reactnavigation.org/docs/stack-navigator/#animationtypeforreplace
<Stack.Navigator initialRouteName='LoginPage' screenOptions={{ headerShown: false, animation: 'slide_from_right' }}>
you have to use animation props in Stack.Navigator in screenOptions

React Native Tab Navigator first tab is focused by default

I'm using React Native BottomTabNavigator.
Example:
<Tab.Navigator tabBarOptions={tabBarOptions} screenOptions={screenOptions}>
<Tab.Screen name="Home" component={Home} />
<Tab.Screen name="Saved" component={Saved} />
<Tab.Screen name="Map" component={Map} />
<Tab.Screen name="Profile" component={Profile} />
</Tab.Navigator>
I want to make the last tab focused instead of the first.
I can't find any option in the documentation.
It should be something like options={{ focused: true }}
Or maybe it's not implemented at all
<Tab.Navigator initialRouteName={"Your Initial Screen Name"}
...>
</Tab.Navigator>

Stack.Navigator fade-transition between Stack.Screens in React-native?

How can I add a transition effect to Stacked Screes in React-native?
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerShown: false,
}}
>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Stocks" component={StocksScreen} />
</Stack.Navigator>
</NavigationContainer>
Is there a default way to achieve a fadeIn / fadeOut effect?
The simplest way to achieve fade effect:
const forFade = ({ current }) => ({
cardStyle: {
opacity: current.progress,
},
});
If you want to apply fade effect for the entire navigator:
<Stack.Navigator
screenOptions={{
headerShown: false,
cardStyleInterpolator: forFade,
}}>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Stocks" component={StocksScreen} />
</Stack.Navigator>
Also you can apply cardStyleInterpolator for single screen via setting options:
<Stack.Screen
name="Home"
component={HomeScreen}
options={{ cardStyleInterpolator: forFade }}/>
You can customize forFade function in order to achieve other effects, or also you can use some pre-made interpolators, as:
forHorizontalIOS
forVerticalIOS
forModalPresentationIOS
forFadeFromBottomAndroid
forRevealFromBottomAndroid
import { CardStyleInterpolators } from '#react-navigation/stack';
<Stack.Screen
name="Profile"
component={Profile}
options={{
cardStyleInterpolator: CardStyleInterpolators.forFadeFromBottomAndroid,
}}
/>;
More info here: https://reactnavigation.org/docs/stack-navigator/#animations
For React Navigation 6.xx you can use the animation option:
<Stack.Screen
name="Profile"
component={Profile}
options={{ animation: 'fade' }}
/>
Supported values:
"default": use the platform default animation
"fade": fade screen in or out
"flip": flip the screen, requires presentation: "modal" (iOS only)
"simple_push": use the platform default animation, but without shadow and native header transition (iOS only)
"slide_from_bottom": slide in the new screen from bottom
"slide_from_right": slide in the new screen from right (Android only, uses default animation on iOS)
"slide_from_left": slide in the new screen from left (Android only, uses default animation on iOS)
"none": don't animate the screen

React Native Custom icon / image in Tab.Screen navigation

I have a bottomtab in my React Native setup;
<NavigationContainer>
<Tab.Navigator>
<Tab.Screen name="News" component={News} />
<Tab.Screen name="Mens" component={Mens} />
<Tab.Screen name="Ladies" component={Ladies} />
<Tab.Screen name="Watch" component={Fixtures} />
</Tab.Navigator>
</NavigationContainer>
What I'd like to do is add in the middle a dummy Tab so I can add a custom icon;
<NavigationContainer>
<Tab.Navigator>
<Tab.Screen name="News" component={News} />
<Tab.Screen name="Mens" component={Mens} />
<Tab.Screen name="logo" />
<Tab.Screen name="Ladies" component={Ladies} />
<Tab.Screen name="Watch" component={Fixtures} />
</Tab.Navigator>
</NavigationContainer>
The challenge I'm having is where to start (TabBarOptions doesn't appear to work within the tab.screen). I've found loads of explains (they seem like overkill for adding an icon), but they all use pre-defined icon sets. What I want to do is create an icon from a custom image and then use that for the logo tab so it appears in my bottom navigation.
You can set the tabbaricon like below. The there are parameters for focused as well which you can use to set images based on condition.
<Tab.Screen
name="Settings1"
component={SettingsScreen}
options={{
title: 'My profile',
tabBarIcon: ({size,focused,color}) => {
return (
<Image
style={{ width: size, height: size }}
source={{
uri:
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADMAAAAzCAYAAAA6oTAqAAAAEXRFWHRTb2Z0d2FyZQBwbmdjcnVzaEB1SfMAAABQSURBVGje7dSxCQBACARB+2/ab8BEeQNhFi6WSYzYLYudDQYGBgYGBgYGBgYGBgYGBgZmcvDqYGBgmhivGQYGBgYGBgYGBgYGBgYGBgbmQw+P/eMrC5UTVAAAAABJRU5ErkJggg==',
}}
/>
);
},
}}
/>