PopupWindow.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import React from 'react'
  2. import Global from '../utils/Global';
  3. import Toast from '@remobile/react-native-toast';
  4. import {Dimensions, Image, Modal, StyleSheet, Text, TouchableOpacity, View} from 'react-native'
  5. const {width, height} = Dimensions.get('window');
  6. let mwidth = 180;
  7. let mheight = 220;
  8. const bgColor = Global.titleBackgroundColor;
  9. const top = 50;
  10. let dataArray;
  11. export default class MenuModal extends React.Component {
  12. constructor(props) {
  13. super(props);
  14. this.state = {
  15. isVisible: this.props.show,
  16. }
  17. mwidth = this.props.width;
  18. mheight = this.props.height;
  19. dataArray = this.props.dataArray;
  20. }
  21. componentWillReceiveProps(nextProps) {
  22. this.setState({isVisible: nextProps.show});
  23. }
  24. closeModal() {
  25. this.setState({
  26. isVisible: false
  27. });
  28. this.props.closeModal(false);
  29. }
  30. render() {
  31. var menuItems = [];
  32. var icons = this.props.menuIcons;
  33. var texts = this.props.menuTexts;
  34. for (var i = 0; i < icons.length; i++) {
  35. menuItems.push(
  36. <TouchableOpacity key={i} activeOpacity={0.3} onPress={this.handlePopMenuItemClick} style={styles.itemView}>
  37. <Image style={styles.imgStyle} source={icons[i]}/>
  38. <Text style={styles.textStyle}>{texts[i]}</Text>
  39. </TouchableOpacity>
  40. );
  41. }
  42. return (
  43. <View style={styles.container}>
  44. <Modal
  45. transparent={true}
  46. visible={this.state.isVisible}
  47. animationType={'fade'}
  48. onRequestClose={() => this.closeModal()}>
  49. <TouchableOpacity style={styles.container} onPress={() => this.closeModal()}>
  50. <View style={styles.modal}>
  51. {menuItems}
  52. </View>
  53. </TouchableOpacity>
  54. </Modal>
  55. </View>
  56. )
  57. }
  58. handlePopMenuItemClick = () => {
  59. Toast.showShortCenter('Click menu item');
  60. this.closeModal();
  61. }
  62. }
  63. const styles = StyleSheet.create({
  64. container: {
  65. width: width,
  66. height: height,
  67. },
  68. modal: {
  69. backgroundColor: bgColor,
  70. width: mwidth,
  71. height: mheight,
  72. position: 'absolute',
  73. left: width - mwidth - 10,
  74. top: top,
  75. padding: 5,
  76. justifyContent: 'center',
  77. alignItems: 'center',
  78. },
  79. itemView: {
  80. flexDirection: 'row',
  81. alignItems: 'center',
  82. flex: 1,
  83. width: mwidth,
  84. paddingLeft: 10,
  85. paddingRight: 10,
  86. paddingTop: 8,
  87. paddingBottom: 8,
  88. },
  89. textStyle: {
  90. color: '#fff',
  91. fontSize: 16,
  92. marginLeft: 5,
  93. },
  94. imgStyle: {
  95. width: 32,
  96. height: 32,
  97. marginTop: 5,
  98. marginBottom: 5,
  99. marginLeft: 5,
  100. marginRight: 5,
  101. }
  102. });