Devops: KTLint to lint Kotlin code (#6)
* Adds KTLint as a GitHub action * Adds KTLint to the gradle project for IDE integration * Adds .editorconfig to configure KTLint (android/)
This commit is contained in:
@@ -1,156 +1,154 @@
|
||||
package com.mrousavy.camera
|
||||
|
||||
import android.util.Log
|
||||
import com.facebook.react.bridge.ReactContext
|
||||
import com.facebook.react.bridge.ReadableArray
|
||||
import com.facebook.react.bridge.ReadableMap
|
||||
import com.facebook.react.common.MapBuilder
|
||||
import com.facebook.react.uimanager.SimpleViewManager
|
||||
import com.facebook.react.uimanager.ThemedReactContext
|
||||
import com.facebook.react.uimanager.annotations.ReactProp
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
class CameraViewManager : SimpleViewManager<CameraView>() {
|
||||
private fun addChangedPropToTransaction(view: CameraView, changedProp: String) {
|
||||
if (cameraViewTransactions[view] == null) {
|
||||
cameraViewTransactions[view] = ArrayList()
|
||||
}
|
||||
cameraViewTransactions[view]!!.add(changedProp)
|
||||
private fun addChangedPropToTransaction(view: CameraView, changedProp: String) {
|
||||
if (cameraViewTransactions[view] == null) {
|
||||
cameraViewTransactions[view] = ArrayList()
|
||||
}
|
||||
cameraViewTransactions[view]!!.add(changedProp)
|
||||
}
|
||||
|
||||
@ReactProp(name = "cameraId")
|
||||
fun setCameraId(view: CameraView, cameraId: String) {
|
||||
if (view.cameraId != cameraId)
|
||||
addChangedPropToTransaction(view, "cameraId")
|
||||
view.cameraId = cameraId
|
||||
}
|
||||
@ReactProp(name = "cameraId")
|
||||
fun setCameraId(view: CameraView, cameraId: String) {
|
||||
if (view.cameraId != cameraId)
|
||||
addChangedPropToTransaction(view, "cameraId")
|
||||
view.cameraId = cameraId
|
||||
}
|
||||
|
||||
@ReactProp(name = "enableDepthData")
|
||||
fun setEnableDepthData(view: CameraView, enableDepthData: Boolean) {
|
||||
if (view.enableDepthData != enableDepthData)
|
||||
addChangedPropToTransaction(view, "enableDepthData")
|
||||
view.enableDepthData = enableDepthData
|
||||
}
|
||||
@ReactProp(name = "enableDepthData")
|
||||
fun setEnableDepthData(view: CameraView, enableDepthData: Boolean) {
|
||||
if (view.enableDepthData != enableDepthData)
|
||||
addChangedPropToTransaction(view, "enableDepthData")
|
||||
view.enableDepthData = enableDepthData
|
||||
}
|
||||
|
||||
@ReactProp(name = "enableHighResolutionCapture")
|
||||
fun setEnableHighResolutionCapture(view: CameraView, enableHighResolutionCapture: Boolean?) {
|
||||
if (view.enableHighResolutionCapture != enableHighResolutionCapture)
|
||||
addChangedPropToTransaction(view, "enableHighResolutionCapture")
|
||||
view.enableHighResolutionCapture = enableHighResolutionCapture
|
||||
}
|
||||
@ReactProp(name = "enableHighResolutionCapture")
|
||||
fun setEnableHighResolutionCapture(view: CameraView, enableHighResolutionCapture: Boolean?) {
|
||||
if (view.enableHighResolutionCapture != enableHighResolutionCapture)
|
||||
addChangedPropToTransaction(view, "enableHighResolutionCapture")
|
||||
view.enableHighResolutionCapture = enableHighResolutionCapture
|
||||
}
|
||||
|
||||
@ReactProp(name = "enablePortraitEffectsMatteDelivery")
|
||||
fun setEnablePortraitEffectsMatteDelivery(view: CameraView, enablePortraitEffectsMatteDelivery: Boolean) {
|
||||
if (view.enablePortraitEffectsMatteDelivery != enablePortraitEffectsMatteDelivery)
|
||||
addChangedPropToTransaction(view, "enablePortraitEffectsMatteDelivery")
|
||||
view.enablePortraitEffectsMatteDelivery = enablePortraitEffectsMatteDelivery
|
||||
}
|
||||
@ReactProp(name = "enablePortraitEffectsMatteDelivery")
|
||||
fun setEnablePortraitEffectsMatteDelivery(view: CameraView, enablePortraitEffectsMatteDelivery: Boolean) {
|
||||
if (view.enablePortraitEffectsMatteDelivery != enablePortraitEffectsMatteDelivery)
|
||||
addChangedPropToTransaction(view, "enablePortraitEffectsMatteDelivery")
|
||||
view.enablePortraitEffectsMatteDelivery = enablePortraitEffectsMatteDelivery
|
||||
}
|
||||
|
||||
@ReactProp(name = "scannableCodes")
|
||||
fun setScannableCodes(view: CameraView, scannableCodes: ReadableArray?) {
|
||||
if (view.scannableCodes != scannableCodes)
|
||||
addChangedPropToTransaction(view, "scannableCodes")
|
||||
view.scannableCodes = scannableCodes
|
||||
}
|
||||
@ReactProp(name = "scannableCodes")
|
||||
fun setScannableCodes(view: CameraView, scannableCodes: ReadableArray?) {
|
||||
if (view.scannableCodes != scannableCodes)
|
||||
addChangedPropToTransaction(view, "scannableCodes")
|
||||
view.scannableCodes = scannableCodes
|
||||
}
|
||||
|
||||
@ReactProp(name = "format")
|
||||
fun setFormat(view: CameraView, format: ReadableMap?) {
|
||||
if (view.format != format)
|
||||
addChangedPropToTransaction(view, "format")
|
||||
view.format = format
|
||||
}
|
||||
@ReactProp(name = "format")
|
||||
fun setFormat(view: CameraView, format: ReadableMap?) {
|
||||
if (view.format != format)
|
||||
addChangedPropToTransaction(view, "format")
|
||||
view.format = format
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
// 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 = "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 = "lowLightBoost")
|
||||
fun setLowLightBoost(view: CameraView, lowLightBoost: Boolean?) {
|
||||
if (view.lowLightBoost != lowLightBoost)
|
||||
addChangedPropToTransaction(view, "lowLightBoost")
|
||||
view.lowLightBoost = lowLightBoost
|
||||
}
|
||||
|
||||
@ReactProp(name = "colorSpace")
|
||||
fun setColorSpace(view: CameraView, colorSpace: String?) {
|
||||
if (view.colorSpace != colorSpace)
|
||||
addChangedPropToTransaction(view, "colorSpace")
|
||||
view.colorSpace = colorSpace
|
||||
}
|
||||
@ReactProp(name = "colorSpace")
|
||||
fun setColorSpace(view: CameraView, colorSpace: String?) {
|
||||
if (view.colorSpace != colorSpace)
|
||||
addChangedPropToTransaction(view, "colorSpace")
|
||||
view.colorSpace = colorSpace
|
||||
}
|
||||
|
||||
@ReactProp(name = "isActive")
|
||||
fun setIsActive(view: CameraView, isActive: Boolean) {
|
||||
if (view.isActive != isActive)
|
||||
addChangedPropToTransaction(view, "isActive")
|
||||
view.isActive = isActive
|
||||
}
|
||||
@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) {
|
||||
if (view.torch != torch)
|
||||
addChangedPropToTransaction(view, "torch")
|
||||
// TODO: why THE FUCK is this not being called?
|
||||
view.torch = torch
|
||||
}
|
||||
@ReactProp(name = "torch")
|
||||
fun setTorch(view: CameraView, torch: String) {
|
||||
if (view.torch != torch)
|
||||
addChangedPropToTransaction(view, "torch")
|
||||
// TODO: why THE FUCK is this not being called?
|
||||
view.torch = torch
|
||||
}
|
||||
|
||||
@ReactProp(name = "zoom")
|
||||
fun setZoom(view: CameraView, zoom: Double) {
|
||||
if (view.zoom != zoom)
|
||||
addChangedPropToTransaction(view, "zoom")
|
||||
// TODO: why THE FUCK is this not being called?
|
||||
view.zoom = zoom
|
||||
}
|
||||
@ReactProp(name = "zoom")
|
||||
fun setZoom(view: CameraView, zoom: Double) {
|
||||
if (view.zoom != zoom)
|
||||
addChangedPropToTransaction(view, "zoom")
|
||||
// TODO: why THE FUCK is this not being called?
|
||||
view.zoom = zoom
|
||||
}
|
||||
|
||||
@ReactProp(name = "enableZoomGesture")
|
||||
fun setEnableZoomGesture(view: CameraView, enableZoomGesture: Boolean) {
|
||||
if (view.enableZoomGesture != enableZoomGesture)
|
||||
addChangedPropToTransaction(view, "enableZoomGesture")
|
||||
view.enableZoomGesture = enableZoomGesture
|
||||
}
|
||||
@ReactProp(name = "enableZoomGesture")
|
||||
fun setEnableZoomGesture(view: CameraView, enableZoomGesture: Boolean) {
|
||||
if (view.enableZoomGesture != enableZoomGesture)
|
||||
addChangedPropToTransaction(view, "enableZoomGesture")
|
||||
view.enableZoomGesture = enableZoomGesture
|
||||
}
|
||||
|
||||
override fun onAfterUpdateTransaction(view: CameraView) {
|
||||
super.onAfterUpdateTransaction(view)
|
||||
val changedProps = cameraViewTransactions[view] ?: ArrayList()
|
||||
view.update(changedProps)
|
||||
cameraViewTransactions.remove(view)
|
||||
}
|
||||
override fun onAfterUpdateTransaction(view: CameraView) {
|
||||
super.onAfterUpdateTransaction(view)
|
||||
val changedProps = cameraViewTransactions[view] ?: ArrayList()
|
||||
view.update(changedProps)
|
||||
cameraViewTransactions.remove(view)
|
||||
}
|
||||
|
||||
public override fun createViewInstance(context: ThemedReactContext): CameraView {
|
||||
return CameraView(context)
|
||||
}
|
||||
public override fun createViewInstance(context: ThemedReactContext): CameraView {
|
||||
return CameraView(context)
|
||||
}
|
||||
|
||||
override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any>? {
|
||||
return MapBuilder.builder<String, Any>()
|
||||
.put("cameraInitialized", MapBuilder.of("registrationName", "onInitialized"))
|
||||
.put("cameraError", MapBuilder.of("registrationName", "onError"))
|
||||
.put("cameraCodeScanned", MapBuilder.of("registrationName", "onCodeScanned"))
|
||||
.build()
|
||||
}
|
||||
override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any>? {
|
||||
return MapBuilder.builder<String, Any>()
|
||||
.put("cameraInitialized", MapBuilder.of("registrationName", "onInitialized"))
|
||||
.put("cameraError", MapBuilder.of("registrationName", "onError"))
|
||||
.put("cameraCodeScanned", MapBuilder.of("registrationName", "onCodeScanned"))
|
||||
.build()
|
||||
}
|
||||
|
||||
override fun onDropViewInstance(view: CameraView) {
|
||||
Log.d(REACT_CLASS, "onDropViewInstance() called!")
|
||||
super.onDropViewInstance(view)
|
||||
}
|
||||
override fun onDropViewInstance(view: CameraView) {
|
||||
Log.d(REACT_CLASS, "onDropViewInstance() called!")
|
||||
super.onDropViewInstance(view)
|
||||
}
|
||||
|
||||
override fun getName(): String {
|
||||
return REACT_CLASS
|
||||
}
|
||||
override fun getName(): String {
|
||||
return REACT_CLASS
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val REACT_CLASS = "CameraView"
|
||||
companion object {
|
||||
const val REACT_CLASS = "CameraView"
|
||||
|
||||
val cameraViewTransactions: HashMap<CameraView, ArrayList<String>> = HashMap()
|
||||
}
|
||||
val cameraViewTransactions: HashMap<CameraView, ArrayList<String>> = HashMap()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user