Skip to content

Commit

Permalink
(All) Fix content alignment, Add orientation dependent spacing #33
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkeppeler committed Mar 7, 2023
1 parent 50ca86b commit 344ced7
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ fun CalendarView(
CalendarStyle.WEEK -> null
},
buttonsVisible = selection.withButtonView && calendarState.mode == CalendarDisplayMode.CALENDAR
) {
) { orientation ->
ButtonsComponent(
orientation = orientation,
selection = selection,
onPositiveValid = calendarState.valid,
onNegative = { selection.onNegativeClick?.invoke() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ fun ClockView(
onNextAction = clockState::onNextAction
)
}
) {
) { orientation ->
ButtonsComponent(
orientation = orientation,
selection = selection,
onNegative = { selection.onNegativeClick?.invoke() },
onPositive = clockState::onFinish,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ fun ColorView(
},
buttonsVisible = selection.withButtonView
|| config.displayMode != ColorSelectionMode.TEMPLATE
) {
) { orientation ->
ButtonsComponent(
orientation = orientation,
selection = selection,
onPositiveValid = colorState.valid,
onNegative = { selection.onNegativeClick?.invoke() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.maxkeppeker.sheets.core.models.base.BaseSelection
import com.maxkeppeker.sheets.core.models.base.IconSource
import com.maxkeppeker.sheets.core.models.base.LibOrientation
import com.maxkeppeker.sheets.core.models.base.SelectionButton
import com.maxkeppeker.sheets.core.utils.TestTags
import com.maxkeppeker.sheets.core.views.ButtonsComponent
Expand All @@ -49,6 +50,7 @@ class ButtonsComponentTests {
var closeCalled = false
rule.setContent {
ButtonsComponent(
orientation = LibOrientation.PORTRAIT,
selection = object : BaseSelection() {},
onPositive = { positiveCalled = true },
onNegative = { negativeCalled = true },
Expand All @@ -70,6 +72,7 @@ class ButtonsComponentTests {
var closeCalled = false
rule.setContent {
ButtonsComponent(
orientation = LibOrientation.PORTRAIT,
selection = object : BaseSelection() {},
onPositive = { positiveCalled = true },
onNegative = { negativeCalled = true },
Expand All @@ -91,6 +94,7 @@ class ButtonsComponentTests {
var closeCalled = false
rule.setContent {
ButtonsComponent(
orientation = LibOrientation.PORTRAIT,
selection = object : BaseSelection() {},
onPositive = { positiveCalled = true },
onNegative = { negativeCalled = true },
Expand All @@ -112,6 +116,7 @@ class ButtonsComponentTests {
var extraCalled = false
rule.setContent {
ButtonsComponent(
orientation = LibOrientation.PORTRAIT,
selection = object : BaseSelection() {
override val extraButton = SelectionButton("Test button")
override val onExtraButtonClick = { extraCalled = true }
Expand All @@ -134,6 +139,7 @@ class ButtonsComponentTests {
val text = "test-text-positive"
rule.setContent {
ButtonsComponent(
orientation = LibOrientation.PORTRAIT,
selection = object : BaseSelection() {
override val positiveButton = SelectionButton(text)
},
Expand All @@ -154,6 +160,7 @@ class ButtonsComponentTests {
val text = "test-text-negative"
rule.setContent {
ButtonsComponent(
orientation = LibOrientation.PORTRAIT,
selection = object : BaseSelection() {
override val negativeButton = SelectionButton(text)
},
Expand All @@ -174,6 +181,7 @@ class ButtonsComponentTests {
val text = "test-text-extra"
rule.setContent {
ButtonsComponent(
orientation = LibOrientation.PORTRAIT,
selection = object : BaseSelection() {
override val extraButton = SelectionButton(text)
},
Expand All @@ -194,6 +202,7 @@ class ButtonsComponentTests {
val icon = IconSource(Icons.Rounded.Face)
rule.setContent {
ButtonsComponent(
orientation = LibOrientation.PORTRAIT,
selection = object : BaseSelection() {
override val positiveButton = SelectionButton("", icon)
},
Expand All @@ -217,6 +226,7 @@ class ButtonsComponentTests {
val icon = IconSource(Icons.Rounded.Face)
rule.setContent {
ButtonsComponent(
orientation = LibOrientation.PORTRAIT,
selection = object : BaseSelection() {
override val negativeButton = SelectionButton("", icon)
},
Expand All @@ -240,6 +250,7 @@ class ButtonsComponentTests {
val icon = IconSource(Icons.Rounded.Face)
rule.setContent {
ButtonsComponent(
orientation = LibOrientation.PORTRAIT,
selection = object : BaseSelection() {
override val extraButton = SelectionButton("", icon)
},
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/com/maxkeppeker/sheets/core/CoreView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ fun CoreView(
header = header,
layout = { body() },
buttonsVisible = selection.withButtonView
) {
) {orientation ->
ButtonsComponent(
orientation = orientation,
onPositiveValid = onPositiveValid,
selection = selection,
onNegative = { selection.onNegativeClick?.invoke() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import com.maxkeppeker.sheets.core.models.base.BaseSelection
import com.maxkeppeker.sheets.core.models.base.ButtonStyle
import com.maxkeppeker.sheets.core.models.base.LibOrientation
import com.maxkeppeker.sheets.core.models.base.SelectionButton
import com.maxkeppeker.sheets.core.utils.TestTags
import com.maxkeppeker.sheets.core.utils.testTags
import com.maxkeppeler.sheets.core.R

/**
* Header component of the dialog.
* @param orientation The orientation configuration for the dialog.
* @param selection The selection configuration for the dialog.
* @param onPositive Listener that is invoked when the positive button is clicked.
* @param onNegative Listener that is invoked when the negative button is clicked.
Expand All @@ -40,17 +42,27 @@ import com.maxkeppeler.sheets.core.R
@ExperimentalMaterial3Api
@Composable
fun ButtonsComponent(
orientation: LibOrientation,
selection: BaseSelection,
onPositive: () -> Unit,
onNegative: () -> Unit,
onClose: () -> Unit,
onPositiveValid: Boolean = true,
) {

val buttonPadding = when (orientation) {
LibOrientation.PORTRAIT -> Modifier
.padding(top = dimensionResource(id = R.dimen.scd_normal_150))
.padding(bottom = dimensionResource(id = R.dimen.scd_normal_150))
.padding(horizontal = dimensionResource(id = R.dimen.scd_normal_150))
LibOrientation.LANDSCAPE -> Modifier
.padding(top = dimensionResource(id = R.dimen.scd_small_100))
.padding(bottom = dimensionResource(id = R.dimen.scd_small_100))
.padding(horizontal = dimensionResource(id = R.dimen.scd_small_100))
}

Row(
modifier = Modifier
.padding(vertical = dimensionResource(id = R.dimen.scd_small_100))
.padding(horizontal = dimensionResource(id = R.dimen.scd_normal_100)),
modifier = buttonPadding,
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.End
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fun FrameBase(
layoutLandscape: @Composable (RowScope.() -> Unit)? = null,
layoutLandscapeVerticalAlignment: Alignment.Vertical = Alignment.CenterVertically,
buttonsVisible: Boolean = true,
buttons: @Composable (ColumnScope.() -> Unit)? = null,
buttons: @Composable (ColumnScope.(LibOrientation) -> Unit)? = null,
) {
val layoutDirection = LocalLayoutDirection.current
val shouldUseLandscapeLayout = shouldUseLandscape()
Expand All @@ -82,7 +82,7 @@ fun FrameBase(

Column(
modifier = Modifier.wrapContentSize(),
horizontalAlignment = Alignment.End
horizontalAlignment = Alignment.Start
) {

header?.takeUnless { deviceOrientation == LibOrientation.LANDSCAPE }?.let {
Expand Down Expand Up @@ -138,7 +138,7 @@ fun FrameBase(
buttons?.let { buttons ->
if (buttonsVisible) {
Column(modifier = Modifier.testTag(TestTags.FRAME_BASE_BUTTONS)) {
buttons.invoke(this)
buttons.invoke(this, deviceOrientation)
}
} else Spacer(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ fun DateTimeView(
}
},
buttonsVisible = selection.withButtonView
) {
) { orientation ->
ButtonsComponent(
orientation = orientation,
onPositiveValid = dateTimeState.valid,
selection = selection,
onNegative = { selection.onNegativeClick?.invoke() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ fun DurationView(
onEmptyAction = durationState::onEmptyAction
)
}
) {
) { orientation ->
ButtonsComponent(
orientation = orientation,
onPositiveValid = durationState.valid,
selection = selection,
onNegative = { selection.onNegativeClick?.invoke() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ fun EmojiView(
}
},
buttonsVisible = selection.withButtonView
) {
) { orientation ->
ButtonsComponent(
orientation = orientation,
onPositiveValid = emojiState.valid,
selection = selection,
onNegative = { selection.onNegativeClick?.invoke() },
Expand Down
3 changes: 2 additions & 1 deletion info/src/main/java/com/maxkeppeler/sheets/info/InfoView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ fun InfoView(
header = header,
layout = { BodyComponent(body) },
buttonsVisible = selection.withButtonView
) {
) {orientation ->
ButtonsComponent(
orientation = orientation,
selection = selection,
onNegative = { selection.onNegativeClick?.invoke() },
onPositive = selection.onPositiveClick::invoke,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ fun InputView(
)
},
buttonsVisible = selection.withButtonView
) {
) { orientation ->
ButtonsComponent(
orientation = orientation,
selection = selection,
onPositiveValid = inputState.valid,
onNegative = { selection.onNegativeClick?.invoke() },
Expand Down
3 changes: 2 additions & 1 deletion list/src/main/java/com/maxkeppeler/sheets/list/ListView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ fun ListView(
)
},
buttonsVisible = selection.withButtonView
) {
) {orientation ->
ButtonsComponent(
orientation = orientation,
onPositiveValid = listState.valid,
selection = selection,
onNegative = { selection.onNegativeClick?.invoke() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ fun OptionView(
)
},
buttonsVisible = selection.withButtonView
) {
) {orientation ->
ButtonsComponent(
orientation = orientation,
onPositiveValid = optionState.valid,
selection = selection,
onNegative = { selection.onNegativeClick?.invoke() },
Expand Down

0 comments on commit 344ced7

Please sign in to comment.