Code Monkey home page Code Monkey logo

jetpack_compose_country_code_picker's Introduction

Jetpack Compose Country Code Picker

Jetpack Compose Country Code Picker

Buy Me A Coffee

If you are looking for Country Phone Code Picker for Jetpack Compose you can use the package.

  • Country numbers hints
  • Phone number visualTransformation (Automatic number formatting)
  • Automatic country recognition (detection by sim card if sim card is inserted)
  • With TextField
  • Can Customize
  • Adding language translations

Languages:

  • Turkish
  • English
  • Italian
  • Arabic

New features will be added every day. This project is open source without any profit motive.

For language support, you can translate the file below and send it to me. https://github.com/togisoft/jetpack_compose_country_code_picker/blob/master/ccp/src/main/res/values/strings.xml

Screenshots

Rounded Field Usage

        val context = LocalContext.current
var phoneCode by rememberSaveable { mutableStateOf(getDefaultPhoneCode(context)) }
var defaultLang by rememberSaveable { mutableStateOf(getDefaultLangCode(context)) }
val phoneNumber = rememberSaveable { mutableStateOf("") }
var isValidPhone by remember { mutableStateOf(true) }

TogiRoundedPicker(
    value = phoneNumber.value,
    onValueChange = { phoneNumber.value = it },
    defaultCountry = getLibCountries().single { it.countryCode == defaultLang },
    pickedCountry = {
        phoneCode = it.countryPhoneCode
        defaultLang = it.countryCode
    },
    error = isValidPhone
)

  // With Country Phone Code
@Composable
fun SelectCountryWithCountryCode() {
    val context = LocalContext.current
    var phoneCode by rememberSaveable { mutableStateOf(getDefaultPhoneCode(context)) }
    var defaultLang by rememberSaveable { mutableStateOf(getDefaultLangCode(context)) }
    val phoneNumber = rememberSaveable { mutableStateOf("") }
    var isValidPhone by remember { mutableStateOf(true) }
    var verifyText by remember { mutableStateOf("") }
    Column(
        modifier = Modifier.padding(16.dp)
    ) {
        Text(
            text = verifyText,
            fontWeight = FontWeight.Bold,
            modifier = Modifier
                .fillMaxWidth()
                .wrapContentSize(Alignment.Center)
        )
        TogiCountryCodePicker(
            pickedCountry = {
                phoneCode = it.countryPhoneCode
                defaultLang = it.countryCode
            },
            defaultCountry = getLibCountries().single { it.countryCode == defaultLang },
            focusedBorderColor = MaterialTheme.colors.primary,
            unfocusedBorderColor = MaterialTheme.colors.primary,
            dialogAppBarTextColor = Color.Black,
            dialogAppBarColor = Color.White,
            error = isValidPhone,
            text = phoneNumber.value,
            onValueChange = { phoneNumber.value = it }
        )

        val fullPhoneNumber = "$phoneCode${phoneNumber.value}"
        val checkPhoneNumber = checkPhoneNumber(
            phone = phoneNumber.value,
            fullPhoneNumber = fullPhoneNumber,
            countryCode = defaultLang
        )
        Button(
            onClick = {
                verifyText = if (checkPhoneNumber) {
                    isValidPhone = true
                    "Phone Number Correct"
                } else {
                    isValidPhone = false
                    "Phone Number is Wrong"

                }
            },
            modifier = Modifier.fillMaxWidth()
                .padding(16.dp)
                .height(60.dp)
        ) {
            Text(text = "Phone Verify")
        }
    }
}

<- ********* Extras ********* ->

  • focusedBorderColor = TextField Border Color
  • unfocusedBorderColor = TextField Unfocused Border Color
  • cursorColor = TextField Cursor Color
  • dialogAppBarColor = Dialog Top App Bar Background Color
  • dialogAppBarTextColor = Dialog Top App Bar Text Color

How to add in your project

In the build.gradle add maven central repository

    repositories {
    maven { url 'https://jitpack.io' }
}

Step 2. Add the dependency

  dependencies {
	    implementation 'com.github.togisoft:jetpack_compose_country_code_picker:1.1.3'

	}  

jetpack_compose_country_code_picker's People

Contributors

togisoft avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.