Ish*_*san 5 android react-native
我正在尝试使用 捕获 Android 上键盘显示/隐藏事件的事件React Native。我陷入了死胡同。
这是我的清单设置:
<activity
android:launchMode="singleTop"
android:name=".MainActivity"
android:screenOrientation="portrait"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
这是我的 RN 组件:
import React, {Component} from 'react';
import {
View,Keyboard
} from 'react-native';
export default class KeyboardAwareComponent extends Component {
componentDidMount() {
Keyboard.addListener("keyboardDidShow",()=>{
console.log("Show event");
})
}
render() {
return <View />
}
}
Run Code Online (Sandbox Code Playgroud)
提前非常感谢您:)
以下是直接来自文档的一些事件。
键盘将显示
键盘显示
键盘将隐藏
键盘隐藏
键盘将改变框架
键盘更改帧
import React, { Component } from 'react';
import { Keyboard, TextInput } from 'react-native';
class Example extends Component {
componentWillMount () {
this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow);
this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide);
}
componentWillUnmount () {
this.keyboardDidShowListener.remove();
this.keyboardDidHideListener.remove();
}
_keyboardDidShow () {
alert('Keyboard Shown');
}
_keyboardDidHide () {
alert('Keyboard Hidden');
}
render() {
return (
<TextInput
onSubmitEditing={Keyboard.dismiss}
/>
);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4501 次 |
| 最近记录: |