Skip to content
This repository has been archived by the owner on Feb 8, 2020. It is now read-only.

Commit

Permalink
fix: fix backgroundColor in sceneContainerStyle overriden by theme
Browse files Browse the repository at this point in the history
Closes #215
  • Loading branch information
satya164 committed Dec 16, 2019
1 parent 9fc1af0 commit ebd145a
Showing 1 changed file with 34 additions and 71 deletions.
105 changes: 34 additions & 71 deletions packages/material-top-tabs/src/views/MaterialTopTabView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { View } from 'react-native';
import { TabView, SceneRendererProps } from 'react-native-tab-view';
import { Route, useTheme } from '@react-navigation/native';
import { TabNavigationState, TabActions } from '@react-navigation/routers';
Expand All @@ -16,49 +15,35 @@ type Props = MaterialTopTabNavigationConfig & {
state: TabNavigationState;
navigation: MaterialTopTabNavigationHelpers;
descriptors: MaterialTopTabDescriptorMap;
tabBarPosition: 'top' | 'bottom';
tabBarPosition?: 'top' | 'bottom';
};

function SceneContent({ children }: { children: React.ReactNode }) {
export default function MaterialTopTabView({
lazyPlaceholder,
tabBar = (props: MaterialTopTabBarProps) => <MaterialTopTabBar {...props} />,
tabBarOptions,
state,
navigation,
descriptors,
sceneContainerStyle,
...rest
}: Props) {
const { colors } = useTheme();

return (
<View style={{ flex: 1, backgroundColor: colors.background }}>
{children}
</View>
);
}

export default class MaterialTopTabView extends React.PureComponent<Props> {
static defaultProps = {
tabBarPosition: 'top',
};

private renderLazyPlaceholder = (props: { route: Route<string> }) => {
const { lazyPlaceholder } = this.props;

const renderLazyPlaceholder = (props: { route: Route<string> }) => {
if (lazyPlaceholder != null) {
return lazyPlaceholder(props);
}

return null;
};

private renderTabBar = (props: SceneRendererProps) => {
const { state, descriptors } = this.props;
const renderTabBar = (props: SceneRendererProps) => {
const route = state.routes[state.index];
const options = descriptors[route.key].options;

const tabBarVisible = options.tabBarVisible !== false;

const {
navigation,
tabBar = (props: MaterialTopTabBarProps) => (
<MaterialTopTabBar {...props} />
),
tabBarOptions,
} = this.props;

if (tabBarVisible === false) {
return null;
}
Expand All @@ -72,47 +57,25 @@ export default class MaterialTopTabView extends React.PureComponent<Props> {
});
};

private handleSwipeStart = () =>
this.props.navigation.emit({
type: 'swipeStart',
});

private handleSwipeEnd = () =>
this.props.navigation.emit({
type: 'swipeEnd',
});

render() {
const {
/* eslint-disable @typescript-eslint/no-unused-vars */
lazyPlaceholder,
tabBar,
tabBarOptions,
/* eslint-enable @typescript-eslint/no-unused-vars */
state,
navigation,
descriptors,
...rest
} = this.props;

return (
<TabView
{...rest}
onIndexChange={index =>
navigation.dispatch({
...TabActions.jumpTo(state.routes[index].name),
target: state.key,
})
}
renderScene={({ route }) => (
<SceneContent>{descriptors[route.key].render()}</SceneContent>
)}
navigationState={state}
renderTabBar={this.renderTabBar}
renderLazyPlaceholder={this.renderLazyPlaceholder}
onSwipeStart={this.handleSwipeStart}
onSwipeEnd={this.handleSwipeEnd}
/>
);
}
return (
<TabView
{...rest}
onIndexChange={index =>
navigation.dispatch({
...TabActions.jumpTo(state.routes[index].name),
target: state.key,
})
}
renderScene={({ route }) => descriptors[route.key].render()}
navigationState={state}
renderTabBar={renderTabBar}
renderLazyPlaceholder={renderLazyPlaceholder}
onSwipeStart={() => navigation.emit({ type: 'swipeStart' })}
onSwipeEnd={() => navigation.emit({ type: 'swipeEnd' })}
sceneContainerStyle={[
{ backgroundColor: colors.background },
sceneContainerStyle,
]}
/>
);
}

0 comments on commit ebd145a

Please sign in to comment.