0

我正在使用抽屉菜单,我需要为每个菜单项添加图标。如何添加图标以使它们显示在 eah 活动名称之前?

我的代码 -

class SideMenu extends Component {

    renderMenu() {
        let menuArray = [
            {
                id:1,
                screen: 'HomeDrawer',
                title: 'Dashboard',
            },
            {
                id:2,
                screen: 'AccountSettings',
                title: 'Account Settings',
            },
            {
                id:3,
                screen: 'NotificationSettings',
                title: 'Notification Settings',
            }
        ]

        return menuArray.map((item) => {
            return(
                <TouchableWithoutFeedback 
                    onPress={this.navigateToScreen(item.screen)} key={item.id}>
                    <View style={styles.menuItemContainer}>
                        <View  style={{ flex:2 }}>
                            <Text style={styles.menuText}>{item.title}</Text>
                        </View>
                    </View>
                </TouchableWithoutFeedback>
            )
        })
    }

    render() {
        return(
            <View style={{ flex:1, backgroundColor:'#FFFFFF' }}>
                <ScrollView>
                    <View style={{ height: '30%', marginBottom: 50}}>         
                    <LinearGradient 
                        start={{ x: 0, y:0 }}
                        end={{ x: 1, y: 0 }}
                        colors={['#1865e5', '#159af6']}
                        style={{height: 200}} >         


                    <View style={{ elevation: 5,}}>
                        <Image
                            source={require('../assets/logo.png')}
                            style={{ height:100, width:100, marginLeft: 10, marginTop: 30, marginBottom: 10 }}
                        />
                    </View>

                    <View>
                    {
                            this.state.userDetails ?

                            <View>

                                    <Text style={{ fontWeight: "bold", fontSize:15, color: '#FFFFFF', marginLeft: 10 }}>{this.state.userDetails && this.state.userDetails.Details[0].name}</Text>
                                    <Text style={{ fontSize:14, color: '#FFFFFF', marginLeft: 10 }}>{this.state.userDetails && this.state.userDetails.Details[0].email}</Text>
                            </View>

                            :
                            <Text>Loading...</Text>
                    }

                    </View>                    
                    </LinearGradient>  
                    </View>                  
                    { this.renderMenu() }

                    <TouchableWithoutFeedback 
                        onPress={ () => {
                            Alert.alert(
                                'Logout',
                                'Are you sure you want to logout?',
                                [
                                  {text: 'No', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
                                  {text: 'Yes', onPress: () => {

                                    AsyncStorage.removeItem('userDetails', () => 
                                    {

                                    });
                                    this.navigateToScreen('Login')();
                                  }},
                                ],
                                { cancelable: false }
                              )
                        }}>
                        <View style={styles.menuItemContainer}>
                            <View  style={{ flex:3 }}>
                                <Text style={styles.menuText}>Logout</Text>
                            </View>
                        </View>
                    </TouchableWithoutFeedback>

                </ScrollView>
            </View>
        )
    }
}

})

export default SideMenu

达到 -

需要添加这些位于每个选项卡左侧的图标

尝试icon为每个 id 和图像添加属性,但不幸的是它没有按预期工作。

如何添加资产文件夹中的图标,以便它可以按照与此问题一起附加的设计显示?

4

1 回答 1

1

您必须制作自定义侧边栏以增加添加图标的灵活性。

于 2018-06-13T12:08:06.787 回答