im-js / im.js

一个基于 react-native + mobx + socket.io + node 的仿微信 JS-Wechat

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

如何让键盘不消失

fukuaxiaoqiang opened this issue · comments

commented

点击发送的时候 如何输入框不失去焦点且键盘不消失

源代码在逻辑上是矛盾的,要更改 RN 的源代码,iOS 可以如下实现,但是代价有点大。
OC 源码中 是在 shouldChangeTextInRange 事件捕获 "\n" 字符串来实现 return key 的,如果_blurOnSubmit 为 true 则捕获

源码:https://github.com/facebook/react-native/blob/0e55f5b26dc60d8ce37e49b4766d7e9ec0a57605/Libraries/Text/RCTTextView.m#L349-L380

然后在 textFieldShouldEndEditing 之中,通过 _blurOnSubmit 来是判断键盘是否需要 dismiss,如果 _blurOnSubmit 为 false 则保持 keyBoard

源码:https://github.com/facebook/react-native/blob/0e55f5b26dc60d8ce37e49b4766d7e9ec0a57605/Libraries/Text/RCTTextField.m#L202-L209