auto-detect composer language from keyboard
adds a new expo-keyboard-language native module that reads the current keyboard language on iOS (via first responder's textInputMode) and Android (via InputMethodManager). iOS also gets real-time updates when the keyboard language changes. users opt in via Settings > Languages > "Automatically detect post language from keyboard" (native only, marked experimental). when enabled, the composer language tracks the keyboard language. users can override per-session by selecting a language manually, and re-enable auto mode via the "Automatic" item in the language menu. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
group = 'expo.modules.keyboardlanguage'
|
||||
version = '1.0.0'
|
||||
|
||||
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
||||
apply from: expoModulesCorePlugin
|
||||
applyKotlinExpoModulesCorePlugin()
|
||||
useCoreDependencies()
|
||||
useExpoPublishing()
|
||||
|
||||
def useManagedAndroidSdkVersions = false
|
||||
if (useManagedAndroidSdkVersions) {
|
||||
useDefaultAndroidSdkVersions()
|
||||
} else {
|
||||
buildscript {
|
||||
ext.safeExtGet = { prop, fallback ->
|
||||
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
||||
}
|
||||
}
|
||||
project.android {
|
||||
compileSdkVersion safeExtGet("compileSdkVersion", 34)
|
||||
defaultConfig {
|
||||
minSdkVersion safeExtGet("minSdkVersion", 21)
|
||||
targetSdkVersion safeExtGet("targetSdkVersion", 34)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
android {
|
||||
namespace "expo.modules.keyboardlanguage"
|
||||
defaultConfig {
|
||||
versionCode 1
|
||||
versionName "1.0.0"
|
||||
}
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package expo.modules.keyboardlanguage
|
||||
|
||||
import android.os.Build
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import androidx.core.content.getSystemService
|
||||
import expo.modules.kotlin.modules.Module
|
||||
import expo.modules.kotlin.modules.ModuleDefinition
|
||||
|
||||
class ExpoKeyboardLanguageModule : Module() {
|
||||
override fun definition() =
|
||||
ModuleDefinition {
|
||||
Name("ExpoKeyboardLanguage")
|
||||
|
||||
Function("getCurrentKeyboardLanguage") {
|
||||
val context = appContext.reactContext ?: return@Function null
|
||||
val imm = context.getSystemService<InputMethodManager>() ?: return@Function null
|
||||
val subtype = imm.currentInputMethodSubtype ?: return@Function null
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
val tag = subtype.languageTag
|
||||
if (tag.isNotEmpty()) return@Function tag
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
val locale = subtype.locale
|
||||
if (locale.isNotEmpty()) return@Function locale
|
||||
|
||||
return@Function null
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user