App copy.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import React from 'react'
  2. import type {Node} from 'react'
  3. import {
  4. SafeAreaView,
  5. StatusBar,
  6. StyleSheet,
  7. Text,
  8. useColorScheme,
  9. View,
  10. TouchableOpacity,
  11. Alert,
  12. } from 'react-native'
  13. import RecordScreen from 'react-native-record-screen'
  14. import FileViewer from 'react-native-file-viewer'
  15. import { RNCamera } from 'react-native-camera'
  16. import PushNotification from 'react-native-push-notification'
  17. let lastScreeRecordPath: String = ''
  18. let lastCameraPath: String = ''
  19. let cameraController: RNCamera = null
  20. let isRecorded = false
  21. const App: () => Node = () =>
  22. {
  23. return (
  24. <SafeAreaView style={ styles.safeAreaView }>
  25. <StatusBar barStyle={'light-content'}/>
  26. <View style={ styles.container }>
  27. <Button
  28. text = 'Start record'
  29. onPress = { startScreeRecord }
  30. />
  31. <Button
  32. text = 'Stop record'
  33. onPress = { stopScreeRecord }
  34. />
  35. <Button
  36. text = 'Open screen record'
  37. onPress = { openLastScreeRecord }
  38. />
  39. <Button
  40. text = 'Open camera record'
  41. onPress = { openLastCameraRecord }
  42. />
  43. <Button
  44. text = 'Send a notification'
  45. onPress = { sendANotification }
  46. />
  47. </View>
  48. <RNCamera
  49. style = { styles.cameraView }
  50. ref = { ref => cameraController = ref }
  51. type = { RNCamera.Constants.Type.front }
  52. // flashMode={RNCamera.Constants.FlashMode.on}
  53. androidCameraPermissionOptions = {{
  54. title: 'Permission to use camera',
  55. message: 'We need your permission to use your camera',
  56. buttonPositive: 'Ok',
  57. buttonNegative: 'Cancel',
  58. }}
  59. androidRecordAudioPermissionOptions = {{
  60. title: 'Permission to use audio recording',
  61. message: 'We need your permission to use your audio',
  62. buttonPositive: 'Ok',
  63. buttonNegative: 'Cancel',
  64. }}
  65. onRecordingStart = { (e) =>
  66. {
  67. console.log('--------- recording bashaldi')
  68. console.log('start res', e?.nativeEvent?.uri)
  69. lastCameraPath = e?.nativeEvent?.uri
  70. } }
  71. />
  72. </SafeAreaView>
  73. )
  74. }
  75. const sendANotification = async () => {
  76. PushNotification.localNotification({
  77. id: 5,
  78. title: "Alisa",
  79. message: "Can you return my ***",
  80. playSound: true,
  81. channelId: "testChanne4",
  82. })
  83. }
  84. const startScreeRecord = async () =>
  85. {
  86. PushNotification.localNotificationSchedule({
  87. id: 6,
  88. title: "Alisa",
  89. message: "Can you return my ***",
  90. playSound: true,
  91. channelId: "testChanne4",
  92. date: new Date(Date.now() + 6 * 1000),
  93. allowWhileIdle: false,
  94. })
  95. let result = await RecordScreen.startRecording({ mic: false })
  96. .catch((error) => Alert.alert('Error when startScreeRecord', JSON.stringify(error)))
  97. console.log('------ bura geldi', result)
  98. if(result)
  99. {
  100. cameraController.recordAsync().catch(error => console.log('Error when startCameraRecord', JSON.stringify(error)))
  101. isRecorded = true
  102. }
  103. }
  104. const stopScreeRecord = async () =>
  105. {
  106. if(!isRecorded)
  107. return
  108. isRecorded = false
  109. let res = null
  110. try
  111. {
  112. let res = await RecordScreen.stopRecording()
  113. .catch((error) =>
  114. Alert.alert('Error when stopScreeRecord', JSON.stringify(error))
  115. )
  116. if(res)
  117. {
  118. const url = res?.result?.outputURL
  119. console.log('url: ', url)
  120. lastScreeRecordPath = url
  121. }
  122. }
  123. catch(error)
  124. {
  125. Alert.alert('Error when RecordScreen.stopRecording()', JSON.stringify(error))
  126. }
  127. try
  128. {
  129. cameraController.stopRecording()
  130. }
  131. catch(error)
  132. {
  133. Alert.alert('Error when stopCameraRecord', JSON.stringify(error))
  134. }
  135. Alert.alert('Success', 'All videos saved')
  136. }
  137. const openLastScreeRecord = async () =>
  138. {
  139. if(lastScreeRecordPath?.length > 0)
  140. FileViewer.open(lastScreeRecordPath)
  141. .then(() => {
  142. console.log('----- success opened')
  143. })
  144. .catch(error => {
  145. Alert.alert('Error when openLastScreeRecord', JSON.stringify(error))
  146. console.log('----- error', error)
  147. })
  148. }
  149. const openLastCameraRecord = async () =>
  150. {
  151. console.log('------- lastCameraPath', lastCameraPath)
  152. if(lastCameraPath?.length > 0)
  153. FileViewer.open(lastCameraPath)
  154. .then(() => {
  155. console.log('----- success opened')
  156. })
  157. .catch(error => {
  158. Alert.alert('Error when openLastCameraRecord', JSON.stringify(error))
  159. console.log('----- error', error)
  160. })
  161. }
  162. const styles = StyleSheet.create({
  163. safeAreaView: {
  164. flex: 1,
  165. },
  166. container: {
  167. flex: 1,
  168. alignItems: 'center',
  169. justifyContent: 'center',
  170. },
  171. btn: {
  172. height: 50,
  173. width: '60%',
  174. marginTop: 20,
  175. alignItems: 'center',
  176. justifyContent: 'center',
  177. backgroundColor: '#3d88f5',
  178. },
  179. btnText: {
  180. fontSize: 18,
  181. color: 'white',
  182. },
  183. cameraView: {
  184. height: 1,
  185. opacity: 0,
  186. },
  187. })
  188. export default App
  189. type BtnProps = {
  190. text: String,
  191. onPress: () => void,
  192. }
  193. const Button = (props: BtnProps) => {
  194. return (
  195. <TouchableOpacity
  196. style = { styles.btn }
  197. onPress = { props.onPress }
  198. >
  199. <Text style={ styles.btnText }>{ props.text }</Text>
  200. </TouchableOpacity>
  201. )
  202. }