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 76b005b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 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

0 comments on commit 76b005b

Please sign in to comment.