diff --git a/Camera.js b/Camera.js index 6ee4c6c..81e20d0 100644 --- a/Camera.js +++ b/Camera.js @@ -67,6 +67,7 @@ export default class Camera extends Component { PropTypes.string, PropTypes.number ]), + keepAwake: PropTypes.bool, onBarCodeRead: PropTypes.func, onFocusChanged: PropTypes.func, onZoomChanged: PropTypes.func, diff --git a/README.md b/README.md index dd1e869..3b1659a 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,10 @@ If `defaultOnFocusComponent` set to false, default internal implementation of vi Called when focus has changed. By default, `onZoomChanged` is not defined and pinch-to-zoom is disabled. +#### `iOS` `keepAwake` + +If set to `true`, the device will not sleep while the camera preview is visible. This mimics the behavior of the default camera app, which keeps the device awake while open. + ## Component instance methods You can access component methods by adding a `ref` (ie. `ref="camera"`) prop to your `` element, then you can use `this.refs.camera.capture(cb)`, etc. inside your component. diff --git a/ios/RCTCamera.m b/ios/RCTCamera.m index bbf0e2d..0d3b185 100644 --- a/ios/RCTCamera.m +++ b/ios/RCTCamera.m @@ -16,6 +16,7 @@ BOOL _onFocusChanged; BOOL _defaultOnFocusComponent; BOOL _onZoomChanged; + BOOL _previousIdleTimerDisabled; } - (void)setAspect:(NSInteger)aspect @@ -90,6 +91,13 @@ } } +- (void)setKeepAwake:(BOOL)enabled +{ + if (enabled) { + [UIApplication sharedApplication].idleTimerDisabled = true; + } +} + - (id)initWithManager:(RCTCameraManager*)manager bridge:(RCTBridge *)bridge { @@ -104,6 +112,7 @@ _onFocusChanged = NO; _defaultOnFocusComponent = YES; _onZoomChanged = NO; + _previousIdleTimerDisabled = [UIApplication sharedApplication].idleTimerDisabled; } return self; } @@ -133,6 +142,7 @@ [self.manager stopSession]; [super removeFromSuperview]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]; + [UIApplication sharedApplication].idleTimerDisabled = _previousIdleTimerDisabled; } - (void)orientationChanged:(NSNotification *)notification{ diff --git a/ios/RCTCameraManager.m b/ios/RCTCameraManager.m index e375329..3687ec3 100644 --- a/ios/RCTCameraManager.m +++ b/ios/RCTCameraManager.m @@ -30,6 +30,7 @@ RCT_EXPORT_VIEW_PROPERTY(type, NSInteger); RCT_EXPORT_VIEW_PROPERTY(orientation, NSInteger); RCT_EXPORT_VIEW_PROPERTY(flashMode, NSInteger); RCT_EXPORT_VIEW_PROPERTY(torchMode, NSInteger); +RCT_EXPORT_VIEW_PROPERTY(keepAwake, BOOL); - (NSDictionary *)constantsToExport {