我一直在尝试实现这个side menu在我的 Android 应用程序中(在 native react 中)。我尝试通过将其放入类中并添加分号来修改它,但每次启动应用程序都会崩溃。
这是我的完整代码:
ps:我的编辑器(Visual Studio Code)指出第 24 行有一个错误(onSideMenuChange (isOpen: boolean) {
),但我不确定这一行有什么问题。
import { SideMenu, List, ListItem } from 'react-native-elements';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
export default class myApp extends Component {
constructor () {
super();
this.state = {
isOpen: false
};
this.toggleSideMenu = this.toggleSideMenu.bind(this);
}
onSideMenuChange (isOpen: boolean) //error: [js] 'types' can only be used in a .ts file.
{
this.setState({
isOpen: isOpen
});
};
toggleSideMenu () {
this.setState({
isOpen: !this.state.isOpen
});
};
render () {
const MenuComponent = (
<View style={{flex: 1, backgroundColor: '#ededed', paddingTop: 50}}>
<List containerStyle={{marginBottom: 20}}>
{
list.map((l, i) => (
<ListItem
roundAvatar
onPress={() => console.log('Pressed')}
avatar={l.avatar_url}
key={i}
title={l.name}
subtitle={l.subtitle}
/>
))
}
</List>
</View>
)
return (
<SideMenu
isOpen={this.state.isOpen}
onChange={this.onSideMenuChange.bind(this)}
menu={MenuComponent}>
<App toggleSideMenu={this.toggleSideMenu.bind(this)} />
</SideMenu>
);
}
}
AppRegistry.registerComponent('myApp', () => myApp);
最佳答案
onSideMenuChange (isOpen: boolean) //error: [js] 'types' can only be used in a .ts file.
{
this.setState({
isOpen: isOpen
});
};
此处不需要冒号,从 onSideMenuChange (isOpen) 行中删除冒号即可使用
关于javascript - 将 react native 侧菜单添加到我的应用程序(来自 react native 元素) - 应用程序在启动时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45204127/