feat: Implement atomically single-lock core/ library on Android (#2049)

* feat: Create base for `CameraConfiguration` diff

* Fix

* Write three configure methods

* Build?

* MOre

* Update CameraView+RecordVideo.kt

* Fix errors

* Update CameraDeviceDetails.kt

* Update CameraSession.kt

* Auto-resize Preview View

* More

* Make it work? idk

* Format

* Call `configure` under mutex, and change isActive

* fix: Make Outputs comparable

* fix: Make CodeScanner comparable

* Format

* fix: Update outputs after reconfiguring

* Update CameraPage.tsx

* fix: Close CaptureSession before
This commit is contained in:
Marc Rousavy
2023-10-24 11:19:03 +02:00
committed by GitHub
parent 23d173f6fc
commit de0d6cda5d
23 changed files with 821 additions and 889 deletions

View File

@@ -18,9 +18,7 @@ class CameraViewManager : ViewGroupManager<CameraView>() {
override fun onAfterUpdateTransaction(view: CameraView) {
super.onAfterUpdateTransaction(view)
val changedProps = cameraViewTransactions[view] ?: ArrayList()
view.update(changedProps)
cameraViewTransactions.remove(view)
view.update()
}
override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any>? =
@@ -35,108 +33,69 @@ class CameraViewManager : ViewGroupManager<CameraView>() {
@ReactProp(name = "cameraId")
fun setCameraId(view: CameraView, cameraId: String) {
if (view.cameraId != cameraId) {
addChangedPropToTransaction(view, "cameraId")
}
view.cameraId = cameraId
}
@ReactProp(name = "photo")
fun setPhoto(view: CameraView, photo: Boolean?) {
if (view.photo != photo) {
addChangedPropToTransaction(view, "photo")
}
view.photo = photo
}
@ReactProp(name = "video")
fun setVideo(view: CameraView, video: Boolean?) {
if (view.video != video) {
addChangedPropToTransaction(view, "video")
}
view.video = video
}
@ReactProp(name = "audio")
fun setAudio(view: CameraView, audio: Boolean?) {
if (view.audio != audio) {
addChangedPropToTransaction(view, "audio")
}
view.audio = audio
}
@ReactProp(name = "enableFrameProcessor")
fun setEnableFrameProcessor(view: CameraView, enableFrameProcessor: Boolean) {
if (view.enableFrameProcessor != enableFrameProcessor) {
addChangedPropToTransaction(view, "enableFrameProcessor")
}
view.enableFrameProcessor = enableFrameProcessor
}
@ReactProp(name = "pixelFormat")
fun setPixelFormat(view: CameraView, pixelFormat: String?) {
val newPixelFormat = PixelFormat.fromUnionValue(pixelFormat)
if (view.pixelFormat != newPixelFormat) {
addChangedPropToTransaction(view, "pixelFormat")
}
view.pixelFormat = newPixelFormat ?: PixelFormat.NATIVE
view.pixelFormat = newPixelFormat
}
@ReactProp(name = "enableDepthData")
fun setEnableDepthData(view: CameraView, enableDepthData: Boolean) {
if (view.enableDepthData != enableDepthData) {
addChangedPropToTransaction(view, "enableDepthData")
}
view.enableDepthData = enableDepthData
}
@ReactProp(name = "enableZoomGesture")
fun setEnableZoomGesture(view: CameraView, enableZoomGesture: Boolean) {
if (view.enableZoomGesture != enableZoomGesture) {
addChangedPropToTransaction(view, "enableZoomGesture")
}
view.enableZoomGesture = enableZoomGesture
}
@ReactProp(name = "videoStabilizationMode")
fun setVideoStabilizationMode(view: CameraView, videoStabilizationMode: String?) {
val newMode = VideoStabilizationMode.fromUnionValue(videoStabilizationMode)
if (view.videoStabilizationMode != newMode) {
addChangedPropToTransaction(view, "videoStabilizationMode")
}
view.videoStabilizationMode = newMode
}
@ReactProp(name = "enableHighQualityPhotos")
fun setEnableHighQualityPhotos(view: CameraView, enableHighQualityPhotos: Boolean?) {
if (view.enableHighQualityPhotos != enableHighQualityPhotos) {
addChangedPropToTransaction(view, "enableHighQualityPhotos")
}
view.enableHighQualityPhotos = enableHighQualityPhotos
}
@ReactProp(name = "enablePortraitEffectsMatteDelivery")
fun setEnablePortraitEffectsMatteDelivery(view: CameraView, enablePortraitEffectsMatteDelivery: Boolean) {
if (view.enablePortraitEffectsMatteDelivery != enablePortraitEffectsMatteDelivery) {
addChangedPropToTransaction(view, "enablePortraitEffectsMatteDelivery")
}
view.enablePortraitEffectsMatteDelivery = enablePortraitEffectsMatteDelivery
}
@ReactProp(name = "format")
fun setFormat(view: CameraView, format: ReadableMap?) {
if (view.format != format) {
addChangedPropToTransaction(view, "format")
}
view.format = format
}
@ReactProp(name = "resizeMode")
fun setResizeMode(view: CameraView, resizeMode: String) {
val newMode = ResizeMode.fromUnionValue(resizeMode)
if (view.resizeMode != newMode) {
addChangedPropToTransaction(view, "resizeMode")
}
view.resizeMode = newMode
}
@@ -145,82 +104,49 @@ class CameraViewManager : ViewGroupManager<CameraView>() {
// of type "Int?" the react bridge throws an error.
@ReactProp(name = "fps", defaultInt = -1)
fun setFps(view: CameraView, fps: Int) {
if (view.fps != fps) {
addChangedPropToTransaction(view, "fps")
}
view.fps = if (fps > 0) fps else null
}
@ReactProp(name = "hdr")
fun setHdr(view: CameraView, hdr: Boolean?) {
if (view.hdr != hdr) {
addChangedPropToTransaction(view, "hdr")
}
view.hdr = hdr
}
@ReactProp(name = "lowLightBoost")
fun setLowLightBoost(view: CameraView, lowLightBoost: Boolean?) {
if (view.lowLightBoost != lowLightBoost) {
addChangedPropToTransaction(view, "lowLightBoost")
}
view.lowLightBoost = lowLightBoost
}
@ReactProp(name = "isActive")
fun setIsActive(view: CameraView, isActive: Boolean) {
if (view.isActive != isActive) {
addChangedPropToTransaction(view, "isActive")
}
view.isActive = isActive
}
@ReactProp(name = "torch")
fun setTorch(view: CameraView, torch: String) {
val newMode = Torch.fromUnionValue(torch)
if (view.torch != newMode) {
addChangedPropToTransaction(view, "torch")
}
view.torch = newMode
}
@ReactProp(name = "zoom")
fun setZoom(view: CameraView, zoom: Double) {
val zoomFloat = zoom.toFloat()
if (view.zoom != zoomFloat) {
addChangedPropToTransaction(view, "zoom")
}
view.zoom = zoomFloat
}
@ReactProp(name = "orientation")
fun setOrientation(view: CameraView, orientation: String?) {
val newMode = Orientation.fromUnionValue(orientation)
if (view.orientation != newMode) {
addChangedPropToTransaction(view, "orientation")
}
view.orientation = newMode
}
@ReactProp(name = "codeScannerOptions")
fun setCodeScanner(view: CameraView, codeScannerOptions: ReadableMap) {
val newCodeScannerOptions = CodeScannerOptions(codeScannerOptions)
if (view.codeScannerOptions != newCodeScannerOptions) {
addChangedPropToTransaction(view, "codeScannerOptions")
}
view.codeScannerOptions = newCodeScannerOptions
}
companion object {
const val TAG = "CameraView"
val cameraViewTransactions: HashMap<CameraView, ArrayList<String>> = HashMap()
private fun addChangedPropToTransaction(view: CameraView, changedProp: String) {
if (cameraViewTransactions[view] == null) {
cameraViewTransactions[view] = ArrayList()
}
cameraViewTransactions[view]!!.add(changedProp)
}
}
}