Enable and apply Ktfmt to xplat/simplesql, xplat/sonar, and xplat/spectrum
Summary: As title. Reviewed By: zertosh Differential Revision: D30425160 fbshipit-source-id: c72d270d7cd3f30990aac55e33e8f72d60ed5fe2
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8e2a839f9d
commit
1db39b8171
@@ -22,8 +22,8 @@ class FlipperLeakListener : OnHeapAnalyzedListener {
|
|||||||
leaks.addAll(heapAnalysis.toLeakList())
|
leaks.addAll(heapAnalysis.toLeakList())
|
||||||
|
|
||||||
AndroidFlipperClient.getInstanceIfInitialized()?.let { client ->
|
AndroidFlipperClient.getInstanceIfInitialized()?.let { client ->
|
||||||
(client.getPlugin(LeakCanary2FlipperPlugin.ID) as? LeakCanary2FlipperPlugin)
|
(client.getPlugin(LeakCanary2FlipperPlugin.ID) as? LeakCanary2FlipperPlugin)?.reportLeaks(
|
||||||
?.reportLeaks(leaks)
|
leaks)
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultListener.onHeapAnalyzed(heapAnalysis)
|
defaultListener.onHeapAnalyzed(heapAnalysis)
|
||||||
@@ -31,13 +31,15 @@ class FlipperLeakListener : OnHeapAnalyzedListener {
|
|||||||
|
|
||||||
private fun HeapAnalysis.toLeakList(): List<Leak> {
|
private fun HeapAnalysis.toLeakList(): List<Leak> {
|
||||||
return if (this is HeapAnalysisSuccess) {
|
return if (this is HeapAnalysisSuccess) {
|
||||||
allLeaks.mapNotNull {
|
allLeaks
|
||||||
|
.mapNotNull {
|
||||||
if (it.leakTraces.isNotEmpty()) {
|
if (it.leakTraces.isNotEmpty()) {
|
||||||
it.leakTraces[0].toLeak(it.shortDescription)
|
it.leakTraces[0].toLeak(it.shortDescription)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}.toList()
|
}
|
||||||
|
.toList()
|
||||||
} else {
|
} else {
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,13 @@ package com.facebook.flipper.plugins.leakcanary2
|
|||||||
import com.facebook.flipper.core.FlipperArray
|
import com.facebook.flipper.core.FlipperArray
|
||||||
import com.facebook.flipper.core.FlipperObject
|
import com.facebook.flipper.core.FlipperObject
|
||||||
import com.facebook.flipper.core.FlipperValue
|
import com.facebook.flipper.core.FlipperValue
|
||||||
|
import java.util.UUID
|
||||||
import shark.LeakTrace
|
import shark.LeakTrace
|
||||||
import shark.LeakTraceObject
|
import shark.LeakTraceObject
|
||||||
import java.util.UUID
|
|
||||||
|
|
||||||
internal data class LeakCanary2Report(val leaks: List<Leak>) : FlipperValue {
|
internal data class LeakCanary2Report(val leaks: List<Leak>) : FlipperValue {
|
||||||
override fun toFlipperObject(): FlipperObject = FlipperObject.Builder()
|
override fun toFlipperObject(): FlipperObject =
|
||||||
|
FlipperObject.Builder()
|
||||||
.put("leaks", leaks.map { it.toFlipperObject() }.toFlipperArray())
|
.put("leaks", leaks.map { it.toFlipperObject() }.toFlipperArray())
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
@@ -44,9 +45,7 @@ internal data class Leak(
|
|||||||
@JvmName("toFlipperObjectStringFlipperObject")
|
@JvmName("toFlipperObjectStringFlipperObject")
|
||||||
private fun Map<String, FlipperObject>.toFlipperObject(): FlipperObject =
|
private fun Map<String, FlipperObject>.toFlipperObject(): FlipperObject =
|
||||||
asIterable()
|
asIterable()
|
||||||
.fold(FlipperObject.Builder()) { builder, entry ->
|
.fold(FlipperObject.Builder()) { builder, entry -> builder.put(entry.key, entry.value) }
|
||||||
builder.put(entry.key, entry.value)
|
|
||||||
}
|
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,23 +57,25 @@ internal fun LeakTrace.toLeak(title: String): Leak {
|
|||||||
retainedSize = retainedHeapByteSize?.let { "$it bytes" } ?: "unknown size",
|
retainedSize = retainedHeapByteSize?.let { "$it bytes" } ?: "unknown size",
|
||||||
signature = signature,
|
signature = signature,
|
||||||
root = elements.first().first,
|
root = elements.first().first,
|
||||||
details = "$this"
|
details = "$this")
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun LeakTrace.getElements(): List<Pair<String, Element>> {
|
private fun LeakTrace.getElements(): List<Pair<String, Element>> {
|
||||||
val referenceElements = referencePath.map { reference ->
|
val referenceElements =
|
||||||
|
referencePath
|
||||||
|
.map { reference ->
|
||||||
val id = UUID.randomUUID().toString()
|
val id = UUID.randomUUID().toString()
|
||||||
id to Element(id, reference.originObject)
|
id to Element(id, reference.originObject)
|
||||||
}.toMutableList()
|
}
|
||||||
|
.toMutableList()
|
||||||
|
|
||||||
val leakId = UUID.randomUUID().toString()
|
val leakId = UUID.randomUUID().toString()
|
||||||
referenceElements.add(leakId to Element(leakId, leakingObject))
|
referenceElements.add(leakId to Element(leakId, leakingObject))
|
||||||
|
|
||||||
return referenceElements.mapIndexed { index, pair ->
|
return referenceElements.mapIndexed { index, pair ->
|
||||||
pair.first to if (index == referenceElements.lastIndex) pair.second else pair.second.copy(
|
pair.first to
|
||||||
children = listOf(referenceElements[index + 1].second.id)
|
if (index == referenceElements.lastIndex) pair.second
|
||||||
)
|
else pair.second.copy(children = listOf(referenceElements[index + 1].second.id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,14 +87,16 @@ internal data class Element(
|
|||||||
val attributes: List<ElementAttribute>,
|
val attributes: List<ElementAttribute>,
|
||||||
val decoration: String = ""
|
val decoration: String = ""
|
||||||
) : FlipperValue {
|
) : FlipperValue {
|
||||||
constructor(id: String, leakObject: LeakTraceObject) : this(
|
constructor(
|
||||||
|
id: String,
|
||||||
|
leakObject: LeakTraceObject
|
||||||
|
) : this(
|
||||||
id = id,
|
id = id,
|
||||||
name = "${leakObject.className} (${leakObject.typeName})",
|
name = "${leakObject.className} (${leakObject.typeName})",
|
||||||
attributes = listOf(
|
attributes =
|
||||||
|
listOf(
|
||||||
ElementAttribute("leaking", leakObject.leakingStatus.shortName),
|
ElementAttribute("leaking", leakObject.leakingStatus.shortName),
|
||||||
ElementAttribute("retaining", leakObject.retaining)
|
ElementAttribute("retaining", leakObject.retaining)))
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
override fun toFlipperObject(): FlipperObject {
|
override fun toFlipperObject(): FlipperObject {
|
||||||
return FlipperObject.Builder()
|
return FlipperObject.Builder()
|
||||||
@@ -121,7 +124,8 @@ internal fun Iterable<FlipperObject>.toFlipperArray(): FlipperArray =
|
|||||||
fold(FlipperArray.Builder()) { builder, row -> builder.put(row) }.build()
|
fold(FlipperArray.Builder()) { builder, row -> builder.put(row) }.build()
|
||||||
|
|
||||||
private val LeakTraceObject.LeakingStatus.shortName: String
|
private val LeakTraceObject.LeakingStatus.shortName: String
|
||||||
get() = when (this) {
|
get() =
|
||||||
|
when (this) {
|
||||||
LeakTraceObject.LeakingStatus.NOT_LEAKING -> "N"
|
LeakTraceObject.LeakingStatus.NOT_LEAKING -> "N"
|
||||||
LeakTraceObject.LeakingStatus.LEAKING -> "Y"
|
LeakTraceObject.LeakingStatus.LEAKING -> "Y"
|
||||||
LeakTraceObject.LeakingStatus.UNKNOWN -> "?"
|
LeakTraceObject.LeakingStatus.UNKNOWN -> "?"
|
||||||
@@ -131,14 +135,8 @@ private val LeakTraceObject.retaining: String
|
|||||||
|
|
||||||
private val EMPTY_FLIPPER_OBJECT = FlipperObject.Builder().build()
|
private val EMPTY_FLIPPER_OBJECT = FlipperObject.Builder().build()
|
||||||
|
|
||||||
data class ElementAttribute(
|
data class ElementAttribute(val name: String, val value: String) : FlipperValue {
|
||||||
val name: String,
|
|
||||||
val value: String
|
|
||||||
) : FlipperValue {
|
|
||||||
override fun toFlipperObject(): FlipperObject {
|
override fun toFlipperObject(): FlipperObject {
|
||||||
return FlipperObject.Builder()
|
return FlipperObject.Builder().put("name", name).put("value", value).build()
|
||||||
.put("name", name)
|
|
||||||
.put("value", value)
|
|
||||||
.build()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,8 @@ import com.facebook.flipper.plugins.retrofit2protobuf.model.CallNestedMessagesPa
|
|||||||
|
|
||||||
object SendProtobufToFlipperFromRetrofit {
|
object SendProtobufToFlipperFromRetrofit {
|
||||||
operator fun invoke(baseUrl: String, service: Class<*>) {
|
operator fun invoke(baseUrl: String, service: Class<*>) {
|
||||||
getNetworkPlugin()?.addProtobufDefinitions(
|
getNetworkPlugin()
|
||||||
baseUrl,
|
?.addProtobufDefinitions(baseUrl, generateProtobufDefinitions(service).toFlipperArray())
|
||||||
generateProtobufDefinitions(service).toFlipperArray()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getNetworkPlugin(): NetworkFlipperPlugin? {
|
private fun getNetworkPlugin(): NetworkFlipperPlugin? {
|
||||||
@@ -30,9 +28,9 @@ object SendProtobufToFlipperFromRetrofit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun generateProtobufDefinitions(service: Class<*>): List<CallNestedMessagesPayload> {
|
private fun generateProtobufDefinitions(service: Class<*>): List<CallNestedMessagesPayload> {
|
||||||
return RetrofitServiceToGenericCallDefinitions(service).let { definitions ->
|
return RetrofitServiceToGenericCallDefinitions(service)
|
||||||
GenericCallDefinitionsToMessageDefinitionsIfProtobuf(definitions)
|
.let { definitions -> GenericCallDefinitionsToMessageDefinitionsIfProtobuf(definitions) }
|
||||||
}.let { messages ->
|
.let { messages ->
|
||||||
messages.map {
|
messages.map {
|
||||||
CallNestedMessagesPayload(
|
CallNestedMessagesPayload(
|
||||||
path = it.path,
|
path = it.path,
|
||||||
@@ -40,8 +38,7 @@ object SendProtobufToFlipperFromRetrofit {
|
|||||||
requestMessageFullName = it.requestMessageFullName,
|
requestMessageFullName = it.requestMessageFullName,
|
||||||
requestDefinitions = it.requestModel,
|
requestDefinitions = it.requestModel,
|
||||||
responseMessageFullName = it.responseMessageFullName,
|
responseMessageFullName = it.responseMessageFullName,
|
||||||
responseDefinitions = it.responseModel
|
responseDefinitions = it.responseModel)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,14 +12,14 @@ import com.facebook.flipper.plugins.retrofit2protobuf.model.GenericCallDefinitio
|
|||||||
import me.haroldmartin.protobufjavatoprotobufjs.ProtobufGeneratedJavaToProtobufJs
|
import me.haroldmartin.protobufjavatoprotobufjs.ProtobufGeneratedJavaToProtobufJs
|
||||||
|
|
||||||
internal object GenericCallDefinitionsToMessageDefinitionsIfProtobuf {
|
internal object GenericCallDefinitionsToMessageDefinitionsIfProtobuf {
|
||||||
operator fun invoke(callDefinitions: List<GenericCallDefinition>): List<FullNamedMessagesCallDefinition> {
|
operator fun invoke(
|
||||||
|
callDefinitions: List<GenericCallDefinition>
|
||||||
|
): List<FullNamedMessagesCallDefinition> {
|
||||||
return callDefinitions.mapNotNull { definition ->
|
return callDefinitions.mapNotNull { definition ->
|
||||||
val responseRootAndMessages = definition.responseType?.let {
|
val responseRootAndMessages =
|
||||||
ProtobufGeneratedJavaToProtobufJs(it)
|
definition.responseType?.let { ProtobufGeneratedJavaToProtobufJs(it) }
|
||||||
}
|
val requestRootAndMessages =
|
||||||
val requestRootAndMessages = definition.requestType?.let {
|
definition.requestType?.let { ProtobufGeneratedJavaToProtobufJs(it) }
|
||||||
ProtobufGeneratedJavaToProtobufJs(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
FullNamedMessagesCallDefinition(
|
FullNamedMessagesCallDefinition(
|
||||||
path = definition.path,
|
path = definition.path,
|
||||||
@@ -27,8 +27,7 @@ internal object GenericCallDefinitionsToMessageDefinitionsIfProtobuf {
|
|||||||
responseMessageFullName = responseRootAndMessages?.rootFullName,
|
responseMessageFullName = responseRootAndMessages?.rootFullName,
|
||||||
responseModel = responseRootAndMessages?.descriptors,
|
responseModel = responseRootAndMessages?.descriptors,
|
||||||
requestMessageFullName = requestRootAndMessages?.rootFullName,
|
requestMessageFullName = requestRootAndMessages?.rootFullName,
|
||||||
requestModel = requestRootAndMessages?.descriptors
|
requestModel = requestRootAndMessages?.descriptors)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,9 +24,7 @@ internal object RetrofitServiceToGenericCallDefinitions {
|
|||||||
path = path,
|
path = path,
|
||||||
method = httpMethod,
|
method = httpMethod,
|
||||||
responseType = responseType,
|
responseType = responseType,
|
||||||
requestType = method.requestBodyType
|
requestType = method.requestBodyType))
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
return methodToProtobufDefinition
|
return methodToProtobufDefinition
|
||||||
}
|
}
|
||||||
@@ -36,7 +34,8 @@ private val Array<Annotation>.urlPathAndMethod: Pair<String, String>?
|
|||||||
get() {
|
get() {
|
||||||
var path: Pair<String, String>? = null
|
var path: Pair<String, String>? = null
|
||||||
for (a in this) {
|
for (a in this) {
|
||||||
path = when (a.annotationClass) {
|
path =
|
||||||
|
when (a.annotationClass) {
|
||||||
retrofit2.http.DELETE::class -> (a as retrofit2.http.DELETE).value to "DELETE"
|
retrofit2.http.DELETE::class -> (a as retrofit2.http.DELETE).value to "DELETE"
|
||||||
retrofit2.http.GET::class -> (a as retrofit2.http.GET).value to "GET"
|
retrofit2.http.GET::class -> (a as retrofit2.http.GET).value to "GET"
|
||||||
retrofit2.http.HEAD::class -> (a as retrofit2.http.HEAD).value to "HEAD"
|
retrofit2.http.HEAD::class -> (a as retrofit2.http.HEAD).value to "HEAD"
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ internal data class CallNestedMessagesPayload(
|
|||||||
private fun Map<*, *>.toFlipperObject(): FlipperObject {
|
private fun Map<*, *>.toFlipperObject(): FlipperObject {
|
||||||
val builder = FlipperObject.Builder()
|
val builder = FlipperObject.Builder()
|
||||||
this.forEach { (key, value) ->
|
this.forEach { (key, value) ->
|
||||||
val castValue = when (value) {
|
val castValue =
|
||||||
|
when (value) {
|
||||||
is Map<*, *> -> value.toFlipperObject()
|
is Map<*, *> -> value.toFlipperObject()
|
||||||
is Iterable<*> -> value.toFlipperArray()
|
is Iterable<*> -> value.toFlipperArray()
|
||||||
else -> value
|
else -> value
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
|
|
||||||
package com.facebook.flipper.sample.tutorial
|
package com.facebook.flipper.sample.tutorial
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import com.facebook.flipper.sample.tutorial.ui.RootComponent
|
import com.facebook.flipper.sample.tutorial.ui.RootComponent
|
||||||
import com.facebook.litho.LithoView
|
import com.facebook.litho.LithoView
|
||||||
import com.facebook.litho.sections.SectionContext
|
import com.facebook.litho.sections.SectionContext
|
||||||
@@ -20,8 +20,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
setContentView(
|
setContentView(LithoView.create(this, RootComponent.create(sectionContext).build()))
|
||||||
LithoView.create(this, RootComponent.create(sectionContext).build())
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ package com.facebook.flipper.sample.tutorial
|
|||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
|
|
||||||
object MarineMammals {
|
object MarineMammals {
|
||||||
val list = listOf(
|
val list =
|
||||||
|
listOf(
|
||||||
MarineMammal(
|
MarineMammal(
|
||||||
"Polar Bear",
|
"Polar Bear",
|
||||||
"https://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Ursus_maritimus_4_1996-08-04.jpg/190px-Ursus_maritimus_4_1996-08-04.jpg".toUri()),
|
"https://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Ursus_maritimus_4_1996-08-04.jpg/190px-Ursus_maritimus_4_1996-08-04.jpg".toUri()),
|
||||||
@@ -22,6 +23,5 @@ object MarineMammals {
|
|||||||
"https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/FL_fig04.jpg/230px-FL_fig04.jpg".toUri()),
|
"https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/FL_fig04.jpg/230px-FL_fig04.jpg".toUri()),
|
||||||
MarineMammal(
|
MarineMammal(
|
||||||
"Bottlenose Dolphin",
|
"Bottlenose Dolphin",
|
||||||
"https://upload.wikimedia.org/wikipedia/commons/thumb/1/10/Tursiops_truncatus_01.jpg/220px-Tursiops_truncatus_01.jpg".toUri())
|
"https://upload.wikimedia.org/wikipedia/commons/thumb/1/10/Tursiops_truncatus_01.jpg/220px-Tursiops_truncatus_01.jpg".toUri()))
|
||||||
)
|
|
||||||
}
|
}
|
||||||
@@ -20,12 +20,15 @@ class SeaMammalFlipperPlugin : FlipperPlugin {
|
|||||||
override fun onConnect(connection: FlipperConnection?) {
|
override fun onConnect(connection: FlipperConnection?) {
|
||||||
this.connection = connection
|
this.connection = connection
|
||||||
|
|
||||||
MarineMammals.list.mapIndexed { index, (title, picture_url) ->
|
MarineMammals.list
|
||||||
|
.mapIndexed { index, (title, picture_url) ->
|
||||||
FlipperObject.Builder()
|
FlipperObject.Builder()
|
||||||
.put("id", index)
|
.put("id", index)
|
||||||
.put("title", title)
|
.put("title", title)
|
||||||
.put("url", picture_url).build()
|
.put("url", picture_url)
|
||||||
}.forEach(this::newRow)
|
.build()
|
||||||
|
}
|
||||||
|
.forEach(this::newRow)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDisconnect() {
|
override fun onDisconnect() {
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import com.facebook.litho.annotations.LayoutSpec
|
|||||||
import com.facebook.litho.annotations.OnCreateLayout
|
import com.facebook.litho.annotations.OnCreateLayout
|
||||||
import com.facebook.litho.annotations.Prop
|
import com.facebook.litho.annotations.Prop
|
||||||
import com.facebook.litho.widget.Card
|
import com.facebook.litho.widget.Card
|
||||||
|
|
||||||
import com.facebook.yoga.YogaEdge.HORIZONTAL
|
import com.facebook.yoga.YogaEdge.HORIZONTAL
|
||||||
import com.facebook.yoga.YogaEdge.VERTICAL
|
import com.facebook.yoga.YogaEdge.VERTICAL
|
||||||
|
|
||||||
@@ -23,17 +22,10 @@ import com.facebook.yoga.YogaEdge.VERTICAL
|
|||||||
object FeedItemCardSpec {
|
object FeedItemCardSpec {
|
||||||
|
|
||||||
@OnCreateLayout
|
@OnCreateLayout
|
||||||
fun onCreateLayout(
|
fun onCreateLayout(c: ComponentContext, @Prop mammal: MarineMammal): Component =
|
||||||
c: ComponentContext,
|
|
||||||
@Prop mammal: MarineMammal
|
|
||||||
): Component =
|
|
||||||
Column.create(c)
|
Column.create(c)
|
||||||
.paddingDip(VERTICAL, 8f)
|
.paddingDip(VERTICAL, 8f)
|
||||||
.paddingDip(HORIZONTAL, 16f)
|
.paddingDip(HORIZONTAL, 16f)
|
||||||
.child(
|
.child(Card.create(c).content(MarineMammelComponent.create(c).mammal(mammal)))
|
||||||
Card.create(c)
|
|
||||||
.content(
|
|
||||||
MarineMammelComponent.create(c)
|
|
||||||
.mammal(mammal)))
|
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
@@ -25,17 +25,13 @@ object FeedSectionSpec {
|
|||||||
@OnCreateChildren
|
@OnCreateChildren
|
||||||
fun onCreateChildren(c: SectionContext, @Prop data: List<MarineMammal>): Children =
|
fun onCreateChildren(c: SectionContext, @Prop data: List<MarineMammal>): Children =
|
||||||
Children.create()
|
Children.create()
|
||||||
.child(DataDiffSection.create<MarineMammal>(c)
|
.child(
|
||||||
|
DataDiffSection.create<MarineMammal>(c)
|
||||||
.data(data)
|
.data(data)
|
||||||
.renderEventHandler(FeedSection.render(c)))
|
.renderEventHandler(FeedSection.render(c)))
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
@OnEvent(RenderEvent::class)
|
@OnEvent(RenderEvent::class)
|
||||||
fun render(
|
fun render(c: SectionContext, @FromEvent model: MarineMammal): RenderInfo =
|
||||||
c: SectionContext,
|
ComponentRenderInfo.create().component(FeedItemCard.create(c).mammal(model).build()).build()
|
||||||
@FromEvent model: MarineMammal
|
|
||||||
): RenderInfo =
|
|
||||||
ComponentRenderInfo.create()
|
|
||||||
.component(FeedItemCard.create(c).mammal(model).build())
|
|
||||||
.build()
|
|
||||||
}
|
}
|
||||||
@@ -17,22 +17,16 @@ import com.facebook.litho.annotations.OnCreateLayout
|
|||||||
import com.facebook.litho.annotations.Prop
|
import com.facebook.litho.annotations.Prop
|
||||||
import com.facebook.litho.widget.Text
|
import com.facebook.litho.widget.Text
|
||||||
import com.facebook.yoga.YogaEdge.BOTTOM
|
import com.facebook.yoga.YogaEdge.BOTTOM
|
||||||
import com.facebook.yoga.YogaEdge.LEFT
|
|
||||||
import com.facebook.yoga.YogaEdge.HORIZONTAL
|
import com.facebook.yoga.YogaEdge.HORIZONTAL
|
||||||
|
import com.facebook.yoga.YogaEdge.LEFT
|
||||||
import com.facebook.yoga.YogaPositionType.ABSOLUTE
|
import com.facebook.yoga.YogaPositionType.ABSOLUTE
|
||||||
|
|
||||||
@LayoutSpec
|
@LayoutSpec
|
||||||
object MarineMammelComponentSpec {
|
object MarineMammelComponentSpec {
|
||||||
@OnCreateLayout
|
@OnCreateLayout
|
||||||
fun onCreateLayout(
|
fun onCreateLayout(c: ComponentContext, @Prop mammal: MarineMammal): Component =
|
||||||
c: ComponentContext,
|
|
||||||
@Prop mammal: MarineMammal
|
|
||||||
): Component =
|
|
||||||
Column.create(c)
|
Column.create(c)
|
||||||
.child(SingleImageComponent.create(c)
|
.child(SingleImageComponent.create(c).image(mammal.picture_url).build())
|
||||||
.image(mammal.picture_url)
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
.child(
|
.child(
|
||||||
Text.create(c)
|
Text.create(c)
|
||||||
.text(mammal.title)
|
.text(mammal.title)
|
||||||
@@ -44,5 +38,4 @@ object MarineMammelComponentSpec {
|
|||||||
.positionDip(LEFT, 4f)
|
.positionDip(LEFT, 4f)
|
||||||
.paddingDip(HORIZONTAL, 6f))
|
.paddingDip(HORIZONTAL, 6f))
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,20 +20,15 @@ import com.facebook.litho.fresco.FrescoImage
|
|||||||
@LayoutSpec
|
@LayoutSpec
|
||||||
object SingleImageComponentSpec {
|
object SingleImageComponentSpec {
|
||||||
|
|
||||||
@PropDefault
|
@PropDefault val imageAspectRatio = 1f
|
||||||
val imageAspectRatio = 1f
|
|
||||||
|
|
||||||
@OnCreateLayout
|
@OnCreateLayout
|
||||||
fun onCreateLayout(
|
fun onCreateLayout(
|
||||||
c: ComponentContext,
|
c: ComponentContext,
|
||||||
@Prop image: Uri,
|
@Prop image: Uri,
|
||||||
@Prop(optional = true) imageAspectRatio: Float): Component =
|
@Prop(optional = true) imageAspectRatio: Float
|
||||||
Fresco.newDraweeControllerBuilder()
|
): Component =
|
||||||
.setUri(image)
|
Fresco.newDraweeControllerBuilder().setUri(image).build().let {
|
||||||
.build().let {
|
FrescoImage.create(c).controller(it).imageAspectRatio(imageAspectRatio).build()
|
||||||
FrescoImage.create(c)
|
|
||||||
.controller(it)
|
|
||||||
.imageAspectRatio(imageAspectRatio)
|
|
||||||
.build()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,9 +7,8 @@
|
|||||||
|
|
||||||
package com.facebook.flipper.sample.tutorial
|
package com.facebook.flipper.sample.tutorial
|
||||||
|
|
||||||
import org.junit.Test
|
|
||||||
|
|
||||||
import org.junit.Assert.*
|
import org.junit.Assert.*
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example local unit test, which will execute on the development machine (host).
|
* Example local unit test, which will execute on the development machine (host).
|
||||||
|
|||||||
Reference in New Issue
Block a user