Replies: 1 comment 5 replies
|
I created a bridge for it package <>
import android.os.Build
import android.util.Log
import android.view.autofill.AutofillManager
import androidx.appcompat.app.AppCompatActivity
/// Bridges the Android Autofill framework to Swift so a successful sign-in triggers the
/// "Save password?" prompt. SwiftUI/Skip has no hook for `AutofillManager.commit()`, so without
/// this call the framework never learns a credential was submitted and nothing gets saved —
/// which means nothing is ever available to autofill later.
/// Uses a `companion object` (not a top-level `object`) so SkipBridge's Reflector
/// (which calls `kotlin.companionObjectInstance`) can resolve the static methods.
class AutofillBridge {
companion object {
private const val TAG = "AutofillBridge"
private var activity: AppCompatActivity? = null
@JvmStatic
fun setup(activity: AppCompatActivity) {
Companion.activity = activity
}
/// Tells the Autofill framework the current fill session ended in success, so it can
/// offer to save the just-entered credential. No-op pre-API 26, with no autofill service
/// configured, or with no in-flight fill session (e.g. a restored session on cold launch).
@JvmStatic
fun commit() {
val ctx = activity ?: run {
Log.e(TAG, "No activity available to commit autofill session")
return
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
val manager = ctx.getSystemService(AutofillManager::class.java)
manager?.commit()
Log.i(TAG, "Autofill session committed")
}
}
}And then add --- Update I forgot to add the Swift side: #if os(Android)
#if SKIP_BRIDGE
import SkipBridge
#endif
/// Tells the Android Autofill framework a sign-in just succeeded, via Kotlin `AutofillBridge`
/// (SkipFuse bridge mode). Without this, the framework never sees a completed fill session and
/// the "Save password?" prompt never appears.
enum AndroidAutofillBridge {
/// Uses raw JNI (`JClass.callStatic`) instead of `AnyDynamicObject` to avoid the
/// Reflector/JObject bridging issues — this is a direct JVM static method invocation.
@MainActor
static func commitSuccessfulSignIn() {
#if SKIP_BRIDGE
jniContext {
do {
let cls = try JClass(name: "<>/<>/AutofillBridge")
let methodID = cls.getStaticMethodID(name: "commit", sig: "()V")!
try cls.callStatic(method: methodID, options: .kotlincompat, args: [])
} catch {
// Best-effort: a missing autofill session or bridge failure just means no
// save prompt this time, not a broken sign-in.
}
}
#endif
}
}
#endifAnd then somewhere the dismiss action: #if os(Android)
AndroidAutofillBridge.commitSuccessfulSignIn()
#endif |
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
With iOS you get automatic keychain suggestions in TextFields. How do you accomplish the same functionality on Skip / Android?
Android suggests the email, but not the password.
All reactions