Basic Litho support

Summary: Added an initial litho Tree observer and descriptors, its quiet naive and will be improved in a future diff

Reviewed By: lblasa

Differential Revision: D39466931

fbshipit-source-id: 66a462882af2e585b9719ee2f61595449f99c5e5
This commit is contained in:
Luke De Feo
2022-09-13 11:05:42 -07:00
committed by Facebook GitHub Bot
parent 24ec43eb92
commit 0562178739
8 changed files with 175 additions and 5 deletions

View File

@@ -21,14 +21,18 @@ import kotlinx.serialization.json.Json
const val LogTag = "FlipperUIDebugger"
class UIDebuggerFlipperPlugin(val application: Application) : FlipperPlugin {
class UIDebuggerFlipperPlugin(
val application: Application,
descriptorRegister: DescriptorRegister?,
observerFactory: TreeObserverFactory?
) : FlipperPlugin {
private val context: Context =
Context(
ApplicationRef(application),
ConnectionRef(null),
DescriptorRegister.withDefaults(),
TreeObserverFactory.withDefaults())
descriptorRegister = descriptorRegister ?: DescriptorRegister.withDefaults(),
observerFactory = observerFactory ?: TreeObserverFactory.withDefaults())
private val nativeScanScheduler = Scheduler(NativeScanScheduler(context))

View File

@@ -14,6 +14,7 @@ import com.facebook.flipper.plugins.uidebugger.LogTag
import com.facebook.flipper.plugins.uidebugger.SubtreeUpdate
import com.facebook.flipper.plugins.uidebugger.TreeObserver
import com.facebook.flipper.plugins.uidebugger.core.Context
import com.facebook.flipper.plugins.uidebugger.identityHashCode
typealias DecorView = View
@@ -40,6 +41,16 @@ class DecorViewObserver(val context: Context) : TreeObserver<DecorView>() {
val start = System.currentTimeMillis()
if (start - lastSend > throttleTimeMs) {
val (nodes, skipped) = context.layoutTraversal.traverse(node)
for (observerRoot in skipped) {
if (!children.containsKey(observerRoot.identityHashCode())) {
val observer = context.observerFactory.createObserver(observerRoot, context)!!
observer.subscribe(observerRoot)
children[observerRoot.identityHashCode()] = observer
}
}
val traversalComplete = System.currentTimeMillis()
context.treeObserverManager.emit(
SubtreeUpdate("DecorView", nodes, start, traversalComplete))

View File

@@ -8,6 +8,8 @@
package com.facebook.flipper.plugins.uidebugger
import com.facebook.flipper.plugins.uidebugger.core.ApplicationRef
import com.facebook.flipper.plugins.uidebugger.descriptors.DescriptorRegister
import com.facebook.flipper.plugins.uidebugger.observers.TreeObserverFactory
import org.junit.Assert
import org.junit.Before
import org.junit.Test
@@ -30,7 +32,11 @@ class UIDebuggerFlipperPluginTest {
@Throws(Exception::class)
@Test
fun emptyTest() {
var plugin = UIDebuggerFlipperPlugin(app)
var plugin =
UIDebuggerFlipperPlugin(
app,
DescriptorRegister.Companion.withDefaults(),
TreeObserverFactory.Companion.withDefaults())
Assert.assertNotNull(plugin)
}
}