native 封装选择弹出框示例(试用ios&android)(2)

const selectedArr = ["拍照", "图库"]; class Demo extends Component { constructor(props) { super(props); this.showAlertSelected = this.showAlertSelected.bind(this); this.callbackSelected = this.callbackSelected.bind(this); } showAlertSelected(){ this.dialog.show("请选择照片", selectedArr, '#333333', this.callbackSelected); } // 回调 callbackSelected(i){ switch (i){ case 0: // 拍照 this.takePhoto(); break; case 1: // 图库 this.pickMultiple(); break; } } render() { return ( <View style={stylesCommon.container}> <TouchableOpacity onPress={() => {this.showAlertSelected();}}> <View style={styles.imageBorder}> <Text style={styles.photoText}></Text> </View> </TouchableOpacity> <DialogSelected ref={(dialog)=>{ this.dialog = dialog; }} /> </View> ); } }

再来一张其他界面调用该组件的效果图~

native 封装选择弹出框示例(试用ios&android)

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyfygg.html