expo-camera 12.3.0 → 13.0.0-beta.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 +21 -0
- package/android/build.gradle +2 -2
- package/android/src/main/java/expo/modules/camera/CameraExceptions.kt +7 -0
- package/android/src/main/java/expo/modules/camera/CameraViewHelper.kt +41 -55
- package/android/src/main/java/expo/modules/camera/CameraViewModule.kt +264 -0
- package/android/src/main/java/expo/modules/camera/Events.kt +30 -0
- package/android/src/main/java/expo/modules/camera/{Constants.kt → ExifTags.kt} +0 -39
- package/android/src/main/java/expo/modules/camera/ExpoCameraView.kt +114 -98
- package/android/src/main/java/expo/modules/camera/Options.kt +23 -0
- package/android/src/main/java/expo/modules/camera/tasks/ResolveTakenPictureAsyncTask.kt +28 -44
- package/build/Camera.types.d.ts +9 -1
- package/build/Camera.types.d.ts.map +1 -1
- package/build/Camera.types.js.map +1 -1
- package/build/ExponentCameraManager.d.ts.map +1 -1
- package/build/ExponentCameraManager.js +2 -2
- package/build/ExponentCameraManager.js.map +1 -1
- package/expo-module.config.json +10 -0
- package/ios/EXCamera/CameraViewModule.swift +333 -0
- package/ios/EXCamera/EXCamera.h +3 -5
- package/ios/EXCamera/EXCamera.m +32 -4
- package/ios/EXCamera/TakePictureOptions.swift +23 -0
- package/ios/EXCamera/Utilities/EXCameraUtils.h +3 -3
- package/ios/EXCamera.podspec +8 -2
- package/package.json +2 -3
- package/plugin/build/withCamera.js +1 -1
- package/src/Camera.types.ts +7 -1
- package/src/ExponentCameraManager.ts +2 -3
- package/android/src/main/java/expo/modules/camera/CameraModule.kt +0 -217
- package/android/src/main/java/expo/modules/camera/CameraPackage.kt +0 -10
- package/android/src/main/java/expo/modules/camera/CameraViewManager.kt +0 -116
- package/android/src/main/java/expo/modules/camera/events/BarCodeScannedEvent.kt +0 -50
- package/android/src/main/java/expo/modules/camera/events/CameraMountErrorEvent.kt +0 -33
- package/android/src/main/java/expo/modules/camera/events/CameraReadyEvent.kt +0 -23
- package/android/src/main/java/expo/modules/camera/events/FaceDetectionErrorEvent.kt +0 -39
- package/android/src/main/java/expo/modules/camera/events/FacesDetectedEvent.kt +0 -46
- package/android/src/main/java/expo/modules/camera/events/PictureSavedEvent.kt +0 -41
- package/ios/EXCamera/EXCameraManager.h +0 -9
- package/ios/EXCamera/EXCameraManager.m +0 -435
- package/ios/EXCamera.xcframework/Info.plist +0 -40
- 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/EXCamera.framework/Modules/module.modulemap +0 -6
- 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/ios/EXCamera.xcframework/ios-arm64_x86_64-simulator/EXCamera.framework/Modules/module.modulemap +0 -6
- package/unimodule.json +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,27 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 13.0.0-beta.1 — 2022-10-06
|
|
14
|
+
|
|
15
|
+
### 🛠 Breaking changes
|
|
16
|
+
|
|
17
|
+
- [plugin] Upgrade minimum runtime requirement to Node 14 (LTS). ([#18204](https://github.com/expo/expo/pull/18204) by [@EvanBacon](https://github.com/EvanBacon))
|
|
18
|
+
- Bumped iOS deployment target to 13.0 and deprecated support for iOS 12. ([#18873](https://github.com/expo/expo/pull/18873) by [@tsapeta](https://github.com/tsapeta))
|
|
19
|
+
|
|
20
|
+
### 🎉 New features
|
|
21
|
+
|
|
22
|
+
- On iOS and Android, added new `additionalExif` parameter to `takePictureAsync()` method so that users can add extra information to the photos, such as GPS coordinates. ([#18469](https://github.com/expo/expo/pull/18469) by [@alexyangjie](https://github.com/alexyangjie))
|
|
23
|
+
- Native module for camera view is now written in Swift using the new API. ([#18703](https://github.com/expo/expo/pull/18703) by [@tsapeta](https://github.com/tsapeta))
|
|
24
|
+
|
|
25
|
+
### 🐛 Bug fixes
|
|
26
|
+
|
|
27
|
+
- Fix error when calling `takePictureAsync()` on Android emulator. ([#18704](https://github.com/expo/expo/pull/18704)) by [@keith-kurak](https://github.com/keith-kurak))
|
|
28
|
+
|
|
29
|
+
### 💡 Others
|
|
30
|
+
|
|
31
|
+
- Drop `@expo/config-plugins` dependency in favor of peer dependency on `expo`. ([#18595](https://github.com/expo/expo/pull/18595) by [@EvanBacon](https://github.com/EvanBacon))
|
|
32
|
+
- Refactored inline Android emulator checks to use enhanced checking in `EmulatorUtilities.isRunningOnEmulator()`. ([#16177](https://github.com/expo/expo/pull/16177)) by [@kbrandwijk](https://github.com/kbrandwijk), [@keith-kurak](https://github.com/keith-kurak))
|
|
33
|
+
|
|
13
34
|
## 12.3.0 — 2022-07-07
|
|
14
35
|
|
|
15
36
|
### 🐛 Bug fixes
|
package/android/build.gradle
CHANGED
|
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
|
|
|
3
3
|
apply plugin: 'maven-publish'
|
|
4
4
|
|
|
5
5
|
group = 'host.exp.exponent'
|
|
6
|
-
version = '
|
|
6
|
+
version = '13.0.0-beta.1'
|
|
7
7
|
|
|
8
8
|
buildscript {
|
|
9
9
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
@@ -74,7 +74,7 @@ android {
|
|
|
74
74
|
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
75
75
|
targetSdkVersion safeExtGet("targetSdkVersion", 31)
|
|
76
76
|
versionCode 32
|
|
77
|
-
versionName "
|
|
77
|
+
versionName "13.0.0-beta.1"
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
lintOptions {
|
|
@@ -7,65 +7,15 @@ import android.graphics.Color
|
|
|
7
7
|
import android.graphics.Paint
|
|
8
8
|
import android.media.CamcorderProfile
|
|
9
9
|
import android.os.Bundle
|
|
10
|
-
import android.view.ViewGroup
|
|
11
10
|
|
|
12
11
|
import com.google.android.cameraview.CameraView
|
|
13
12
|
|
|
14
|
-
import
|
|
15
|
-
import expo.modules.camera.events.CameraReadyEvent
|
|
16
|
-
import expo.modules.interfaces.barcodescanner.BarCodeScannerResult
|
|
17
|
-
import expo.modules.core.interfaces.services.EventEmitter
|
|
18
|
-
import expo.modules.camera.events.FacesDetectedEvent
|
|
19
|
-
import expo.modules.interfaces.facedetector.FaceDetectorInterface
|
|
20
|
-
import expo.modules.camera.events.FaceDetectionErrorEvent
|
|
21
|
-
import expo.modules.camera.events.PictureSavedEvent
|
|
22
|
-
import expo.modules.camera.events.BarCodeScannedEvent
|
|
13
|
+
import java.io.ByteArrayOutputStream
|
|
23
14
|
import java.io.IOException
|
|
24
15
|
import java.text.SimpleDateFormat
|
|
25
16
|
import java.util.*
|
|
26
17
|
|
|
27
18
|
object CameraViewHelper {
|
|
28
|
-
// Mount error event
|
|
29
|
-
@JvmStatic
|
|
30
|
-
fun emitMountErrorEvent(emitter: EventEmitter, view: ViewGroup, message: String) {
|
|
31
|
-
val event = CameraMountErrorEvent.obtain(message)
|
|
32
|
-
emitter.emit(view.id, event)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Camera ready event
|
|
36
|
-
@JvmStatic
|
|
37
|
-
fun emitCameraReadyEvent(emitter: EventEmitter, view: ViewGroup) {
|
|
38
|
-
val event = CameraReadyEvent.obtain()
|
|
39
|
-
emitter.emit(view.id, event)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Bar code read event
|
|
43
|
-
@JvmStatic
|
|
44
|
-
fun emitBarCodeReadEvent(emitter: EventEmitter, view: ViewGroup, barCode: BarCodeScannerResult) {
|
|
45
|
-
val event = BarCodeScannedEvent.obtain(view.id, barCode)
|
|
46
|
-
emitter.emit(view.id, event)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Face detection events
|
|
50
|
-
@JvmStatic
|
|
51
|
-
fun emitFacesDetectedEvent(emitter: EventEmitter, view: ViewGroup, faces: List<Bundle>) {
|
|
52
|
-
val event = FacesDetectedEvent.obtain(view.id, faces)
|
|
53
|
-
emitter.emit(view.id, event)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@JvmStatic
|
|
57
|
-
fun emitFaceDetectionErrorEvent(emitter: EventEmitter, view: ViewGroup, faceDetector: FaceDetectorInterface) {
|
|
58
|
-
val event = FaceDetectionErrorEvent.obtain(faceDetector)
|
|
59
|
-
emitter.emit(view.id, event)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Picture saved
|
|
63
|
-
@JvmStatic
|
|
64
|
-
fun emitPictureSavedEvent(emitter: EventEmitter, view: ViewGroup, info: Bundle) {
|
|
65
|
-
val event = PictureSavedEvent.obtain(info)
|
|
66
|
-
emitter.emit(view.id, event)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
19
|
// Utilities
|
|
70
20
|
@JvmStatic
|
|
71
21
|
fun getCorrectCameraRotation(rotation: Int, facing: Int) =
|
|
@@ -108,6 +58,38 @@ object CameraViewHelper {
|
|
|
108
58
|
return exifMap
|
|
109
59
|
}
|
|
110
60
|
|
|
61
|
+
@JvmStatic
|
|
62
|
+
@Throws(IllegalArgumentException::class)
|
|
63
|
+
fun setExifData(baseExif: ExifInterface, exifMap: Map<String, Any>) {
|
|
64
|
+
for ((_, name) in exifTags) {
|
|
65
|
+
exifMap[name]?.let {
|
|
66
|
+
// Convert possible type to string before putting into baseExif
|
|
67
|
+
when (it) {
|
|
68
|
+
is String -> baseExif.setAttribute(name, it)
|
|
69
|
+
is Number -> baseExif.setAttribute(name, it.toDouble().toBigDecimal().toPlainString())
|
|
70
|
+
is Boolean -> baseExif.setAttribute(name, it.toString())
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (exifMap.containsKey(ExifInterface.TAG_GPS_LATITUDE) &&
|
|
76
|
+
exifMap.containsKey(ExifInterface.TAG_GPS_LONGITUDE) &&
|
|
77
|
+
exifMap[ExifInterface.TAG_GPS_LATITUDE] is Number &&
|
|
78
|
+
exifMap[ExifInterface.TAG_GPS_LONGITUDE] is Number
|
|
79
|
+
) {
|
|
80
|
+
baseExif.setLatLong(
|
|
81
|
+
exifMap[ExifInterface.TAG_GPS_LATITUDE] as Double,
|
|
82
|
+
exifMap[ExifInterface.TAG_GPS_LONGITUDE] as Double
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (exifMap.containsKey(ExifInterface.TAG_GPS_ALTITUDE) &&
|
|
87
|
+
exifMap[ExifInterface.TAG_GPS_ALTITUDE] is Number
|
|
88
|
+
) {
|
|
89
|
+
baseExif.setAltitude(exifMap[ExifInterface.TAG_GPS_ALTITUDE] as Double)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
111
93
|
@JvmStatic
|
|
112
94
|
@Throws(IOException::class)
|
|
113
95
|
fun addExifData(baseExif: ExifInterface, additionalExif: ExifInterface) {
|
|
@@ -120,9 +102,9 @@ object CameraViewHelper {
|
|
|
120
102
|
baseExif.saveAttributes()
|
|
121
103
|
}
|
|
122
104
|
|
|
123
|
-
fun generateSimulatorPhoto(width: Int, height: Int):
|
|
124
|
-
val
|
|
125
|
-
val canvas = Canvas(
|
|
105
|
+
fun generateSimulatorPhoto(width: Int, height: Int): ByteArray {
|
|
106
|
+
val fakePhotoBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
|
107
|
+
val canvas = Canvas(fakePhotoBitmap)
|
|
126
108
|
val background = Paint().apply {
|
|
127
109
|
color = Color.BLACK
|
|
128
110
|
}
|
|
@@ -134,6 +116,10 @@ object CameraViewHelper {
|
|
|
134
116
|
val calendar = Calendar.getInstance()
|
|
135
117
|
val simpleDateFormat = SimpleDateFormat("dd.MM.yy HH:mm:ss", Locale.US)
|
|
136
118
|
canvas.drawText(simpleDateFormat.format(calendar.time), width * 0.1f, height * 0.9f, textPaint)
|
|
137
|
-
|
|
119
|
+
|
|
120
|
+
val stream = ByteArrayOutputStream()
|
|
121
|
+
fakePhotoBitmap.compress(Bitmap.CompressFormat.PNG, 90, stream)
|
|
122
|
+
val fakePhotoByteArray = stream.toByteArray()
|
|
123
|
+
return fakePhotoByteArray
|
|
138
124
|
}
|
|
139
125
|
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
package expo.modules.camera
|
|
2
|
+
|
|
3
|
+
import android.Manifest
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import com.google.android.cameraview.AspectRatio
|
|
6
|
+
import com.google.android.cameraview.Size
|
|
7
|
+
import expo.modules.camera.tasks.ResolveTakenPictureAsyncTask
|
|
8
|
+
import expo.modules.core.interfaces.services.UIManager
|
|
9
|
+
import expo.modules.core.utilities.EmulatorUtilities
|
|
10
|
+
import expo.modules.interfaces.barcodescanner.BarCodeScannerSettings
|
|
11
|
+
import expo.modules.interfaces.permissions.Permissions
|
|
12
|
+
import expo.modules.kotlin.Promise
|
|
13
|
+
import expo.modules.kotlin.exception.Exceptions
|
|
14
|
+
import expo.modules.kotlin.functions.Queues
|
|
15
|
+
import expo.modules.kotlin.modules.Module
|
|
16
|
+
import expo.modules.kotlin.modules.ModuleDefinition
|
|
17
|
+
|
|
18
|
+
class CameraViewModule : Module() {
|
|
19
|
+
override fun definition() = ModuleDefinition {
|
|
20
|
+
Name("ExponentCamera")
|
|
21
|
+
|
|
22
|
+
Constants(
|
|
23
|
+
"Type" to mapOf(
|
|
24
|
+
"front" to com.google.android.cameraview.Constants.FACING_FRONT,
|
|
25
|
+
"back" to com.google.android.cameraview.Constants.FACING_BACK
|
|
26
|
+
),
|
|
27
|
+
"FlashMode" to mapOf(
|
|
28
|
+
"off" to com.google.android.cameraview.Constants.FLASH_OFF,
|
|
29
|
+
"on" to com.google.android.cameraview.Constants.FLASH_ON,
|
|
30
|
+
"auto" to com.google.android.cameraview.Constants.FLASH_AUTO,
|
|
31
|
+
"torch" to com.google.android.cameraview.Constants.FLASH_TORCH
|
|
32
|
+
),
|
|
33
|
+
"AutoFocus" to mapOf(
|
|
34
|
+
"on" to true,
|
|
35
|
+
"off" to false
|
|
36
|
+
),
|
|
37
|
+
"WhiteBalance" to mapOf(
|
|
38
|
+
"auto" to com.google.android.cameraview.Constants.WB_AUTO,
|
|
39
|
+
"cloudy" to com.google.android.cameraview.Constants.WB_CLOUDY,
|
|
40
|
+
"sunny" to com.google.android.cameraview.Constants.WB_SUNNY,
|
|
41
|
+
"shadow" to com.google.android.cameraview.Constants.WB_SHADOW,
|
|
42
|
+
"fluorescent" to com.google.android.cameraview.Constants.WB_FLUORESCENT,
|
|
43
|
+
"incandescent" to com.google.android.cameraview.Constants.WB_INCANDESCENT
|
|
44
|
+
),
|
|
45
|
+
"VideoQuality" to mapOf(
|
|
46
|
+
"2160p" to VIDEO_2160P,
|
|
47
|
+
"1080p" to VIDEO_1080P,
|
|
48
|
+
"720p" to VIDEO_720P,
|
|
49
|
+
"480p" to VIDEO_480P,
|
|
50
|
+
"4:3" to VIDEO_4x3
|
|
51
|
+
),
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
AsyncFunction("pausePreview") { viewTag: Int ->
|
|
55
|
+
val view = findView(viewTag)
|
|
56
|
+
|
|
57
|
+
if (view.cameraView.isCameraOpened) {
|
|
58
|
+
view.cameraView.pausePreview()
|
|
59
|
+
}
|
|
60
|
+
}.runOnQueue(Queues.MAIN)
|
|
61
|
+
|
|
62
|
+
AsyncFunction("resumePreview") { viewTag: Int ->
|
|
63
|
+
val view = findView(viewTag)
|
|
64
|
+
|
|
65
|
+
if (view.cameraView.isCameraOpened) {
|
|
66
|
+
view.cameraView.resumePreview()
|
|
67
|
+
}
|
|
68
|
+
}.runOnQueue(Queues.MAIN)
|
|
69
|
+
|
|
70
|
+
AsyncFunction("takePicture") { options: PictureOptions, viewTag: Int, promise: Promise ->
|
|
71
|
+
val cacheDirectory = reactContext.cacheDir
|
|
72
|
+
val view = findView(viewTag)
|
|
73
|
+
|
|
74
|
+
if (!EmulatorUtilities.isRunningOnEmulator()) {
|
|
75
|
+
if (!view.cameraView.isCameraOpened) {
|
|
76
|
+
throw CameraExceptions.CameraIsNotRunning()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
view.takePicture(options, promise, cacheDirectory)
|
|
80
|
+
} else {
|
|
81
|
+
val image = CameraViewHelper.generateSimulatorPhoto(view.width, view.height)
|
|
82
|
+
ResolveTakenPictureAsyncTask(image, promise, options, cacheDirectory, view).execute()
|
|
83
|
+
}
|
|
84
|
+
}.runOnQueue(Queues.MAIN)
|
|
85
|
+
|
|
86
|
+
AsyncFunction("record") { options: RecordingOptions, viewTag: Int, promise: Promise ->
|
|
87
|
+
if (!permissionsManager.hasGrantedPermissions(Manifest.permission.RECORD_AUDIO)) {
|
|
88
|
+
throw Exceptions.MissingPermissions(Manifest.permission.RECORD_AUDIO)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
val cacheDirectory = reactContext.cacheDir
|
|
92
|
+
val view = findView(viewTag)
|
|
93
|
+
|
|
94
|
+
if (!view.cameraView.isCameraOpened) {
|
|
95
|
+
throw CameraExceptions.CameraIsNotRunning()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
view.record(options, promise, cacheDirectory)
|
|
99
|
+
}.runOnQueue(Queues.MAIN)
|
|
100
|
+
|
|
101
|
+
AsyncFunction("stopRecording") { viewTag: Int ->
|
|
102
|
+
val view = findView(viewTag)
|
|
103
|
+
|
|
104
|
+
if (view.cameraView.isCameraOpened) {
|
|
105
|
+
view.cameraView.stopRecording()
|
|
106
|
+
}
|
|
107
|
+
}.runOnQueue(Queues.MAIN)
|
|
108
|
+
|
|
109
|
+
AsyncFunction("getSupportedRatios") { viewTag: Int ->
|
|
110
|
+
val view = findView(viewTag)
|
|
111
|
+
|
|
112
|
+
if (!view.cameraView.isCameraOpened) {
|
|
113
|
+
throw CameraExceptions.CameraIsNotRunning()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return@AsyncFunction view.cameraView.supportedAspectRatios.map { it.toString() }
|
|
117
|
+
}.runOnQueue(Queues.MAIN)
|
|
118
|
+
|
|
119
|
+
AsyncFunction("getAvailablePictureSizes") { ratio: String?, viewTag: Int ->
|
|
120
|
+
val view = findView(viewTag)
|
|
121
|
+
|
|
122
|
+
if (!view.cameraView.isCameraOpened) {
|
|
123
|
+
throw CameraExceptions.CameraIsNotRunning()
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
val sizes = view.cameraView.getAvailablePictureSizes(AspectRatio.parse(ratio))
|
|
127
|
+
return@AsyncFunction sizes.map { it.toString() }
|
|
128
|
+
}.runOnQueue(Queues.MAIN)
|
|
129
|
+
|
|
130
|
+
AsyncFunction("requestPermissionsAsync") { promise: Promise ->
|
|
131
|
+
Permissions.askForPermissionsWithPermissionsManager(
|
|
132
|
+
permissionsManager,
|
|
133
|
+
promise,
|
|
134
|
+
Manifest.permission.CAMERA
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
AsyncFunction("requestCameraPermissionsAsync") { promise: Promise ->
|
|
139
|
+
Permissions.askForPermissionsWithPermissionsManager(
|
|
140
|
+
permissionsManager,
|
|
141
|
+
promise,
|
|
142
|
+
Manifest.permission.CAMERA
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
AsyncFunction("requestMicrophonePermissionsAsync") { promise: Promise ->
|
|
147
|
+
Permissions.askForPermissionsWithPermissionsManager(
|
|
148
|
+
permissionsManager,
|
|
149
|
+
promise,
|
|
150
|
+
Manifest.permission.RECORD_AUDIO
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
AsyncFunction("getPermissionsAsync") { promise: Promise ->
|
|
155
|
+
Permissions.getPermissionsWithPermissionsManager(
|
|
156
|
+
permissionsManager,
|
|
157
|
+
promise,
|
|
158
|
+
Manifest.permission.CAMERA
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
AsyncFunction("getCameraPermissionsAsync") { promise: Promise ->
|
|
163
|
+
Permissions.getPermissionsWithPermissionsManager(
|
|
164
|
+
permissionsManager,
|
|
165
|
+
promise,
|
|
166
|
+
Manifest.permission.CAMERA
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
AsyncFunction("getMicrophonePermissionsAsync") { promise: Promise ->
|
|
171
|
+
Permissions.getPermissionsWithPermissionsManager(
|
|
172
|
+
permissionsManager,
|
|
173
|
+
promise,
|
|
174
|
+
Manifest.permission.RECORD_AUDIO
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
View(ExpoCameraView::class) {
|
|
179
|
+
Events(
|
|
180
|
+
"onCameraReady",
|
|
181
|
+
"onMountError",
|
|
182
|
+
"onBarCodeScanned",
|
|
183
|
+
"onFacesDetected",
|
|
184
|
+
"onFaceDetectionError",
|
|
185
|
+
"onPictureSaved"
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
OnViewDestroys<ExpoCameraView> { view ->
|
|
189
|
+
val uiManager = appContext.legacyModule<UIManager>()
|
|
190
|
+
uiManager?.unregisterLifecycleEventListener(view)
|
|
191
|
+
view.cameraView.stop()
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
Prop("type") { view: ExpoCameraView, type: Int ->
|
|
195
|
+
view.cameraView.facing = type
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
Prop("ratio") { view: ExpoCameraView, ratio: String? ->
|
|
199
|
+
if (ratio == null) {
|
|
200
|
+
return@Prop
|
|
201
|
+
}
|
|
202
|
+
view.cameraView.setAspectRatio(AspectRatio.parse(ratio))
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
Prop("flashMode") { view: ExpoCameraView, torchMode: Int ->
|
|
206
|
+
view.cameraView.flash = torchMode
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
Prop("autoFocus") { view: ExpoCameraView, autoFocus: Boolean ->
|
|
210
|
+
view.cameraView.autoFocus = autoFocus
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
Prop("focusDepth") { view: ExpoCameraView, depth: Float ->
|
|
214
|
+
view.cameraView.focusDepth = depth
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
Prop("zoom") { view: ExpoCameraView, zoom: Float ->
|
|
218
|
+
view.cameraView.zoom = zoom
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
Prop("whiteBalance") { view: ExpoCameraView, whiteBalance: Int ->
|
|
222
|
+
view.cameraView.whiteBalance = whiteBalance
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
Prop("pictureSize") { view: ExpoCameraView, size: String? ->
|
|
226
|
+
if (size == null) {
|
|
227
|
+
return@Prop
|
|
228
|
+
}
|
|
229
|
+
view.cameraView.pictureSize = Size.parse(size)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
Prop("barCodeScannerSettings") { view: ExpoCameraView, settings: Map<String, Any?>? ->
|
|
233
|
+
view.setBarCodeScannerSettings(BarCodeScannerSettings(settings))
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
Prop("useCamera2Api") { view: ExpoCameraView, useCamera2Api: Boolean ->
|
|
237
|
+
view.cameraView.setUsingCamera2Api(useCamera2Api)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
Prop("barCodeScannerEnabled") { view: ExpoCameraView, barCodeScannerEnabled: Boolean ->
|
|
241
|
+
view.setShouldScanBarCodes(barCodeScannerEnabled)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
Prop("faceDetectorEnabled") { view: ExpoCameraView, faceDetectorEnabled: Boolean ->
|
|
245
|
+
view.setShouldDetectFaces(faceDetectorEnabled)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
Prop("faceDetectorSettings") { view: ExpoCameraView, settings: Map<String, Any>? ->
|
|
249
|
+
view.setFaceDetectorSettings(settings)
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private val reactContext: Context
|
|
255
|
+
get() = appContext.reactContext ?: throw Exceptions.ReactContextLost()
|
|
256
|
+
|
|
257
|
+
private val permissionsManager: Permissions
|
|
258
|
+
get() = appContext.permissions ?: throw Exceptions.PermissionsModuleNotFound()
|
|
259
|
+
|
|
260
|
+
private fun findView(viewTag: Int): ExpoCameraView {
|
|
261
|
+
return appContext.findView(viewTag)
|
|
262
|
+
?: throw Exceptions.ViewNotFound(ExpoCameraView::class, viewTag)
|
|
263
|
+
}
|
|
264
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
package expo.modules.camera
|
|
2
|
+
|
|
3
|
+
import android.os.Bundle
|
|
4
|
+
import expo.modules.kotlin.records.Field
|
|
5
|
+
import expo.modules.kotlin.records.Record
|
|
6
|
+
|
|
7
|
+
data class BarCodeScannedEvent(
|
|
8
|
+
@Field val target: Int,
|
|
9
|
+
@Field val data: String,
|
|
10
|
+
@Field val type: Int
|
|
11
|
+
) : Record
|
|
12
|
+
|
|
13
|
+
data class CameraMountErrorEvent(
|
|
14
|
+
@Field val message: String
|
|
15
|
+
) : Record
|
|
16
|
+
|
|
17
|
+
data class FaceDetectionErrorEvent(
|
|
18
|
+
@Field val isOperational: Boolean
|
|
19
|
+
) : Record
|
|
20
|
+
|
|
21
|
+
data class FacesDetectedEvent(
|
|
22
|
+
@Field val type: String,
|
|
23
|
+
@Field val faces: List<Bundle>,
|
|
24
|
+
@Field val target: Int
|
|
25
|
+
) : Record
|
|
26
|
+
|
|
27
|
+
data class PictureSavedEvent(
|
|
28
|
+
@Field val id: Int,
|
|
29
|
+
@Field val data: Bundle
|
|
30
|
+
) : Record
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
package expo.modules.camera
|
|
2
2
|
|
|
3
3
|
import androidx.exifinterface.media.ExifInterface
|
|
4
|
-
import com.google.android.cameraview.Constants
|
|
5
|
-
|
|
6
|
-
const val REACT_CLASS = "ExponentCamera"
|
|
7
|
-
const val TAG = "ExponentCameraModule"
|
|
8
|
-
const val ERROR_TAG = "E_CAMERA"
|
|
9
4
|
|
|
10
5
|
const val VIDEO_2160P = 0
|
|
11
6
|
const val VIDEO_1080P = 1
|
|
@@ -13,40 +8,6 @@ const val VIDEO_720P = 2
|
|
|
13
8
|
const val VIDEO_480P = 3
|
|
14
9
|
const val VIDEO_4x3 = 4
|
|
15
10
|
|
|
16
|
-
val typeConstants = mapOf(
|
|
17
|
-
"front" to Constants.FACING_FRONT,
|
|
18
|
-
"back" to Constants.FACING_BACK
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
val flashModeConstants = mapOf(
|
|
22
|
-
"off" to Constants.FLASH_OFF,
|
|
23
|
-
"on" to Constants.FLASH_ON,
|
|
24
|
-
"auto" to Constants.FLASH_AUTO,
|
|
25
|
-
"torch" to Constants.FLASH_TORCH
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
val autoFocusConstants = mapOf(
|
|
29
|
-
"on" to true,
|
|
30
|
-
"off" to false
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
val whiteBalanceConstants = mapOf(
|
|
34
|
-
"auto" to Constants.WB_AUTO,
|
|
35
|
-
"cloudy" to Constants.WB_CLOUDY,
|
|
36
|
-
"sunny" to Constants.WB_SUNNY,
|
|
37
|
-
"shadow" to Constants.WB_SHADOW,
|
|
38
|
-
"fluorescent" to Constants.WB_FLUORESCENT,
|
|
39
|
-
"incandescent" to Constants.WB_INCANDESCENT
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
val videoQualityConstants = mapOf(
|
|
43
|
-
"2160p" to VIDEO_2160P,
|
|
44
|
-
"1080p" to VIDEO_1080P,
|
|
45
|
-
"720p" to VIDEO_720P,
|
|
46
|
-
"480p" to VIDEO_480P,
|
|
47
|
-
"4:3" to VIDEO_4x3
|
|
48
|
-
)
|
|
49
|
-
|
|
50
11
|
val exifTags = arrayOf(
|
|
51
12
|
arrayOf("string", ExifInterface.TAG_ARTIST),
|
|
52
13
|
arrayOf("int", ExifInterface.TAG_BITS_PER_SAMPLE),
|