11import type React from 'react' ;
2- import { useState , useRef } from 'react' ;
2+ import { useState , useRef , useEffect } from 'react' ;
33import { StyleSheet , Text , View , TouchableOpacity , Image , Animated , ScrollView } from 'react-native' ;
44import Camera from '../../src/Camera' ;
55import { type CameraApi , CameraType , type CaptureData } from '../../src/types' ;
@@ -33,7 +33,7 @@ function median(values: number[]): number {
3333 return sortedValues . length % 2 ? sortedValues [ half ] : ( sortedValues [ half - 1 ] + sortedValues [ half ] ) / 2 ;
3434}
3535
36- const CameraExample = ( { onBack } : { onBack : ( ) => void } ) => {
36+ const CameraExample = ( { onBack, stress } : { onBack : ( ) => void ; stress ?: boolean } ) => {
3737 const cameraRef = useRef < CameraApi > ( null ) ;
3838 const [ currentFlashArrayPosition , setCurrentFlashArrayPosition ] = useState ( 0 ) ;
3939 const [ captureImages , setCaptureImages ] = useState < CaptureData [ ] > ( [ ] ) ;
@@ -46,6 +46,15 @@ const CameraExample = ({ onBack }: { onBack: () => void }) => {
4646 const [ orientationAnim ] = useState ( new Animated . Value ( 3 ) ) ;
4747 const [ resize , setResize ] = useState < 'contain' | 'cover' > ( 'contain' ) ;
4848
49+ // zoom to random positions every 10ms:
50+ useEffect ( ( ) => {
51+ if ( stress !== true ) return ;
52+ const interval = setInterval ( ( ) => {
53+ setZoom ( Math . random ( ) * 10 ) ;
54+ } , 500 ) ;
55+ return ( ) => clearInterval ( interval ) ;
56+ } , [ stress ] ) ;
57+
4958 // iOS will error out if capturing too fast,
5059 // so block capturing until the current capture is done
5160 // This also minimizes issues of delayed capturing
@@ -107,7 +116,7 @@ const CameraExample = ({ onBack }: { onBack: () => void }) => {
107116 if ( ! image ) return ;
108117
109118 setCaptured ( true ) ;
110- setCaptureImages ( prev => [ ...prev , image ] ) ;
119+ setCaptureImages ( ( prev ) => [ ...prev , image ] ) ;
111120 console . log ( 'image' , image ) ;
112121 times . push ( Date . now ( ) - start ) ;
113122 }
@@ -215,10 +224,7 @@ const CameraExample = ({ onBack }: { onBack: () => void }) => {
215224
216225 < View style = { styles . cameraContainer } >
217226 { showImageUri ? (
218- < ScrollView
219- maximumZoomScale = { 10 }
220- contentContainerStyle = { { flexGrow : 1 } }
221- >
227+ < ScrollView maximumZoomScale = { 10 } contentContainerStyle = { { flexGrow : 1 } } >
222228 < Image source = { { uri : showImageUri } } style = { styles . cameraPreview } />
223229 </ ScrollView >
224230 ) : (
@@ -237,6 +243,7 @@ const CameraExample = ({ onBack }: { onBack: () => void }) => {
237243 } }
238244 torchMode = { torchMode ? 'on' : 'off' }
239245 shutterPhotoSound
246+ iOsSleepBeforeStarting = { 100 }
240247 maxPhotoQualityPrioritization = "speed"
241248 onCaptureButtonPressIn = { ( ) => {
242249 console . log ( 'capture button pressed in' ) ;
@@ -299,8 +306,7 @@ const CameraExample = ({ onBack }: { onBack: () => void }) => {
299306 } else {
300307 setShowImageUri ( captureImages [ captureImages . length - 1 ] . uri ) ;
301308 }
302- } }
303- >
309+ } } >
304310 < Image source = { { uri : captureImages [ captureImages . length - 1 ] . uri } } style = { styles . thumbnail } />
305311 </ TouchableOpacity >
306312 ) }
0 commit comments