Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not Scrolling horizontally in desktop #605

Open
mihirm-indianic opened this issue Jan 24, 2025 · 1 comment
Open

Not Scrolling horizontally in desktop #605

mihirm-indianic opened this issue Jan 24, 2025 · 1 comment

Comments

@mihirm-indianic
Copy link

Library information:

  • com.kizitonwose.calendar:compose-multiplatform:2.6.2

Describe the bug**

`

data class TransactionState(
val selectedDate: LocalDate = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).date,
val currentMonth: YearMonth = YearMonth(
selectedDate.year,
selectedDate.monthNumber
),
val showMonthPicker: Boolean = false,
val transactions: List = emptyList()
)

class TransactionViewModel : ViewModel() {
private val _state = MutableStateFlow(TransactionState())
val state: StateFlow = _state

init {
    loadTransactions()
}

private fun loadTransactions() {
    viewModelScope.launch {
        val transactions = listOf(
            TransactionItem(
                "Entertainment",
                "Movies at the Mall",
                120,
                "10:00 AM",
                { Icon(Icons.Default.Menu, contentDescription = "Entertainment") },
                Color(0xFF4CAF50)
            ),
            TransactionItem(
                "Shopping",
                "Shoppers stop clothes",
                80,
                "09:00 PM",
                { Icon(Icons.Default.ShoppingCart, contentDescription = "Shopping") },
                Color(0xFFFF5722)
            ),
            TransactionItem(
                "Food",
                "Dinner at Jenny's",
                50,
                "08:30 PM",
                { Icon(Icons.Default.Menu, contentDescription = "Food") },
                Color(0xFF3F51B5)
            ),
            TransactionItem(
                "Pets",
                "Cat Food",
                80,
                "10:30 AM",
                { Icon(Icons.Default.Menu, contentDescription = "Pets") },
                Color(0xFFE91E63)
            ),
            TransactionItem(
                "Shopping",
                "Groceries at Mart",
                80,
                "11:30 PM",
                { Icon(Icons.Default.ShoppingCart, contentDescription = "Shopping") },
                Color(0xFFFF5722)
            ),
            TransactionItem(
                "Entertainment",
                "Pool Table Game",
                20,
                "11:30 PM",
                { Icon(Icons.Default.Menu, contentDescription = "Entertainment") },
                Color(0xFF4CAF50)
            ),
            TransactionItem(
                "Food",
                "Snack at KFC",
                50,
                "11:45 PM",
                { Icon(Icons.Default.Menu, contentDescription = "Food") },
                Color(0xFF3F51B5)
            )
        )
        _state.value = _state.value.copy(transactions = transactions)
    }
}

fun updateSelectedDate(date: LocalDate) {
    viewModelScope.launch {
        _state.value = _state.value.copy(selectedDate = date)
    }
}

fun updateCurrentMonth(month: YearMonth) {
    viewModelScope.launch {
        _state.value = _state.value.copy(
            currentMonth = month,
            // Update selected date if it's not in the new month
            selectedDate = if (_state.value.selectedDate.year != month.year || 
                            _state.value.selectedDate.monthNumber != month.monthNumber) {
                month.atStartOfMonth()
            } else {
                _state.value.selectedDate
            }
        )
    }
}

fun toggleMonthPicker(show: Boolean) {
    viewModelScope.launch {
        _state.value = _state.value.copy(showMonthPicker = show)
    }
}

fun getTotalAmount(): Int {
    return state.value.transactions.sumOf { it.amount }
}

}

val transactionViewModel = viewModel{
TransactionViewModel()
}
val state by transactionViewModel.state.collectAsState()

WeekCalendar(
modifier = Modifier
.fillMaxWidth()
.background(Color.White)
.padding(horizontal = 16.dp, vertical = 8.dp),
state = rememberWeekCalendarState(
startDate = state.currentMonth.atStartOfMonth(),
endDate = state.currentMonth.atEndOfMonth(),
firstDayOfWeek = firstDayOfWeekFromLocale()
),
dayContent = { day ->
Day(day, state.selectedDate) { transactionViewModel.updateSelectedDate(it.date) }
}
)

@composable
fun Day(day: WeekDay, selectedDate: LocalDate, onDateSelected: (WeekDay) -> Unit) {
val isSelected = day.date == selectedDate
Box(
modifier = Modifier
.size(40.dp)
.clickable { onDateSelected(day) },
contentAlignment = Alignment.Center
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = day.date.dayOfWeek.name.take(3),
style = MaterialTheme.typography.bodySmall.copy(
color = if (isSelected) Color(0xFF2196F3) else Color.Gray,
fontWeight = if (isSelected) FontWeight.Medium else FontWeight.Normal
)
)
Text(
text = day.date.dayOfMonth.toString(),
style = MaterialTheme.typography.bodyMedium.copy(
color = if (isSelected) Color(0xFF2196F3) else Color.Black,
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal
)
)
}
}
}

`

cant scroll through dates in desktop it only shows current week dates

@kizitonwose
Copy link
Owner

Here's a recording of the week calendar scrolling on the desktop. I think maybe you are scrolling by dragging the component? Scrolling works with the mouse wheel horizontal scroll.

Screen.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants