SharedDialog.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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
  148. activeOpacity={1}
  149. onPress={this.wechat.bind(this)}
  150. >
  151. <View
  152. style={{
  153. flexDirection: "column",
  154. alignItems: "center",
  155. justifyContent: "center",
  156. left: 40
  157. }}
  158. >
  159. <Image
  160. style={{
  161. height: 43,
  162. width: 43
  163. }}
  164. source={require("../images/share/wechat.png")}
  165. />
  166. <Text
  167. style={{
  168. fontSize: 16,
  169. color: "black"
  170. }}
  171. >
  172. 发给到群/好友
  173. </Text>
  174. </View>
  175. </TouchableOpacity>
  176. </View>
  177. <View style={{ flex: 0.3 }} />
  178. <View
  179. style={{
  180. flex: 1
  181. }}
  182. >
  183. <TouchableOpacity
  184. activeOpacity={1}
  185. onPress={this.circle.bind(this)}
  186. >
  187. <View
  188. style={{
  189. flexDirection: "column",
  190. alignItems: "center",
  191. justifyContent: "center",
  192. right: 40
  193. }}
  194. >
  195. <Image
  196. style={{
  197. height: 43,
  198. width: 43
  199. }}
  200. source={require("../images/share/circle.png")}
  201. />
  202. <Text
  203. style={{
  204. fontSize: 16,
  205. color: "black"
  206. }}
  207. >
  208. 发朋友圈
  209. </Text>
  210. </View>
  211. </TouchableOpacity>
  212. </View>
  213. </View>
  214. </View>
  215. </View>
  216. </Modal>
  217. );
  218. }
  219. wechat() {
  220. alert("wechat");
  221. }
  222. circle() {
  223. alert("circle");
  224. }
  225. setModalVisible(visible) {
  226. this.setState({
  227. modalVisible: visible
  228. });
  229. }
  230. }
  231. /***
  232. 使用方法
  233. <SharedDialog ref={view => (this.shareddialog = view)} />
  234. this.shareddialog.setModalVisible(true);//true显示,false消失
  235. */