React Native iOS中的键盘语言? [英] Keyboard Language in React Native iOS?

查看:71
本文介绍了React Native iOS中的键盘语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在React-Native iOS应用中有什么方法可以知道键盘的语言吗?

Is there any way to know the language of the Keyboard in React-Native iOS apps?

因为我想根据当前语言自动切换 TextInput 方向

Cause I want to switch TextInput direction automatically based on current language

推荐答案

您可以使用以下方法获取devide语言环境:

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.

如果创建一个本地模块,则可以获得键盘语言.

You can get the keyboard language if you create an native module.

此处是示例如何使用Java for Android来获取它:

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);
          }
       }
   }
}

这是如何快速完成此操作,对于IOS:

And here's how to do it with swift, for IOS:

var language = textfield.textInputMode?.primaryLanguage

并且这是方式为react-native创建一个本地模块

And here's how to create a native module for react-native

这篇关于React Native iOS中的键盘语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆