1.2.2 • Published 6 years ago

top-bar-nav v1.2.2

Weekly downloads
33
License
ISC
Repository
-
Last release
6 years ago

top-bar-nav

A top bar navigator for React Native that is super light, simple, and customizable.

Install

npm install --save top-bar-nav

Import

import TopBarNav from 'top-bar-nav';

Usage

import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import TopBarNav from './TopBarNav';

const Scene = ({ index }) => (
	<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
		<Text style={{ fontSize: 20 }}>{index}</Text>
	</View>
);

const ROUTES = {
	Scene
	// ideally you would have a ROUTES object with multiple React component scenes
};

// There are three types of labels (image, text, and element)
const ROUTESTACK = [
	{ image: require('./search.png'), title: 'Scene' },
	{ text: 'Hello', title: 'Scene' }, // title is just the name of the Component being rendered.  See the renderScene property below
	{ element: <Text>World</Text>, title: 'Scene' }
];

export default class Example extends React.Component {
	render() {
		return (
			<View style={{ flex: 1 }}>
				<TopBarNav
					// routeStack and renderScene are required props
					routeStack={ROUTESTACK}
					renderScene={(route, i) => {
						// This is a lot like the now deprecated Navigator component
						let Component = ROUTES[route.title];
						return <Component index={i} />;
					}}
					// Below are optional props
					headerStyle={[styles.headerStyle, { paddingTop: 30 }]} // probably want to add paddingTop if using TopBarNav for the  entire height of screen to account for notches/status bars
					labelStyle={styles.labelStyle}
					underlineStyle={styles.underlineStyle}
					imageStyle={styles.imageStyle}
					sidePadding={40} // Can't set sidePadding in headerStyle because it's needed to calculate the width of the tabs
					inactiveOpacity={1}
					fadeLabels={true}
				/>
			</View>
		);
	}

	anotherRender() {
		// if rendering the nav bar at the bottom is your thing
		return (
			<View style={{ flex: 1 }}>
				<View style={{ flex: 1, transform: [{ scaleY: -1 }] }}>
					<TopBarNav
						// routeStack and renderScene are required props
						routeStack={ROUTESTACK}
						renderScene={(route, i) => {
							// This is a lot like the now deprecated Navigator component
							let Component = ROUTES[route.title];
							return (
								<View style={{ flex: 1, transform: [{ scaleY: -1 }] }}>
									<Component index={i} />
								</View>
							);
						}}
						// Below are optional props
						headerStyle={{ paddingTop: 20, transform: [{ scaleY: -1 }] }} // probably want to add paddingTop: 20 if using TopBarNav for the  entire height of screen on iOS
						underlineStyle={{ height: 3 }}
					/>
				</View>
			</View>
		);
	}
}

const styles = StyleSheet.create({
	headerStyle: {
		borderBottomWidth: 1,
		borderColor: '#e6faff',
		backgroundColor: '#3385ff'
	},
	labelStyle: {
		fontSize: 15,
		fontWeight: '500',
		color: '#fff'
	},
	imageStyle: {
		height: 20,
		width: 20,
		tintColor: '#e6faff'
	},
	underlineStyle: {
		height: 3.6,
		backgroundColor: '#e6faff',
		width: 40
	}
});

Demo

npm.io

npm.io

npm.io

Props

static propTypes = {
	routeStack: PropTypes.array.isRequired,
	initialIndex: PropTypes.number,
	renderScene: PropTypes.func,
	headerStyle: stylePropType,
	textStyle: stylePropType,
	imageStyle: stylePropType,
	underlineStyle: stylePropType,
	sidePadding: PropTypes.number,
	inactiveOpacity: PropTypes.number,
	fadeLabels: PropTypes.bool,
	scrollViewProps: PropTypes.object
};

static defaultProps = {
	initialIndex: 0,
	sidePadding: 0,
	inactiveOpacity: 0.5,
	fadeLabels: false,
	scrollViewProps: {}
};
1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago