-
Notifications
You must be signed in to change notification settings - Fork 719
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issues in :core:designsystem:commonMain
- Loading branch information
Showing
20 changed files
with
93 additions
and
29 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
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
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
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
61 changes: 61 additions & 0 deletions
61
...ain/kotlin/org/mifos/mobile/core/designsystem/utils/NonLetterColorVisualTransformation.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,61 @@ | ||
/* | ||
* Copyright 2024 Mifos Initiative | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* See See https://github.com/openMF/kmp-project-template/blob/main/LICENSE | ||
*/ | ||
package org.mifos.mobile.core.designsystem.utils | ||
|
||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.text.AnnotatedString | ||
import androidx.compose.ui.text.SpanStyle | ||
import androidx.compose.ui.text.input.OffsetMapping | ||
import androidx.compose.ui.text.input.TransformedText | ||
import androidx.compose.ui.text.input.VisualTransformation | ||
import androidx.compose.ui.text.withStyle | ||
|
||
@Composable | ||
fun nonLetterColorVisualTransformation(): VisualTransformation { | ||
val digitColor = MaterialTheme.colorScheme.primary | ||
val specialCharacterColor = MaterialTheme.colorScheme.error | ||
return remember(digitColor, specialCharacterColor) { | ||
NonLetterColorVisualTransformation( | ||
digitColor = digitColor, | ||
specialCharacterColor = specialCharacterColor, | ||
) | ||
} | ||
} | ||
|
||
private class NonLetterColorVisualTransformation( | ||
private val digitColor: Color, | ||
private val specialCharacterColor: Color, | ||
) : VisualTransformation { | ||
|
||
override fun filter(text: AnnotatedString): TransformedText = | ||
TransformedText( | ||
buildTransformedAnnotatedString(text.toString()), | ||
OffsetMapping.Identity, | ||
) | ||
|
||
private fun buildTransformedAnnotatedString(text: String): AnnotatedString { | ||
val builder = AnnotatedString.Builder() | ||
text.toCharArray().forEach { char -> | ||
when { | ||
char.isDigit() -> builder.withStyle(SpanStyle(color = digitColor)) { append(char) } | ||
|
||
!char.isLetter() -> { | ||
builder.withStyle(SpanStyle(color = specialCharacterColor)) { append(char) } | ||
} | ||
|
||
else -> builder.append(char) | ||
} | ||
} | ||
return builder.toAnnotatedString() | ||
} | ||
} |