Skip to content

Commit

Permalink
Migrate Spacer implementations away from subtypes (#2401)
Browse files Browse the repository at this point in the history
When widgets switch to abstract classes, this will no longer be allowed.
  • Loading branch information
JakeWharton authored Oct 23, 2024
1 parent 2f23df9 commit 8367fcf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ internal class UIViewSpacer : Spacer<UIView> {
private fun invalidate() {
value.setNeedsLayout()
}
}

private inner class SpacerUIView : UIView(cValue { CGRectZero }) {
var width = 0.0
var height = 0.0
private class SpacerUIView : UIView(cValue { CGRectZero }) {
var width = 0.0
var height = 0.0

override fun intrinsicContentSize(): CValue<CGSize> {
return CGSizeMake(width, height)
}
override fun intrinsicContentSize(): CValue<CGSize> {
return CGSizeMake(width, height)
}

override fun sizeThatFits(size: CValue<CGSize>): CValue<CGSize> {
return CGSizeMake(width, height)
}
override fun sizeThatFits(size: CValue<CGSize>): CValue<CGSize> {
return CGSizeMake(width, height)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ import kotlin.math.min

internal class ViewSpacer(
context: Context,
) : View(context),
Spacer<View> {
) : Spacer<View> {
private val density = Density(context.resources)

override val value get() = this
override val value: View = SpacerView(context)

override var modifier: Modifier = Modifier

Expand All @@ -44,7 +43,9 @@ internal class ViewSpacer(
value.minimumHeight = with(density) { height.toPxInt() }
value.requestLayout()
}
}

private class SpacerView(context: Context) : View(context) {
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
setMeasuredDimension(
getDefaultSizeSpace(suggestedMinimumWidth, widthMeasureSpec),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ViewFlexContainerTest(
override fun spacer(backgroundColor: Int): Spacer<View> {
return ViewSpacer(paparazzi.context)
.apply {
setBackgroundColor(backgroundColor)
value.setBackgroundColor(backgroundColor)
}
}

Expand Down

0 comments on commit 8367fcf

Please sign in to comment.