Add expo-keyboard-language native module
New Expo module that exposes keyboard language detection via a node handle. On iOS it resolves the React Native view tag to the underlying UITextField/UITextView and returns textInputMode.primaryLanguage (BCP 47 tag). Android and web return null for now. https://claude.ai/code/session_01AMCp4M56WtFPz1pZtwgcvx
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import ExpoModulesCore
|
||||
|
||||
public class ExpoKeyboardLanguageModule: Module {
|
||||
public func definition() -> ModuleDefinition {
|
||||
Name("ExpoKeyboardLanguage")
|
||||
|
||||
Function("getKeyboardLanguage") { (nodeHandle: Int) -> String? in
|
||||
guard let view = self.appContext?.findView(withTag: nodeHandle, ofType: UIView.self) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
if let textInput = self.findTextInput(in: view) {
|
||||
return textInput.textInputMode?.primaryLanguage
|
||||
}
|
||||
|
||||
return view.textInputMode?.primaryLanguage
|
||||
}
|
||||
}
|
||||
|
||||
private func findTextInput(in view: UIView) -> UIView? {
|
||||
if view is UITextField || view is UITextView {
|
||||
return view
|
||||
}
|
||||
|
||||
for subview in view.subviews {
|
||||
if let found = findTextInput(in: subview) {
|
||||
return found
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user