Skip to content

Commit

Permalink
feat: text limit background (#16)
Browse files Browse the repository at this point in the history
* feat: text limit background

* chore: refactor function location
  • Loading branch information
whitescent authored Jan 19, 2024
1 parent f99a5cd commit 0cd8c6a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
Expand Down Expand Up @@ -198,7 +199,32 @@ fun Post(
}
}
BasicTextField(
value = postTextField,
value = postTextField.copy(
annotatedString = buildAnnotatedString {
val text = postTextField.text
val maxInstanceText = state.instance?.maximumTootCharacters ?: DEFAULT_CHARACTER_LIMIT
withStyle(
style = SpanStyle(fontSize = 18.sp, color = AppTheme.colors.primaryContent)
) {
append(
text = text.substring(
startIndex = 0,
endIndex = if (text.length <= maxInstanceText) text.length else maxInstanceText
)
)
}
if (text.length > maxInstanceText) {
withStyle(
style = SpanStyle(
color = AppTheme.colors.primaryContent,
background = AppTheme.colors.textLimitWarningBackground
)
) {
append(text.substring(startIndex = maxInstanceText, endIndex = text.length))
}
}
}
),
onValueChange = viewModel::updateTextFieldValue,
modifier = Modifier
.fillMaxSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable

object AppTheme {

val colors: MastifyColorScheme
@Composable
@ReadOnlyComposable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ interface MastifyColorScheme {
val exploreSearchBarBorder: Color
val exploreSearchBarBackground: Color
val pollOptionBackground: Color
val textLimitWarningBackground: Color
val isLight: Boolean
}

Expand Down Expand Up @@ -88,6 +89,7 @@ open class ColorSchemeImpl(
override val exploreSearchBarBorder: Color,
override val exploreSearchBarBackground: Color,
override val pollOptionBackground: Color,
override val textLimitWarningBackground: Color,
override val isLight: Boolean,
) : MastifyColorScheme

Expand Down Expand Up @@ -117,6 +119,7 @@ object LightColorScheme : ColorSchemeImpl(
exploreSearchBarBorder = Color(0xFFF1F1F1),
exploreSearchBarBackground = Color.White,
pollOptionBackground = Color(0xFFECEEF0),
textLimitWarningBackground = Color(0xFFf8d3de),
isLight = true
)

Expand Down Expand Up @@ -146,6 +149,7 @@ object DarkColorScheme : ColorSchemeImpl(
exploreSearchBarBorder = Color(0xFF222222),
exploreSearchBarBackground = Color(0xFF1D1D1D),
pollOptionBackground = Color(0xFF232323),
textLimitWarningBackground = Color(0xFFf3222d),
isLight = false
)

Expand Down

0 comments on commit 0cd8c6a

Please sign in to comment.