forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore commonMain to AOSP state (material3 formatting)
Partially fixes https://youtrack.jetbrains.com/issue/CMP-5740/Upstreaming.-compilation.-other-fixes Restore to the last merged Jetpack Compose (1.8.0-alpha07) and Material3 (1.4.0-alpha04). ## Testing - CI passes ## Release Notes N/A
- Loading branch information
Showing
10 changed files
with
156 additions
and
77 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
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
91 changes: 91 additions & 0 deletions
91
...se/material3/material3/src/skikoMain/kotlin/androidx/compose/material3/DateInput.skiko.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,91 @@ | ||
/* | ||
* Copyright 2024 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package androidx.compose.material3 | ||
|
||
import androidx.compose.material3.internal.CalendarDate | ||
import androidx.compose.material3.internal.DateInputFormat | ||
import androidx.compose.material3.internal.format | ||
import androidx.compose.runtime.Stable | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Stable | ||
internal actual class DateInputValidator | ||
actual constructor( | ||
private val yearRange: IntRange, | ||
private val selectableDates: SelectableDates, | ||
private val dateInputFormat: DateInputFormat, | ||
private val dateFormatter: DatePickerFormatter, | ||
private val errorDatePattern: String, | ||
private val errorDateOutOfYearRange: String, | ||
private val errorInvalidNotAllowed: String, | ||
private val errorInvalidRangeInput: String | ||
) { | ||
/** | ||
* the currently selected start date in milliseconds. Only checked against when the | ||
* [InputIdentifier] is [InputIdentifier.EndDateInput]. | ||
*/ | ||
actual var currentStartDateMillis: Long? = null | ||
|
||
/** | ||
* the currently selected end date in milliseconds. Only checked against when the | ||
* [InputIdentifier] is [InputIdentifier.StartDateInput]. | ||
*/ | ||
actual var currentEndDateMillis: Long? = null | ||
|
||
actual fun validate( | ||
dateToValidate: CalendarDate?, | ||
inputIdentifier: InputIdentifier, | ||
locale: CalendarLocale | ||
): String { | ||
if (dateToValidate == null) { | ||
return errorDatePattern.format(dateInputFormat.patternWithDelimiters.uppercase()) | ||
} | ||
// Check that the date is within the valid range of years. | ||
if (!yearRange.contains(dateToValidate.year)) { | ||
return errorDateOutOfYearRange.format( | ||
yearRange.first.toLocalString(), | ||
yearRange.last.toLocalString() | ||
) | ||
} | ||
// Check that the provided SelectableDates allows this date to be selected. | ||
with(selectableDates) { | ||
if ( | ||
!isSelectableYear(dateToValidate.year) || | ||
!isSelectableDate(dateToValidate.utcTimeMillis) | ||
) { | ||
return errorInvalidNotAllowed.format( | ||
dateFormatter.formatDate( | ||
dateMillis = dateToValidate.utcTimeMillis, | ||
locale = locale | ||
) | ||
) | ||
} | ||
} | ||
|
||
// Additional validation when the InputIdentifier is for start of end dates in a range input | ||
if ( | ||
(inputIdentifier == InputIdentifier.StartDateInput && | ||
dateToValidate.utcTimeMillis > (currentEndDateMillis ?: Long.MAX_VALUE)) || | ||
(inputIdentifier == InputIdentifier.EndDateInput && | ||
dateToValidate.utcTimeMillis < (currentStartDateMillis ?: Long.MIN_VALUE)) | ||
) { | ||
// The input start date is after the end date, or the end date is before the start date. | ||
return errorInvalidRangeInput | ||
} | ||
|
||
return "" | ||
} | ||
} |
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