diff --git a/calf-ui/src/iosMain/kotlin/com/mohamedrejeb/calf/ui/datepicker/AdaptiveDatePicker.ios.kt b/calf-ui/src/iosMain/kotlin/com/mohamedrejeb/calf/ui/datepicker/AdaptiveDatePicker.ios.kt index ad85f2e..d1a60ad 100644 --- a/calf-ui/src/iosMain/kotlin/com/mohamedrejeb/calf/ui/datepicker/AdaptiveDatePicker.ios.kt +++ b/calf-ui/src/iosMain/kotlin/com/mohamedrejeb/calf/ui/datepicker/AdaptiveDatePicker.ios.kt @@ -6,6 +6,7 @@ import androidx.compose.material3.DatePickerColors import androidx.compose.material3.DatePickerFormatter import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.interop.UIKitView @@ -29,6 +30,7 @@ actual fun AdaptiveDatePicker( val datePicker = remember { UIDatePicker() } + val datePickerManager = remember { DatePickerManager( initialSelectedDateMillis = state.selectedDateMillis, @@ -41,10 +43,15 @@ actual fun AdaptiveDatePicker( ) } + LaunchedEffect(colors) { + datePickerManager.applyColors(colors) + } + UIKitView( factory = { datePicker }, + background = colors.containerColor, modifier = modifier .then( if (datePickerManager.datePickerWidth.value > 0f) @@ -59,4 +66,4 @@ actual fun AdaptiveDatePicker( Modifier ) ) -} \ No newline at end of file +} diff --git a/calf-ui/src/iosMain/kotlin/com/mohamedrejeb/calf/ui/datepicker/DatePickerManager.kt b/calf-ui/src/iosMain/kotlin/com/mohamedrejeb/calf/ui/datepicker/DatePickerManager.kt index 88fea8e..e0d636c 100644 --- a/calf-ui/src/iosMain/kotlin/com/mohamedrejeb/calf/ui/datepicker/DatePickerManager.kt +++ b/calf-ui/src/iosMain/kotlin/com/mohamedrejeb/calf/ui/datepicker/DatePickerManager.kt @@ -67,13 +67,17 @@ class DatePickerManager @OptIn(ExperimentalMaterial3Api::class) internal constru datePickerWidth.value = this.size.width.toFloat() datePickerHeight.value = this.size.height.toFloat() } + applyColors(colors) } - private fun stripTimeFromDate(originalDate: NSDate): NSDate { - val components = NSCalendar.currentCalendar.components( - NSCalendarUnitYear or NSCalendarUnitMonth or NSCalendarUnitDay, - originalDate - ) - return NSCalendar.currentCalendar.dateFromComponents(components) ?: originalDate + fun applyColors(colors: DatePickerColors) { + applyTheme(isDark = !isDark(colors.dayContentColor)) + datePicker.tintColor = colors.selectedDayContentColor.toUIColor() + datePicker.backgroundColor = colors.containerColor.toUIColor() + } + + fun applyTheme(isDark: Boolean) { + datePicker.applyTheme(isDark) } + } \ No newline at end of file