Updates our base textfield and moves to it's a more general package

This commit is contained in:
Vitor Pamplona
2025-03-07 10:52:28 -05:00
parent 797bea9e72
commit 639e2bb645
5 changed files with 39 additions and 40 deletions
@@ -18,7 +18,7 @@
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.utils
package com.vitorpamplona.amethyst.ui.components
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsFocusedAsState
@@ -37,7 +37,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.SolidColor
@@ -48,9 +47,12 @@ import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp
import com.vitorpamplona.amethyst.ui.theme.placeholderText
// COPIED FROM TEXT FIELD
// The only change is the contentPadding below
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MyTextField(
fun ThinPaddingTextField(
value: TextFieldValue,
onValueChange: (TextFieldValue) -> Unit,
modifier: Modifier = Modifier,
@@ -71,9 +73,10 @@ fun MyTextField(
singleLine: Boolean = false,
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
minLines: Int = 1,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
interactionSource: MutableInteractionSource? = null,
shape: Shape = TextFieldDefaults.shape,
colors: TextFieldColors = TextFieldDefaults.colors(),
// new fields
contentPadding: PaddingValues =
if (label == null) {
TextFieldDefaults.contentPaddingWithoutLabel(
@@ -91,37 +94,38 @@ fun MyTextField(
)
},
) {
// COPIED FROM TEXT FIELD
// The only change is the contentPadding below
@Suppress("NAME_SHADOWING")
val interactionSource = interactionSource ?: remember { MutableInteractionSource() }
// If color is not provided via the text style, use content color as a default
val textColor =
textStyle.color.takeOrElse {
val focused by interactionSource.collectIsFocusedAsState()
val targetValue =
when {
!enabled -> MaterialTheme.colorScheme.placeholderText
isError -> MaterialTheme.colorScheme.onSurface
focused -> MaterialTheme.colorScheme.onSurface
else -> MaterialTheme.colorScheme.onSurface
}
rememberUpdatedState(targetValue).value
// this has changed, but only because of private access on the original
when {
!enabled -> MaterialTheme.colorScheme.placeholderText
isError -> MaterialTheme.colorScheme.onSurface
focused -> MaterialTheme.colorScheme.onSurface
else -> MaterialTheme.colorScheme.onSurface
}
}
val mergedTextStyle = textStyle.merge(TextStyle(color = textColor))
CompositionLocalProvider(LocalTextSelectionColors provides LocalTextSelectionColors.current) {
CompositionLocalProvider(LocalTextSelectionColors provides colors.textSelectionColors) {
BasicTextField(
value = value,
modifier =
modifier.defaultMinSize(
minWidth = TextFieldDefaults.MinWidth,
minHeight = 36.dp,
),
modifier
.defaultMinSize(
minWidth = TextFieldDefaults.MinWidth,
minHeight = 36.dp, // this has changed
),
onValueChange = onValueChange,
enabled = enabled,
readOnly = readOnly,
textStyle = mergedTextStyle,
cursorBrush = SolidColor(MaterialTheme.colorScheme.primary),
cursorBrush = SolidColor(MaterialTheme.colorScheme.primary), // this has changed
visualTransformation = visualTransformation,
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions,
@@ -148,7 +152,7 @@ fun MyTextField(
isError = isError,
interactionSource = interactionSource,
colors = colors,
contentPadding = contentPadding,
contentPadding = contentPadding, // this has changed
)
},
)
@@ -53,7 +53,6 @@ import androidx.compose.foundation.selection.toggleable
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Assistant
import androidx.compose.material.icons.filled.Bolt
import androidx.compose.material.icons.filled.CurrencyBitcoin
import androidx.compose.material.icons.filled.LocationOff
@@ -149,6 +148,7 @@ import com.vitorpamplona.amethyst.ui.components.InvoiceRequest
import com.vitorpamplona.amethyst.ui.components.LoadUrlPreview
import com.vitorpamplona.amethyst.ui.components.LoadingAnimation
import com.vitorpamplona.amethyst.ui.components.SecretEmojiRequest
import com.vitorpamplona.amethyst.ui.components.ThinPaddingTextField
import com.vitorpamplona.amethyst.ui.components.VideoView
import com.vitorpamplona.amethyst.ui.components.ZapRaiserRequest
import com.vitorpamplona.amethyst.ui.navigation.Nav
@@ -165,7 +165,6 @@ import com.vitorpamplona.amethyst.ui.note.ShowUserSuggestionList
import com.vitorpamplona.amethyst.ui.note.UsernameDisplay
import com.vitorpamplona.amethyst.ui.note.WatchAndLoadMyEmojiList
import com.vitorpamplona.amethyst.ui.note.ZapSplitIcon
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.utils.MyTextField
import com.vitorpamplona.amethyst.ui.screen.loggedIn.settings.SettingsRow
import com.vitorpamplona.amethyst.ui.stringRes
import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
@@ -737,7 +736,7 @@ private fun MessageField(postViewModel: NewPostViewModel) {
}
}
MyTextField(
ThinPaddingTextField(
value = postViewModel.message,
onValueChange = { postViewModel.updateMessage(it) },
keyboardOptions =
@@ -851,7 +850,7 @@ fun SendDirectMessageTo(postViewModel: NewPostViewModel) {
fontWeight = FontWeight.W500,
)
MyTextField(
ThinPaddingTextField(
value = postViewModel.toUsers,
onValueChange = { postViewModel.updateToUsers(it) },
modifier = Modifier.fillMaxWidth(),
@@ -885,7 +884,7 @@ fun SendDirectMessageTo(postViewModel: NewPostViewModel) {
fontWeight = FontWeight.W500,
)
MyTextField(
ThinPaddingTextField(
value = postViewModel.subject,
onValueChange = { postViewModel.updateSubject(it) },
modifier = Modifier.fillMaxWidth(),
@@ -926,7 +925,7 @@ fun SellProduct(postViewModel: NewPostViewModel) {
fontWeight = FontWeight.W500,
)
MyTextField(
ThinPaddingTextField(
value = postViewModel.title,
onValueChange = {
postViewModel.updateTitle(it)
@@ -962,7 +961,7 @@ fun SellProduct(postViewModel: NewPostViewModel) {
fontWeight = FontWeight.W500,
)
MyTextField(
ThinPaddingTextField(
modifier = Modifier.fillMaxWidth(),
value = postViewModel.price,
onValueChange = {
@@ -1039,7 +1038,7 @@ fun SellProduct(postViewModel: NewPostViewModel) {
.weight(1f)
.padding(end = 5.dp, bottom = 1.dp),
) { currentOption, modifier ->
MyTextField(
ThinPaddingTextField(
value = TextFieldValue(currentOption),
onValueChange = {},
readOnly = true,
@@ -1105,7 +1104,7 @@ fun SellProduct(postViewModel: NewPostViewModel) {
.weight(1f)
.padding(end = 5.dp, bottom = 1.dp),
) { currentOption, modifier ->
MyTextField(
ThinPaddingTextField(
value = TextFieldValue(currentOption),
onValueChange = {},
readOnly = true,
@@ -1132,7 +1131,7 @@ fun SellProduct(postViewModel: NewPostViewModel) {
fontWeight = FontWeight.W500,
)
MyTextField(
ThinPaddingTextField(
value = postViewModel.locationText,
onValueChange = {
postViewModel.updateLocation(it)
@@ -85,6 +85,7 @@ import com.vitorpamplona.amethyst.ui.actions.CrossfadeIfEnabled
import com.vitorpamplona.amethyst.ui.actions.UrlUserTagTransformation
import com.vitorpamplona.amethyst.ui.actions.uploads.SelectFromGallery
import com.vitorpamplona.amethyst.ui.actions.uploads.SelectedMedia
import com.vitorpamplona.amethyst.ui.components.ThinPaddingTextField
import com.vitorpamplona.amethyst.ui.navigation.INav
import com.vitorpamplona.amethyst.ui.navigation.TopBarExtensibleWithBackButton
import com.vitorpamplona.amethyst.ui.note.ClickableUserPicture
@@ -107,7 +108,6 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.list.DisplayRoomSubje
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.list.DisplayUserSetAsSubject
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.list.LoadUser
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.utils.DisplayReplyingToNote
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.utils.MyTextField
import com.vitorpamplona.amethyst.ui.stringRes
import com.vitorpamplona.amethyst.ui.theme.BottomTopHeight
import com.vitorpamplona.amethyst.ui.theme.DividerThickness
@@ -551,7 +551,7 @@ fun PrivateMessageEditFieldRow(
accountViewModel,
)
MyTextField(
ThinPaddingTextField(
value = channelScreenModel.message,
onValueChange = { channelScreenModel.updateMessage(it) },
keyboardOptions =
@@ -98,6 +98,7 @@ import com.vitorpamplona.amethyst.ui.actions.uploads.SelectFromGallery
import com.vitorpamplona.amethyst.ui.components.LoadNote
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
import com.vitorpamplona.amethyst.ui.components.SensitivityWarning
import com.vitorpamplona.amethyst.ui.components.ThinPaddingTextField
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
import com.vitorpamplona.amethyst.ui.components.ZoomableContentView
import com.vitorpamplona.amethyst.ui.navigation.INav
@@ -122,7 +123,6 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.DisappearingScaffold
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.private.RefreshingChatroomFeedView
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.private.ThinSendButton
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.utils.DisplayReplyingToNote
import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.utils.MyTextField
import com.vitorpamplona.amethyst.ui.screen.loggedIn.home.CrossfadeCheckIfVideoIsOnline
import com.vitorpamplona.amethyst.ui.screen.loggedIn.notifications.equalImmutableLists
import com.vitorpamplona.amethyst.ui.stringRes
@@ -171,7 +171,6 @@ import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.receiveAsFlow
@@ -219,7 +218,6 @@ fun Channel(
}
}
@OptIn(FlowPreview::class)
@Composable
fun PrepareChannelViewModels(
baseChannel: Channel,
@@ -257,8 +255,6 @@ fun ChannelScreen(
accountViewModel: AccountViewModel,
nav: INav,
) {
val context = LocalContext.current
NostrChannelDataSource.loadMessagesBetween(accountViewModel.account, channel)
val lifeCycleOwner = LocalLifecycleOwner.current
@@ -507,7 +503,7 @@ fun EditFieldRow(
accountViewModel,
)
MyTextField(
ThinPaddingTextField(
value = channelScreenModel.message,
onValueChange = { channelScreenModel.updateMessage(it) },
keyboardOptions =