1 解决苹果端键盘不收回,本来元素外层加入scrollView可以解决,但比如一个输入框有一个清空按钮,点击清空按钮这个键盘也会收回而且没有执行清空的动作,然后加入下面的代码,以及从react-native引入Keyboard模块,通过点击确认按钮来收回Keyboard.dismiss()键盘。KeyboardAvoidingView使用这个模块避免键盘遮挡界面。
<KeyboardAvoidingView
style={
{
flex:1}}
behavior={
Platform.OS === 'ios' && 'padding'}
>
import {
BackHandler
} from 'react-native';
componentDidMount() {
BackHandler.addEventListener('hardwareBackPress', this.handleBack);
}
componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.handleBack);
}
return true的时候要通过导航语句手动返回当安卓机时下面官网代码解释
BackHandler.addEventListener("hardwareBackPress", function () {
/**
* this.onMainScreen()和this.goBack()两个方法都只是伪方法,需要你自己去实现
* 一般来说都要配合导航器组件使用
*/
if (!this.onMainScreen()) {
this.goBack();
/**
* 返回true时会阻止事件冒泡传递,因而不会执行默认的后退行为
*/
return true;
}
/**
* 返回false时会使事件继续传递,触发其他注册的监听函数,或是系统默认的后退行为
*/
return false;
});