You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rn_cam.native.js 4.5KB

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