问题
Is there any way to know the language of the Keyboard in React-Native iOS apps?
Cause I want to switch TextInput
direction automatically based on current language
回答1:
You can get the devide locale using:
import { NativeModules } from 'react-native'
const locale = NativeModules.SettingsManager.settings.AppleLocale ||
NativeModules.SettingsManager.settings.AppleLanguages[0]
It should produce something like:
"fr_FR"
The keyboard language itself, i didn't found anything until now.
Edit
You can get the keyboard language if you create an native module
.
Here's a example of how to get it using java for android:
private void printInputLanguages() {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
List<InputMethodInfo> ims = imm.getEnabledInputMethodList();
for (InputMethodInfo method : ims) {
List<InputMethodSubtype> submethods = imm.getEnabledInputMethodSubtypeList(method, true);
for (InputMethodSubtype submethod : submethods) {
if (submethod.getMode().equals("keyboard")) {
String currentLocale = submethod.getLocale();
Log.i(TAG, "Available input method locale: " + currentLocale);
}
}
}
}
And here's how to do it with swift, for IOS:
var language = textfield.textInputMode?.primaryLanguage
And here's how to create a native module for react-native
来源:https://stackoverflow.com/questions/64009740/keyboard-language-in-react-native-ios