@@ -101,7 +101,8 @@ const _camera = forwardRef<HandlerRef<any, CameraProps>, CameraProps>((props: Ca
101101 parentHeight
102102 } )
103103 const { layoutRef, layoutStyle, layoutProps } = useLayout ( { props, hasSelfPercent, setWidth, setHeight, nodeRef : cameraRef } )
104- const isPhoto = mode === 'normal'
104+ const isPhoto = useRef < boolean > ( false )
105+ isPhoto . current = mode === 'normal'
105106 const device = useCameraDevice ( devicePosition || 'back' )
106107 const { navigation, pageId } = useContext ( RouteContext ) || { }
107108 const [ zoomValue , setZoomValue ] = useState < number > ( 1 )
@@ -128,7 +129,17 @@ const _camera = forwardRef<HandlerRef<any, CameraProps>, CameraProps>((props: Ca
128129 videoResolution : FRAME_SIZE_MAPPING [ frameSize ] || RESOLUTION_MAPPING [ resolution ]
129130 }
130131 ] )
131-
132+ const isScancode = useCallback ( ( fail : ( res : { errMsg : string } ) => void , complete : ( res : { errMsg : string } ) => void ) => {
133+ if ( ! isPhoto . current ) {
134+ const result = {
135+ errMsg : 'Not allow to invoke takePhoto in \'scanCode\' mode.'
136+ }
137+ fail ( result )
138+ complete ( result )
139+ return true
140+ }
141+ return false
142+ } , [ ] )
132143 const codeScanner = useCodeScanner ( {
133144 codeTypes : [ 'qr' ] ,
134145 onCodeScanned : ( codes : any [ ] ) => {
@@ -164,6 +175,7 @@ const _camera = forwardRef<HandlerRef<any, CameraProps>, CameraProps>((props: Ca
164175 } ,
165176 takePhoto : ( options : TakePhotoOptions = { } ) => {
166177 const { success = noop , fail = noop , complete = noop } = options
178+ if ( isScancode ( fail , complete ) ) return
167179 cameraRef . current ?. takePhoto ?.( {
168180 quality : qualityValue [ options . quality || 'normal' ] as number
169181 } as any ) . then ( ( res : { path : any } ) => {
@@ -185,6 +197,7 @@ const _camera = forwardRef<HandlerRef<any, CameraProps>, CameraProps>((props: Ca
185197 let { timeout = 30 , success = noop , fail = noop , complete = noop , timeoutCallback = noop } = options
186198 timeout = timeout > 300 ? 300 : timeout
187199 let recordTimer : NodeJS . Timeout | null = null
200+ if ( isScancode ( fail , complete ) ) return
188201 try {
189202 const result = {
190203 errMsg : 'startRecord:ok'
@@ -223,6 +236,7 @@ const _camera = forwardRef<HandlerRef<any, CameraProps>, CameraProps>((props: Ca
223236 } ,
224237 stopRecord : ( options : StopRecordOptions = { } ) => {
225238 const { success = noop , fail = noop , complete = noop } = options
239+ if ( isScancode ( fail , complete ) ) return
226240 try {
227241 cameraRef . current ?. stopRecording ( ) . then ( ( ) => {
228242 setTimeout ( ( ) => {
@@ -305,7 +319,7 @@ const _camera = forwardRef<HandlerRef<any, CameraProps>, CameraProps>((props: Ca
305319 onStopped,
306320 device,
307321 format,
308- codeScanner : ! isPhoto ? codeScanner : undefined ,
322+ codeScanner : ! isPhoto . current ? codeScanner : undefined ,
309323 zoom : zoomValue ,
310324 torch : flash
311325 }
0 commit comments