Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved color passing and configuration #50

Merged
merged 4 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ TogiCountryCodePicker(
| textStyle | An optional [TextStyle](https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextStyle) for customizing text style of phone number input field. Defaults to MaterialTheme.typography.body1 |
| keyboardOptions | An optional [KeyboardOptions](https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/KeyboardOptions) to customize keyboard options. |
| keyboardActions | An optional [KeyboardActions](https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/KeyboardActions) to customize keyboard actions. |

| showError | Whether to show error on field when number is invalid, default true. |


## How to add in your project
Expand All @@ -97,8 +97,8 @@ Step 2. Add the dependency - n.b. this currently does not support Material 3.

```kotlin
dependencies {
implementation("androidx.compose.material:material:1.5.3")
implementation("com.github.jump-sdk:jetpack_compose_country_code_picker_emoji:2.2.4")
implementation("androidx.compose.material:material:1.5.4")
implementation("com.github.jump-sdk:jetpack_compose_country_code_picker_emoji:2.2.5")
}
```

Expand Down
2 changes: 1 addition & 1 deletion ccp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ afterEvaluate {
groupId = "com.togisoft"
artifactId = "jetpack_country_code_picker"
// Update version in README when changing below
version = "2.2.4"
version = "2.2.5"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ private const val ROW_PADDING_VERTICAL_SCALING = 1.1f
private val SEARCH_ICON_PADDING = 5.dp
private const val HEADER_TEXT_SIZE_MULTIPLE = 1.5
private val MIN_TAP_DIMENSION = 48.dp
private const val DIVIDER_ALPHA = 0.12f

/**
* @param onDismissRequest Executes when the user tries to dismiss the dialog.
Expand All @@ -72,6 +73,7 @@ private val MIN_TAP_DIMENSION = 48.dp
* @param countryList The list of countries to display in the dialog.
* @param rowPadding The padding to be applied to each row.
* @param backgroundColor The [Color] of the dialog background.
* @param dividerColor The [Color] of the country row dividers.
*/
@Composable
fun CountryDialog(
Expand All @@ -82,6 +84,7 @@ fun CountryDialog(
countryList: ImmutableList<CountryData> = persistentListOf(),
rowPadding: Dp = DEFAULT_ROW_PADDING,
backgroundColor: Color = MaterialTheme.colors.surface,
dividerColor: Color = MaterialTheme.colors.onSurface.copy(alpha = DIVIDER_ALPHA),
) {
val context = LocalContext.current
var searchValue by rememberSaveable { mutableStateOf("") }
Expand Down Expand Up @@ -124,7 +127,7 @@ fun CountryDialog(
Spacer(modifier = Modifier.height(DEFAULT_ROW_PADDING))
LazyColumn {
items(filteredCountries, key = { it.countryIso }) { countryItem ->
Divider()
Divider(color = dividerColor)
CountryRowItem(
rowPadding = rowPadding,
onSelect = { onSelect(countryItem) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ internal fun TogiCodeDialog(
showCountryCode: Boolean,
showFlag: Boolean,
textStyle: TextStyle,
backgroundColor: Color,
) {
val context = LocalContext.current

Expand Down Expand Up @@ -93,6 +94,7 @@ internal fun TogiCodeDialog(
} else {
textStyle.copy(color = MaterialTheme.colors.onSurface)
},
backgroundColor = backgroundColor,
)
}
}
Expand Down Expand Up @@ -145,5 +147,6 @@ private fun TogiCodeDialogPreview() {
showCountryCode = true,
showFlag = true,
textStyle = TextStyle(),
backgroundColor = Color.White,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ private const val TAG = "TogiCountryCodePicker"
* Defaults to MaterialTheme.typography.body1
* @param [keyboardOptions] An optional [KeyboardOptions] to customize keyboard options.
* @param [keyboardActions] An optional [KeyboardActions] to customize keyboard actions.
* @param [showError] Whether to show error on field when number is invalid, default true.
*/
@OptIn(ExperimentalComposeUiApi::class)
@Suppress("LongMethod")
Expand All @@ -102,10 +103,11 @@ fun TogiCountryCodePicker(
initialCountryPhoneCode: PhoneCode? = null,
label: @Composable (() -> Unit)? = null,
textStyle: TextStyle = MaterialTheme.typography.body1.copy(
color = MaterialTheme.colors.onSurface,
color = colors.textColor(enabled = true).value,
),
keyboardOptions: KeyboardOptions? = null,
keyboardActions: KeyboardActions? = null,
showError: Boolean = true,
) {
val context = LocalContext.current
val focusRequester = remember { FocusRequester() }
Expand Down Expand Up @@ -212,6 +214,7 @@ fun TogiCountryCodePicker(
showCountryCode = showCountryCode,
showFlag = showCountryFlag,
textStyle = textStyle,
backgroundColor = colors.backgroundColor(enabled = true).value,
)
},
trailingIcon = {
Expand All @@ -227,7 +230,7 @@ fun TogiCountryCodePicker(
}
}
},
isError = !isNumberValid,
isError = showError && !isNumberValid,
visualTransformation = phoneNumberTransformation,
keyboardOptions = keyboardOptions ?: KeyboardOptions.Default.copy(
keyboardType = KeyboardType.Phone,
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[versions]
kotlin = "1.9.10"
dokka = "1.9.0"
dokka = "1.9.10"

## SDK Versions
minSdk = "24"
targetSdk = "34"
compileSdk = "34"

# Dependencies
android-gradle-plugin = "8.2.0-beta06"
android-gradle-plugin = "8.2.0-rc01"
gradle-versions = "0.49.0"
detekt = "1.23.1"

Expand All @@ -19,7 +19,7 @@ androidx-lifecycle = "2.6.2"
androidx-test-junit = "1.1.5"

# update version in README when changing below
compose = "1.5.3"
compose = "1.5.4"
# https://androidx.dev/storage/compose-compiler/repository/
# https://developer.android.com/jetpack/androidx/releases/compose-compiler
composeCompiler = "1.5.3"
Expand Down