Skip to content

Commit

Permalink
fix: fix headerTransparent not working outside stack navigator
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Aug 11, 2021
1 parent 2e47c42 commit 42c43ff
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 13 deletions.
39 changes: 32 additions & 7 deletions example/src/Screens/BottomTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import {
createBottomTabNavigator,
useBottomTabBarHeight,
} from '@react-navigation/bottom-tabs';
import { HeaderBackButton } from '@react-navigation/elements';
import { HeaderBackButton, useHeaderHeight } from '@react-navigation/elements';
import {
getFocusedRouteNameFromRoute,
NavigatorScreenParams,
ParamListBase,
useIsFocused,
} from '@react-navigation/native';
import type { StackScreenProps } from '@react-navigation/stack';
import { BlurView } from 'expo-blur';
import * as React from 'react';
import { ScrollView, StyleSheet } from 'react-native';
import { ScrollView, StatusBar, StyleSheet } from 'react-native';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';

import Albums from '../Shared/Albums';
Expand All @@ -32,12 +33,22 @@ type BottomTabParams = {
};

const AlbumsScreen = () => {
const headerHeight = useHeaderHeight();
const tabBarHeight = useBottomTabBarHeight();
const isFocused = useIsFocused();

return (
<ScrollView contentContainerStyle={{ paddingBottom: tabBarHeight }}>
<Albums scrollEnabled={false} />
</ScrollView>
<>
{isFocused && <StatusBar barStyle="light-content" />}
<ScrollView
contentContainerStyle={{
paddingTop: headerHeight,
paddingBottom: tabBarHeight,
}}
>
<Albums scrollEnabled={false} />
</ScrollView>
</>
);
};

Expand Down Expand Up @@ -94,11 +105,25 @@ export default function BottomTabsScreen({
component={AlbumsScreen}
options={{
title: 'Albums',
headerTintColor: '#fff',
headerTransparent: true,
headerBackground: () => (
<BlurView
tint="dark"
intensity={100}
style={StyleSheet.absoluteFill}
/>
),
tabBarIcon: getTabBarIcon('image-album'),
tabBarStyle: { position: 'absolute' },
tabBarInactiveTintColor: 'rgba(255, 255, 255, 0.5)',
tabBarActiveTintColor: '#fff',
tabBarStyle: {
position: 'absolute',
borderTopColor: 'rgba(0, 0, 0, .2)',
},
tabBarBackground: () => (
<BlurView
tint="light"
tint="dark"
intensity={100}
style={StyleSheet.absoluteFill}
/>
Expand Down
14 changes: 8 additions & 6 deletions packages/bottom-tabs/src/views/BottomTabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ export default function BottomTabBar({
tabBarVisibilityAnimationConfig,
tabBarStyle,
tabBarBackground,
tabBarActiveTintColor,
tabBarInactiveTintColor,
tabBarActiveBackgroundColor,
tabBarInactiveBackgroundColor,
} = focusedOptions;

const dimensions = useSafeAreaFrame();
Expand Down Expand Up @@ -342,12 +346,10 @@ export default function BottomTabBar({
to={buildLink(route.name, route.params)}
testID={options.tabBarTestID}
allowFontScaling={options.tabBarAllowFontScaling}
activeTintColor={options.tabBarActiveTintColor}
inactiveTintColor={options.tabBarInactiveTintColor}
activeBackgroundColor={options.tabBarActiveBackgroundColor}
inactiveBackgroundColor={
options.tabBarInactiveBackgroundColor
}
activeTintColor={tabBarActiveTintColor}
inactiveTintColor={tabBarInactiveTintColor}
activeBackgroundColor={tabBarActiveBackgroundColor}
inactiveBackgroundColor={tabBarInactiveBackgroundColor}
button={options.tabBarButton}
icon={
options.tabBarIcon ??
Expand Down
1 change: 1 addition & 0 deletions packages/bottom-tabs/src/views/BottomTabView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export default function BottomTabView(props: Props) {
route={descriptor.route}
navigation={descriptor.navigation}
headerShown={descriptor.options.headerShown}
headerTransparent={descriptor.options.headerTransparent}
headerStatusBarHeight={
descriptor.options.headerStatusBarHeight
}
Expand Down
1 change: 1 addition & 0 deletions packages/drawer/src/views/DrawerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ function DrawerViewBase({
route={descriptor.route}
navigation={descriptor.navigation}
headerShown={descriptor.options.headerShown}
headerTransparent={descriptor.options.headerTransparent}
headerStatusBarHeight={descriptor.options.headerStatusBarHeight}
header={header({
layout: dimensions,
Expand Down
9 changes: 9 additions & 0 deletions packages/elements/src/Screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Props = {
header: React.ReactNode;
headerShown?: boolean;
headerStatusBarHeight?: number;
headerTransparent?: boolean;
style?: StyleProp<ViewStyle>;
children: React.ReactNode;
};
Expand All @@ -41,6 +42,7 @@ export default function Screen(props: Props) {
modal = false,
header,
headerShown = true,
headerTransparent,
headerStatusBarHeight = isParentHeaderShown ? 0 : insets.top,
navigation,
route,
Expand Down Expand Up @@ -78,6 +80,7 @@ export default function Screen(props: Props) {

setHeaderHeight(height);
}}
style={headerTransparent ? styles.absolute : null}
>
{header}
</View>
Expand All @@ -97,4 +100,10 @@ const styles = StyleSheet.create({
content: {
flex: 1,
},
absolute: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
},
});
1 change: 1 addition & 0 deletions packages/native-stack/src/views/NativeStackView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default function NativeStackView({ state, descriptors }: Props) {
route={route}
navigation={navigation}
headerShown={headerShown}
headerTransparent={headerTransparent}
header={
header !== undefined ? (
header({
Expand Down

0 comments on commit 42c43ff

Please sign in to comment.