Quero mostrar a barra de navegação no modo retrato e ocultar no modo paisagem (para vídeo em tela cheia). Existe uma maneira de fazer isso?
Você pode implementar sua própria NavBar e passá-la para a cena. Estou usando algo assim
onLayout({nativeEvent}){
const isPortrait = nativeEvent.layout.width === WIDTH;
if (isPortrait){
if (this.state.height != NAVBAR_HEIGHT_PORTRAIT){
this.setState({height: NAVBAR_HEIGHT_PORTRAIT, delta:STATUS_BAR_HEIGHT});
}
} else {
if (this.state.height != NAVBAR_HEIGHT_LANDSCAPE){
this.setState({height: NAVBAR_HEIGHT_LANDSCAPE, delta:0});
}
}
}
render(){
return (
<View onLayout={this.onLayout.bind(this)} style={[styles.container, {height:this.state.height}, this.props.style]} >
{this.props.navBarHeader}
<View style={[styles.container, {height:this.state.height}, this.props.style]} >
<View style={{height:this.state.delta,flex:1}}></View>
<View style={{height:this.state.height-this.state.delta, flexDirection:'row'}}>
{this.props.navigationState.children.length > 1 ? this.renderBackButton(this.props) : this.renderLeftButton(this.props)}
<View style={{flex:1,justifyContent:'center',alignItems:'center'}}>
{this.renderTitle(this.props)}
</View>
{this.renderRightButton(this.props)}
</View>
{this.props.footer}
</View>
</View>
);
}
Talvez pudéssemos incorporar tal lógica dentro dos componentes NavBar se a comunidade quiser e enviar PR.
Sim, estou usando algo semelhante, embora mais simples -
onLayout = event => {
const { width, height } = event.nativeEvent.layout;
var newStyle;
if (width > height) {
newStyle = update(this.state.style, {marginTop: {$set: 0}});
} else {
newStyle = update(this.state.style, {marginTop: {$set: 64}});
}
this.setState({style: newStyle});
// hide navbar in landscape mode
Actions.refresh({hideNavBar: (width > height)});
}
Olá @vinayr, estou tentando fazer algo semelhante, mas na minha cena eu tenho
componentDidMount(){
Actions.refresh({hideNavBar:false});
}
componentWillUnmount(){
Actions.refresh({hideNavBar: true})
}
Então quando eu estou saindo de cena o navbar, mas também recarrega o estado ou algo parecido, porque a cena anterior teve uma validação que empurrou para a cena atual, e quando eu volto ela redireciona novamente para a cena.
Comentários muito úteis
Você pode implementar sua própria NavBar e passá-la para a cena. Estou usando algo assim
Talvez pudéssemos incorporar tal lógica dentro dos componentes NavBar se a comunidade quiser e enviar PR.