Guest User

Untitled

a guest
May 28th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.77 KB | None | 0 0
  1. import React, {Component} from 'react';
  2. import {Text, View, TouchableOpacity, Image,TouchableHighlight,Vibration} from 'react-native';
  3. //import Camera from 'react-native-camera';
  4. import {Camera, Permissions,} from 'expo';
  5.  
  6. const myStyle = {
  7. container: {
  8. flex: 1,
  9. flexDirection: 'row',
  10. },
  11. preview: {
  12. flex: 1,
  13. justifyContent: 'flex-end',
  14. alignItems: 'center'
  15. },
  16. capture: {
  17. flex: 0,
  18. backgroundColor: '#fff',
  19. borderRadius: 5,
  20. color: 'red',
  21. padding: 10,
  22. margin: 40
  23. },
  24. main2: {
  25. flex: 1,
  26. //alignItems: 'flex-start',
  27. flexDirection: 'row',
  28. justifyContent: 'space-between',
  29. },
  30. main: {
  31. flex: 1,
  32. },
  33. borda: {
  34. //flex: 0.1,
  35. alignItems: 'flex-end',
  36. backgroundColor: 'black',
  37. height: 110,
  38. },
  39. borda2: {
  40. backgroundColor: 'black',
  41. width: 60,
  42. },
  43. borda3: {
  44. width: 60,
  45. backgroundColor: 'black',
  46. },
  47. borda4: {
  48. height: 120,
  49. backgroundColor: 'black',
  50. //flex: 1,
  51. alignItems: 'center',
  52. flexDirection: 'row',
  53. justifyContent:'space-between',
  54. },
  55. texto:{
  56. fontSize: 18,
  57. marginBottom: 40,
  58. color: 'white',
  59. },
  60. textoButton:{
  61. fontSize: 18,
  62. color: 'white',
  63. marginTop: 5,
  64. },
  65. button:{
  66. alignSelf: 'flex-end',
  67. alignItems: 'center',
  68. backgroundColor:'transparent',
  69. flexDirection: 'row',
  70. justifyContent:'space-between'
  71. },
  72. cameraStyle:{
  73. width: 70,
  74. height: 57,
  75. //margin:30,
  76. alignItems: 'center',
  77. tintColor: 'white',
  78. },
  79. flipStyle:{
  80. width: 52,
  81. height: 57,
  82. marginLeft:10,
  83. alignItems: 'center',
  84. tintColor: 'white',
  85. },
  86. gallerystyle:{
  87. width: 64,
  88. height: 57,
  89. marginLeft:10,
  90. alignItems: 'center',
  91. tintColor: 'white',
  92. marginRight: 10,
  93. },
  94. closeStyle:{
  95. width: 56,
  96. height: 57,
  97. marginTop: 30,
  98. marginRight: 20,
  99. alignItems: 'flex-end',
  100. tintColor: 'white',
  101. justifyContent:'flex-end'
  102. },
  103. box:{
  104. width: 'auto',
  105. justifyContent: 'space-between',
  106. flexDirection: 'column',
  107. alignItems: 'center',
  108. },
  109. };
  110.  
  111. export default class CameraAcess extends Component {
  112. constructor(props) {
  113. super(props);
  114. this.state = {hasCameraPermission: null, type: Camera.Constants.Type.back,};
  115. }
  116.  
  117. async componentWillMount() {
  118. const {status} = await Permissions.askAsync(Permissions.CAMERA);
  119. this.setState({hasCameraPermission: status === 'granted'});
  120. }
  121. snap = async function(){
  122. if (this.camera) {
  123. this.camera.takePictureAsync().then(data => {
  124. FileSystem.moveAsync({
  125. from: data,
  126. to: '${FileSystem.documentDirectory}photos/Photo_${this.state .photoId}.jpg',
  127. }).then(() => {
  128. this.setState({
  129. photoId: this.state.photoId + 1,
  130. });
  131. Vibration.vibrate();
  132. })
  133. .catch((e) => {
  134. console.log(e, 'ERROR');
  135. });
  136. })
  137. .catch((e) => {
  138. console.log(e, 'takePicture ERROR');
  139. });
  140. }
  141. console.log('I took the picture');
  142. };
  143.  
  144.  
  145. cameraPhoto = require('./Images/camera.png');
  146. flipPhoto = require('./Images/flip.png');
  147. closePhoto = require('./Images/close.png');
  148. galleryPhoto = require('./Images/gallery.png');
  149.  
  150. render() {
  151. const { main,main2, borda, borda2, borda3,borda4,cameraStyle,flipStyle,closeStyle,box,textoButton,gallerystyle} = myStyle;
  152. const {hasCameraPermission} = this.state;
  153. if (hasCameraPermission === null) {
  154. return <View/>;
  155. } else if (hasCameraPermission === false) {
  156. return <Text>No access to camera</Text>;
  157. } else {
  158. return (
  159. <View style={main}>
  160. <Camera style={main} type={this.state.type}>
  161. <TouchableHighlight onPress={() => {this.props.navigator.push({id: 'MenuPrincipal'});}}
  162. style={borda} underlayColor={'black'} activeOpacity={0.6}>
  163. <Image source={this.closePhoto} style={[closeStyle]}/>
  164. </TouchableHighlight>
  165. <View style={main2}>
  166. <View style={[borda2]}/>
  167. <View style={[borda3]}/>
  168. </View>
  169. <View style={[borda4]}>
  170. <TouchableOpacity onPress={() => {this.setState({type: this.state.type === Camera.Constants.Type.back
  171. ? Camera.Constants.Type.front : Camera.Constants.Type.back,});}}>
  172. <View style={box}>
  173. <Image source={this.flipPhoto} style={[flipStyle]}/>
  174. <Text style={textoButton}>
  175. Flip
  176. </Text>
  177. </View>
  178. </TouchableOpacity>
  179.  
  180. <TouchableOpacity onPress={() => {this.snap()}}>
  181. <View style={box}>
  182. <Image source={this.cameraPhoto} style={[cameraStyle]}/>
  183. <Text style={textoButton}>
  184. Capture
  185. </Text>
  186. </View>
  187. </TouchableOpacity>
  188.  
  189. <TouchableOpacity onPress={() => {false}}>
  190. <View style={box}>
  191. <Image source={this.galleryPhoto} style={[gallerystyle]}/>
  192. <Text style={textoButton}>
  193. Gallery
  194. </Text>
  195. </View>
  196. </TouchableOpacity>
  197. </View>
  198. </Camera>
  199. </View>
  200. );
  201. }
  202. }
  203. }
Add Comment
Please, Sign In to add comment