-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add SelectionMode and handle multiply implementations for all calendar views. - add YearPicker and MonthPicker as generic views to select year and month. Add sample of usage in FullDateScreen - simplify examples
- Loading branch information
1 parent
61132b9
commit f9c9f21
Showing
21 changed files
with
431 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
calendar/src/commonMain/kotlin/io/wojciechosak/calendar/config/SelectionMode.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.wojciechosak.calendar.config | ||
|
||
sealed class SelectionMode { | ||
data object Single : SelectionMode() | ||
|
||
data class Multiply(val bufferSize: Int = 2) : SelectionMode() | ||
|
||
data object Range : SelectionMode() | ||
} |
22 changes: 22 additions & 0 deletions
22
calendar/src/commonMain/kotlin/io/wojciechosak/calendar/modifiers/TouchModifers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.wojciechosak.calendar.modifiers | ||
|
||
import androidx.compose.foundation.gestures.awaitEachGesture | ||
import androidx.compose.foundation.gestures.awaitFirstDown | ||
import androidx.compose.foundation.gestures.waitForUpOrCancellation | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.composed | ||
import androidx.compose.ui.input.pointer.PointerEventPass | ||
import androidx.compose.ui.input.pointer.pointerInput | ||
|
||
@Composable | ||
fun Modifier.passTouchGesture(onTouchEvent: () -> Unit): Modifier = | ||
composed { | ||
pointerInput(Unit) { | ||
awaitEachGesture { | ||
awaitFirstDown(requireUnconsumed = false) | ||
val change = waitForUpOrCancellation(pass = PointerEventPass.Initial) | ||
change?.let { onTouchEvent() } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 42 additions & 6 deletions
48
calendar/src/commonMain/kotlin/io/wojciechosak/calendar/view/MonthPicker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,49 @@ | ||
package io.wojciechosak.calendar.view | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.lazy.grid.GridCells | ||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import io.wojciechosak.calendar.modifiers.passTouchGesture | ||
import kotlinx.datetime.Month | ||
|
||
@Composable | ||
fun MonthPicker() { | ||
} | ||
|
||
@Composable | ||
fun MonthView(name: String) { | ||
Text(name) | ||
fun MonthPicker( | ||
columns: Int = 4, | ||
horizontalArrangement: Arrangement.Horizontal = Arrangement.Center, | ||
verticalArrangement: Arrangement.Vertical = Arrangement.Center, | ||
modifier: Modifier = Modifier, | ||
userScrollEnabled: Boolean = true, | ||
monthCount: Int = 12, | ||
onMonthSelected: (Month) -> Unit = {}, | ||
monthView: @Composable (month: Month) -> Unit = { month -> | ||
Text(month.name) | ||
}, | ||
) { | ||
require(monthCount in 0..12) { | ||
throw IllegalArgumentException("Month count should be greater than 0 and <= 12!") | ||
} | ||
LazyVerticalGrid( | ||
columns = GridCells.Fixed(columns), | ||
horizontalArrangement = horizontalArrangement, | ||
verticalArrangement = verticalArrangement, | ||
userScrollEnabled = userScrollEnabled, | ||
modifier = modifier, | ||
) { | ||
items(monthCount) { index -> | ||
val selectedMonth = Month.entries.getOrNull(index) | ||
Box( | ||
modifier = | ||
Modifier | ||
.passTouchGesture { selectedMonth?.let { month -> onMonthSelected(month) } }, | ||
contentAlignment = Alignment.Center, | ||
) { | ||
selectedMonth?.let { month -> monthView(month) } | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.