-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add country search option
- Loading branch information
Showing
8 changed files
with
184 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<resources> | ||
<string name="app_name">JetCountyPicker</string> | ||
<string name="select_country_text">Select country</string> | ||
</resources> |
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
99 changes: 99 additions & 0 deletions
99
countrypicker/src/main/java/com/canopas/campose/countrypicker/CountrySearchView.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,99 @@ | ||
package com.canopas.campose.countrypicker | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.material.* | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Search | ||
import androidx.compose.material.icons.rounded.Clear | ||
import androidx.compose.runtime.* | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
|
||
@OptIn(ExperimentalMaterialApi::class) | ||
@Composable | ||
fun countrySearchView(state: ModalBottomSheetState): String { | ||
|
||
var searchValue: String by rememberSaveable { mutableStateOf("") } | ||
var showClearIcon by rememberSaveable { mutableStateOf(false) } | ||
|
||
showClearIcon = searchValue.isNotEmpty() | ||
|
||
if (!state.isVisible) { | ||
searchValue = "" | ||
} | ||
|
||
Row { | ||
Box( | ||
modifier = Modifier | ||
.background( | ||
color = Color.White.copy(alpha = 0.1f) | ||
) | ||
) { | ||
TextField( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.height(48.dp), | ||
value = searchValue, | ||
onValueChange = { | ||
searchValue = it | ||
}, | ||
textStyle = LocalTextStyle.current.copy( | ||
fontSize = 14.sp | ||
), | ||
singleLine = true, | ||
leadingIcon = { | ||
Icon( | ||
Icons.Default.Search, | ||
contentDescription = null, | ||
tint = Color.Black.copy(0.2f) | ||
) | ||
}, | ||
trailingIcon = { | ||
if (showClearIcon) { | ||
IconButton(onClick = { | ||
searchValue = "" | ||
}) { | ||
Icon( | ||
imageVector = Icons.Rounded.Clear, | ||
tint = MaterialTheme.colors.onBackground, | ||
contentDescription = "Clear icon" | ||
) | ||
} | ||
} | ||
}, | ||
colors = TextFieldDefaults.textFieldColors( | ||
backgroundColor = Color.Transparent, | ||
focusedIndicatorColor = Color.Transparent, | ||
disabledIndicatorColor = Color.Transparent, | ||
unfocusedIndicatorColor = Color.Transparent | ||
) | ||
) | ||
if (searchValue.isEmpty()) { | ||
Text( | ||
text = stringResource(R.string.search_text), | ||
style = MaterialTheme.typography.body1, | ||
color = Color.Gray, | ||
modifier = Modifier | ||
.align(Alignment.CenterStart) | ||
.padding(start = 52.dp) | ||
) | ||
} | ||
} | ||
} | ||
return searchValue | ||
} | ||
|
||
|
||
@OptIn(ExperimentalMaterialApi::class) | ||
@Preview(showBackground = true) | ||
@Composable | ||
fun PreviewSearchView() { | ||
countrySearchView(rememberModalBottomSheetState(ModalBottomSheetValue.Hidden)) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="search_text">Search</string> | ||
</resources> |