prevent freezing when opened 2 times via navigator (http://stackoverflow.com/questions/33046061/) (#380)

This commit is contained in:
matejkriz 2016-09-13 05:31:46 +02:00 committed by Zack Story
parent ae88ac7405
commit f4bf30e17b
1 changed files with 5 additions and 1 deletions

View File

@ -34,7 +34,10 @@ RCT_EXPORT_MODULE();
self.previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:self.session];
self.previewLayer.needsDisplayOnBoundsChange = YES;
return [[RCTCamera alloc] initWithManager:self bridge:self.bridge];
if(!self.camera){
self.camera = [[RCTCamera alloc] initWithManager:self bridge:self.bridge];
}
return self.camera;
}
- (NSDictionary *)constantsToExport
@ -434,6 +437,7 @@ RCT_EXPORT_METHOD(hasFlash:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRej
return;
#endif
dispatch_async(self.sessionQueue, ^{
self.camera = nil;
[self.previewLayer removeFromSuperlayer];
[self.session commitConfiguration];
[self.session stopRunning];