图像中有错误。 我正在尝试使用右侧菜单制作应用程序。我做了很多尝试,我几乎成功使用了react bootstrap,但实际上没有成功。现在,我尝试使用此弹出菜单,但出现很多错误。幸运的是,我解决了大多数问题,但是我不知道如何解决这一问题。我希望该菜单打开我创建并称为设置的第二个页面(屏幕)。我希望它可以打开网站的链接。有人知道如何解决此错误吗? 这是我的代码: 主页:
import React from 'react';
import {Text,View,Button,Icon} from 'react-native';
import PopupMenu from './popupmenu';
onPopupEvent = (eventName, index) => {
if (eventName !== 'itemSelected') return
if (index === 0) showSettins = () =>{this.props.navigation.navigate('Settings');}
else showSettins = () =>{this.props.navigation.navigate('Settings');}
}
export default class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Home',
headerRight:(
<PopupMenu actions={['Settings']} onPress={this.onPopupEvent} />
),
};
render() {
const {navigate} = this.props.navigation;
return (
<View>
<Text>Home</Text>
</View>
);
}
}
弹出菜单页面:
import React, { Component} from 'react'
import PropTypes from 'prop-types'
import { View, UIManager, findNodeHandle, TouchableOpacity } from 'react-native'
import Icon from 'react-native-vector-icons/MaterialIcons'
const ICON_SIZE = 24
export default class PopupMenu extends Component {
static propTypes = {
// array of strings, will be list items of Menu
actions: PropTypes.arrayOf(PropTypes.string).isRequired,
onPress: PropTypes.func.isRequired
}
constructor (props) {
super(props)
this.state = {
icon: null
}
}
onError () {
console.log('Popup Error')
}
onPress = () => {
if (this.state.icon) {
UIManager.showPopupMenu(
findNodeHandle(this.state.icon),
this.props.actions,
this.onError,
this.props.onPress
)
}
}
render () {
return (
<View>
<TouchableOpacity onPress={this.onPress}>
<Icon
name='more-vert'
size={ICON_SIZE}
color={'grey'}
ref={this.onRef} />
</TouchableOpacity>
</View>
)
}
onRef = icon => {
if (!this.state.icon) {
this.setState({icon})
}
}
}