Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Spacer implementations away from subtypes #2401

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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