-
Notifications
You must be signed in to change notification settings - Fork 3
Utils
K M Rejowan Ahmmed edited this page May 13, 2024
·
2 revisions
This is a collection of utility functions that I use in my projects. This will add some functionality to your project that you might find useful.
This will detect the country based on the user's device.
var country by remember {
mutableStateOf(Country.Bangladesh)
}
if (!LocalInspectionMode.current) {
CCPUtils.getCountryAutomatically(context = LocalContext.current).let {
it?.let {
country = it
}
}
}
This will validate the phone number based on the selected country.
val validatePhoneNumber = remember(context) {
CCPValidator(context = context)
}
var isNumberValid: Boolean by rememberSaveable(country, text) {
mutableStateOf(
validatePhoneNumber(
number = text, countryCode = country.countryCode
),
)
}
OutlinedTextField(
value = text,
onValueChange = {
isNumberValid = validatePhoneNumber(
number = it, countryCode = country.countryCode
)
},
// Other properties
)
This will transform the phone number based on the selected country. Attach this to text field to see the transformation. It's already integrated with CountryCodePickerTextField
.
OutlinedTextField(
// Other properties
visualTransformation = CCPTransformer(context, country.countryIso)
// Other properties
)
This will transform the phone number based on the selected country. Attach this to text field to see the transformation. It's already integrated with CountryCodePickerTextField
.
OutlinedTextField(
// Other properties
visualTransformation = CCPTransformer(context, country.countryIso)
// Other properties
)
data class ViewCustomization(
var showFlag: Boolean = true,
var showCountryIso: Boolean = false,
var showCountryName: Boolean = false,
var showCountryCode: Boolean = true,
var showArrow: Boolean = true,
var clipToFull: Boolean = false,
)
Important
I've full tutorial on this library on YouTube. You can check it out here