我是新手,我尝试使用
制作社交媒体按钮import { SocialIcon } from 'react-native-elements';
并使用
<SocialIcon type='facebook'/>
但如何在OnPress( )
中发送网址。 ?
答案 0 :(得分:1)
开始链接的相应活动(网址,电子邮件, 联系等),致电:
Linking.openURL(url).catch(err => console.error('An error occurred', err));
您可以将url
换成真实网址,将其包含在传递到SocialIcon
组件的onPress
道具中的非常具体的处理程序中,或者(这很多)更多React-y),您可以创建一个可重用的组件,即:
class SocialButton extends Component {
static propTypes = {
url: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
};
handleClick = () => {
Linking.openURL(this.props.url).catch(err => console.error("An error occurred", err));
};
render() {
return <SocialIcon type={this.props.type} url={this.props.url} onPress={this.handleClick} />;
}
}
并按以下方式使用:
<SocialButton type="facebook" url="https://www.facebook.com/wonderloveapp/" />