简体   繁体   English

如何在RNRF中使自定义导航栏透明

[英]How can I make the custom navigation bar transparent in RNRF

I have tried all the options in react-native-router-flux like: navigationBarStyle or navTransparent and also navigationBarStyle={[STYLES.navBar]} all of these are not working while trying to make the custom navigation bar transparent Is there any ways to make it transparent using react-navigation and should I change from react-native-router-flux to react-navigation to do this I have posted it as an issue in Git Hub here is the link : Github issue #2132 我已经尝试了react-native-router-flux中的所有选项,例如: navigationBarStylenavTransparent ,还有navigationBarStyle={[STYLES.navBar]}在试图使自定义导航栏透明时,所有这些都不起作用。是否有任何方法可以使用react-navigation使它透明,并且应该将它从react-native-router-flux更改为react-navigation,我将其发布为Git Hub中的问题,这里是链接: Github问题#2132

since I found it hard using react-navigation I have switched to RNRF is there any solution to make the custom navBar transparent other than switching from RNRF to RN or is it a bug in RN 因为我发现使用反应导航很难,所以我已切换到RNRF,除了从RNRF切换到RN之外,是否有任何解决方案可以使自定义navBar透明化,或者是RN中的错误

这就是我的navBar现在的样子

here's the code that i use in my NavBar.js file : 这是我在NavBar.js文件中使用的代码:

 import { View, Image, StatusBar, TouchableWithoutFeedback } from 'react-native'; import React, { Component } from 'react'; import { Actions } from 'react-native-router-flux'; class NavBar extends Component { render() { return ( <View style={styles.backgroundStyle}> <StatusBar /> <View style={{ flexDirection: 'row' }}> <TouchableWithoutFeedback onPress={() => Actions.pop()}> <Image source={require('./Images/back-arrow.png')} style={styles.backarrowStyle} /> </TouchableWithoutFeedback> <Image source={require('./Images/help.png')} style={styles.helpStyle} /> <Image source={require('./Images/setting.png')} style={styles.settingStyle} /> </View> </View> ); } } const styles = { backgroundStyle: { backgroundColor: 'transparent', }, backarrowStyle: { resizeMode: 'contain', flexDirection: 'row', width: 55, height: 55, left: 0, justifyContent: 'flex-start' }, helpStyle: { resizeMode: 'contain', width: 50, height: 50, left: 210, justifyContent: 'flex-end', position: 'relative' }, settingStyle: { resizeMode: 'contain', width: 50, height: 50, justifyContent: 'flex-end', position: 'relative', left: 210 } }; export default NavBar; 

and this is my Router.js file: 这是我的Router.js文件:

 import React from 'react'; import { Scene, Router } from 'react-native-router-flux'; import MainScreen from './components/MainScreen'; import ChallengeScreen from './components/ChallengeScreen'; import NavBar from './components/NavBar'; import Toss from './components/Toss'; const RouterComponent = () => { return ( <Router> <Scene key="root"> <Scene key="homeScreen" component={MainScreen} hideNavBar={1} /> <Scene key="screen2" component={ChallengeScreen} navBar={NavBar} /> <Scene key="screen3" component={Toss} navBar={NavBar} /> </Scene> </Router> ); }; export default RouterComponent; 

What you can do is set semi-transparent navbar by setting navbar opacity in navigationBarStyle 您可以通过在navigationBarStyle中设置导航栏不透明度来设置半透明导航栏

<Scene key="scene2" component={ChallengeScreen} 
       navigationBarStyle={{opacity:0.3}}/> 

but the problem is the whole navbar including left and right button will be inherit the opacity. 但问题是整个导航栏(包括左右按钮)将继承不透明度。 I recommend just set hidenavbar={true} and implement custom navbar in the scene component. 我建议只设置hidenavbar = {true}并在场景组件中实现自定义导航栏。 For eg: in Scene2 component (ChallengeScreen) 例如:在Scene2组件(ChallengeScreen)中

 render() {
     const customNavbar = {
       <View style={{position:'absolute', top:0, flexDirection:'row', justifyContent:'space-between', backgroundColor:'transparent', padding:10}}>
           <TouchableOpacity>
            <Text>Left Button</Text>
           </TouchableOpacity>
           <Text>Title</Text>
           <TouchableOpacity>
              <Text>Right Button</Text>
           </TouchableOpacity>
       </View>
    }

   return () {
     <View style={{flex:1}}>
         {customNavbar}
         <View></View>
     </View>
   }
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM