【问题标题】:NativeBase Drawer PropsNativeBase 抽屉道具
【发布时间】:2018-05-22 18:04:56
【问题描述】:

是否可以在抽屉侧边栏传递道具(侧边栏是我的自定义组件)。在此示例中,测试道具未显示在 SideBar 中

render () {
 const sideBar = <SideBar onRest={this.changeToRest} test="12" />
    return (
      <Drawer ref={ref => (this.drawer = ref)} content={sideBar}>
....

【问题讨论】:

    标签: react-native native-base


    【解决方案1】:

    是的,可以将道具传递给侧边栏自定义组件

    <SideBar onRest={this.changeToRest} test="12" />
    
    1.Here you can pass the test="12" as a props 
    
    2.You can get the props at the sidebar component {this.props.test} like that
    

    【讨论】:

    • 是的,我做的完全一样,但在 SideBar {this.props.test} 中没有显示
    • 你在使用侧边栏自定义组件吗?
    • 不只是export class SideBar extends Component {
    【解决方案2】:

    您可以将 Sidebar 组件添加到 Drawer DrawerNavigator,如下所示

    const DrawerNav = DrawerNavigator({
        MainScreen: {
            screen: TabNav
        },
        ProfileScreen: {
            screen: ProfileNav
        },
        NotificationScreen : {
            screen: NotificationNav
    
        },
        RewardScreen: {
            screen : RewardNav
        }
    
    
    },{
        drawerPosition: 'left',
        initialRouteName: 'MainScreen',
        contentComponent: props => <SideBarNav {...props} test="12"/>
    });
    

    【讨论】:

    • 然后将&lt;Drawer ref={ref =&gt; (this.drawer = ref)} content={sideBar}&gt; 更改为``` (this.drawer = ref)} >```?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-09
    • 1970-01-01
    • 1970-01-01
    • 2014-12-23
    • 1970-01-01
    • 2020-12-11
    相关资源
    最近更新 更多