Skip to content

Commit

Permalink
Convert SavedReplyGlyphComponentSpec to KComponent
Browse files Browse the repository at this point in the history
Summary:
## This Diff
This diff converts `SavedReplyGlyphComponentSpec` to KComponent and updates both the MTV and UTV usages (although UTV code will eventually be deleted).

Note: I had to make some changes to core Litho code for this diff. The `StyleCompat` (to be used in Java code) object does not expose a method for setting touch expansion while `Style` (to be used in Kotlin code) does. I added a method to `StyleCompat` to allow us to set this in Java-land, following the example of similar props (e.g. margin).

Differential Revision: D67408743

fbshipit-source-id: eeef53e85cb1a14cbce81d5545d879ad9fd91f94
  • Loading branch information
Haseeb Saeed authored and facebook-github-bot committed Dec 24, 2024
1 parent 7fa45cd commit 2e0182e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions litho-core/src/main/java/com/facebook/litho/StyleCompat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import com.facebook.litho.view.onClick
import com.facebook.litho.view.onLongClick
import com.facebook.litho.view.onTouch
import com.facebook.litho.view.testKey
import com.facebook.litho.view.touchExpansion
import com.facebook.litho.view.wrapInView
import com.facebook.rendercore.dp
import com.facebook.rendercore.px
Expand Down Expand Up @@ -218,6 +219,11 @@ object StyleCompat {

/** @see [JavaStyle.onClick] */
@JvmStatic fun onClick(action: (ClickEvent) -> Unit): JavaStyle = JavaStyle().onClick(action)

/** @see [JavaStyle.touchExpansionDip] */
@JvmStatic
fun touchExpansionDip(yogaEdge: YogaEdge, value: Float): JavaStyle =
JavaStyle().touchExpansionDip(yogaEdge, value)
}

class JavaStyle {
Expand Down Expand Up @@ -496,6 +502,23 @@ class JavaStyle {
return this
}

fun touchExpansionDip(yogaEdge: YogaEdge, value: Float): JavaStyle {
val valueDip = value.dp
style =
when (yogaEdge) {
YogaEdge.LEFT -> style.touchExpansion(left = valueDip)
YogaEdge.VERTICAL -> style.touchExpansion(vertical = valueDip)
YogaEdge.TOP -> style.touchExpansion(top = valueDip)
YogaEdge.RIGHT -> style.touchExpansion(right = valueDip)
YogaEdge.BOTTOM -> style.touchExpansion(bottom = valueDip)
YogaEdge.START -> style.touchExpansion(start = valueDip)
YogaEdge.END -> style.touchExpansion(end = valueDip)
YogaEdge.HORIZONTAL -> style.touchExpansion(horizontal = valueDip)
YogaEdge.ALL -> style.touchExpansion(all = valueDip)
}
return this
}

fun build(): Style {
return style
}
Expand Down

0 comments on commit 2e0182e

Please sign in to comment.