Skip to content

Commit

Permalink
Rename networkBoundResource and include SearchField
Browse files Browse the repository at this point in the history
  • Loading branch information
jeluchu committed Oct 31, 2021
1 parent 6bb121b commit 747a029
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package com.jeluchu.jchucomponentscompose.ui.modifier

import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun Int.cornerRadius() = RoundedCornerShape(this.dp)
fun Int.cornerRadius() = RoundedCornerShape(this.dp)

@Composable
fun Int.Height() = Spacer(modifier = Modifier.height(this.dp))

@Composable
fun Int.Width() = Spacer(modifier = Modifier.width(this.dp))
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.jeluchu.jchucomponentscompose.ui.textfields

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Search
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.jeluchu.jchucomponentscompose.core.extensions.strings.empty

@Composable
fun SearchView(
modifier: Modifier = Modifier,
state: MutableState<TextFieldValue>,
labelText: String = String.empty(),
styleLabel: TextStyle = LocalTextStyle.current,
colorLabelText: Color = Color.DarkGray,
cornerRadious: Dp = 15.dp,
bgContent: Color = Color.DarkGray,
bgCard: Color = Color.White
) {

val focusManager = LocalFocusManager.current

Row(
modifier = modifier
) {

TextField(
label = {
Text(
text = labelText,
style = styleLabel,
color = colorLabelText
)
},
value = state.value,
modifier = Modifier
.clip(RoundedCornerShape(cornerRadious))
.background(bgCard)
.fillMaxWidth()
.height(53.dp),
textStyle = TextStyle(
fontSize = 16.sp,
fontWeight = FontWeight.Bold
),
onValueChange = { value ->
state.value = value
}, colors = TextFieldDefaults.textFieldColors(
textColor = bgContent,
disabledTextColor = Color.Transparent,
backgroundColor = bgCard,
focusedIndicatorColor = Color.Transparent,
errorIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent,
disabledIndicatorColor = Color.Transparent,
cursorColor = bgContent
),
leadingIcon = {
Icon(
Icons.Default.Search,
tint = bgContent,
contentDescription = "",
modifier = Modifier
.padding(15.dp)
.size(24.dp)
)
},
singleLine = true,
keyboardActions = KeyboardActions(
onDone = {
focusManager.clearFocus()
}
),
keyboardOptions = KeyboardOptions.Default.copy(
imeAction = ImeAction.Done
)
)

}

}

@Preview(showBackground = true)
@Composable
fun SearchViewPreview() {
val textState = remember { mutableStateOf(TextFieldValue("")) }
SearchView(state = textState)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.map
import retrofit2.HttpException
import java.io.IOException

inline fun <ResultType, RequestType> networkBoundResourceNew(
inline fun <ResultType, RequestType> networkBoundResource(
crossinline query: () -> Flow<ResultType>,
crossinline fetch: suspend () -> RequestType,
crossinline saveFetchResult: suspend (RequestType) -> Unit,
Expand Down

0 comments on commit 747a029

Please sign in to comment.