React-native-router-flux: Existe uma maneira de ocultar a barra de navegação quando a orientação muda?

Criado em 18 abr. 2016  ·  3Comentários  ·  Fonte: aksonov/react-native-router-flux

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?

Comentários muito úteis

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.

Todos 3 comentários

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.

Esta página foi útil?
0 / 5 - 0 avaliações

Questões relacionadas

rafaelcorreiapoli picture rafaelcorreiapoli  ·  3Comentários

moaxaca picture moaxaca  ·  3Comentários

fgrs picture fgrs  ·  3Comentários

luco picture luco  ·  3Comentários

VictorK1902 picture VictorK1902  ·  3Comentários