打开react-native-sidebar onPress

时间:2017-04-06 07:30:38

标签: android ios reactjs react-native jsx

O /

我最近开始使用react-native并制作了几个较小的测试应用程序。 我的最新项目应该包括侧边栏菜单,我react-native-sidebar。但我似乎无法弄清楚我打算如何打开侧边栏 - 遗憾的是他们的文档没有提供任何关于任何事情的信息。

代码:

renderLeftSidebar()
{
   return <Text>LEFT SIDE BAR CONTENT</Text>        
}

renderContent()
{
    return(<Button onPress={___OPEN__SIDEBAR___}><Text>Open Sidebar</Text></Button>)   
}

render() {
    return (
        <Sidebar leftSidebar         = { this.renderLeftSidebar() }
                 open                = 'left'
                 style               = {styles.leftSidebarContainer}>
            { this.renderContent() }
        </Sidebar>
    )
}

const styles = StyleSheet.create({

leftSidebarContainer:
{
    flex: 1,
},
});

因为我设置侧边栏打开='左'它开始打开,但我如何更改它 - 所以它只是在我按下我的按钮时打开?

1 个答案:

答案 0 :(得分:0)

自己弄清楚,我必须为侧边栏设置参考:

ref = {(c) => this._leftsidebar = c}

然后只需致电:

this._sidebar.open('left')