SharedDialog.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /**
  2. * Sample React Native App
  3. * https://github.com/facebook/react-native
  4. *
  5. * @format
  6. * @flow
  7. */
  8. import React, { Component } from 'react';
  9. import {
  10. Platform,
  11. StyleSheet,
  12. Text,
  13. View,
  14. Image,
  15. TouchableOpacity,
  16. ImageBackground,
  17. TextInput,
  18. Button,
  19. StatusBar,
  20. Modal,
  21. TouchableHighlight,
  22. DeviceEventEmitter
  23. } from 'react-native';
  24. type Props = {};
  25. export default class SharedDialog extends Component<Props> {
  26. state = {
  27. modalVisible: false
  28. };
  29. setModalVisible(visible) {
  30. this.setState({
  31. modalVisible: visible
  32. });
  33. }
  34. render() {
  35. return (
  36. <Modal
  37. animationType="slide"
  38. transparent={true}
  39. visible={this.state.modalVisible}
  40. onRequestClose={() => {
  41. this.setState({ modalVisible: false });
  42. }}
  43. >
  44. <View
  45. style={{
  46. flex: 1,
  47. flexDirection: 'column'
  48. }}
  49. >
  50. <TouchableOpacity
  51. style={{
  52. flex: 3.5,
  53. backgroundColor: 'rgba(0, 0, 0, 0.5)',
  54. width: '100%'
  55. }}
  56. activeOpacity={1}
  57. onPress={() => this.setState({ modalVisible: false })}
  58. >
  59. <View
  60. style={{
  61. flex: 3.5,
  62. width: '100%'
  63. }}
  64. />
  65. </TouchableOpacity>
  66. <View
  67. style={{
  68. flex: 1,
  69. width: '100%'
  70. }}
  71. >
  72. <View
  73. style={{
  74. flex: 1.5,
  75. width: '100%',
  76. flexDirection: 'row',
  77. backgroundColor: 'white'
  78. }}
  79. >
  80. <View
  81. style={{
  82. flex: 1,
  83. width: '100%',
  84. alignItems: 'center',
  85. justifyContent: 'center'
  86. }}
  87. >
  88. <View
  89. style={{
  90. height: 2,
  91. left: 40,
  92. backgroundColor: '#979797',
  93. width: '60%'
  94. }}
  95. />
  96. </View>
  97. <View
  98. style={{
  99. flex: 1,
  100. width: '100%',
  101. alignItems: 'center',
  102. justifyContent: 'center'
  103. }}
  104. >
  105. <Text
  106. style={{
  107. fontSize: 18,
  108. color: 'black'
  109. }}
  110. >
  111. 分享
  112. </Text>
  113. </View>
  114. <View
  115. style={{
  116. flex: 1,
  117. alignItems: 'center',
  118. justifyContent: 'center',
  119. width: '100%'
  120. }}
  121. >
  122. <View
  123. style={{
  124. height: 2,
  125. right: 40,
  126. backgroundColor: '#979797',
  127. width: '60%'
  128. }}
  129. />
  130. </View>
  131. </View>
  132. <View
  133. style={{
  134. flex: 2,
  135. backgroundColor: 'white',
  136. flexDirection: 'row',
  137. justifyContent: 'center',
  138. width: '100%'
  139. }}
  140. >
  141. <View
  142. style={{
  143. flex: 1,
  144. alignItems: 'center'
  145. }}
  146. >
  147. <TouchableOpacity activeOpacity={1} onPress={this.wechat.bind(this)}>
  148. <View
  149. style={{
  150. flexDirection: 'column',
  151. alignItems: 'center',
  152. justifyContent: 'center',
  153. left: 40
  154. }}
  155. >
  156. <Image
  157. style={{
  158. height: 43,
  159. width: 43
  160. }}
  161. source={require('../images/share/wechat.png')}
  162. />
  163. <Text
  164. style={{
  165. fontSize: 16,
  166. color: 'black'
  167. }}
  168. >
  169. 发给到群/好友
  170. </Text>
  171. </View>
  172. </TouchableOpacity>
  173. </View>
  174. <View style={{ flex: 0.3 }} />
  175. <View
  176. style={{
  177. flex: 1
  178. }}
  179. >
  180. <TouchableOpacity activeOpacity={1} onPress={this.circle.bind(this)}>
  181. <View
  182. style={{
  183. flexDirection: 'column',
  184. alignItems: 'center',
  185. justifyContent: 'center',
  186. right: 40
  187. }}
  188. >
  189. <Image
  190. style={{
  191. height: 43,
  192. width: 43
  193. }}
  194. source={require('../images/share/circle.png')}
  195. />
  196. <Text
  197. style={{
  198. fontSize: 16,
  199. color: 'black'
  200. }}
  201. >
  202. 发朋友圈
  203. </Text>
  204. </View>
  205. </TouchableOpacity>
  206. </View>
  207. </View>
  208. </View>
  209. </View>
  210. </Modal>
  211. );
  212. }
  213. wechat() {
  214. this.setModalVisible(false);
  215. this.props.friend();
  216. }
  217. circle() {
  218. this.setModalVisible(false);
  219. this.props.CircleOfFriends();
  220. }
  221. setModalVisible(visible) {
  222. this.setState({
  223. modalVisible: visible
  224. });
  225. }
  226. }
  227. /***
  228. 使用方法
  229. <SharedDialog ref={view => (this.shareddialog = view)} />
  230. this.shareddialog.setModalVisible(true);//true显示,false消失
  231. */