Skip to content

Commit

Permalink
Track Button.color property
Browse files Browse the repository at this point in the history
  • Loading branch information
squarejesse committed Jun 14, 2024
1 parent da51750 commit 81c5a56
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ abstract class AbstractChangeListenerTest {
c.setContent {
Button(text, onClick = null)
}
assertThat(c.awaitSnapshot()).containsExactly("text hi", "onClick false", "modifier Modifier", "onEndChanges")
assertThat(c.awaitSnapshot()).containsExactly("text hi", "onClick false", "color 0", "modifier Modifier", "onEndChanges")

text = "hello"
assertThat(c.awaitSnapshot()).containsExactly("text hello", "onEndChanges")
Expand All @@ -123,7 +123,7 @@ abstract class AbstractChangeListenerTest {
Button("hi", onClick = null)
Text(text)
}
assertThat(c.awaitSnapshot()).containsExactly("text hi", "onClick false", "modifier Modifier", "onEndChanges")
assertThat(c.awaitSnapshot()).containsExactly("text hi", "onClick false", "color 0", "modifier Modifier", "onEndChanges")

text = "hello"
assertThat(c.awaitSnapshot()).isEmpty()
Expand All @@ -145,7 +145,7 @@ abstract class AbstractChangeListenerTest {
c.setContent {
Button("hi", onClick = null, modifier = modifier)
}
assertThat(c.awaitSnapshot()).containsExactly("text hi", "onClick false", "modifier Modifier", "onEndChanges")
assertThat(c.awaitSnapshot()).containsExactly("text hi", "onClick false", "color 0", "modifier Modifier", "onEndChanges")

modifier = with(object : TestScope {}) {
Modifier.accessibilityDescription("hey")
Expand All @@ -170,7 +170,7 @@ abstract class AbstractChangeListenerTest {
c.setContent {
Button(text, onClick = null, modifier = modifier)
}
assertThat(c.awaitSnapshot()).containsExactly("text hi", "onClick false", "modifier Modifier", "onEndChanges")
assertThat(c.awaitSnapshot()).containsExactly("text hi", "onClick false", "color 0", "modifier Modifier", "onEndChanges")

text = "hello"
modifier = with(object : TestScope {}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class ListeningButton :
changes += "onClick ${onClick != null}"
}

override fun color(color: UInt) {
changes += "color $color"
}

override fun onEndChanges() {
changes += "onEndChanges"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ internal class ViewButton(
},
)
}

override fun color(color: UInt) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ class HtmlButton(
null
}
}

override fun color(color: UInt) {
}
}
7 changes: 5 additions & 2 deletions test-app/ios-uikit/TestApp/ButtonBinding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ButtonBinding: Button {
// this function will update the bounds and trigger relayout in the parent.
root.sizeToFit()
}

func onClick(onClick: (() -> Void)? = nil) {
self.onClick = onClick
if (onClick != nil) {
Expand All @@ -45,7 +45,10 @@ class ButtonBinding: Button {
root.removeTarget(self, action: #selector(clicked), for: .touchUpInside)
}
}


func color(color: UInt32) {
}

@objc func clicked() {
self.onClick?()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public data class Text(
public data class Button(
@Property(1) val text: String?,
@Property(2) val onClick: (() -> Unit)?,
@Property(3) val color: UInt,
@Property(3) @Default("0u") val color: UInt,
)

/** Like [Button] but with a required lambda. */
Expand Down

0 comments on commit 81c5a56

Please sign in to comment.