Skip to content

Commit

Permalink
Migrate Spacer implementations away from subtypes
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 committed Oct 23, 2024
1 parent f377665 commit 814a4db
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 814a4db

Please sign in to comment.