Skip to content

Commit

Permalink
feat: add sceneContainerStyle prop to bottom-tabs navigator (#8947)
Browse files Browse the repository at this point in the history
This feature adds the sceneContainerStyle prop to the bottom-tabs navigator, to allow setting styles on the container's view. It's already implemented in the material-top-tabs and drawer navigators, I've simply ported it into the bottom-tabs navigator.

It also fixes this issue:

#8076

Co-authored-by: Satyajit Sahoo <satyajit.happy@gmail.com>
  • Loading branch information
wwdrew and satya164 committed Oct 23, 2020
1 parent 261a33a commit f01bb48
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function BottomTabNavigator({
backBehavior,
children,
screenOptions,
sceneContainerStyle,
...rest
}: Props) {
const { state, descriptors, navigation } = useNavigationBuilder<
Expand All @@ -43,6 +44,7 @@ function BottomTabNavigator({
state={state}
navigation={navigation}
descriptors={descriptors}
sceneContainerStyle={sceneContainerStyle}
/>
);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/bottom-tabs/src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ export type BottomTabNavigationConfig<T = BottomTabBarOptions> = {
* Options for the tab bar which will be passed as props to the tab bar component.
*/
tabBarOptions?: T;
/**
* Style object for the component wrapping the screen content.
*/
sceneContainerStyle?: StyleProp<ViewStyle>;
};

export type BottomTabBarOptions = {
Expand Down
19 changes: 15 additions & 4 deletions packages/bottom-tabs/src/views/BottomTabView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { View, StyleSheet } from 'react-native';
import { View, StyleSheet, StyleProp, ViewStyle } from 'react-native';

import {
NavigationHelpersContext,
Expand Down Expand Up @@ -31,17 +31,19 @@ type State = {
function SceneContent({
isFocused,
children,
style,
}: {
isFocused: boolean;
children: React.ReactNode;
style?: StyleProp<ViewStyle>;
}) {
const { colors } = useTheme();

return (
<View
accessibilityElementsHidden={!isFocused}
importantForAccessibility={isFocused ? 'auto' : 'no-hide-descendants'}
style={[styles.content, { backgroundColor: colors.background }]}
style={[styles.content, { backgroundColor: colors.background }, style]}
>
{children}
</View>
Expand Down Expand Up @@ -85,7 +87,13 @@ export default class BottomTabView extends React.Component<Props, State> {
};

render() {
const { state, descriptors, navigation, lazy } = this.props;
const {
state,
descriptors,
navigation,
lazy,
sceneContainerStyle,
} = this.props;
const { routes } = state;
const { loaded } = this.state;

Expand Down Expand Up @@ -114,7 +122,10 @@ export default class BottomTabView extends React.Component<Props, State> {
style={StyleSheet.absoluteFill}
isVisible={isFocused}
>
<SceneContent isFocused={isFocused}>
<SceneContent
isFocused={isFocused}
style={sceneContainerStyle}
>
{descriptor.render()}
</SceneContent>
</ResourceSavingScene>
Expand Down

0 comments on commit f01bb48

Please sign in to comment.