简体   繁体   English

将react-native侧面菜单添加到我的应用程序(通过react-native元素)-应用程序在启动时崩溃

[英]Adding react-native side menu to my application (from react-native elements) - application crashes on launching

I have been trying to implement this side menu in my android application (in react native). 我一直在尝试在我的android应用程序中实现此侧面菜单 (在react native中)。 I tried modifying it by putting it in a class and adding semicolons, but the app crashes every time I launch it. 我尝试通过将其放入类中并添加分号来对其进行修改,但是每次启动该应用程序时,该应用程序都会崩溃。

here is my full code: 这是我的完整代码:

ps: my editor (visual studio code) points out an error at line 24( onSideMenuChange (isOpen: boolean) { ) but I'm not sure whats is wrong with this line. ps:我的编辑器(Visual Studio代码)在第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
          });
        };

here colon in not required, remove colon from line onSideMenuChange (isOpen) adn it will work 这里不需要冒号,请从onSideMenuChange(isOpen)行删除冒号,它将起作用

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

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