3ca5a865a1
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
34 lines
811 B
Swift
34 lines
811 B
Swift
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
|
|
}
|
|
}
|