Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add sceneContainerStyle prop to bottom-tabs navigator #8947

Merged
merged 3 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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