Use chained descriptor for snapshots

Summary:
This change removes the getSnapshot implementation from ViewGroupDescriptor.

Instead we rely on the chain implementation to get one.

Once we do get a snapshot, return.

Reviewed By: LukeDefeo

Differential Revision: D39849484

fbshipit-source-id: bfa0b1af22cf501777687295b8d792f8144a8d3b
This commit is contained in:
Lorenzo Blasa
2022-09-27 13:00:04 -07:00
committed by Facebook GitHub Bot
parent ff3fb338ab
commit 8bb711ddfb
2 changed files with 1 additions and 27 deletions

View File

@@ -105,7 +105,7 @@ abstract class ChainedDescriptor<T> : NodeDescriptor<T> {
/** Get a snapshot of the node. */
final override fun getSnapshot(node: T, bitmap: Bitmap?): Bitmap? {
return onGetSnapshot(node, bitmap)
return onGetSnapshot(node, bitmap) ?: mSuper?.onGetSnapshot(node, bitmap)
}
open fun onGetSnapshot(node: T, bitmap: Bitmap?): Bitmap? {

View File

@@ -7,8 +7,6 @@
package com.facebook.flipper.plugins.uidebugger.descriptors
import android.graphics.Bitmap
import android.graphics.Canvas
import android.os.Build
import android.view.View
import android.view.ViewGroup
@@ -50,30 +48,6 @@ object ViewGroupDescriptor : ChainedDescriptor<ViewGroup>() {
attributeSections["ViewGroup"] = InspectableObject(viewGroupAttrs)
}
override fun onGetSnapshot(node: ViewGroup, bitmap: Bitmap?): Bitmap? {
if (node.width <= 0 || node.height <= 0) {
return null
}
var workingBitmap = bitmap
try {
val differentSize =
if (bitmap != null) (node.width != bitmap.width || node.height != bitmap.height)
else false
if (workingBitmap == null || differentSize) {
val viewWidth: Int = node.width
val viewHeight: Int = node.height
workingBitmap = BitmapPool.createBitmapWithDefaultConfig(viewWidth, viewHeight)
}
val canvas = Canvas(workingBitmap)
node.draw(canvas)
} catch (e: OutOfMemoryError) {}
return workingBitmap
}
private val LayoutModeMapping: EnumMapping<Int> =
object :
EnumMapping<Int>(