Skip to content

Commit

Permalink
Use Fill for SimpleColumn
Browse files Browse the repository at this point in the history
  • Loading branch information
squarejesse committed Nov 4, 2024
1 parent e1e1460 commit d861e69
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ final class SnapshotTestingCallback : Redwood_snapshot_testingUIViewSnapshotCall
func verifySnapshot(view: UIView, name: String?, delay: TimeInterval = 0.0) {
// Set `record` to true to generate new snapshots. Be sure to revert that before committing!
// Note that tests always fail when `record` is true.
assertSnapshot(of: view, as: .wait(for: delay, on: .image), named: name, record: false, file: fileName, testName: testName)
assertSnapshot(of: view, as: .wait(for: delay, on: .image), named: name, record: true, file: fileName, testName: testName)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package app.cash.redwood.snapshot.testing

import androidx.compose.ui.unit.Dp as ComposeDp
import app.cash.redwood.Modifier as RedwoodModifier
import app.cash.redwood.snapshot.testing.Color as ColorWidget
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -32,11 +35,8 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp as ComposeDp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import app.cash.redwood.Modifier as RedwoodModifier
import app.cash.redwood.snapshot.testing.Color as ColorWidget
import app.cash.redwood.ui.Dp
import app.cash.redwood.ui.toPlatformDp

Expand Down Expand Up @@ -113,6 +113,7 @@ class ComposeUiColumn : SimpleColumn<@Composable () -> Unit> {
override var modifier: RedwoodModifier = RedwoodModifier

override val value = @Composable {
// We'd like to pass Modifier.fillMaxWidth() to all children.
Column {
for (child in children) {
child()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package app.cash.redwood.snapshot.testing
import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.ScrollView
import android.widget.TextView
Expand Down Expand Up @@ -67,7 +68,17 @@ class ViewColor(context: Context) : Color<View> {
private val density = Density(context.resources)
override val value = object : View(context) {
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
setMeasuredDimension(minimumWidth, minimumHeight)
val width = when (MeasureSpec.getMode(widthMeasureSpec)) {
MeasureSpec.EXACTLY -> MeasureSpec.getSize(widthMeasureSpec)
MeasureSpec.AT_MOST -> minimumWidth.coerceAtMost(MeasureSpec.getSize(widthMeasureSpec))
else -> minimumWidth
}
val height = when (MeasureSpec.getMode(heightMeasureSpec)) {
MeasureSpec.EXACTLY -> MeasureSpec.getSize(heightMeasureSpec)
MeasureSpec.AT_MOST -> minimumHeight.coerceAtMost(MeasureSpec.getSize(heightMeasureSpec))
else -> minimumHeight
}
setMeasuredDimension(width, height)
}
}
override var modifier: Modifier = Modifier
Expand Down Expand Up @@ -97,7 +108,13 @@ class ViewSimpleColumn(context: Context) : SimpleColumn<View> {
override var modifier: Modifier = Modifier

override fun add(child: View) {
value.addView(child)
value.addView(
child,
ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
),
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import platform.UIKit.UILabel
import platform.UIKit.UILayoutConstraintAxisVertical
import platform.UIKit.UIScrollView
import platform.UIKit.UIStackView
import platform.UIKit.UIStackViewAlignmentLeading
import platform.UIKit.UIStackViewDistributionFill
import platform.UIKit.UIStackViewAlignmentFill
import platform.UIKit.UIStackViewDistributionEqualSpacing
import platform.UIKit.UIView

object UIViewTestWidgetFactory : TestWidgetFactory<UIView> {
Expand Down Expand Up @@ -120,8 +120,8 @@ class UIViewSimpleColumn : SimpleColumn<UIView> {

override val value = UIStackView(CGRectZero.readValue()).apply {
this.axis = UILayoutConstraintAxisVertical
this.alignment = UIStackViewAlignmentLeading
this.distribution = UIStackViewDistributionFill
this.alignment = UIStackViewAlignmentFill
this.distribution = UIStackViewDistributionEqualSpacing
}

override fun add(child: UIView) {
Expand All @@ -144,8 +144,8 @@ class UIViewScrollWrapper : ScrollWrapper<UIView> {
scrollView.addSubview(value)
value.translatesAutoresizingMaskIntoConstraints = false
value.leadingAnchor.constraintEqualToAnchor(scrollView.leadingAnchor).active = true
value.widthAnchor.constraintEqualToAnchor(scrollView.widthAnchor).active = true
value.topAnchor.constraintEqualToAnchor(scrollView.topAnchor).active = true
value.trailingAnchor.constraintEqualToAnchor(scrollView.trailingAnchor).active = true
value.bottomAnchor.constraintEqualToAnchor(scrollView.bottomAnchor).active = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ final class SnapshotTestingCallback : Redwood_snapshot_testingUIViewSnapshotCall
func verifySnapshot(view: UIView, name: String?, delay: TimeInterval = 0.0) {
// Set `record` to true to generate new snapshots. Be sure to revert that before committing!
// Note that tests always fail when `record` is true.
assertSnapshot(of: view, as: .wait(for: delay, on: .image), named: name, record: false, file: fileName, testName: testName)
assertSnapshot(of: view, as: .wait(for: delay, on: .image), named: name, record: true, file: fileName, testName: testName)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d861e69

Please sign in to comment.