Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

rn_cam.native.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. // import React, { PureComponent } from 'react';
  2. // import { AppRegistry, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
  3. import { RNCamera } from 'react-native-camera';
  4. import React, { Fragment, useState, useCallback, useRef,PureComponent } from 'react';
  5. // import { StyleSheet, View, SafeAreaView, Text, Image, Modal } from 'react-native';
  6. import { StyleSheet, View, SafeAreaView, Text, Image, Modal,TouchableOpacity } from 'react-native';
  7. import Btn from 'react-native-camera/example/src/Btn';
  8. import Desc from 'react-native-camera/example/src/Desc';
  9. class ExampleApp extends PureComponent {
  10. render() {
  11. var rn_cam_styles_z = tglob_au.run_dev_cbs("rn_cam_styles",{that:this}) || {}
  12. var rn_cam_styles = rn_cam_styles_z.o
  13. return (
  14. <View style={rn_cam_styles.container || {}}>
  15. <RNCamera
  16. ref={ref => {
  17. this.camera = ref;
  18. }}
  19. style={rn_cam_styles.preview}
  20. type={RNCamera.Constants.Type.back}
  21. flashMode={RNCamera.Constants.FlashMode.on}
  22. androidCameraPermissionOptions={{
  23. title: 'Permission to use camera',
  24. message: 'We need your permission to use your camera',
  25. buttonPositive: 'Ok',
  26. buttonNegative: 'Cancel',
  27. }}
  28. /*
  29. androidRecordAudioPermissionOptions={{
  30. title: 'Permission to use audio recording',
  31. message: 'We need your permission to use your audio',
  32. buttonPositive: 'Ok',
  33. buttonNegative: 'Cancel',
  34. }}
  35. */
  36. onGoogleVisionBarcodesDetected={({ barcodes }) => {
  37. console.log(barcodes);
  38. }}
  39. />
  40. <View style={{ flex: 0, flexDirection: 'row', justifyContent: 'center' }}>
  41. <TouchableOpacity onPress={this.takePicture.bind(this)} style={rn_cam_styles.capture}>
  42. <Text style={{ fontSize: 14 }}> SNAP </Text>
  43. </TouchableOpacity>
  44. </View>
  45. </View>
  46. );
  47. }
  48. takePicture = async () => {
  49. if (this.camera) {
  50. const options = { quality: 0.5, base64: true };
  51. const data = await this.camera.takePictureAsync(options);
  52. console.log(data.uri);
  53. }
  54. };
  55. }
  56. const styles0 = StyleSheet.create({
  57. container: {
  58. flex: 1,
  59. flexDirection: 'column',
  60. backgroundColor: 'black',
  61. },
  62. preview: {
  63. flex: 1,
  64. justifyContent: 'flex-end',
  65. alignItems: 'center',
  66. },
  67. capture: {
  68. flex: 0,
  69. backgroundColor: '#fff',
  70. borderRadius: 5,
  71. padding: 15,
  72. paddingHorizontal: 20,
  73. alignSelf: 'center',
  74. margin: 20,
  75. },
  76. });
  77. const styles = StyleSheet.create({
  78. root: {
  79. padding: 50,
  80. },
  81. preview: {
  82. marginTop: 20,
  83. width: 200,
  84. height: 200,
  85. borderWidth: 1,
  86. borderColor: '#aaa',
  87. },
  88. modal: {
  89. alignSelf: 'flex-end',
  90. padding: 20,
  91. backgroundColor: '#eee',
  92. },
  93. buttons: {
  94. flexDirection: 'row',
  95. },
  96. });
  97. const ModalExample = () => {
  98. const [opened, setOpened] = useState(false);
  99. const [source, setSource] = useState(null);
  100. const modalRef = useRef();
  101. const onOpenModal = useCallback(() => setOpened(true), []);
  102. const onCapture = useCallback(uri => {
  103. setSource({ uri });
  104. setOpened(false);
  105. }, []);
  106. const onPressCapture = useCallback(() => {
  107. captureScreen().then(onCapture);
  108. }, [onCapture]);
  109. const onPressCaptureModalContent = useCallback(() => {
  110. captureRef(modalRef).then(onCapture);
  111. }, [onCapture]);
  112. return (
  113. <Fragment>
  114. <SafeAreaView>
  115. <View style={styles.root}>
  116. <Desc
  117. desc="We can notice that, in current implementation, react-native-view-shot does not
  118. screenshot Modal as part of a captureScreen."
  119. />
  120. <Btn onPress={onOpenModal} label="Open Modal" />
  121. <Image fadeDuration={0} source={source} style={styles.preview} resizeMode="contain" />
  122. </View>
  123. </SafeAreaView>
  124. <Modal transparent animated animationType="slide" visible={opened}>
  125. <SafeAreaView>
  126. <View ref={modalRef} style={styles.modal}>
  127. <Text>This is a modal</Text>
  128. <View style={styles.buttons}>
  129. <Btn onPress={onPressCapture} label="Capture Screen" />
  130. <Btn onPress={onPressCaptureModalContent} label="Capture This" />
  131. </View>
  132. </View>
  133. </SafeAreaView>
  134. </Modal>
  135. </Fragment>
  136. );
  137. };
  138. ModalExample.navigationOptions = {
  139. title: 'Modal',
  140. };
  141. export {ExampleApp,ModalExample}