Keyboard Language in React Native iOS?

情到浓时终转凉″ 提交于 2021-02-17 01:57:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!