2021-02-19 12:41:49 -07:00
|
|
|
package com.mrousavy.camera
|
2021-02-19 08:28:14 -07:00
|
|
|
|
|
|
|
import com.facebook.react.bridge.ReadableMap
|
|
|
|
import com.facebook.react.common.MapBuilder
|
|
|
|
import com.facebook.react.uimanager.ThemedReactContext
|
2023-08-21 04:50:14 -06:00
|
|
|
import com.facebook.react.uimanager.ViewGroupManager
|
2021-02-19 08:28:14 -07:00
|
|
|
import com.facebook.react.uimanager.annotations.ReactProp
|
2023-08-21 04:50:14 -06:00
|
|
|
import com.mrousavy.camera.parsers.Orientation
|
2023-08-21 06:43:12 -06:00
|
|
|
import com.mrousavy.camera.parsers.PixelFormat
|
2023-08-21 04:50:14 -06:00
|
|
|
import com.mrousavy.camera.parsers.Torch
|
|
|
|
import com.mrousavy.camera.parsers.VideoStabilizationMode
|
2021-08-25 03:33:57 -06:00
|
|
|
|
|
|
|
@Suppress("unused")
|
2023-08-21 06:43:12 -06:00
|
|
|
class CameraViewManager : ViewGroupManager<CameraView>() {
|
2021-08-25 03:33:57 -06:00
|
|
|
|
|
|
|
public override fun createViewInstance(context: ThemedReactContext): CameraView {
|
2023-08-21 04:50:14 -06:00
|
|
|
return CameraView(context)
|
2021-08-25 03:33:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onAfterUpdateTransaction(view: CameraView) {
|
|
|
|
super.onAfterUpdateTransaction(view)
|
|
|
|
val changedProps = cameraViewTransactions[view] ?: ArrayList()
|
|
|
|
view.update(changedProps)
|
|
|
|
cameraViewTransactions.remove(view)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any>? {
|
|
|
|
return MapBuilder.builder<String, Any>()
|
2021-10-11 10:27:23 -06:00
|
|
|
.put("cameraViewReady", MapBuilder.of("registrationName", "onViewReady"))
|
2021-08-25 03:33:57 -06:00
|
|
|
.put("cameraInitialized", MapBuilder.of("registrationName", "onInitialized"))
|
|
|
|
.put("cameraError", MapBuilder.of("registrationName", "onError"))
|
|
|
|
.build()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getName(): String {
|
|
|
|
return TAG
|
2021-02-26 02:56:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@ReactProp(name = "cameraId")
|
|
|
|
fun setCameraId(view: CameraView, cameraId: String) {
|
|
|
|
if (view.cameraId != cameraId)
|
|
|
|
addChangedPropToTransaction(view, "cameraId")
|
|
|
|
view.cameraId = cameraId
|
|
|
|
}
|
|
|
|
|
2021-06-07 05:08:40 -06:00
|
|
|
@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
|
|
|
|
}
|
|
|
|
|
2021-07-12 07:16:03 -06:00
|
|
|
@ReactProp(name = "enableFrameProcessor")
|
|
|
|
fun setEnableFrameProcessor(view: CameraView, enableFrameProcessor: Boolean) {
|
|
|
|
if (view.enableFrameProcessor != enableFrameProcessor)
|
|
|
|
addChangedPropToTransaction(view, "enableFrameProcessor")
|
|
|
|
view.enableFrameProcessor = enableFrameProcessor
|
|
|
|
}
|
|
|
|
|
2023-08-21 04:50:14 -06:00
|
|
|
@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
|
|
|
|
}
|
|
|
|
|
2021-02-26 02:56:20 -07:00
|
|
|
@ReactProp(name = "enableDepthData")
|
|
|
|
fun setEnableDepthData(view: CameraView, enableDepthData: Boolean) {
|
|
|
|
if (view.enableDepthData != enableDepthData)
|
|
|
|
addChangedPropToTransaction(view, "enableDepthData")
|
|
|
|
view.enableDepthData = enableDepthData
|
|
|
|
}
|
|
|
|
|
2023-08-23 07:39:24 -06:00
|
|
|
@ReactProp(name = "enableZoomGesture")
|
|
|
|
fun setEnableZoomGesture(view: CameraView, enableZoomGesture: Boolean) {
|
|
|
|
if (view.enableZoomGesture != enableZoomGesture)
|
|
|
|
addChangedPropToTransaction(view, "enableZoomGesture")
|
|
|
|
view.enableZoomGesture = enableZoomGesture
|
|
|
|
}
|
|
|
|
|
2023-08-21 04:50:14 -06:00
|
|
|
@ReactProp(name = "videoStabilizationMode")
|
|
|
|
fun setVideoStabilizationMode(view: CameraView, videoStabilizationMode: String?) {
|
|
|
|
val newMode = VideoStabilizationMode.fromUnionValue(videoStabilizationMode)
|
|
|
|
if (view.videoStabilizationMode != newMode)
|
|
|
|
addChangedPropToTransaction(view, "videoStabilizationMode")
|
|
|
|
view.videoStabilizationMode = newMode
|
|
|
|
}
|
|
|
|
|
2021-06-10 05:49:34 -06:00
|
|
|
@ReactProp(name = "enableHighQualityPhotos")
|
|
|
|
fun setEnableHighQualityPhotos(view: CameraView, enableHighQualityPhotos: Boolean?) {
|
|
|
|
if (view.enableHighQualityPhotos != enableHighQualityPhotos)
|
|
|
|
addChangedPropToTransaction(view, "enableHighQualityPhotos")
|
|
|
|
view.enableHighQualityPhotos = enableHighQualityPhotos
|
2021-02-26 02:56:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
|
}
|
|
|
|
|
2021-08-25 03:33:57 -06:00
|
|
|
// TODO: Change when TurboModules release.
|
2021-02-26 02:56:20 -07:00
|
|
|
// We're treating -1 as "null" here, because when I make the fps parameter
|
|
|
|
// 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) {
|
2023-08-21 04:50:14 -06:00
|
|
|
val newMode = Torch.fromUnionValue(torch)
|
|
|
|
if (view.torch != newMode)
|
2021-02-26 02:56:20 -07:00
|
|
|
addChangedPropToTransaction(view, "torch")
|
2023-08-21 04:50:14 -06:00
|
|
|
view.torch = newMode
|
2021-02-26 02:56:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@ReactProp(name = "zoom")
|
|
|
|
fun setZoom(view: CameraView, zoom: Double) {
|
2021-07-29 03:44:22 -06:00
|
|
|
val zoomFloat = zoom.toFloat()
|
|
|
|
if (view.zoom != zoomFloat)
|
2021-02-26 02:56:20 -07:00
|
|
|
addChangedPropToTransaction(view, "zoom")
|
2021-07-29 03:44:22 -06:00
|
|
|
view.zoom = zoomFloat
|
2021-02-26 02:56:20 -07:00
|
|
|
}
|
|
|
|
|
2022-01-04 08:57:40 -07:00
|
|
|
@ReactProp(name = "orientation")
|
2023-08-21 04:50:14 -06:00
|
|
|
fun setOrientation(view: CameraView, orientation: String?) {
|
|
|
|
val newMode = Orientation.fromUnionValue(orientation)
|
|
|
|
if (view.orientation != newMode)
|
2022-01-04 08:57:40 -07:00
|
|
|
addChangedPropToTransaction(view, "orientation")
|
2023-08-21 04:50:14 -06:00
|
|
|
view.orientation = newMode
|
2022-01-04 08:57:40 -07:00
|
|
|
}
|
|
|
|
|
2021-02-26 02:56:20 -07:00
|
|
|
companion object {
|
2021-07-07 07:00:32 -06:00
|
|
|
const val TAG = "CameraView"
|
2021-02-26 02:56:20 -07:00
|
|
|
|
|
|
|
val cameraViewTransactions: HashMap<CameraView, ArrayList<String>> = HashMap()
|
2021-08-25 03:33:57 -06:00
|
|
|
|
|
|
|
private fun addChangedPropToTransaction(view: CameraView, changedProp: String) {
|
|
|
|
if (cameraViewTransactions[view] == null) {
|
|
|
|
cameraViewTransactions[view] = ArrayList()
|
|
|
|
}
|
|
|
|
cameraViewTransactions[view]!!.add(changedProp)
|
|
|
|
}
|
2021-02-26 02:56:20 -07:00
|
|
|
}
|
2021-02-19 08:28:14 -07:00
|
|
|
}
|