@@ -330,6 +330,7 @@ export class Camera extends React.PureComponent<CameraProps> {
330
330
}
331
331
//#endregion
332
332
333
+ //#region Lifecycle
333
334
/**
334
335
* @internal
335
336
*/
@@ -339,40 +340,45 @@ export class Camera extends React.PureComponent<CameraProps> {
339
340
throw new Error ( 'Frame Processors are not enabled. Make sure you install react-native-reanimated 2.2.0 or above!' ) ;
340
341
}
341
342
343
+ private setFrameProcessor ( frameProcessor : ( frame : Frame ) => void ) : void {
344
+ this . assertFrameProcessorsEnabled ( ) ;
345
+ // @ts -expect-error JSI functions aren't typed
346
+ global . setFrameProcessor ( this . handle , frameProcessor ) ;
347
+ }
348
+
349
+ private unsetFrameProcessor ( ) : void {
350
+ this . assertFrameProcessorsEnabled ( ) ;
351
+ // @ts -expect-error JSI functions aren't typed
352
+ global . setFrameProcessor ( this . handle , this . props . frameProcessor ) ;
353
+ }
354
+
342
355
/**
343
356
* @internal
344
357
*/
345
358
componentWillUnmount ( ) : void {
346
- if ( this . lastFrameProcessor != null || this . props . frameProcessor != null ) {
347
- this . assertFrameProcessorsEnabled ( ) ;
348
- // @ts -expect-error JSI functions aren't typed
349
- global . unsetFrameProcessor ( this . handle ) ;
350
- }
359
+ if ( this . lastFrameProcessor != null || this . props . frameProcessor != null ) this . unsetFrameProcessor ( ) ;
360
+ }
361
+
362
+ /**
363
+ * @internal
364
+ */
365
+ componentDidMount ( ) : void {
366
+ if ( this . props . frameProcessor != null ) this . setFrameProcessor ( this . props . frameProcessor ) ;
351
367
}
352
368
353
369
/**
354
370
* @internal
355
371
*/
356
372
componentDidUpdate ( ) : void {
357
373
if ( this . props . frameProcessor !== this . lastFrameProcessor ) {
358
- this . assertFrameProcessorsEnabled ( ) ;
359
- // frameProcessor argument changed. Update native to reflect the change.
360
- if ( this . props . frameProcessor != null ) {
361
- // 1. Spawn threaded JSI Runtime (if not already done)
362
- // 2. Add video data output to Camera stream (if not already done)
363
- // 3. Workletize the frameProcessor and prepare it for being called with frames
364
- // @ts -expect-error JSI functions aren't typed
365
- global . setFrameProcessor ( this . handle , this . props . frameProcessor ) ;
366
- } else {
367
- // 1. Destroy the threaded runtime
368
- // 2. remove the frame processor
369
- // 3. Remove the video data output
370
- // @ts -expect-error JSI functions aren't typed
371
- global . unsetFrameProcessor ( this . handle ) ;
372
- }
374
+ // frameProcessor argument identity changed. Update native to reflect the change.
375
+ if ( this . props . frameProcessor != null ) this . setFrameProcessor ( this . props . frameProcessor ) ;
376
+ else this . unsetFrameProcessor ( ) ;
377
+
373
378
this . lastFrameProcessor = this . props . frameProcessor ;
374
379
}
375
380
}
381
+ //#endregion
376
382
377
383
/**
378
384
* @internal
0 commit comments