expo-camera 13.7.0 → 13.9.0
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 +30 -0
- package/android/build.gradle +62 -32
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/expo/modules/camera/CameraViewModule.kt +2 -2
- package/android/src/main/java/expo/modules/camera/Options.kt +2 -2
- package/android/src/main/java/expo/modules/camera/next/CameraExceptions.kt +9 -0
- package/android/src/main/java/expo/modules/camera/next/CameraViewHelper.kt +40 -0
- package/android/src/main/java/expo/modules/camera/next/CameraViewNextModule.kt +158 -0
- package/android/src/main/java/expo/modules/camera/next/ExpoCameraView.kt +479 -0
- package/android/src/main/java/expo/modules/camera/next/Options.kt +22 -0
- package/android/src/main/java/expo/modules/camera/next/analyzers/BarcodeAnalyzer.kt +77 -0
- package/android/src/main/java/expo/modules/camera/next/records/CameraRecords.kt +71 -0
- package/android/src/main/java/expo/modules/camera/next/tasks/PictureSavedDelegate.kt +7 -0
- package/android/src/main/java/expo/modules/camera/next/tasks/ResolveTakenPicture.kt +248 -0
- package/android/src/main/java/expo/modules/camera/next/utils/FileSystemUtils.kt +22 -0
- package/android/src/main/java/expo/modules/camera/next/utils/ImageDimensions.kt +16 -0
- package/android/src/main/java/expo/modules/camera/utils/FileSystemUtils.kt +8 -0
- package/build/Camera.d.ts +1 -1
- package/build/Camera.d.ts.map +1 -1
- package/build/Camera.js +2 -2
- package/build/Camera.js.map +1 -1
- package/build/{ExponentCamera.d.ts → ExpoCamera.d.ts} +1 -1
- package/build/ExpoCamera.d.ts.map +1 -0
- package/build/ExpoCamera.js +4 -0
- package/build/ExpoCamera.js.map +1 -0
- package/build/ExponentCamera.web.js +9 -6
- package/build/ExponentCamera.web.js.map +1 -1
- package/build/ExponentCameraManager.d.ts.map +1 -1
- package/build/ExponentCameraManager.js +1 -1
- package/build/ExponentCameraManager.js.map +1 -1
- package/build/next/Camera.d.ts +139 -0
- package/build/next/Camera.d.ts.map +1 -0
- package/build/next/Camera.js +256 -0
- package/build/next/Camera.js.map +1 -0
- package/build/next/Camera.types.d.ts +396 -0
- package/build/next/Camera.types.d.ts.map +1 -0
- package/build/next/Camera.types.js +15 -0
- package/build/next/Camera.types.js.map +1 -0
- package/build/next/ExpoCamera.d.ts +5 -0
- package/build/next/ExpoCamera.d.ts.map +1 -0
- package/build/next/ExpoCamera.js +4 -0
- package/build/next/ExpoCamera.js.map +1 -0
- package/build/next/ExpoCamera.web.d.ts +13 -0
- package/build/next/ExpoCamera.web.d.ts.map +1 -0
- package/build/next/ExpoCamera.web.js +106 -0
- package/build/next/ExpoCamera.web.js.map +1 -0
- package/build/next/ExpoCameraManager.d.ts +3 -0
- package/build/next/ExpoCameraManager.d.ts.map +1 -0
- package/build/next/ExpoCameraManager.js +3 -0
- package/build/next/ExpoCameraManager.js.map +1 -0
- package/build/next/ExpoCameraManager.web.d.ts +42 -0
- package/build/next/ExpoCameraManager.web.d.ts.map +1 -0
- package/build/next/ExpoCameraManager.web.js +216 -0
- package/build/next/ExpoCameraManager.web.js.map +1 -0
- package/build/next/index.d.ts +4 -0
- package/build/next/index.d.ts.map +1 -0
- package/build/next/index.js +4 -0
- package/build/next/index.js.map +1 -0
- package/build/next/utils/props.d.ts +8 -0
- package/build/next/utils/props.d.ts.map +1 -0
- package/build/next/utils/props.js +33 -0
- package/build/next/utils/props.js.map +1 -0
- package/expo-module.config.json +5 -2
- package/ios/CameraEnums.swift +98 -0
- package/ios/CameraExceptions.swift +55 -0
- package/ios/CameraPermissionsRequester.swift +125 -0
- package/ios/CameraRecordingOptions.swift +57 -0
- package/ios/CameraView.swift +982 -0
- package/ios/{EXCamera/CameraViewModule.swift → CameraViewModule.swift} +98 -90
- package/ios/CameraViewNextModule.swift +231 -0
- package/ios/{EXCamera.podspec → ExpoCamera.podspec} +7 -4
- package/ios/ExpoCameraUtils.swift +175 -0
- package/ios/Next/BarcodeRecord.swift +75 -0
- package/ios/Next/BarcodeScanner.swift +182 -0
- package/ios/Next/BarcodeScannerUtils.swift +117 -0
- package/ios/Next/CameraEnumsNext.swift +29 -0
- package/ios/Next/CameraRecordingOptionsNext.swift +54 -0
- package/ios/Next/CameraViewNext.swift +777 -0
- package/ios/Next/ExpoCameraUtilsNext.swift +175 -0
- package/ios/Next/PreviewView.swift +24 -0
- package/ios/Next/Scanner+Delegates.swift +52 -0
- package/ios/Next/TakePictureOptionsNext.swift +23 -0
- package/ios/Next/VisionScannerDelegate.swift +25 -0
- package/next.d.ts +1 -0
- package/next.js +1 -0
- package/package.json +2 -2
- package/src/Camera.tsx +3 -3
- package/src/{ExponentCamera.ts → ExpoCamera.ts} +1 -1
- package/src/ExponentCamera.web.tsx +4 -3
- package/src/ExponentCameraManager.ts +1 -1
- package/src/next/Camera.tsx +349 -0
- package/src/next/Camera.types.ts +447 -0
- package/src/next/ExpoCamera.ts +9 -0
- package/src/next/ExpoCamera.web.tsx +164 -0
- package/src/next/ExpoCameraManager.ts +3 -0
- package/src/next/ExpoCameraManager.web.ts +239 -0
- package/src/next/index.ts +9 -0
- package/src/next/utils/props.ts +45 -0
- package/build/ExponentCamera.d.ts.map +0 -1
- package/build/ExponentCamera.js +0 -4
- package/build/ExponentCamera.js.map +0 -1
- package/ios/EXCamera/EXCamera.h +0 -112
- package/ios/EXCamera/EXCamera.m +0 -1046
- package/ios/EXCamera/EXCameraCameraPermissionRequester.h +0 -7
- package/ios/EXCamera/EXCameraCameraPermissionRequester.m +0 -54
- package/ios/EXCamera/EXCameraMicrophonePermissionRequester.h +0 -7
- package/ios/EXCamera/EXCameraMicrophonePermissionRequester.m +0 -54
- package/ios/EXCamera/EXCameraPermissionRequester.h +0 -7
- package/ios/EXCamera/EXCameraPermissionRequester.m +0 -54
- package/ios/EXCamera/Utilities/EXCameraUtils.h +0 -35
- package/ios/EXCamera/Utilities/EXCameraUtils.m +0 -228
- /package/ios/{EXCamera/TakePictureOptions.swift → TakePictureOptions.swift} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,36 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 13.9.0 — 2023-11-14
|
|
14
|
+
|
|
15
|
+
### 🛠 Breaking changes
|
|
16
|
+
|
|
17
|
+
- Bumped iOS deployment target to 13.4. ([#25063](https://github.com/expo/expo/pull/25063) by [@gabrieldonadel](https://github.com/gabrieldonadel))
|
|
18
|
+
- On `Android` bump `compileSdkVersion` and `targetSdkVersion` to `34`. ([#24708](https://github.com/expo/expo/pull/24708) by [@alanjhughes](https://github.com/alanjhughes))
|
|
19
|
+
|
|
20
|
+
### 🎉 New features
|
|
21
|
+
|
|
22
|
+
- [iOS] Rewrote Objective-C classes to Swift. ([#22604](https://github.com/expo/expo/pull/22604) by [@alanjhughes](https://github.com/alanjhughes))
|
|
23
|
+
|
|
24
|
+
### 🐛 Bug fixes
|
|
25
|
+
|
|
26
|
+
- [iOS] Fix a regression from ([#22604](https://github.com/expo/expo/pull/22604) that prevented the barcode scanner from starting.([#25053](https://github.com/expo/expo/pull/25053) by [@alanjhughes](https://github.com/alanjhughes))
|
|
27
|
+
|
|
28
|
+
### 💡 Others
|
|
29
|
+
|
|
30
|
+
- Use `pointerEvent` style instead of prop. ([#24931](https://github.com/expo/expo/pull/24931) by [@EvanBacon](https://github.com/EvanBacon))
|
|
31
|
+
|
|
32
|
+
## 13.8.0 — 2023-10-17
|
|
33
|
+
|
|
34
|
+
### 🛠 Breaking changes
|
|
35
|
+
|
|
36
|
+
- Dropped support for Android SDK 21 and 22. ([#24201](https://github.com/expo/expo/pull/24201) by [@behenate](https://github.com/behenate))
|
|
37
|
+
- Mark the `ratio` param of `getAvailablePictureSizes` as required because omitting it causes a crash on Android. On iOS, the param has no effect. ([#24234](https://github.com/expo/expo/pull/24234) by [@vonovak](https://github.com/vonovak))
|
|
38
|
+
|
|
39
|
+
### 💡 Others
|
|
40
|
+
|
|
41
|
+
- Ship untranspiled JSX to support custom handling of `jsx` and `createElement`. ([#24889](https://github.com/expo/expo/pull/24889) by [@EvanBacon](https://github.com/EvanBacon))
|
|
42
|
+
|
|
13
43
|
## 13.7.0 — 2023-09-15
|
|
14
44
|
|
|
15
45
|
_This version does not introduce any user-facing changes._
|
package/android/build.gradle
CHANGED
|
@@ -3,15 +3,20 @@ apply plugin: 'kotlin-android'
|
|
|
3
3
|
apply plugin: 'maven-publish'
|
|
4
4
|
|
|
5
5
|
group = 'host.exp.exponent'
|
|
6
|
-
version = '13.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
version = '13.9.0'
|
|
7
|
+
|
|
8
|
+
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
9
|
+
if (expoModulesCorePlugin.exists()) {
|
|
10
|
+
apply from: expoModulesCorePlugin
|
|
11
|
+
applyKotlinExpoModulesCorePlugin()
|
|
12
|
+
// Remove this check, but keep the contents after SDK49 support is dropped
|
|
13
|
+
if (safeExtGet("expoProvidesDefaultConfig", false)) {
|
|
14
|
+
useExpoPublishing()
|
|
15
|
+
useCoreDependencies()
|
|
13
16
|
}
|
|
17
|
+
}
|
|
14
18
|
|
|
19
|
+
buildscript {
|
|
15
20
|
// Simple helper that allows the root project to override versions declared by this library.
|
|
16
21
|
ext.safeExtGet = { prop, fallback ->
|
|
17
22
|
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
@@ -35,23 +40,44 @@ buildscript {
|
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
42
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
// Remove this if and it's contents, when support for SDK49 is dropped
|
|
44
|
+
if (!safeExtGet("expoProvidesDefaultConfig", false)) {
|
|
45
|
+
afterEvaluate {
|
|
46
|
+
publishing {
|
|
47
|
+
publications {
|
|
48
|
+
release(MavenPublication) {
|
|
49
|
+
from components.release
|
|
50
|
+
}
|
|
43
51
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
repositories {
|
|
53
|
+
maven {
|
|
54
|
+
url = mavenLocal().url
|
|
55
|
+
}
|
|
48
56
|
}
|
|
49
57
|
}
|
|
50
58
|
}
|
|
51
59
|
}
|
|
52
60
|
|
|
53
61
|
android {
|
|
54
|
-
|
|
62
|
+
// Remove this if and it's contents, when support for SDK49 is dropped
|
|
63
|
+
if (!safeExtGet("expoProvidesDefaultConfig", false)) {
|
|
64
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 34)
|
|
65
|
+
|
|
66
|
+
defaultConfig {
|
|
67
|
+
minSdkVersion safeExtGet("minSdkVersion", 23)
|
|
68
|
+
targetSdkVersion safeExtGet("targetSdkVersion", 34)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
publishing {
|
|
72
|
+
singleVariant("release") {
|
|
73
|
+
withSourcesJar()
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
lintOptions {
|
|
78
|
+
abortOnError false
|
|
79
|
+
}
|
|
80
|
+
}
|
|
55
81
|
|
|
56
82
|
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
|
|
57
83
|
if (agpVersion.tokenize('.')[0].toInteger() < 8) {
|
|
@@ -67,19 +93,8 @@ android {
|
|
|
67
93
|
|
|
68
94
|
namespace "expo.modules.camera"
|
|
69
95
|
defaultConfig {
|
|
70
|
-
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
71
|
-
targetSdkVersion safeExtGet("targetSdkVersion", 33)
|
|
72
96
|
versionCode 32
|
|
73
|
-
versionName "13.
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
lintOptions {
|
|
77
|
-
abortOnError false
|
|
78
|
-
}
|
|
79
|
-
publishing {
|
|
80
|
-
singleVariant("release") {
|
|
81
|
-
withSourcesJar()
|
|
82
|
-
}
|
|
97
|
+
versionName "13.9.0"
|
|
83
98
|
}
|
|
84
99
|
}
|
|
85
100
|
|
|
@@ -91,10 +106,25 @@ repositories {
|
|
|
91
106
|
}
|
|
92
107
|
|
|
93
108
|
dependencies {
|
|
94
|
-
|
|
109
|
+
// Remove this if and it's contents, when support for SDK49 is dropped
|
|
110
|
+
if (!safeExtGet("expoProvidesDefaultConfig", false)) {
|
|
111
|
+
implementation project(':expo-modules-core')
|
|
112
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
|
|
113
|
+
}
|
|
114
|
+
def camerax_version = "1.3.0"
|
|
95
115
|
|
|
96
|
-
api "androidx.exifinterface:exifinterface:1.
|
|
116
|
+
api "androidx.exifinterface:exifinterface:1.3.6"
|
|
97
117
|
api 'com.google.android:cameraview:1.0.0'
|
|
98
118
|
|
|
99
|
-
implementation "
|
|
119
|
+
implementation "androidx.camera:camera-core:${camerax_version}"
|
|
120
|
+
implementation "androidx.camera:camera-camera2:${camerax_version}"
|
|
121
|
+
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
|
|
122
|
+
implementation "androidx.camera:camera-video:${camerax_version}"
|
|
123
|
+
|
|
124
|
+
implementation "androidx.camera:camera-view:${camerax_version}"
|
|
125
|
+
implementation "androidx.camera:camera-extensions:${camerax_version}"
|
|
126
|
+
implementation "com.google.mlkit:barcode-scanning:17.2.0"
|
|
127
|
+
implementation 'androidx.camera:camera-mlkit-vision:1.4.0-alpha02'
|
|
128
|
+
|
|
129
|
+
api 'com.google.android:cameraview:1.0.0'
|
|
100
130
|
}
|
|
@@ -17,7 +17,7 @@ import java.io.File
|
|
|
17
17
|
|
|
18
18
|
class CameraViewModule : Module() {
|
|
19
19
|
override fun definition() = ModuleDefinition {
|
|
20
|
-
Name("
|
|
20
|
+
Name("ExpoCamera")
|
|
21
21
|
|
|
22
22
|
Constants(
|
|
23
23
|
"Type" to mapOf(
|
|
@@ -114,7 +114,7 @@ class CameraViewModule : Module() {
|
|
|
114
114
|
return@AsyncFunction view.cameraView.supportedAspectRatios.map { it.toString() }
|
|
115
115
|
}.runOnQueue(Queues.MAIN)
|
|
116
116
|
|
|
117
|
-
AsyncFunction("getAvailablePictureSizes") { ratio: String
|
|
117
|
+
AsyncFunction("getAvailablePictureSizes") { ratio: String, viewTag: Int ->
|
|
118
118
|
val view = findView(viewTag)
|
|
119
119
|
|
|
120
120
|
if (!view.cameraView.isCameraOpened) {
|
|
@@ -16,8 +16,8 @@ class PictureOptions : Record {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
class RecordingOptions : Record {
|
|
19
|
-
@Field val maxDuration: Int =
|
|
20
|
-
@Field val maxFileSize: Int =
|
|
19
|
+
@Field val maxDuration: Int = 0
|
|
20
|
+
@Field val maxFileSize: Int = 0
|
|
21
21
|
@Field val quality: Int = CamcorderProfile.QUALITY_HIGH
|
|
22
22
|
@Field val mute: Boolean = false
|
|
23
23
|
@Field val videoBitrate: Int? = null
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
package expo.modules.camera.next
|
|
2
|
+
|
|
3
|
+
import expo.modules.kotlin.exception.CodedException
|
|
4
|
+
|
|
5
|
+
class CameraExceptions {
|
|
6
|
+
class ImageCaptureFailed : CodedException(message = "Failed to capture image")
|
|
7
|
+
|
|
8
|
+
class VideoRecordingFailed(cause: String?) : CodedException("Video recording failed: $cause")
|
|
9
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
package expo.modules.camera.next
|
|
2
|
+
|
|
3
|
+
import android.graphics.Bitmap
|
|
4
|
+
import android.graphics.Canvas
|
|
5
|
+
import android.graphics.Color
|
|
6
|
+
import android.graphics.Paint
|
|
7
|
+
import expo.modules.camera.next.records.CameraType
|
|
8
|
+
import java.io.ByteArrayOutputStream
|
|
9
|
+
import java.text.SimpleDateFormat
|
|
10
|
+
import java.util.Calendar
|
|
11
|
+
import java.util.Locale
|
|
12
|
+
|
|
13
|
+
object CameraViewHelper {
|
|
14
|
+
// Utilities
|
|
15
|
+
@JvmStatic
|
|
16
|
+
fun getCorrectCameraRotation(rotation: Int, facing: CameraType) =
|
|
17
|
+
if (facing == CameraType.FRONT) (rotation - 90 + 360) % 360
|
|
18
|
+
else (-rotation + 90 + 360) % 360
|
|
19
|
+
|
|
20
|
+
fun generateSimulatorPhoto(width: Int, height: Int): ByteArray {
|
|
21
|
+
val fakePhotoBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
|
|
22
|
+
val canvas = Canvas(fakePhotoBitmap)
|
|
23
|
+
val background = Paint().apply {
|
|
24
|
+
color = Color.BLACK
|
|
25
|
+
}
|
|
26
|
+
canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), background)
|
|
27
|
+
val textPaint = Paint().apply {
|
|
28
|
+
color = Color.YELLOW
|
|
29
|
+
textSize = 35f
|
|
30
|
+
}
|
|
31
|
+
val calendar = Calendar.getInstance()
|
|
32
|
+
val simpleDateFormat = SimpleDateFormat("dd.MM.yy HH:mm:ss", Locale.US)
|
|
33
|
+
canvas.drawText(simpleDateFormat.format(calendar.time), width * 0.1f, height * 0.9f, textPaint)
|
|
34
|
+
|
|
35
|
+
val stream = ByteArrayOutputStream()
|
|
36
|
+
fakePhotoBitmap.compress(Bitmap.CompressFormat.PNG, 90, stream)
|
|
37
|
+
val fakePhotoByteArray = stream.toByteArray()
|
|
38
|
+
return fakePhotoByteArray
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
package expo.modules.camera.next
|
|
2
|
+
|
|
3
|
+
import android.Manifest
|
|
4
|
+
import android.util.Log
|
|
5
|
+
import expo.modules.camera.next.records.BarCodeSettings
|
|
6
|
+
import expo.modules.camera.next.records.CameraMode
|
|
7
|
+
import expo.modules.camera.next.records.CameraType
|
|
8
|
+
import expo.modules.camera.next.records.FlashMode
|
|
9
|
+
import expo.modules.camera.next.tasks.ResolveTakenPicture
|
|
10
|
+
import expo.modules.core.errors.ModuleDestroyedException
|
|
11
|
+
import expo.modules.core.utilities.EmulatorUtilities
|
|
12
|
+
import expo.modules.interfaces.permissions.Permissions
|
|
13
|
+
import expo.modules.kotlin.Promise
|
|
14
|
+
import expo.modules.kotlin.exception.Exceptions
|
|
15
|
+
import expo.modules.kotlin.functions.Queues
|
|
16
|
+
import expo.modules.kotlin.modules.Module
|
|
17
|
+
import expo.modules.kotlin.modules.ModuleDefinition
|
|
18
|
+
import kotlinx.coroutines.CoroutineScope
|
|
19
|
+
import kotlinx.coroutines.Dispatchers
|
|
20
|
+
import kotlinx.coroutines.cancel
|
|
21
|
+
import kotlinx.coroutines.launch
|
|
22
|
+
import java.io.File
|
|
23
|
+
|
|
24
|
+
val cameraEvents = arrayOf(
|
|
25
|
+
"onCameraReady",
|
|
26
|
+
"onMountError",
|
|
27
|
+
"onBarCodeScanned",
|
|
28
|
+
"onFacesDetected",
|
|
29
|
+
"onFaceDetectionError",
|
|
30
|
+
"onPictureSaved"
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
class CameraViewNextModule : Module() {
|
|
34
|
+
private val moduleScope = CoroutineScope(Dispatchers.Main)
|
|
35
|
+
override fun definition() = ModuleDefinition {
|
|
36
|
+
Name("ExpoCameraNext")
|
|
37
|
+
|
|
38
|
+
Events("onModernBarcodeScanned")
|
|
39
|
+
|
|
40
|
+
AsyncFunction("requestCameraPermissionsAsync") { promise: Promise ->
|
|
41
|
+
Permissions.askForPermissionsWithPermissionsManager(
|
|
42
|
+
permissionsManager,
|
|
43
|
+
promise,
|
|
44
|
+
Manifest.permission.CAMERA
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
AsyncFunction("requestMicrophonePermissionsAsync") { promise: Promise ->
|
|
49
|
+
Permissions.askForPermissionsWithPermissionsManager(
|
|
50
|
+
permissionsManager,
|
|
51
|
+
promise,
|
|
52
|
+
Manifest.permission.RECORD_AUDIO
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
AsyncFunction("getCameraPermissionsAsync") { promise: Promise ->
|
|
57
|
+
Permissions.getPermissionsWithPermissionsManager(
|
|
58
|
+
permissionsManager,
|
|
59
|
+
promise,
|
|
60
|
+
Manifest.permission.CAMERA
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
AsyncFunction("getMicrophonePermissionsAsync") { promise: Promise ->
|
|
65
|
+
Permissions.getPermissionsWithPermissionsManager(
|
|
66
|
+
permissionsManager,
|
|
67
|
+
promise,
|
|
68
|
+
Manifest.permission.RECORD_AUDIO
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
OnDestroy {
|
|
73
|
+
try {
|
|
74
|
+
moduleScope.cancel(ModuleDestroyedException())
|
|
75
|
+
} catch (e: IllegalStateException) {
|
|
76
|
+
Log.e(TAG, "The scope does not have a job in it")
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
View(ExpoCameraView::class) {
|
|
81
|
+
Events(cameraEvents)
|
|
82
|
+
|
|
83
|
+
Prop("type") { view, type: CameraType ->
|
|
84
|
+
view.lenFacing = type
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
Prop("flashMode") { view, flashMode: FlashMode ->
|
|
88
|
+
view.setCameraFlashMode(flashMode)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
Prop("enableTorch") { view, enabled: Boolean ->
|
|
92
|
+
view.setTorchEnabled(enabled)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
Prop("zoom") { view, zoom: Float ->
|
|
96
|
+
view.camera?.cameraControl?.setLinearZoom(zoom)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
Prop("mode") { view, mode: CameraMode ->
|
|
100
|
+
view.cameraMode = mode
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
Prop("mute") { view, muted: Boolean? ->
|
|
104
|
+
view.mute = muted ?: false
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
Prop("barCodeScannerSettings") { view, settings: BarCodeSettings? ->
|
|
108
|
+
if (settings == null) {
|
|
109
|
+
return@Prop
|
|
110
|
+
}
|
|
111
|
+
view.setBarCodeScannerSettings(settings)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
Prop("barCodeScannerEnabled") { view, barCodeScannerEnabled: Boolean? ->
|
|
115
|
+
view.setShouldScanBarCodes(barCodeScannerEnabled ?: false)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
AsyncFunction("takePicture") { view: ExpoCameraView, options: PictureOptions, promise: Promise ->
|
|
119
|
+
if (!EmulatorUtilities.isRunningOnEmulator()) {
|
|
120
|
+
view.takePicture(options, promise, cacheDirectory)
|
|
121
|
+
} else {
|
|
122
|
+
val image = CameraViewHelper.generateSimulatorPhoto(view.width, view.height)
|
|
123
|
+
moduleScope.launch {
|
|
124
|
+
ResolveTakenPicture(image, promise, options, cacheDirectory) { response ->
|
|
125
|
+
view.onPictureSaved(response)
|
|
126
|
+
}.resolve()
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}.runOnQueue(Queues.MAIN)
|
|
130
|
+
|
|
131
|
+
AsyncFunction("record") { view: ExpoCameraView, options: RecordingOptions, promise: Promise ->
|
|
132
|
+
if (!view.mute && !permissionsManager.hasGrantedPermissions(Manifest.permission.RECORD_AUDIO)) {
|
|
133
|
+
throw Exceptions.MissingPermissions(Manifest.permission.RECORD_AUDIO)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
view.record(options, promise, cacheDirectory)
|
|
137
|
+
}.runOnQueue(Queues.MAIN)
|
|
138
|
+
|
|
139
|
+
AsyncFunction("stopRecording") { view: ExpoCameraView ->
|
|
140
|
+
view.activeRecording?.close()
|
|
141
|
+
}.runOnQueue(Queues.MAIN)
|
|
142
|
+
|
|
143
|
+
OnViewDestroys { view ->
|
|
144
|
+
view.cancelCoroutineScope()
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private val cacheDirectory: File
|
|
150
|
+
get() = appContext.cacheDirectory
|
|
151
|
+
|
|
152
|
+
private val permissionsManager: Permissions
|
|
153
|
+
get() = appContext.permissions ?: throw Exceptions.PermissionsModuleNotFound()
|
|
154
|
+
|
|
155
|
+
companion object {
|
|
156
|
+
internal val TAG = CameraViewNextModule::class.java.simpleName
|
|
157
|
+
}
|
|
158
|
+
}
|