[英]React Native | How access to endCoordinates of Keyboard using Typescript and recompose
所以我在我的本机应用程序中使用 recompose 和 typescript,我尝试访问键盘的 endCoordinates 以获取键盘高度。 我关注了这篇文章和这篇文章,但我无法访问 endCoordinates,它始终未定义。
这是我试过的:
const withLifeCycle = lifecycle<Handlers, {}> ({
componentDidMount() {
// @ts-ignore
this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this.props._keyboardDidShow)
},
componentWillUnmount() {
// @ts-ignore
this.keyboardDidShowListener.remove();
}
})
interface Handlers {
_keyboardDidShow: (e:any) => void;
}
// WrappedProps have some other props for some other part of codes
export const enhance = compose<WrappedProps, Props>(
withHandlers<
Props,
{}
>({
_keyboardDidShow: (e) => () =>{
console.log(e.endCoordinates) // This is Undefined
}
}),
withLifeCycle
);
我认为问题在于我需要将 keyboardDidShow 事件类型传递给方法的方式,因为e
对象没有任何endCoordinates
。
从react-native
导入KeyboardEvent
const _keyboardDidShow = (props: KeyboardEvent)
const { endCoordinates } = props;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.