gpt4 book ai didi

react-native - 使用 react-native 抽屉实现侧边栏/汉堡菜单

转载 作者:行者123 更新时间:2023-12-04 05:16:58 32 4
gpt4 key购买 nike

我对 React-Native 还是很陌生。我正在尝试通过实现“ react 原生抽屉”组件将侧边栏/汉堡菜单添加到我的应用程序中。首先,我试图将 GitHub 中的示例代码添加到我的新测试项目中,以了解它是如何工作的。我面对屏幕上的错误。

如果我得到一些帮助,那会让我非常高兴。或者你能告诉我更简单的方法来为我的项目实现侧边栏/汉堡菜单。

import Drawer from 'react-native-drawer';
import React, {Component} from 'react';
import SideBarContent from '../common/SideBarContent';
import {Text,View} from 'react-native';

class SideBar extends Component{

closeControlPanel = () => {
this._drawer.close()
};
openControlPanel = () => {
this._drawer.open()
};

render()
{
const drawerStyles = {
drawer: { shadowColor: '#000000', shadowOpacity: 0.8, shadowRadius: 3},
main: {paddingLeft: 3},
}


return (
<Drawer
type="static"
content={<SideBarContent/>}
openDrawerOffset={100}
styles={drawerStyles}
tweenHandler={Drawer.tweenPresets.parallax}
>
<View><Text>Drawer</Text></View>
</Drawer>
);
}
}

这是我的 SideBarContent 组件。

import React, {Component} from 'react';
import {Text,View} from 'react-native';


class SideBarContent extends Component{
render()
{
return(
<View>
<Text>Order History</Text>
<Text>Account</Text>
<Text>Basket</Text>
<Text>About us</Text>
</View>
);
}
}

enter image description here

最佳答案

由于我不在系统上,所以没有检查代码的工作情况,但这应该可以工作。

import Drawer from 'react-native-drawer';
import React, {Component} from 'react';
import SideBarContent from '../common/SideBarContent';
import {Text,View} from 'react-native';

export default class SideBar extends Component{

constructor(){
super();
this.closeControlPanel = this.closeControlPanel.bind(this);
this.openControlPanel = this.openControlPanel.bind(this);
}

closeControlPanel = () => {
this._drawer.close()
};
openControlPanel = () => {
this._drawer.open()
};

render()
{
const drawerStyles = {
drawer: { shadowColor: '#000000', shadowOpacity: 0.8, shadowRadius: 3},
main: {paddingLeft: 3},
}

return (
<Drawer
type="static"
content={<SideBarContent />}
ref = {(ref) => this._drawer = ref}
openDrawerOffset={100}
styles={drawerStyles}
tweenHandler={Drawer.tweenPresets.parallax}
>
<View>
<Text onPress={this.openControlPanel}>
Drawer
</Text>
</View>
</Drawer>
);
}
}

另一个文件 SideBarContent

 import React, {Component} from 'react';
import {Text,View} from 'react-native';


export default class SideBarContent extends Component{
constructor() {
super();
}
render()
{
return(
<View>
<Text>Order History</Text>
<Text>Account</Text>
<Text>Basket</Text>
<Text>About us</Text>
</View>
);
}
}

如果有任何问题请告诉我..

关于react-native - 使用 react-native 抽屉实现侧边栏/汉堡菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42747087/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com