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
@@ -7,21 +7,19 @@
|
||||
|
||||
package com.facebook.flipper.sample.tutorial
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.facebook.flipper.sample.tutorial.ui.RootComponent
|
||||
import com.facebook.litho.LithoView
|
||||
import com.facebook.litho.sections.SectionContext
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
private val sectionContext: SectionContext by lazy { SectionContext(this) }
|
||||
private val sectionContext: SectionContext by lazy { SectionContext(this) }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setContentView(
|
||||
LithoView.create(this, RootComponent.create(sectionContext).build())
|
||||
)
|
||||
}
|
||||
setContentView(LithoView.create(this, RootComponent.create(sectionContext).build()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,4 +9,4 @@ package com.facebook.flipper.sample.tutorial
|
||||
|
||||
import android.net.Uri
|
||||
|
||||
data class MarineMammal(val title: String, val picture_url: Uri)
|
||||
data class MarineMammal(val title: String, val picture_url: Uri)
|
||||
|
||||
@@ -10,18 +10,18 @@ package com.facebook.flipper.sample.tutorial
|
||||
import androidx.core.net.toUri
|
||||
|
||||
object MarineMammals {
|
||||
val list = listOf(
|
||||
MarineMammal(
|
||||
"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()),
|
||||
MarineMammal(
|
||||
"Sea Otter",
|
||||
"https://upload.wikimedia.org/wikipedia/commons/thumb/1/15/Sea_otter_cropped.jpg/220px-Sea_otter_cropped.jpg".toUri()),
|
||||
MarineMammal(
|
||||
"West Indian Manatee",
|
||||
"https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/FL_fig04.jpg/230px-FL_fig04.jpg".toUri()),
|
||||
MarineMammal(
|
||||
"Bottlenose Dolphin",
|
||||
"https://upload.wikimedia.org/wikipedia/commons/thumb/1/10/Tursiops_truncatus_01.jpg/220px-Tursiops_truncatus_01.jpg".toUri())
|
||||
)
|
||||
}
|
||||
val list =
|
||||
listOf(
|
||||
MarineMammal(
|
||||
"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()),
|
||||
MarineMammal(
|
||||
"Sea Otter",
|
||||
"https://upload.wikimedia.org/wikipedia/commons/thumb/1/15/Sea_otter_cropped.jpg/220px-Sea_otter_cropped.jpg".toUri()),
|
||||
MarineMammal(
|
||||
"West Indian Manatee",
|
||||
"https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/FL_fig04.jpg/230px-FL_fig04.jpg".toUri()),
|
||||
MarineMammal(
|
||||
"Bottlenose Dolphin",
|
||||
"https://upload.wikimedia.org/wikipedia/commons/thumb/1/10/Tursiops_truncatus_01.jpg/220px-Tursiops_truncatus_01.jpg".toUri()))
|
||||
}
|
||||
|
||||
@@ -19,23 +19,23 @@ import com.facebook.litho.editor.flipper.LithoFlipperDescriptors
|
||||
import com.facebook.soloader.SoLoader
|
||||
|
||||
class TutorialApplication : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
SoLoader.init(this, false)
|
||||
Fresco.initialize(this)
|
||||
SoLoader.init(this, false)
|
||||
Fresco.initialize(this)
|
||||
|
||||
// Normally, you would want to make these dependent on BuildConfig.DEBUG.
|
||||
ComponentsConfiguration.isDebugModeEnabled = true
|
||||
ComponentsConfiguration.enableRenderInfoDebugging = true
|
||||
// Normally, you would want to make these dependent on BuildConfig.DEBUG.
|
||||
ComponentsConfiguration.isDebugModeEnabled = true
|
||||
ComponentsConfiguration.enableRenderInfoDebugging = true
|
||||
|
||||
val flipperClient = AndroidFlipperClient.getInstance(this)
|
||||
val descriptorMapping = DescriptorMapping.withDefaults()
|
||||
LithoFlipperDescriptors.addWithSections(descriptorMapping)
|
||||
val flipperClient = AndroidFlipperClient.getInstance(this)
|
||||
val descriptorMapping = DescriptorMapping.withDefaults()
|
||||
LithoFlipperDescriptors.addWithSections(descriptorMapping)
|
||||
|
||||
flipperClient.addPlugin(InspectorFlipperPlugin(this, descriptorMapping))
|
||||
flipperClient.addPlugin(FrescoFlipperPlugin())
|
||||
flipperClient.addPlugin(SeaMammalFlipperPlugin())
|
||||
flipperClient.start()
|
||||
}
|
||||
flipperClient.addPlugin(InspectorFlipperPlugin(this, descriptorMapping))
|
||||
flipperClient.addPlugin(FrescoFlipperPlugin())
|
||||
flipperClient.addPlugin(SeaMammalFlipperPlugin())
|
||||
flipperClient.start()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,28 +13,31 @@ import com.facebook.flipper.core.FlipperPlugin
|
||||
import com.facebook.flipper.sample.tutorial.MarineMammals
|
||||
|
||||
class SeaMammalFlipperPlugin : FlipperPlugin {
|
||||
private var connection: FlipperConnection? = null
|
||||
private var connection: FlipperConnection? = null
|
||||
|
||||
override fun getId(): String = "sea-mammals"
|
||||
override fun getId(): String = "sea-mammals"
|
||||
|
||||
override fun onConnect(connection: FlipperConnection?) {
|
||||
this.connection = connection
|
||||
override fun onConnect(connection: FlipperConnection?) {
|
||||
this.connection = connection
|
||||
|
||||
MarineMammals.list.mapIndexed { index, (title, picture_url) ->
|
||||
FlipperObject.Builder()
|
||||
.put("id", index)
|
||||
.put("title", title)
|
||||
.put("url", picture_url).build()
|
||||
}.forEach(this::newRow)
|
||||
}
|
||||
MarineMammals.list
|
||||
.mapIndexed { index, (title, picture_url) ->
|
||||
FlipperObject.Builder()
|
||||
.put("id", index)
|
||||
.put("title", title)
|
||||
.put("url", picture_url)
|
||||
.build()
|
||||
}
|
||||
.forEach(this::newRow)
|
||||
}
|
||||
|
||||
override fun onDisconnect() {
|
||||
connection = null
|
||||
}
|
||||
override fun onDisconnect() {
|
||||
connection = null
|
||||
}
|
||||
|
||||
override fun runInBackground(): Boolean = true
|
||||
override fun runInBackground(): Boolean = true
|
||||
|
||||
private fun newRow(row: FlipperObject) {
|
||||
connection?.send("newRow", row)
|
||||
}
|
||||
private fun newRow(row: FlipperObject) {
|
||||
connection?.send("newRow", row)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import com.facebook.litho.annotations.LayoutSpec
|
||||
import com.facebook.litho.annotations.OnCreateLayout
|
||||
import com.facebook.litho.annotations.Prop
|
||||
import com.facebook.litho.widget.Card
|
||||
|
||||
import com.facebook.yoga.YogaEdge.HORIZONTAL
|
||||
import com.facebook.yoga.YogaEdge.VERTICAL
|
||||
|
||||
@@ -23,17 +22,10 @@ import com.facebook.yoga.YogaEdge.VERTICAL
|
||||
object FeedItemCardSpec {
|
||||
|
||||
@OnCreateLayout
|
||||
fun onCreateLayout(
|
||||
c: ComponentContext,
|
||||
@Prop mammal: MarineMammal
|
||||
): Component =
|
||||
fun onCreateLayout(c: ComponentContext, @Prop mammal: MarineMammal): Component =
|
||||
Column.create(c)
|
||||
.paddingDip(VERTICAL, 8f)
|
||||
.paddingDip(HORIZONTAL, 16f)
|
||||
.child(
|
||||
Card.create(c)
|
||||
.content(
|
||||
MarineMammelComponent.create(c)
|
||||
.mammal(mammal)))
|
||||
.child(Card.create(c).content(MarineMammelComponent.create(c).mammal(mammal)))
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,20 +22,16 @@ import com.facebook.litho.widget.RenderInfo
|
||||
|
||||
@GroupSectionSpec
|
||||
object FeedSectionSpec {
|
||||
@OnCreateChildren
|
||||
fun onCreateChildren(c: SectionContext, @Prop data: List<MarineMammal>): Children =
|
||||
Children.create()
|
||||
.child(DataDiffSection.create<MarineMammal>(c)
|
||||
.data(data)
|
||||
.renderEventHandler(FeedSection.render(c)))
|
||||
.build()
|
||||
@OnCreateChildren
|
||||
fun onCreateChildren(c: SectionContext, @Prop data: List<MarineMammal>): Children =
|
||||
Children.create()
|
||||
.child(
|
||||
DataDiffSection.create<MarineMammal>(c)
|
||||
.data(data)
|
||||
.renderEventHandler(FeedSection.render(c)))
|
||||
.build()
|
||||
|
||||
@OnEvent(RenderEvent::class)
|
||||
fun render(
|
||||
c: SectionContext,
|
||||
@FromEvent model: MarineMammal
|
||||
): RenderInfo =
|
||||
ComponentRenderInfo.create()
|
||||
.component(FeedItemCard.create(c).mammal(model).build())
|
||||
.build()
|
||||
}
|
||||
@OnEvent(RenderEvent::class)
|
||||
fun render(c: SectionContext, @FromEvent model: MarineMammal): RenderInfo =
|
||||
ComponentRenderInfo.create().component(FeedItemCard.create(c).mammal(model).build()).build()
|
||||
}
|
||||
|
||||
@@ -17,32 +17,25 @@ import com.facebook.litho.annotations.OnCreateLayout
|
||||
import com.facebook.litho.annotations.Prop
|
||||
import com.facebook.litho.widget.Text
|
||||
import com.facebook.yoga.YogaEdge.BOTTOM
|
||||
import com.facebook.yoga.YogaEdge.LEFT
|
||||
import com.facebook.yoga.YogaEdge.HORIZONTAL
|
||||
import com.facebook.yoga.YogaEdge.LEFT
|
||||
import com.facebook.yoga.YogaPositionType.ABSOLUTE
|
||||
|
||||
@LayoutSpec
|
||||
object MarineMammelComponentSpec {
|
||||
@OnCreateLayout
|
||||
fun onCreateLayout(
|
||||
c: ComponentContext,
|
||||
@Prop mammal: MarineMammal
|
||||
): Component =
|
||||
Column.create(c)
|
||||
.child(SingleImageComponent.create(c)
|
||||
.image(mammal.picture_url)
|
||||
.build()
|
||||
)
|
||||
.child(
|
||||
Text.create(c)
|
||||
.text(mammal.title)
|
||||
.textStyle(Typeface.BOLD)
|
||||
.textSizeDip(24f)
|
||||
.backgroundColor(0xDDFFFFFF.toInt())
|
||||
.positionType(ABSOLUTE)
|
||||
.positionDip(BOTTOM, 4f)
|
||||
.positionDip(LEFT, 4f)
|
||||
.paddingDip(HORIZONTAL, 6f))
|
||||
.build()
|
||||
|
||||
@OnCreateLayout
|
||||
fun onCreateLayout(c: ComponentContext, @Prop mammal: MarineMammal): Component =
|
||||
Column.create(c)
|
||||
.child(SingleImageComponent.create(c).image(mammal.picture_url).build())
|
||||
.child(
|
||||
Text.create(c)
|
||||
.text(mammal.title)
|
||||
.textStyle(Typeface.BOLD)
|
||||
.textSizeDip(24f)
|
||||
.backgroundColor(0xDDFFFFFF.toInt())
|
||||
.positionType(ABSOLUTE)
|
||||
.positionDip(BOTTOM, 4f)
|
||||
.positionDip(LEFT, 4f)
|
||||
.paddingDip(HORIZONTAL, 6f))
|
||||
.build()
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ import com.facebook.yoga.YogaEdge
|
||||
|
||||
@LayoutSpec
|
||||
object RootComponentSpec {
|
||||
@OnCreateLayout
|
||||
fun onCreateLayout(c: ComponentContext): Component =
|
||||
RecyclerCollectionComponent.create(c)
|
||||
.disablePTR(true)
|
||||
.section(FeedSection.create(SectionContext(c)).data(MarineMammals.list).build())
|
||||
.paddingDip(YogaEdge.TOP, 8f)
|
||||
.build()
|
||||
}
|
||||
@OnCreateLayout
|
||||
fun onCreateLayout(c: ComponentContext): Component =
|
||||
RecyclerCollectionComponent.create(c)
|
||||
.disablePTR(true)
|
||||
.section(FeedSection.create(SectionContext(c)).data(MarineMammals.list).build())
|
||||
.paddingDip(YogaEdge.TOP, 8f)
|
||||
.build()
|
||||
}
|
||||
|
||||
@@ -20,20 +20,15 @@ import com.facebook.litho.fresco.FrescoImage
|
||||
@LayoutSpec
|
||||
object SingleImageComponentSpec {
|
||||
|
||||
@PropDefault
|
||||
val imageAspectRatio = 1f
|
||||
@PropDefault val imageAspectRatio = 1f
|
||||
|
||||
@OnCreateLayout
|
||||
fun onCreateLayout(
|
||||
c: ComponentContext,
|
||||
@Prop image: Uri,
|
||||
@Prop(optional = true) imageAspectRatio: Float): Component =
|
||||
Fresco.newDraweeControllerBuilder()
|
||||
.setUri(image)
|
||||
.build().let {
|
||||
FrescoImage.create(c)
|
||||
.controller(it)
|
||||
.imageAspectRatio(imageAspectRatio)
|
||||
.build()
|
||||
@Prop(optional = true) imageAspectRatio: Float
|
||||
): Component =
|
||||
Fresco.newDraweeControllerBuilder().setUri(image).build().let {
|
||||
FrescoImage.create(c).controller(it).imageAspectRatio(imageAspectRatio).build()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,8 @@
|
||||
|
||||
package com.facebook.flipper.sample.tutorial
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
@@ -17,8 +16,8 @@ import org.junit.Assert.*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user