mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-04 04:01:52 +00:00
narrowd down test file for core lib
This commit is contained in:
@@ -1,33 +1,12 @@
|
||||
import * as React from "react";
|
||||
import {
|
||||
StyleSheet,
|
||||
Dimensions,
|
||||
View,
|
||||
StyleProp,
|
||||
ViewStyle
|
||||
} from "react-native";
|
||||
import { View } from "react-native";
|
||||
import { TabStack, renderSubView } from "react-router-navigation-core";
|
||||
import { TabBarProps, TabProps } from "react-router-navigation";
|
||||
import { TabViewAnimated } from "react-native-tab-view";
|
||||
import {
|
||||
TabBarProps,
|
||||
TabSubViewProps,
|
||||
TabProps
|
||||
} from "react-router-navigation";
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1
|
||||
},
|
||||
scene: {
|
||||
flex: 1,
|
||||
overflow: "hidden"
|
||||
}
|
||||
});
|
||||
|
||||
type Props = TabBarProps & {
|
||||
children?: Array<React.ReactElement<TabProps>>;
|
||||
lazy?: boolean;
|
||||
style?: StyleProp<ViewStyle>;
|
||||
};
|
||||
|
||||
type State = {
|
||||
@@ -35,54 +14,12 @@ type State = {
|
||||
};
|
||||
|
||||
class BottomNavigation extends React.Component<Props, State> {
|
||||
static defaultProps = {
|
||||
lazy: true
|
||||
};
|
||||
|
||||
state = { key: Math.random().toString(10) };
|
||||
|
||||
renderPager = (sceneProps: TabSubViewProps) => <View />;
|
||||
|
||||
renderNavigationBar = (
|
||||
sceneProps: TabSubViewProps,
|
||||
props: TabSubViewProps
|
||||
) => {
|
||||
// Hide tab bar
|
||||
if (sceneProps.hideTabBar) return null;
|
||||
// Custom tab bar
|
||||
if (sceneProps.renderTabBar) {
|
||||
return React.createElement(sceneProps.renderTabBar, sceneProps);
|
||||
}
|
||||
// Default tab bar
|
||||
return <View />;
|
||||
};
|
||||
|
||||
renderSceneView = (sceneProps: TabSubViewProps) => {
|
||||
const { render, children, component, lazy, loadedTabs } = sceneProps;
|
||||
const { key } = sceneProps;
|
||||
if (lazy && !loadedTabs.includes(key)) {
|
||||
return null;
|
||||
} else if (render) {
|
||||
return render(sceneProps);
|
||||
} else if (children && typeof children === "function") {
|
||||
return children(sceneProps);
|
||||
} else if (component) {
|
||||
return React.createElement(component, sceneProps);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
renderScene = (sceneProps: TabSubViewProps) => {
|
||||
return (
|
||||
<View style={styles.scene}>{this.renderSceneView(sceneProps)}</View>
|
||||
);
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<TabStack
|
||||
{...this.props}
|
||||
style={styles.container}
|
||||
forceSync
|
||||
render={props => {
|
||||
const ownProps = { ...this.props, ...props };
|
||||
@@ -90,19 +27,17 @@ class BottomNavigation extends React.Component<Props, State> {
|
||||
<TabViewAnimated
|
||||
{...props}
|
||||
key={`transitioner_${this.state.key}`}
|
||||
style={[styles.container, this.props.style]}
|
||||
initialLayout={Dimensions.get("window")}
|
||||
animationEnabled={false}
|
||||
renderPager={renderSubView(
|
||||
this.renderPager,
|
||||
sceneProps => <View />,
|
||||
ownProps
|
||||
)}
|
||||
renderFooter={renderSubView(
|
||||
this.renderNavigationBar,
|
||||
sceneProps => <View />,
|
||||
ownProps
|
||||
)}
|
||||
renderScene={renderSubView(
|
||||
this.renderScene,
|
||||
sceneProps => <View />,
|
||||
ownProps
|
||||
)}
|
||||
/>
|
||||
@@ -112,5 +47,3 @@ class BottomNavigation extends React.Component<Props, State> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default BottomNavigation;
|
||||
|
||||
Reference in New Issue
Block a user