Я пытаюсь внедрить собственное представление Android в свое приложение React, я использую новую архитектуру < /p> Итак, вот мой пример кода < /p> [code]class ReactMyCamera: ConstraintLayout {
private var viewFinder: PreviewView = PreviewView(context) private var mCameraProvider: ProcessCameraProvider? = null private lateinit var cameraExecutor: ExecutorService
private var imageCapture: ImageCapture? = null private var button: Button = Button(context)
companion object { private const val FILENAME_FORMAT = "yyyy-MM-dd-HH-mm-ss-SSS" }
private fun setupLayoutHack() { Choreographer.getInstance().postFrameCallback(object : Choreographer.FrameCallback { override fun doFrame(frameTimeNanos: Long) { manuallyLayoutChildren() viewTreeObserver.dispatchOnGlobalLayout() Choreographer.getInstance().postFrameCallback(this) } }) }
private fun manuallyLayoutChildren() { for (i in 0 until childCount) { val child = getChildAt(i) child.measure( MeasureSpec.makeMeasureSpec(measuredWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(measuredHeight, MeasureSpec.EXACTLY) ) child.layout(0, 0, child.measuredWidth, child.measuredHeight) } }
.... } < /code> Теперь проблема в том, что я не вижу камеру, кнопка занимает всю ширину и высоту, если экран, теперь, когда я использую тот же код в нативном Android, она работает абсолютно нормально < /p> Клон этого репо < /p> npm install
private val REQUIRED_PERMISSIONS = mutableListOf(Manifest.permission.CAMERA).apply { if (Build.VERSION.SDK_INT Я также пытался сделать следующие вещи < /p> 1. override fun requestLayout() { super.requestLayout() post(measureAndLayout) }
private val measureAndLayout = Runnable { measure( MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY) ) layout(left, top, right, bottom) } < /code> [list] [*] private val measureAndlayout = runnable { ream ( mameaspec.makemeasperspec(width, mearspec.exactly), measurespec.makemeaspec-(height.xactly), exactly), exactly), exactly), exactly), exactly) < /br /measerspec.makemeaspec- ceace.xactly). /> Layout (слева, вверху, справа, внизу) } < /p> переопределить веселье намеров (WidthMeasurespec: int, heightmeaspec: int) { var maxwidth = 0 var maxheight = 0 for (i in 0 in gildcount) {br /> gath = 0 for (i in 0 in gildcount) { gate) {br /> gate) (child.visibility! = Gone) { child.measure(widthmeasurespec, termespec.unspecifififified) maxwidth = maxwidth.coerceatleast (child.measuredwidth) maxheight = maxheight.coerceatles /> val finalwidth = maxwidth.coerceatleasteast (prevededminimumwidth) val finalheight = maxheight.coerceatleast (prevededminimumheight) setmeaseRedDimension (finalwidth, finalHeight) (контекст как TheMedReActContext). /> (контекст как TheMedReactContext) .getNativeModule (uimanagermodule :: class.java) ? Int, справа: int, внизу: int) { super.onlayout(Changed, слева, вверху, справа, внизу) вручные /> super.onmeasure(widthmeasurespec, heightmeaspecpec) measurechildren (widthmeasurespec, heightmeaspec) } < /p> < /li> override fun requestlayout () {br />super.RequestlAyout. /> post (measureAndlayout) } < /p> private val measureAndLayout = Runnable { measure( MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY) ) layout(left, top, right, bottom) }
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { var maxWidth = 0 var maxHeight = 0 for (i in 0 until childCount) { val child = getChildAt(i) if (child.visibility != GONE) { child.measure(widthMeasureSpec, MeasureSpec.UNSPECIFIED) maxWidth = maxWidth.coerceAtLeast(child.measuredWidth) maxHeight = maxHeight.coerceAtLeast(child.measuredHeight) } } val finalWidth = maxWidth.coerceAtLeast(suggestedMinimumWidth) val finalHeight = maxHeight.coerceAtLeast(suggestedMinimumHeight) setMeasuredDimension(finalWidth, finalHeight) (context as ThemedReactContext).runOnNativeModulesQueueThread { (context as ThemedReactContext).getNativeModule(UIManagerModule::class.java) ?.updateNodeSize(id, finalWidth, finalHeight) } } [/code]
Я пытаюсь внедрить собственное представление Android в свое приложение React, я использую новую архитектуру
Итак, вот мой пример кода
class ReactMyCamera: ConstraintLayout {
private var viewFinder: PreviewView = PreviewView(context)
private var...
Я начинаю изучать создание мобильных приложений с помощью React Native и, даже после изучения множества руководств, сталкиваюсь с повторяющимися проблемами.
Я создал новое приложение с помощью реакции -native команда init MyApp — я заметил, что в...
Я столкнулся с проблемой в моем проекте React Native CLI, когда приложение iOS отображает белый экран при открытии приложения и после его перезагрузки. Приложение работает без проблем при первом запуске, но последующие перезагрузки (CMD + R)...