Shoutem UI toolkit contains two different NavigationBar
components:
1) Simple 3-column NavigationBar
that can be used on any screen or Modal
window
2) Redux
and stack-based NavigationBar
enables any view to act as a navigation view using reducers to manipulate state at a top-level object. Can be used only on components that are within the stack (i.e. it cannot be used on Modal
window). Internally, it relies on NavigationExperimental
from react-native-navigation-experimental-compat
.
import { NavigationBar } from '@shoutem/ui'
NavigationBar
is node
for Navigator React Native component. It provides a simpler way to use 3-column navigation bar.
centerComponent
prop to a Title
component with the provided string as the title textNavigationBar
(e.g. screen title)NavigationBar
(e.g. back button)NavigationBar
(e.g. drop-down menu button)true
, the leftComponent
will become a back arrow which triggers navigateBack
on tapBack
button if hasHistory
is set to true
Text
color to white and background colors to transparentNavigationBar
component, allowing component to be used inline with other components, i.e. ListView
, without its content overlapping NavigationBar
View
that holds all components within NavigationBar
View
container that holds leftComponent
, centerComponent
and rightComponent
objects<NavigationBar
centerComponent={<Title>TITLE</Title>}
/>
<ImageBackground
source={{uri: 'https://shoutem.github.io/img/ui-toolkit/examples/image-3.png'}}
style={{ width: 375, height: 70 }}
>
<NavigationBar
styleName="clear"
centerComponent={<Title>TITLE</Title>}
/>
</ImageBackground>
<NavigationBar
leftComponent={<Icon name="sidebar" />}
centerComponent={<Title>TITLE</Title>}
/>
constructor(props){
super(props);
this.state = {
filters: [
{ name: 'Filter', value: 'Filter' },
{ name: 'Sport', value: 'Sport' },
{ name: 'Food', value: 'Food' },
],
}
}
render() {
return (
<NavigationBar
styleName="inline"
leftComponent={
<Button>
<Icon name="sidebar" />
</Button>
}
centerComponent={
<Title>
{this.state.selectedFilter
? this.state.selectedFilter.value
: this.state.filters[0].value}
</Title>
}
rightComponent={
<DropDownMenu
options={this.state.filters}
selectedOption={this.state.selectedFilter ? this.state.selectedFilter : this.state.filters[0]}
onOptionSelected={(filter) => this.setState({ selectedFilter: filter })}
titleProperty="name"
valueProperty="value"
/>
}
/>
);
}
<NavigationBar
leftComponent={<Icon name="sidebar" />}
centerComponent={<Title>TITLE</Title>}
rightComponent={(
<Button styleName="clear">
<Text>List</Text>
</Button>
)}
/>
<NavigationBar
leftComponent={<Icon name="sidebar" />}
centerComponent={<Title>TITLE</Title>}
rightComponent={(
<Button>
<Icon name="cart" />
</Button>
)}
/>
<NavigationBar
hasHistory
centerComponent={<Title>TITLE</Title>}
share={{
link: 'http://shoutem.github.io',
text: 'This is the best',
title: 'Super cool UI Toolkit',
}}
/>
<NavigationBar
styleName="no-border"
hasHistory
centerComponent={<Title>TITLE</Title>}
share={{
link: 'http://shoutem.github.io',
text: 'This is the best',
title: 'Super cool UI Toolkit',
}}
/>
<NavigationBar
hasHistory
centerComponent={<Title>TITLE</Title>}
rightComponent={(
<Button styleName="clear">
<Text>Report</Text>
</Button>
)}
/>
<NavigationBar
leftComponent={(
<Button>
<Icon name="close" />
</Button>
)}
centerComponent={<Title>TITLE</Title>}
share={{
link: 'http://shoutem.github.io',
text: 'This is the best',
title: 'Super cool UI Toolkit',
}}
/>
<NavigationBar
leftComponent={(
<Button>
<Icon name="close" />
</Button>
)}
centerComponent={<Title>TITLE</Title>}
rightComponent={(
<Button styleName="clear">
<Text>Post</Text>
</Button>
)}
/>
<NavigationBar
leftComponent={(
<Button>
<Text>Cancel</Text>
</Button>
)}
centerComponent={<Title>TITLE</Title>}
rightComponent={(
<Button>
<Text>Done</Text>
</Button>
)}
/>
<NavigationBar
leftComponent={(
<Button>
<Text>Cancel</Text>
</Button>
)}
centerComponent={<Title>TITLE</Title>}
rightComponent={(
<Button styleName="muted">
<Text>Done</Text>
</Button>
)}
/>
<NavigationBar
styleName="clear"
hasHistory
centerComponent={<Title>TITLE</Title>}
share={{
link: 'http://shoutem.github.io',
text: 'This is the best',
title: 'Super cool UI Toolkit',
}}
/>
import { NavigationBar } from '@shoutem/ui/navigation'
This NavigationBar
and CardStack
components provide simpler API for navigation between Screens
(scenes) with respect to its underlying Redux-based NavigationExperimental
React Native component.
NavigationBar
(example: back button)View
that has container
styleName and virtual
propNavigationBar
(example: drop-down menu button)View
that has container
styleName and virtual
prophasHistory
Prop is set to true
title
component/prop in NavigationBar
View
that has container
styleName and virtual
propText
color to white and background colors to transparentText
color to white and applies linear gradient to backgroundView
that holds all components within NavigationBar
View
container that holds leftComponent
, centerComponent
and rightComponent
objectsleftComponent
)NavigationBar
View
(container)In order to use this NavigationBar
component, you will need to initialize CardStack
as root component of your application and define base NavigationBar.View
which will hold actual NavigationBar
according to provided props.
class App extends Component {
static propTypes = {
onNavigateBack: React.PropTypes.func.isRequired,
navigationState: React.PropTypes.object,
scene: React.PropTypes.object,
};
constructor(props) {
super(props);
this.renderNavBar = this.renderNavBar.bind(this);
this.renderScene = this.renderScene.bind(this);
}
renderScene(props) {
const { route } = props.scene;
let Screen = route.key === 'RestaurantDetails' ? RestaurantDetails : RestaurantsList;
return (<Screen {...route.props} />);
}
renderNavBar(props) {
const { onNavigateBack } = this.props;
return (
<NavigationBar.View
{...props}
onNavigateBack={onNavigateBack}
/>
);
}
render() {
const { navigationState, onNavigateBack } = this.props;
return (
<CardStack
navigationState={navigationState}
onNavigateBack={onNavigateBack}
renderNavBar={this.renderNavBar}
renderScene={this.renderScene}
/>
);
}
}
Also, on each screen where you want to have NavigationBar, you’ll need to define it as every other component.
<NavigationBar
title="title goes here"
styleName="clear"
/>
Note that example above is just a part of required code. For a full example, refer to RestaurantApp example, where App
is root application component holding code above.