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