expo-camera 11.2.2 → 12.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -13
- package/android/build.gradle +3 -6
- package/android/src/main/java/expo/modules/camera/CameraModule.java +5 -5
- package/android/src/main/java/expo/modules/camera/CameraPackage.java +3 -3
- package/android/src/main/java/expo/modules/camera/CameraViewHelper.java +1 -1
- package/android/src/main/java/expo/modules/camera/CameraViewManager.java +4 -4
- package/android/src/main/java/expo/modules/camera/ExpoCameraView.java +5 -5
- package/android/src/main/java/expo/modules/camera/events/BarCodeScannedEvent.java +1 -1
- package/android/src/main/java/expo/modules/camera/events/CameraMountErrorEvent.java +1 -1
- package/android/src/main/java/expo/modules/camera/events/CameraReadyEvent.java +1 -1
- package/android/src/main/java/expo/modules/camera/events/FaceDetectionErrorEvent.java +1 -1
- package/android/src/main/java/expo/modules/camera/events/FacesDetectedEvent.java +1 -1
- package/android/src/main/java/expo/modules/camera/events/PictureSavedEvent.java +1 -1
- package/android/src/main/java/expo/modules/camera/tasks/ResolveTakenPictureAsyncTask.java +1 -1
- package/build/Camera.d.ts +26 -0
- package/build/Camera.js +103 -68
- package/build/Camera.js.map +1 -1
- package/build/Camera.types.d.ts +2 -2
- package/build/Camera.types.js +1 -1
- package/build/Camera.types.js.map +1 -1
- package/build/ExponentCamera.js +1 -1
- package/build/ExponentCamera.js.map +1 -1
- package/build/ExponentCamera.web.js +2 -1
- package/build/ExponentCamera.web.js.map +1 -1
- package/build/ExponentCameraManager.js +1 -1
- package/build/ExponentCameraManager.js.map +1 -1
- package/build/ExponentCameraManager.web.js +1 -1
- package/build/ExponentCameraManager.web.js.map +1 -1
- package/build/WebCameraUtils.js +4 -4
- package/build/WebCameraUtils.js.map +1 -1
- package/build/WebConstants.d.ts +1 -1
- package/build/WebUserMediaManager.js +9 -9
- package/build/WebUserMediaManager.js.map +1 -1
- package/build/useWebCameraStream.js +2 -2
- package/build/useWebCameraStream.js.map +1 -1
- package/build/utils/props.js +1 -1
- package/build/utils/props.js.map +1 -1
- package/ios/EXCamera/EXCamera.h +6 -6
- package/ios/EXCamera/EXCamera.m +76 -76
- package/ios/EXCamera/EXCameraCameraPermissionRequester.m +5 -5
- package/ios/EXCamera/EXCameraManager.h +4 -4
- package/ios/EXCamera/EXCameraManager.m +59 -59
- package/ios/EXCamera/EXCameraMicrophonePermissionRequester.m +5 -5
- package/ios/EXCamera/EXCameraPermissionRequester.m +5 -5
- package/ios/EXCamera.podspec +2 -2
- package/ios/EXCamera.xcframework/Info.plist +5 -5
- package/ios/EXCamera.xcframework/ios-arm64/EXCamera.framework/EXCamera +0 -0
- package/ios/EXCamera.xcframework/ios-arm64/EXCamera.framework/Info.plist +0 -0
- package/ios/EXCamera.xcframework/ios-arm64_x86_64-simulator/EXCamera.framework/EXCamera +0 -0
- package/ios/EXCamera.xcframework/ios-arm64_x86_64-simulator/EXCamera.framework/Info.plist +0 -0
- package/package.json +6 -6
- package/plugin/build/withCamera.js +2 -2
- package/plugin/src/withCamera.ts +2 -2
- package/src/Camera.tsx +61 -17
- package/src/Camera.types.ts +7 -2
- package/src/ExponentCamera.ts +3 -4
- package/src/ExponentCamera.web.tsx +1 -1
- package/src/ExponentCameraManager.ts +1 -1
- package/src/ExponentCameraManager.web.ts +2 -2
- package/src/WebCameraUtils.ts +5 -11
- package/src/WebUserMediaManager.ts +10 -10
- package/src/useWebCameraStream.ts +2 -2
- package/src/utils/props.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,32 +10,34 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## 12.0.1 — 2021-10-01
|
|
14
14
|
|
|
15
15
|
_This version does not introduce any user-facing changes._
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## 12.0.0 — 2021-09-28
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
### 🛠 Breaking changes
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
- Deprecate `getPermissionsAsync` and `requestPermissionsAsync` methods, use specific permission requesters. ([#13855](https://github.com/expo/expo/pull/13855) by [@bycedric](https://github.com/bycedric))
|
|
22
|
+
- Dropped support for iOS 11.0 ([#14383](https://github.com/expo/expo/pull/14383) by [@cruzach](https://github.com/cruzach))
|
|
23
|
+
|
|
24
|
+
### 🎉 New features
|
|
25
|
+
|
|
26
|
+
- Add `useCameraPermissions` and `useMicrophonePermissions` hooks from modules factory. ([#13855](https://github.com/expo/expo/pull/13855) by [@bycedric](https://github.com/bycedric))
|
|
22
27
|
|
|
23
28
|
### 🐛 Bug fixes
|
|
24
29
|
|
|
30
|
+
- Fix QR code scanner in expo web by updating `@koale/useworker` to `^4.0.2` ([#14138](https://github.com/expo/expo/pull/13341) by [@fguitton](https://github.com/fguitton))
|
|
25
31
|
- Update video codec validation to properly reject an invalid codec option. ([#13341](https://github.com/expo/expo/pull/13341) by [@ajsmth](https://github.com/ajsmth))
|
|
26
32
|
- Add `get/requestMicrophonePermissionsAsync()` and `get/requestCameraPermissionsAsync()` methods to named exports. ([#13621](https://github.com/expo/expo/pull/13621) by [@ajsmth](https://github.com/ajsmth))
|
|
27
33
|
- Fix regression in video quality option of recordAsync() ([#13659](https://github.com/expo/expo/pull/13659) by [@ajsmth](https://github.com/ajsmth))
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
## 11.2.1 — 2021-06-24
|
|
34
|
+
- Update permission validation to check for only camera permissions in `initWithModuleRegistry()` ([#13690](https://github.com/expo/expo/pull/13690) by [@ajsmth](https://github.com/ajsmth))
|
|
35
|
+
- Fix building errors from use_frameworks! in Podfile. ([#14523](https://github.com/expo/expo/pull/14523) by [@kudo](https://github.com/kudo))
|
|
31
36
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
## 11.2.0 — 2021-06-22
|
|
35
|
-
|
|
36
|
-
### 🐛 Bug fixes
|
|
37
|
+
### 💡 Others
|
|
37
38
|
|
|
38
|
-
-
|
|
39
|
+
- Migrated from `@unimodules/core` to `expo-modules-core`. ([#13750](https://github.com/expo/expo/pull/13750) by [@tsapeta](https://github.com/tsapeta))
|
|
40
|
+
- Updated `@expo/config-plugins` ([#14443](https://github.com/expo/expo/pull/14443) by [@EvanBacon](https://github.com/EvanBacon))
|
|
39
41
|
|
|
40
42
|
## 11.1.1 — 2021-06-16
|
|
41
43
|
|
package/android/build.gradle
CHANGED
|
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
|
|
|
3
3
|
apply plugin: 'maven'
|
|
4
4
|
|
|
5
5
|
group = 'host.exp.exponent'
|
|
6
|
-
version = '
|
|
6
|
+
version = '12.0.1'
|
|
7
7
|
|
|
8
8
|
buildscript {
|
|
9
9
|
// Simple helper that allows the root project to override versions declared by this library.
|
|
@@ -57,7 +57,7 @@ android {
|
|
|
57
57
|
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
58
58
|
targetSdkVersion safeExtGet("targetSdkVersion", 30)
|
|
59
59
|
versionCode 32
|
|
60
|
-
versionName "
|
|
60
|
+
versionName "12.0.1"
|
|
61
61
|
}
|
|
62
62
|
lintOptions {
|
|
63
63
|
abortOnError false
|
|
@@ -71,11 +71,8 @@ repositories {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
apply from: project(":unimodules-core").file("../unimodules-core.gradle")
|
|
75
|
-
|
|
76
74
|
dependencies {
|
|
77
|
-
|
|
78
|
-
unimodule 'expo-modules-core'
|
|
75
|
+
implementation project(':expo-modules-core')
|
|
79
76
|
|
|
80
77
|
api "androidx.exifinterface:exifinterface:1.0.0"
|
|
81
78
|
api 'com.google.android:cameraview:1.0.0'
|
|
@@ -9,11 +9,11 @@ import com.google.android.cameraview.AspectRatio;
|
|
|
9
9
|
import com.google.android.cameraview.Constants;
|
|
10
10
|
import com.google.android.cameraview.Size;
|
|
11
11
|
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
12
|
+
import expo.modules.core.ExportedModule;
|
|
13
|
+
import expo.modules.core.ModuleRegistry;
|
|
14
|
+
import expo.modules.core.Promise;
|
|
15
|
+
import expo.modules.core.interfaces.ExpoMethod;
|
|
16
|
+
import expo.modules.core.interfaces.services.UIManager;
|
|
17
17
|
|
|
18
18
|
import java.io.File;
|
|
19
19
|
import java.util.ArrayList;
|
|
@@ -6,9 +6,9 @@ import android.content.Context;
|
|
|
6
6
|
import java.util.Collections;
|
|
7
7
|
import java.util.List;
|
|
8
8
|
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
9
|
+
import expo.modules.core.ExportedModule;
|
|
10
|
+
import expo.modules.core.BasePackage;
|
|
11
|
+
import expo.modules.core.ViewManager;
|
|
12
12
|
|
|
13
13
|
public class CameraPackage extends BasePackage {
|
|
14
14
|
@Override
|
|
@@ -17,7 +17,7 @@ import java.util.Calendar;
|
|
|
17
17
|
import java.util.List;
|
|
18
18
|
import java.util.Locale;
|
|
19
19
|
|
|
20
|
-
import
|
|
20
|
+
import expo.modules.core.interfaces.services.EventEmitter;
|
|
21
21
|
import expo.modules.camera.events.BarCodeScannedEvent;
|
|
22
22
|
import expo.modules.camera.events.CameraMountErrorEvent;
|
|
23
23
|
import expo.modules.camera.events.CameraReadyEvent;
|
|
@@ -9,10 +9,10 @@ import java.util.ArrayList;
|
|
|
9
9
|
import java.util.List;
|
|
10
10
|
import java.util.Map;
|
|
11
11
|
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
12
|
+
import expo.modules.core.ViewManager;
|
|
13
|
+
import expo.modules.core.interfaces.ExpoProp;
|
|
14
|
+
import expo.modules.core.ModuleRegistry;
|
|
15
|
+
import expo.modules.core.interfaces.services.UIManager;
|
|
16
16
|
|
|
17
17
|
import expo.modules.interfaces.barcodescanner.BarCodeScannerSettings;
|
|
18
18
|
|
|
@@ -12,11 +12,11 @@ import android.view.View;
|
|
|
12
12
|
import com.google.android.cameraview.CameraView;
|
|
13
13
|
import com.google.android.cameraview.Size;
|
|
14
14
|
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
15
|
+
import expo.modules.core.ModuleRegistry;
|
|
16
|
+
import expo.modules.core.Promise;
|
|
17
|
+
import expo.modules.core.interfaces.LifecycleEventListener;
|
|
18
|
+
import expo.modules.core.interfaces.services.EventEmitter;
|
|
19
|
+
import expo.modules.core.interfaces.services.UIManager;
|
|
20
20
|
|
|
21
21
|
import java.io.File;
|
|
22
22
|
import java.io.IOException;
|
|
@@ -3,7 +3,7 @@ package expo.modules.camera.events;
|
|
|
3
3
|
import android.os.Bundle;
|
|
4
4
|
import androidx.core.util.Pools;
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import expo.modules.core.interfaces.services.EventEmitter;
|
|
7
7
|
import expo.modules.camera.CameraViewManager;
|
|
8
8
|
import expo.modules.interfaces.barcodescanner.BarCodeScannerResult;
|
|
9
9
|
|
|
@@ -3,7 +3,7 @@ package expo.modules.camera.events;
|
|
|
3
3
|
import android.os.Bundle;
|
|
4
4
|
import androidx.core.util.Pools;
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import expo.modules.core.interfaces.services.EventEmitter;
|
|
7
7
|
import expo.modules.camera.CameraViewManager;
|
|
8
8
|
|
|
9
9
|
public class CameraMountErrorEvent extends EventEmitter.BaseEvent {
|
|
@@ -3,7 +3,7 @@ package expo.modules.camera.events;
|
|
|
3
3
|
import android.os.Bundle;
|
|
4
4
|
import androidx.core.util.Pools;
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import expo.modules.core.interfaces.services.EventEmitter;
|
|
7
7
|
import expo.modules.camera.CameraViewManager;
|
|
8
8
|
|
|
9
9
|
public class CameraReadyEvent extends EventEmitter.BaseEvent {
|
|
@@ -3,7 +3,7 @@ package expo.modules.camera.events;
|
|
|
3
3
|
import android.os.Bundle;
|
|
4
4
|
import androidx.core.util.Pools;
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import expo.modules.core.interfaces.services.EventEmitter;
|
|
7
7
|
|
|
8
8
|
import expo.modules.camera.CameraViewManager;
|
|
9
9
|
import expo.modules.interfaces.facedetector.FaceDetectorInterface;
|
|
@@ -5,7 +5,7 @@ import androidx.core.util.Pools;
|
|
|
5
5
|
|
|
6
6
|
import java.util.List;
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import expo.modules.core.interfaces.services.EventEmitter;
|
|
9
9
|
import expo.modules.camera.CameraViewManager;
|
|
10
10
|
|
|
11
11
|
public class FacesDetectedEvent extends EventEmitter.BaseEvent {
|
|
@@ -3,7 +3,7 @@ package expo.modules.camera.events;
|
|
|
3
3
|
import android.os.Bundle;
|
|
4
4
|
import androidx.core.util.Pools;
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import expo.modules.core.interfaces.services.EventEmitter;
|
|
7
7
|
import expo.modules.camera.CameraViewManager;
|
|
8
8
|
|
|
9
9
|
public class PictureSavedEvent extends EventEmitter.BaseEvent {
|
|
@@ -19,7 +19,7 @@ import java.io.FileOutputStream;
|
|
|
19
19
|
import java.io.IOException;
|
|
20
20
|
import java.util.Map;
|
|
21
21
|
|
|
22
|
-
import
|
|
22
|
+
import expo.modules.core.Promise;
|
|
23
23
|
|
|
24
24
|
import expo.modules.camera.CameraViewHelper;
|
|
25
25
|
import expo.modules.camera.utils.FileSystemUtils;
|
package/build/Camera.d.ts
CHANGED
|
@@ -12,12 +12,38 @@ export default class Camera extends React.Component<CameraProps> {
|
|
|
12
12
|
whiteBalance: Record<"auto" | "sunny" | "cloudy" | "shadow" | "incandescent" | "fluorescent" | "continuous" | "manual", string | number | undefined>;
|
|
13
13
|
};
|
|
14
14
|
static defaultProps: CameraProps;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use `getCameraPermissionsAync` or `getMicrophonePermissionsAsync` instead.
|
|
17
|
+
*/
|
|
15
18
|
static getPermissionsAsync(): Promise<PermissionResponse>;
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Use `requestCameraPermissionsAsync` or `requestMicrophonePermissionsAsync` instead.
|
|
21
|
+
*/
|
|
16
22
|
static requestPermissionsAsync(): Promise<PermissionResponse>;
|
|
17
23
|
static getCameraPermissionsAsync(): Promise<PermissionResponse>;
|
|
18
24
|
static requestCameraPermissionsAsync(): Promise<PermissionResponse>;
|
|
25
|
+
/**
|
|
26
|
+
* Check or request permissions to access the camera.
|
|
27
|
+
* This uses both `requestCameraPermissionsAsync` and `getCameraPermissionsAsync` to interact with the permissions.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const [status, requestPermission] = Camera.useCameraPermissions();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
static useCameraPermissions: (options?: import("expo-modules-core").PermissionHookOptions<object> | undefined) => [PermissionResponse | null, () => Promise<PermissionResponse>, () => Promise<PermissionResponse>];
|
|
19
35
|
static getMicrophonePermissionsAsync(): Promise<PermissionResponse>;
|
|
20
36
|
static requestMicrophonePermissionsAsync(): Promise<PermissionResponse>;
|
|
37
|
+
/**
|
|
38
|
+
* Check or request permissions to access the microphone.
|
|
39
|
+
* This uses both `requestMicrophonePermissionsAsync` and `getMicrophonePermissionsAsync` to interact with the permissions.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const [status, requestPermission] = Camera.useMicrophonePermissions();
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
static useMicrophonePermissions: (options?: import("expo-modules-core").PermissionHookOptions<object> | undefined) => [PermissionResponse | null, () => Promise<PermissionResponse>, () => Promise<PermissionResponse>];
|
|
21
47
|
_cameraHandle?: number | null;
|
|
22
48
|
_cameraRef?: React.Component | null;
|
|
23
49
|
_lastEvents: {
|
package/build/Camera.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Platform, UnavailabilityError } from '
|
|
1
|
+
import { createPermissionHook, Platform, UnavailabilityError } from 'expo-modules-core';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { findNodeHandle } from 'react-native';
|
|
4
4
|
import { PermissionStatus, } from './Camera.types';
|
|
@@ -40,51 +40,6 @@ function _onPictureSaved({ nativeEvent, }) {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
export default class Camera extends React.Component {
|
|
43
|
-
constructor() {
|
|
44
|
-
super(...arguments);
|
|
45
|
-
this._lastEvents = {};
|
|
46
|
-
this._lastEventsTimes = {};
|
|
47
|
-
this._onCameraReady = () => {
|
|
48
|
-
if (this.props.onCameraReady) {
|
|
49
|
-
this.props.onCameraReady();
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
this._onMountError = ({ nativeEvent }) => {
|
|
53
|
-
if (this.props.onMountError) {
|
|
54
|
-
this.props.onMountError(nativeEvent);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
this._onObjectDetected = (callback) => ({ nativeEvent }) => {
|
|
58
|
-
const { type } = nativeEvent;
|
|
59
|
-
if (this._lastEvents[type] &&
|
|
60
|
-
this._lastEventsTimes[type] &&
|
|
61
|
-
JSON.stringify(nativeEvent) === this._lastEvents[type] &&
|
|
62
|
-
new Date().getTime() - this._lastEventsTimes[type].getTime() < EventThrottleMs) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
if (callback) {
|
|
66
|
-
callback(nativeEvent);
|
|
67
|
-
this._lastEventsTimes[type] = new Date();
|
|
68
|
-
this._lastEvents[type] = JSON.stringify(nativeEvent);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
this._setReference = (ref) => {
|
|
72
|
-
if (ref) {
|
|
73
|
-
this._cameraRef = ref;
|
|
74
|
-
// TODO(Bacon): Unify these - perhaps with hooks?
|
|
75
|
-
if (Platform.OS === 'web') {
|
|
76
|
-
this._cameraHandle = ref;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
this._cameraHandle = findNodeHandle(ref);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
this._cameraRef = null;
|
|
84
|
-
this._cameraHandle = null;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
43
|
static async isAvailableAsync() {
|
|
89
44
|
if (!CameraManager.isAvailableAsync) {
|
|
90
45
|
throw new UnavailabilityError('expo-camera', 'isAvailableAsync');
|
|
@@ -103,10 +58,39 @@ export default class Camera extends React.Component {
|
|
|
103
58
|
}
|
|
104
59
|
return await CameraManager.getAvailableVideoCodecsAsync();
|
|
105
60
|
}
|
|
61
|
+
static Constants = {
|
|
62
|
+
Type: CameraManager.Type,
|
|
63
|
+
FlashMode: CameraManager.FlashMode,
|
|
64
|
+
AutoFocus: CameraManager.AutoFocus,
|
|
65
|
+
WhiteBalance: CameraManager.WhiteBalance,
|
|
66
|
+
VideoQuality: CameraManager.VideoQuality,
|
|
67
|
+
VideoStabilization: CameraManager.VideoStabilization || {},
|
|
68
|
+
VideoCodec: CameraManager.VideoCodec,
|
|
69
|
+
};
|
|
70
|
+
// Values under keys from this object will be transformed to native options
|
|
71
|
+
static ConversionTables = ConversionTables;
|
|
72
|
+
static defaultProps = {
|
|
73
|
+
zoom: 0,
|
|
74
|
+
ratio: '4:3',
|
|
75
|
+
focusDepth: 0,
|
|
76
|
+
faceDetectorSettings: {},
|
|
77
|
+
type: CameraManager.Type.back,
|
|
78
|
+
autoFocus: CameraManager.AutoFocus.on,
|
|
79
|
+
flashMode: CameraManager.FlashMode.off,
|
|
80
|
+
whiteBalance: CameraManager.WhiteBalance.auto,
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* @deprecated Use `getCameraPermissionsAync` or `getMicrophonePermissionsAsync` instead.
|
|
84
|
+
*/
|
|
106
85
|
static async getPermissionsAsync() {
|
|
86
|
+
console.warn(`"getPermissionsAsync()" is now deprecated. Please use "getCameraPermissionsAsync()" or "getMicrophonePermissionsAsync()" instead.`);
|
|
107
87
|
return CameraManager.getPermissionsAsync();
|
|
108
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* @deprecated Use `requestCameraPermissionsAsync` or `requestMicrophonePermissionsAsync` instead.
|
|
91
|
+
*/
|
|
109
92
|
static async requestPermissionsAsync() {
|
|
93
|
+
console.warn(`"requestPermissionsAsync()" is now deprecated. Please use "requestCameraPermissionsAsync()" or "requestMicrophonePermissionsAsync()" instead.`);
|
|
110
94
|
return CameraManager.requestPermissionsAsync();
|
|
111
95
|
}
|
|
112
96
|
static async getCameraPermissionsAsync() {
|
|
@@ -115,12 +99,44 @@ export default class Camera extends React.Component {
|
|
|
115
99
|
static async requestCameraPermissionsAsync() {
|
|
116
100
|
return CameraManager.requestCameraPermissionsAsync();
|
|
117
101
|
}
|
|
102
|
+
// @needsAudit
|
|
103
|
+
/**
|
|
104
|
+
* Check or request permissions to access the camera.
|
|
105
|
+
* This uses both `requestCameraPermissionsAsync` and `getCameraPermissionsAsync` to interact with the permissions.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* const [status, requestPermission] = Camera.useCameraPermissions();
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
static useCameraPermissions = createPermissionHook({
|
|
113
|
+
getMethod: Camera.getCameraPermissionsAsync,
|
|
114
|
+
requestMethod: Camera.requestCameraPermissionsAsync,
|
|
115
|
+
});
|
|
118
116
|
static async getMicrophonePermissionsAsync() {
|
|
119
117
|
return CameraManager.getMicrophonePermissionsAsync();
|
|
120
118
|
}
|
|
121
119
|
static async requestMicrophonePermissionsAsync() {
|
|
122
120
|
return CameraManager.requestMicrophonePermissionsAsync();
|
|
123
121
|
}
|
|
122
|
+
// @needsAudit
|
|
123
|
+
/**
|
|
124
|
+
* Check or request permissions to access the microphone.
|
|
125
|
+
* This uses both `requestMicrophonePermissionsAsync` and `getMicrophonePermissionsAsync` to interact with the permissions.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* const [status, requestPermission] = Camera.useMicrophonePermissions();
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
static useMicrophonePermissions = createPermissionHook({
|
|
133
|
+
getMethod: Camera.getMicrophonePermissionsAsync,
|
|
134
|
+
requestMethod: Camera.requestMicrophonePermissionsAsync,
|
|
135
|
+
});
|
|
136
|
+
_cameraHandle;
|
|
137
|
+
_cameraRef;
|
|
138
|
+
_lastEvents = {};
|
|
139
|
+
_lastEventsTimes = {};
|
|
124
140
|
async takePictureAsync(options) {
|
|
125
141
|
const pictureOptions = ensurePictureOptions(options);
|
|
126
142
|
return await CameraManager.takePicture(pictureOptions, this._cameraHandle);
|
|
@@ -162,36 +178,55 @@ export default class Camera extends React.Component {
|
|
|
162
178
|
}
|
|
163
179
|
CameraManager.resumePreview(this._cameraHandle);
|
|
164
180
|
}
|
|
181
|
+
_onCameraReady = () => {
|
|
182
|
+
if (this.props.onCameraReady) {
|
|
183
|
+
this.props.onCameraReady();
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
_onMountError = ({ nativeEvent }) => {
|
|
187
|
+
if (this.props.onMountError) {
|
|
188
|
+
this.props.onMountError(nativeEvent);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
_onObjectDetected = (callback) => ({ nativeEvent }) => {
|
|
192
|
+
const { type } = nativeEvent;
|
|
193
|
+
if (this._lastEvents[type] &&
|
|
194
|
+
this._lastEventsTimes[type] &&
|
|
195
|
+
JSON.stringify(nativeEvent) === this._lastEvents[type] &&
|
|
196
|
+
new Date().getTime() - this._lastEventsTimes[type].getTime() < EventThrottleMs) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (callback) {
|
|
200
|
+
callback(nativeEvent);
|
|
201
|
+
this._lastEventsTimes[type] = new Date();
|
|
202
|
+
this._lastEvents[type] = JSON.stringify(nativeEvent);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
_setReference = (ref) => {
|
|
206
|
+
if (ref) {
|
|
207
|
+
this._cameraRef = ref;
|
|
208
|
+
// TODO(Bacon): Unify these - perhaps with hooks?
|
|
209
|
+
if (Platform.OS === 'web') {
|
|
210
|
+
this._cameraHandle = ref;
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
this._cameraHandle = findNodeHandle(ref);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
this._cameraRef = null;
|
|
218
|
+
this._cameraHandle = null;
|
|
219
|
+
}
|
|
220
|
+
};
|
|
165
221
|
render() {
|
|
166
222
|
const nativeProps = ensureNativeProps(this.props);
|
|
167
223
|
const onBarCodeScanned = this.props.onBarCodeScanned
|
|
168
224
|
? this._onObjectDetected(this.props.onBarCodeScanned)
|
|
169
225
|
: undefined;
|
|
170
226
|
const onFacesDetected = this._onObjectDetected(this.props.onFacesDetected);
|
|
171
|
-
return (React.createElement(ExponentCamera,
|
|
227
|
+
return (React.createElement(ExponentCamera, { ...nativeProps, ref: this._setReference, onCameraReady: this._onCameraReady, onMountError: this._onMountError, onBarCodeScanned: onBarCodeScanned, onFacesDetected: onFacesDetected, onPictureSaved: _onPictureSaved }));
|
|
172
228
|
}
|
|
173
229
|
}
|
|
174
|
-
Camera.Constants = {
|
|
175
|
-
Type: CameraManager.Type,
|
|
176
|
-
FlashMode: CameraManager.FlashMode,
|
|
177
|
-
AutoFocus: CameraManager.AutoFocus,
|
|
178
|
-
WhiteBalance: CameraManager.WhiteBalance,
|
|
179
|
-
VideoQuality: CameraManager.VideoQuality,
|
|
180
|
-
VideoStabilization: CameraManager.VideoStabilization || {},
|
|
181
|
-
VideoCodec: CameraManager.VideoCodec,
|
|
182
|
-
};
|
|
183
|
-
// Values under keys from this object will be transformed to native options
|
|
184
|
-
Camera.ConversionTables = ConversionTables;
|
|
185
|
-
Camera.defaultProps = {
|
|
186
|
-
zoom: 0,
|
|
187
|
-
ratio: '4:3',
|
|
188
|
-
focusDepth: 0,
|
|
189
|
-
faceDetectorSettings: {},
|
|
190
|
-
type: CameraManager.Type.back,
|
|
191
|
-
autoFocus: CameraManager.AutoFocus.on,
|
|
192
|
-
flashMode: CameraManager.FlashMode.off,
|
|
193
|
-
whiteBalance: CameraManager.WhiteBalance.auto,
|
|
194
|
-
};
|
|
195
230
|
export const { Constants, getPermissionsAsync, requestPermissionsAsync, getCameraPermissionsAsync, requestCameraPermissionsAsync, getMicrophonePermissionsAsync, requestMicrophonePermissionsAsync, } = Camera;
|
|
196
231
|
export { PermissionStatus, };
|
|
197
232
|
//# sourceMappingURL=Camera.js.map
|
package/build/Camera.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Camera.js","sourceRoot":"","sources":["../src/Camera.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAYL,gBAAgB,GAEjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,aAAa,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEpE,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAEpC,IAAI,kBAAkB,GAAG,CAAC,CAAC;AAE3B,SAAS,oBAAoB,CAAC,OAA8B;IAC1D,MAAM,cAAc,GAClB,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IAEzD,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE;QAC3B,cAAc,CAAC,OAAO,GAAG,CAAC,CAAC;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E,aAAa,CAAC,YAAY;IACxC,kBAAkB,EAAE,aAAa,CAAC,kBAAkB,IAAI,EAAE;IAC1D,UAAU,EAAE,aAAa,CAAC,UAAU;CACrC,CAAC;AAEF,2EAA2E;AACpE,uBAAgB,GAAG,gBAAgB,CAAC;AAEpC,mBAAY,GAAgB;IACjC,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,KAAK;IACZ,UAAU,EAAE,CAAC;IACb,oBAAoB,EAAE,EAAE;IACxB,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,IAAI;IAC7B,SAAS,EAAE,aAAa,CAAC,SAAS,CAAC,EAAE;IACrC,SAAS,EAAE,aAAa,CAAC,SAAS,CAAC,GAAG;IACtC,YAAY,EAAE,aAAa,CAAC,YAAY,CAAC,IAAI;CAC9C,CAAC;AA0JJ,MAAM,CAAC,MAAM,EACX,SAAS,EACT,mBAAmB,EACnB,uBAAuB,EACvB,yBAAyB,EACzB,6BAA6B,EAC7B,6BAA6B,EAC7B,iCAAiC,GAClC,GAAG,MAAM,CAAC;AAEX,OAAO,EAOL,gBAAgB,GAKjB,CAAC","sourcesContent":["import { Platform, UnavailabilityError } from '@unimodules/core';\nimport * as React from 'react';\nimport { findNodeHandle } from 'react-native';\n\nimport {\n BarCodeScanningResult,\n CameraCapturedPicture,\n CameraMountError,\n CameraNativeProps,\n CameraPictureOptions,\n CameraProps,\n CameraRecordingOptions,\n ConstantsType,\n FaceDetectionResult,\n PermissionExpiration,\n PermissionResponse,\n PermissionStatus,\n VideoCodec,\n} from './Camera.types';\nimport ExponentCamera from './ExponentCamera';\nimport CameraManager from './ExponentCameraManager';\nimport { ConversionTables, ensureNativeProps } from './utils/props';\n\nconst EventThrottleMs = 500;\n\nconst _PICTURE_SAVED_CALLBACKS = {};\n\nlet _GLOBAL_PICTURE_ID = 1;\n\nfunction ensurePictureOptions(options?: CameraPictureOptions): CameraPictureOptions {\n const pictureOptions: CameraPictureOptions =\n !options || typeof options !== 'object' ? {} : options;\n\n if (!pictureOptions.quality) {\n pictureOptions.quality = 1;\n }\n if (pictureOptions.onPictureSaved) {\n const id = _GLOBAL_PICTURE_ID++;\n _PICTURE_SAVED_CALLBACKS[id] = pictureOptions.onPictureSaved;\n pictureOptions.id = id;\n pictureOptions.fastMode = true;\n }\n return pictureOptions;\n}\n\nfunction ensureRecordingOptions(options?: CameraRecordingOptions): CameraRecordingOptions {\n let recordingOptions = options || {};\n\n if (!recordingOptions || typeof recordingOptions !== 'object') {\n recordingOptions = {};\n } else if (typeof recordingOptions.quality === 'string') {\n recordingOptions.quality = Camera.Constants.VideoQuality[recordingOptions.quality];\n }\n\n return recordingOptions;\n}\n\nfunction _onPictureSaved({\n nativeEvent,\n}: {\n nativeEvent: { data: CameraCapturedPicture; id: number };\n}) {\n const { id, data } = nativeEvent;\n const callback = _PICTURE_SAVED_CALLBACKS[id];\n if (callback) {\n callback(data);\n delete _PICTURE_SAVED_CALLBACKS[id];\n }\n}\n\nexport default class Camera extends React.Component<CameraProps> {\n static async isAvailableAsync(): Promise<boolean> {\n if (!CameraManager.isAvailableAsync) {\n throw new UnavailabilityError('expo-camera', 'isAvailableAsync');\n }\n\n return await CameraManager.isAvailableAsync();\n }\n\n static async getAvailableCameraTypesAsync(): Promise<('front' | 'back')[]> {\n if (!CameraManager.getAvailableCameraTypesAsync) {\n throw new UnavailabilityError('expo-camera', 'getAvailableCameraTypesAsync');\n }\n\n return await CameraManager.getAvailableCameraTypesAsync();\n }\n\n static async getAvailableVideoCodecsAsync(): Promise<string[]> {\n if (!CameraManager.getAvailableVideoCodecsAsync) {\n throw new UnavailabilityError('Camera', 'getAvailableVideoCodecsAsync');\n }\n\n return await CameraManager.getAvailableVideoCodecsAsync();\n }\n\n static Constants: ConstantsType = {\n Type: CameraManager.Type,\n FlashMode: CameraManager.FlashMode,\n AutoFocus: CameraManager.AutoFocus,\n WhiteBalance: CameraManager.WhiteBalance,\n VideoQuality: CameraManager.VideoQuality,\n VideoStabilization: CameraManager.VideoStabilization || {},\n VideoCodec: CameraManager.VideoCodec,\n };\n\n // Values under keys from this object will be transformed to native options\n static ConversionTables = ConversionTables;\n\n static defaultProps: CameraProps = {\n zoom: 0,\n ratio: '4:3',\n focusDepth: 0,\n faceDetectorSettings: {},\n type: CameraManager.Type.back,\n autoFocus: CameraManager.AutoFocus.on,\n flashMode: CameraManager.FlashMode.off,\n whiteBalance: CameraManager.WhiteBalance.auto,\n };\n\n static async getPermissionsAsync(): Promise<PermissionResponse> {\n return CameraManager.getPermissionsAsync();\n }\n\n static async requestPermissionsAsync(): Promise<PermissionResponse> {\n return CameraManager.requestPermissionsAsync();\n }\n\n static async getCameraPermissionsAsync(): Promise<PermissionResponse> {\n return CameraManager.getCameraPermissionsAsync();\n }\n\n static async requestCameraPermissionsAsync(): Promise<PermissionResponse> {\n return CameraManager.requestCameraPermissionsAsync();\n }\n\n static async getMicrophonePermissionsAsync(): Promise<PermissionResponse> {\n return CameraManager.getMicrophonePermissionsAsync();\n }\n\n static async requestMicrophonePermissionsAsync(): Promise<PermissionResponse> {\n return CameraManager.requestMicrophonePermissionsAsync();\n }\n\n _cameraHandle?: number | null;\n _cameraRef?: React.Component | null;\n _lastEvents: { [eventName: string]: string } = {};\n _lastEventsTimes: { [eventName: string]: Date } = {};\n\n async takePictureAsync(options?: CameraPictureOptions): Promise<CameraCapturedPicture> {\n const pictureOptions = ensurePictureOptions(options);\n\n return await CameraManager.takePicture(pictureOptions, this._cameraHandle);\n }\n\n async getSupportedRatiosAsync(): Promise<string[]> {\n if (!CameraManager.getSupportedRatios) {\n throw new UnavailabilityError('Camera', 'getSupportedRatiosAsync');\n }\n\n return await CameraManager.getSupportedRatios(this._cameraHandle);\n }\n\n async getAvailablePictureSizesAsync(ratio?: string): Promise<string[]> {\n if (!CameraManager.getAvailablePictureSizes) {\n throw new UnavailabilityError('Camera', 'getAvailablePictureSizesAsync');\n }\n return await CameraManager.getAvailablePictureSizes(ratio, this._cameraHandle);\n }\n\n async recordAsync(\n options?: CameraRecordingOptions\n ): Promise<{ uri: string; codec?: VideoCodec }> {\n if (!CameraManager.record) {\n throw new UnavailabilityError('Camera', 'recordAsync');\n }\n\n const recordingOptions = ensureRecordingOptions(options);\n return await CameraManager.record(recordingOptions, this._cameraHandle);\n }\n\n stopRecording() {\n if (!CameraManager.stopRecording) {\n throw new UnavailabilityError('Camera', 'stopRecording');\n }\n\n CameraManager.stopRecording(this._cameraHandle);\n }\n\n pausePreview() {\n if (!CameraManager.pausePreview) {\n throw new UnavailabilityError('Camera', 'pausePreview');\n }\n\n CameraManager.pausePreview(this._cameraHandle);\n }\n\n resumePreview() {\n if (!CameraManager.resumePreview) {\n throw new UnavailabilityError('Camera', 'resumePreview');\n }\n\n CameraManager.resumePreview(this._cameraHandle);\n }\n\n _onCameraReady = () => {\n if (this.props.onCameraReady) {\n this.props.onCameraReady();\n }\n };\n\n _onMountError = ({ nativeEvent }: { nativeEvent: { message: string } }) => {\n if (this.props.onMountError) {\n this.props.onMountError(nativeEvent);\n }\n };\n\n _onObjectDetected = (callback?: Function) => ({ nativeEvent }: { nativeEvent: any }) => {\n const { type } = nativeEvent;\n if (\n this._lastEvents[type] &&\n this._lastEventsTimes[type] &&\n JSON.stringify(nativeEvent) === this._lastEvents[type] &&\n new Date().getTime() - this._lastEventsTimes[type].getTime() < EventThrottleMs\n ) {\n return;\n }\n\n if (callback) {\n callback(nativeEvent);\n this._lastEventsTimes[type] = new Date();\n this._lastEvents[type] = JSON.stringify(nativeEvent);\n }\n };\n\n _setReference = (ref?: React.Component) => {\n if (ref) {\n this._cameraRef = ref;\n // TODO(Bacon): Unify these - perhaps with hooks?\n if (Platform.OS === 'web') {\n this._cameraHandle = ref as any;\n } else {\n this._cameraHandle = findNodeHandle(ref);\n }\n } else {\n this._cameraRef = null;\n this._cameraHandle = null;\n }\n };\n\n render() {\n const nativeProps = ensureNativeProps(this.props);\n\n const onBarCodeScanned = this.props.onBarCodeScanned\n ? this._onObjectDetected(this.props.onBarCodeScanned)\n : undefined;\n const onFacesDetected = this._onObjectDetected(this.props.onFacesDetected);\n\n return (\n <ExponentCamera\n {...nativeProps}\n ref={this._setReference}\n onCameraReady={this._onCameraReady}\n onMountError={this._onMountError}\n onBarCodeScanned={onBarCodeScanned}\n onFacesDetected={onFacesDetected}\n onPictureSaved={_onPictureSaved}\n />\n );\n }\n}\n\nexport const {\n Constants,\n getPermissionsAsync,\n requestPermissionsAsync,\n getCameraPermissionsAsync,\n requestCameraPermissionsAsync,\n getMicrophonePermissionsAsync,\n requestMicrophonePermissionsAsync,\n} = Camera;\n\nexport {\n CameraCapturedPicture,\n CameraNativeProps,\n CameraPictureOptions,\n CameraProps,\n CameraRecordingOptions,\n PermissionResponse,\n PermissionStatus,\n PermissionExpiration,\n BarCodeScanningResult,\n FaceDetectionResult,\n CameraMountError,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"Camera.js","sourceRoot":"","sources":["../src/Camera.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxF,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAYL,gBAAgB,GAEjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,aAAa,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEpE,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAEpC,IAAI,kBAAkB,GAAG,CAAC,CAAC;AAE3B,SAAS,oBAAoB,CAAC,OAA8B;IAC1D,MAAM,cAAc,GAClB,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IAE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gB,GAKjB,CAAC","sourcesContent":["import { createPermissionHook, Platform, UnavailabilityError } from 'expo-modules-core';\nimport * as React from 'react';\nimport { findNodeHandle } from 'react-native';\n\nimport {\n BarCodeScanningResult,\n CameraCapturedPicture,\n CameraMountError,\n CameraNativeProps,\n CameraPictureOptions,\n CameraProps,\n CameraRecordingOptions,\n ConstantsType,\n FaceDetectionResult,\n PermissionExpiration,\n PermissionResponse,\n PermissionStatus,\n VideoCodec,\n} from './Camera.types';\nimport ExponentCamera from './ExponentCamera';\nimport CameraManager from './ExponentCameraManager';\nimport { ConversionTables, ensureNativeProps } from './utils/props';\n\nconst EventThrottleMs = 500;\n\nconst _PICTURE_SAVED_CALLBACKS = {};\n\nlet _GLOBAL_PICTURE_ID = 1;\n\nfunction ensurePictureOptions(options?: CameraPictureOptions): CameraPictureOptions {\n const pictureOptions: CameraPictureOptions =\n !options || typeof options !== 'object' ? {} : options;\n\n if (!pictureOptions.quality) {\n pictureOptions.quality = 1;\n }\n if (pictureOptions.onPictureSaved) {\n const id = _GLOBAL_PICTURE_ID++;\n _PICTURE_SAVED_CALLBACKS[id] = pictureOptions.onPictureSaved;\n pictureOptions.id = id;\n pictureOptions.fastMode = true;\n }\n return pictureOptions;\n}\n\nfunction ensureRecordingOptions(options?: CameraRecordingOptions): CameraRecordingOptions {\n let recordingOptions = options || {};\n\n if (!recordingOptions || typeof recordingOptions !== 'object') {\n recordingOptions = {};\n } else if (typeof recordingOptions.quality === 'string') {\n recordingOptions.quality = Camera.Constants.VideoQuality[recordingOptions.quality];\n }\n\n return recordingOptions;\n}\n\nfunction _onPictureSaved({\n nativeEvent,\n}: {\n nativeEvent: { data: CameraCapturedPicture; id: number };\n}) {\n const { id, data } = nativeEvent;\n const callback = _PICTURE_SAVED_CALLBACKS[id];\n if (callback) {\n callback(data);\n delete _PICTURE_SAVED_CALLBACKS[id];\n }\n}\n\nexport default class Camera extends React.Component<CameraProps> {\n static async isAvailableAsync(): Promise<boolean> {\n if (!CameraManager.isAvailableAsync) {\n throw new UnavailabilityError('expo-camera', 'isAvailableAsync');\n }\n\n return await CameraManager.isAvailableAsync();\n }\n\n static async getAvailableCameraTypesAsync(): Promise<('front' | 'back')[]> {\n if (!CameraManager.getAvailableCameraTypesAsync) {\n throw new UnavailabilityError('expo-camera', 'getAvailableCameraTypesAsync');\n }\n\n return await CameraManager.getAvailableCameraTypesAsync();\n }\n\n static async getAvailableVideoCodecsAsync(): Promise<string[]> {\n if (!CameraManager.getAvailableVideoCodecsAsync) {\n throw new UnavailabilityError('Camera', 'getAvailableVideoCodecsAsync');\n }\n\n return await CameraManager.getAvailableVideoCodecsAsync();\n }\n\n static Constants: ConstantsType = {\n Type: CameraManager.Type,\n FlashMode: CameraManager.FlashMode,\n AutoFocus: CameraManager.AutoFocus,\n WhiteBalance: CameraManager.WhiteBalance,\n VideoQuality: CameraManager.VideoQuality,\n VideoStabilization: CameraManager.VideoStabilization || {},\n VideoCodec: CameraManager.VideoCodec,\n };\n\n // Values under keys from this object will be transformed to native options\n static ConversionTables = ConversionTables;\n\n static defaultProps: CameraProps = {\n zoom: 0,\n ratio: '4:3',\n focusDepth: 0,\n faceDetectorSettings: {},\n type: CameraManager.Type.back,\n autoFocus: CameraManager.AutoFocus.on,\n flashMode: CameraManager.FlashMode.off,\n whiteBalance: CameraManager.WhiteBalance.auto,\n };\n\n /**\n * @deprecated Use `getCameraPermissionsAync` or `getMicrophonePermissionsAsync` instead.\n */\n static async getPermissionsAsync(): Promise<PermissionResponse> {\n console.warn(\n `\"getPermissionsAsync()\" is now deprecated. Please use \"getCameraPermissionsAsync()\" or \"getMicrophonePermissionsAsync()\" instead.`\n );\n return CameraManager.getPermissionsAsync();\n }\n\n /**\n * @deprecated Use `requestCameraPermissionsAsync` or `requestMicrophonePermissionsAsync` instead.\n */\n static async requestPermissionsAsync(): Promise<PermissionResponse> {\n console.warn(\n `\"requestPermissionsAsync()\" is now deprecated. Please use \"requestCameraPermissionsAsync()\" or \"requestMicrophonePermissionsAsync()\" instead.`\n );\n return CameraManager.requestPermissionsAsync();\n }\n\n static async getCameraPermissionsAsync(): Promise<PermissionResponse> {\n return CameraManager.getCameraPermissionsAsync();\n }\n\n static async requestCameraPermissionsAsync(): Promise<PermissionResponse> {\n return CameraManager.requestCameraPermissionsAsync();\n }\n\n // @needsAudit\n /**\n * Check or request permissions to access the camera.\n * This uses both `requestCameraPermissionsAsync` and `getCameraPermissionsAsync` to interact with the permissions.\n *\n * @example\n * ```ts\n * const [status, requestPermission] = Camera.useCameraPermissions();\n * ```\n */\n static useCameraPermissions = createPermissionHook({\n getMethod: Camera.getCameraPermissionsAsync,\n requestMethod: Camera.requestCameraPermissionsAsync,\n });\n\n static async getMicrophonePermissionsAsync(): Promise<PermissionResponse> {\n return CameraManager.getMicrophonePermissionsAsync();\n }\n\n static async requestMicrophonePermissionsAsync(): Promise<PermissionResponse> {\n return CameraManager.requestMicrophonePermissionsAsync();\n }\n\n // @needsAudit\n /**\n * Check or request permissions to access the microphone.\n * This uses both `requestMicrophonePermissionsAsync` and `getMicrophonePermissionsAsync` to interact with the permissions.\n *\n * @example\n * ```ts\n * const [status, requestPermission] = Camera.useMicrophonePermissions();\n * ```\n */\n static useMicrophonePermissions = createPermissionHook({\n getMethod: Camera.getMicrophonePermissionsAsync,\n requestMethod: Camera.requestMicrophonePermissionsAsync,\n });\n\n _cameraHandle?: number | null;\n _cameraRef?: React.Component | null;\n _lastEvents: { [eventName: string]: string } = {};\n _lastEventsTimes: { [eventName: string]: Date } = {};\n\n async takePictureAsync(options?: CameraPictureOptions): Promise<CameraCapturedPicture> {\n const pictureOptions = ensurePictureOptions(options);\n\n return await CameraManager.takePicture(pictureOptions, this._cameraHandle);\n }\n\n async getSupportedRatiosAsync(): Promise<string[]> {\n if (!CameraManager.getSupportedRatios) {\n throw new UnavailabilityError('Camera', 'getSupportedRatiosAsync');\n }\n\n return await CameraManager.getSupportedRatios(this._cameraHandle);\n }\n\n async getAvailablePictureSizesAsync(ratio?: string): Promise<string[]> {\n if (!CameraManager.getAvailablePictureSizes) {\n throw new UnavailabilityError('Camera', 'getAvailablePictureSizesAsync');\n }\n return await CameraManager.getAvailablePictureSizes(ratio, this._cameraHandle);\n }\n\n async recordAsync(\n options?: CameraRecordingOptions\n ): Promise<{ uri: string; codec?: VideoCodec }> {\n if (!CameraManager.record) {\n throw new UnavailabilityError('Camera', 'recordAsync');\n }\n\n const recordingOptions = ensureRecordingOptions(options);\n return await CameraManager.record(recordingOptions, this._cameraHandle);\n }\n\n stopRecording() {\n if (!CameraManager.stopRecording) {\n throw new UnavailabilityError('Camera', 'stopRecording');\n }\n\n CameraManager.stopRecording(this._cameraHandle);\n }\n\n pausePreview() {\n if (!CameraManager.pausePreview) {\n throw new UnavailabilityError('Camera', 'pausePreview');\n }\n\n CameraManager.pausePreview(this._cameraHandle);\n }\n\n resumePreview() {\n if (!CameraManager.resumePreview) {\n throw new UnavailabilityError('Camera', 'resumePreview');\n }\n\n CameraManager.resumePreview(this._cameraHandle);\n }\n\n _onCameraReady = () => {\n if (this.props.onCameraReady) {\n this.props.onCameraReady();\n }\n };\n\n _onMountError = ({ nativeEvent }: { nativeEvent: { message: string } }) => {\n if (this.props.onMountError) {\n this.props.onMountError(nativeEvent);\n }\n };\n\n _onObjectDetected =\n (callback?: Function) =>\n ({ nativeEvent }: { nativeEvent: any }) => {\n const { type } = nativeEvent;\n if (\n this._lastEvents[type] &&\n this._lastEventsTimes[type] &&\n JSON.stringify(nativeEvent) === this._lastEvents[type] &&\n new Date().getTime() - this._lastEventsTimes[type].getTime() < EventThrottleMs\n ) {\n return;\n }\n\n if (callback) {\n callback(nativeEvent);\n this._lastEventsTimes[type] = new Date();\n this._lastEvents[type] = JSON.stringify(nativeEvent);\n }\n };\n\n _setReference = (ref?: React.Component) => {\n if (ref) {\n this._cameraRef = ref;\n // TODO(Bacon): Unify these - perhaps with hooks?\n if (Platform.OS === 'web') {\n this._cameraHandle = ref as any;\n } else {\n this._cameraHandle = findNodeHandle(ref);\n }\n } else {\n this._cameraRef = null;\n this._cameraHandle = null;\n }\n };\n\n render() {\n const nativeProps = ensureNativeProps(this.props);\n\n const onBarCodeScanned = this.props.onBarCodeScanned\n ? this._onObjectDetected(this.props.onBarCodeScanned)\n : undefined;\n const onFacesDetected = this._onObjectDetected(this.props.onFacesDetected);\n\n return (\n <ExponentCamera\n {...nativeProps}\n ref={this._setReference}\n onCameraReady={this._onCameraReady}\n onMountError={this._onMountError}\n onBarCodeScanned={onBarCodeScanned}\n onFacesDetected={onFacesDetected}\n onPictureSaved={_onPictureSaved}\n />\n );\n }\n}\n\nexport const {\n Constants,\n getPermissionsAsync,\n requestPermissionsAsync,\n getCameraPermissionsAsync,\n requestCameraPermissionsAsync,\n getMicrophonePermissionsAsync,\n requestMicrophonePermissionsAsync,\n} = Camera;\n\nexport {\n CameraCapturedPicture,\n CameraNativeProps,\n CameraPictureOptions,\n CameraProps,\n CameraRecordingOptions,\n PermissionResponse,\n PermissionStatus,\n PermissionExpiration,\n BarCodeScanningResult,\n FaceDetectionResult,\n CameraMountError,\n};\n"]}
|
package/build/Camera.types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PermissionResponse, PermissionStatus, PermissionExpiration } from 'expo-modules-core';
|
|
1
|
+
import { PermissionResponse, PermissionStatus, PermissionExpiration, PermissionHookOptions } from 'expo-modules-core';
|
|
2
2
|
import { ViewProps } from 'react-native';
|
|
3
3
|
export declare enum CameraType {
|
|
4
4
|
/**
|
|
@@ -281,4 +281,4 @@ export declare type BarCodeSettings = {
|
|
|
281
281
|
barCodeTypes: string[];
|
|
282
282
|
interval?: number;
|
|
283
283
|
};
|
|
284
|
-
export { PermissionResponse, PermissionStatus, PermissionExpiration };
|
|
284
|
+
export { PermissionResponse, PermissionStatus, PermissionExpiration, PermissionHookOptions };
|
package/build/Camera.types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Camera.types.js","sourceRoot":"","sources":["../src/Camera.types.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Camera.types.js","sourceRoot":"","sources":["../src/Camera.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,GAGjB,MAAM,mBAAmB,CAAC;AAG3B,MAAM,CAAN,IAAY,UASX;AATD,WAAY,UAAU;IACpB;;OAEG;IACH,6BAAe,CAAA;IACf;;OAEG;IACH,2BAAa,CAAA;AACf,CAAC,EATW,UAAU,KAAV,UAAU,QASrB;AAED,MAAM,CAAN,IAAY,SAiBX;AAjBD,WAAY,SAAS;IACnB;;OAEG;IACH,sBAAS,CAAA;IACT;;OAEG;IACH,wBAAW,CAAA;IACX;;OAEG;IACH,0BAAa,CAAA;IACb;;OAEG;IACH,4BAAe,CAAA;AACjB,CAAC,EAjBW,SAAS,KAAT,SAAS,QAiBpB;AAED,MAAM,CAAN,IAAY,SAiBX;AAjBD,WAAY,SAAS;IACnB;;OAEG;IACH,sBAAS,CAAA;IACT;;OAEG;IACH,wBAAW,CAAA;IACX;;OAEG;IACH,0BAAa,CAAA;IACb;;OAEG;IACH,sCAAyB,CAAA;AAC3B,CAAC,EAjBW,SAAS,KAAT,SAAS,QAiBpB;AAED,MAAM,CAAN,IAAY,YAiCX;AAjCD,WAAY,YAAY;IACtB;;OAEG;IACH,6BAAa,CAAA;IACb;;OAEG;IACH,+BAAe,CAAA;IACf;;OAEG;IACH,iCAAiB,CAAA;IACjB;;OAEG;IACH,iCAAiB,CAAA;IACjB;;OAEG;IACH,6CAA6B,CAAA;IAC7B;;OAEG;IACH,2CAA2B,CAAA;IAC3B;;OAEG;IACH,yCAAyB,CAAA;IACzB;;OAEG;IACH,iCAAiB,CAAA;AACnB,CAAC,EAjCW,YAAY,KAAZ,YAAY,QAiCvB;AAED,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,wBAAW,CAAA;IACX,wBAAW,CAAA;AACb,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,UAqBX;AArBD,WAAY,UAAU;IACpB;;OAEG;IACH,2BAAa,CAAA;IACb;;OAEG;IACH,2BAAa,CAAA;IACb;;OAEG;IACH,2BAAa,CAAA;IACb;;OAEG;IACH,qCAAuB,CAAA;IACvB;;OAEG;IACH,sCAAwB,CAAA;AAC1B,CAAC,EArBW,UAAU,KAAV,UAAU,QAqBrB;AA2LD,OAAO,EAAsB,gBAAgB,EAA+C,CAAC","sourcesContent":["import {\n PermissionResponse,\n PermissionStatus,\n PermissionExpiration,\n PermissionHookOptions,\n} from 'expo-modules-core';\nimport { ViewProps } from 'react-native';\n\nexport enum CameraType {\n /**\n * @platforms ios, android, web\n */\n front = 'front',\n /**\n * @platforms ios, android, web\n */\n back = 'back',\n}\n\nexport enum FlashMode {\n /**\n * @platforms ios, android, web\n */\n on = 'on',\n /**\n * @platforms ios, android, web\n */\n off = 'off',\n /**\n * @platforms ios, android, web\n */\n auto = 'auto',\n /**\n * @platforms ios, android, web\n */\n torch = 'torch',\n}\n\nexport enum AutoFocus {\n /**\n * @platforms ios, android, web\n */\n on = 'on',\n /**\n * @platforms ios, android, web\n */\n off = 'off',\n /**\n * @platforms web\n */\n auto = 'auto',\n /**\n * @platforms web\n */\n singleShot = 'singleShot',\n}\n\nexport enum WhiteBalance {\n /**\n * @platforms ios, android, web\n */\n auto = 'auto',\n /**\n * @platforms ios, android\n */\n sunny = 'sunny',\n /**\n * @platforms ios, android\n */\n cloudy = 'cloudy',\n /**\n * @platforms ios, android\n */\n shadow = 'shadow',\n /**\n * @platforms ios, android\n */\n incandescent = 'incandescent',\n /**\n * @platforms ios, android\n */\n fluorescent = 'fluorescent',\n /**\n * @platforms web\n */\n continuous = 'continuous',\n /**\n * @platforms web\n */\n manual = 'manual',\n}\n\nexport enum ImageType {\n png = 'png',\n jpg = 'jpg',\n}\n\n/**\n * This option specifies what codec to use when recording a video.\n */\nexport enum VideoCodec {\n /**\n * @platforms ios\n */\n H264 = 'avc1',\n /**\n * @platforms ios\n */\n HEVC = 'hvc1',\n /**\n * @platforms ios\n */\n JPEG = 'jpeg',\n /**\n * @platforms ios\n */\n AppleProRes422 = 'apcn',\n /**\n * @platforms ios\n */\n AppleProRes4444 = 'ap4h',\n}\n\nexport type ImageParameters = {\n imageType: ImageType;\n quality: number | null;\n};\n\nexport type ImageSize = {\n width: number;\n height: number;\n};\n\nexport type WebCameraSettings = Partial<{\n autoFocus: string;\n flashMode: string;\n whiteBalance: string;\n exposureCompensation: number;\n colorTemperature: number;\n iso: number;\n brightness: number;\n contrast: number;\n saturation: number;\n sharpness: number;\n focusDistance: number;\n zoom: number;\n}>;\n\nexport type CapturedPicture = {\n width: number;\n height: number;\n uri: string;\n base64?: string;\n // note(bacon): The types are currently only defined for web.\n exif?: Partial<MediaTrackSettings>;\n};\n\nexport type CameraPictureOptions = {\n quality?: number;\n base64?: boolean;\n exif?: boolean;\n onPictureSaved?: (picture: CameraCapturedPicture) => void;\n // TODO(Bacon): Is it possible to implement this in the browser?\n skipProcessing?: boolean;\n // Web-only\n scale?: number;\n imageType?: ImageType;\n isImageMirror?: boolean;\n // internal\n id?: number;\n fastMode?: boolean;\n};\n\nexport type CameraRecordingOptions = {\n maxDuration?: number;\n maxFileSize?: number;\n quality?: number | string;\n mute?: boolean;\n mirror?: boolean;\n // Android\n videoBitrate?: number;\n // iOS\n codec?: VideoCodec;\n};\n\nexport type CameraCapturedPicture = {\n width: number;\n height: number;\n uri: string;\n base64?: string;\n exif?: any;\n};\n\nexport type PictureSavedListener = (event: {\n nativeEvent: { data: CapturedPicture; id: number };\n}) => void;\n\nexport type CameraReadyListener = () => void;\n\nexport type MountErrorListener = (event: { nativeEvent: CameraMountError }) => void;\n\nexport type CameraMountError = { message: string };\n\ntype Point = {\n x: number;\n y: number;\n};\n\nexport type BarCodePoint = Point;\n\nexport type BarCodeScanningResult = {\n type: string;\n data: string;\n /** @platform web */\n cornerPoints?: BarCodePoint[];\n};\n\nexport type Face = {\n faceID: number;\n bounds: {\n origin: Point;\n size: {\n height: number;\n width: number;\n };\n };\n rollAngle: number;\n yawAngle: number;\n smilingProbability: number;\n leftEarPosition: Point;\n rightEarPosition: Point;\n leftEyePosition: Point;\n leftEyeOpenProbability: number;\n rightEyePosition: Point;\n rightEyeOpenProbability: number;\n leftCheekPosition: Point;\n rightCheekPosition: Point;\n mouthPosition: Point;\n leftMouthPosition: Point;\n rightMouthPosition: Point;\n noseBasePosition: Point;\n};\n\nexport type FaceDetectionResult = { faces: Face[] };\n\nexport type ConstantsType = {\n Type: typeof CameraType;\n FlashMode: typeof FlashMode;\n AutoFocus: typeof AutoFocus;\n WhiteBalance: typeof WhiteBalance;\n VideoQuality: any;\n VideoStabilization: any;\n VideoCodec: typeof VideoCodec;\n};\n\nexport type CameraProps = ViewProps & {\n type?: number | keyof typeof CameraType;\n flashMode?: number | keyof typeof FlashMode;\n whiteBalance?: number | keyof typeof WhiteBalance;\n autoFocus?: boolean | number | keyof typeof AutoFocus;\n zoom?: number;\n ratio?: string;\n focusDepth?: number;\n onCameraReady?: Function;\n useCamera2Api?: boolean;\n pictureSize?: string;\n videoStabilizationMode?: number;\n onMountError?: (event: CameraMountError) => void;\n barCodeScannerSettings?: object;\n onBarCodeScanned?: (scanningResult: BarCodeScanningResult) => void;\n faceDetectorSettings?: object;\n onFacesDetected?: (faces: FaceDetectionResult) => void;\n poster?: string;\n};\n\nexport type CameraNativeProps = {\n pointerEvents?: any;\n style?: any;\n ref?: Function;\n onCameraReady?: CameraReadyListener;\n onMountError?: MountErrorListener;\n onBarCodeScanned?: (event: { nativeEvent: BarCodeScanningResult }) => void;\n onFacesDetected?: (event: { nativeEvent: FaceDetectionResult }) => void;\n onFaceDetectionError?: (event: { nativeEvent: Error }) => void;\n onPictureSaved?: PictureSavedListener;\n type?: number | string;\n flashMode?: number | string;\n autoFocus?: string | boolean | number;\n focusDepth?: number;\n zoom?: number;\n whiteBalance?: number | string;\n pictureSize?: string;\n barCodeScannerSettings?: BarCodeSettings;\n faceDetectorSettings?: object;\n barCodeScannerEnabled?: boolean;\n faceDetectorEnabled?: boolean;\n // Android\n ratio?: string;\n useCamera2Api?: boolean;\n // Web\n poster?: string;\n};\n\nexport type BarCodeSettings = {\n barCodeTypes: string[];\n interval?: number;\n};\n\nexport { PermissionResponse, PermissionStatus, PermissionExpiration, PermissionHookOptions };\n"]}
|
package/build/ExponentCamera.js
CHANGED