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

Support of android autofill services #249

Open
Alex009 opened this issue Jun 21, 2020 · 0 comments
Open

Support of android autofill services #249

Alex009 opened this issue Jun 21, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@Alex009
Copy link
Member

Alex009 commented Jun 21, 2020

Now android try to suggest correct autofill type, but fails and show invalid autofill hints. To fix it required some autofill support.
For now particall solution is:
common:

enum class AutoFillType {
    EMAIL,
    PHONE,
    PHONE_CURRENT,
    FULL_NAME,
    FIRST_NAME,
    LAST_NAME,
    MIDDLE_NAME,
    USERNAME,
    PASSWORD,
    NEW_PASSWORD,
    NEW_USERNAME,
    BIRTHDAY_FULL
}

expect fun InputType.withAutoFill(autoFillType: AutoFillType): InputType

android:

actual fun InputType.withAutoFill(autoFillType: AutoFillType): InputType {
    val decoratedInputType = this
    return object : InputType {
        override fun applyTo(editText: EditText) {
            decoratedInputType.applyTo(editText)

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                autoFillType.applyTo(editText)
            }
        }
    }
}

@RequiresApi(Build.VERSION_CODES.O)
private fun AutoFillType.applyTo(editText: EditText) {
    val hints: Array<String> = when (this) {
        AutoFillType.EMAIL -> arrayOf(HintConstants.AUTOFILL_HINT_EMAIL_ADDRESS)
        AutoFillType.PHONE -> arrayOf(HintConstants.AUTOFILL_HINT_PHONE_NUMBER)
        AutoFillType.PHONE_CURRENT -> arrayOf(HintConstants.AUTOFILL_HINT_PHONE_NUMBER_DEVICE)
        AutoFillType.FULL_NAME -> arrayOf(HintConstants.AUTOFILL_HINT_PERSON_NAME)
        AutoFillType.FIRST_NAME -> arrayOf(HintConstants.AUTOFILL_HINT_PERSON_NAME_GIVEN)
        AutoFillType.PASSWORD -> arrayOf(HintConstants.AUTOFILL_HINT_PASSWORD)
        AutoFillType.LAST_NAME -> arrayOf(HintConstants.AUTOFILL_HINT_PERSON_NAME_FAMILY)
        AutoFillType.MIDDLE_NAME -> arrayOf(HintConstants.AUTOFILL_HINT_PERSON_NAME_MIDDLE)
        AutoFillType.USERNAME -> arrayOf(HintConstants.AUTOFILL_HINT_USERNAME)
        AutoFillType.NEW_PASSWORD -> arrayOf(HintConstants.AUTOFILL_HINT_NEW_PASSWORD)
        AutoFillType.NEW_USERNAME -> arrayOf(HintConstants.AUTOFILL_HINT_NEW_USERNAME)
        AutoFillType.BIRTHDAY_FULL -> arrayOf(HintConstants.AUTOFILL_HINT_BIRTH_DATE_FULL)
    }
    @Suppress("SpreadOperator")
    editText.setAutofillHints(*hints)
    editText.importantForAutofill = View.IMPORTANT_FOR_AUTOFILL_YES
}

ios:

actual fun InputType.withAutoFill(autoFillType: AutoFillType): InputType {
    return this
}

usage is simple:

input(
    size = WidgetSize.Const(SizeSpec.MatchConstraint, SizeSpec.WrapContent),
    id = Ids.PhoneInput,
    label = const(strings.phone),
    field = viewModel.phoneField,
    inputType = InputType.customPhone().withAutoFill(AutoFillType.PHONE_CURRENT)
)
@Alex009 Alex009 added the enhancement New feature or request label Jun 21, 2020
@Alex009 Alex009 added this to the 0.1.0-dev-20 milestone Jun 21, 2020
@Alex009 Alex009 modified the milestones: 0.1.0-dev-20, 0.1.0-dev-21 Aug 30, 2020
@Alex009 Alex009 modified the milestones: 0.1.0, 0.2.0 Jul 15, 2021
@Alex009 Alex009 removed this from the 0.2.0 milestone Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant