Skip to content

Commit

Permalink
Remove default padding in compose wrap button (#321)
Browse files Browse the repository at this point in the history
* Remove default padding in compose wrap button

* Add attribute

* Done Jesus comments
  • Loading branch information
DevPabloGarcia authored Nov 30, 2023
1 parent 56fe971 commit cdb3f61
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Button @JvmOverloads constructor(
private var style: ButtonStyle by mutableStateOf(ButtonStyle.PRIMARY)
private var isEnable: Boolean by mutableStateOf(true)
private var onClick: () -> Unit by mutableStateOf({})
private var invalidatePaddings: Boolean by mutableStateOf(false)

init {
attrs?.let {
Expand All @@ -43,6 +44,7 @@ class Button @JvmOverloads constructor(
isLoading = styledAttrs.getBoolean(R.styleable.Button_isLoading, false)
style = styledAttrs.getInt(R.styleable.Button_style, 0).toButtonStyle()
isEnable = enabledTypedArray.getBoolean(0, true)
invalidatePaddings = styledAttrs.getBoolean(R.styleable.Button_invalidatePaddings, false)
icon = styledAttrs.getResourceId(R.styleable.Button_icon, 0).takeIf { it != 0 }
withChevron = styledAttrs.getBoolean(R.styleable.Button_withChevron, false)
} finally {
Expand Down Expand Up @@ -85,6 +87,7 @@ class Button @JvmOverloads constructor(
enabled = isEnable,
icon = icon,
withChevron = withChevron,
invalidatePaddings = invalidatePaddings,
onClickListener = onClick
)
}
Expand All @@ -105,4 +108,4 @@ private fun Int?.toButtonStyle(): ButtonStyle = when (this) {
10 -> ButtonStyle.SECONDARY_SMALL_INVERSE
11 -> ButtonStyle.LINK_INVERSE
else -> ButtonStyle.PRIMARY
}
}
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs_components.xml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@
<declare-styleable name="Button">
<attr name="isLoading" format="boolean" />
<attr name="loadingText" format="string" />
<attr name="invalidatePaddings" format="boolean"/>
<attr name="style" format="enum">
<enum name="PRIMARY" value="0" />
<enum name="PRIMARY_SMALL" value="1" />
Expand Down

0 comments on commit cdb3f61

Please sign in to comment.