因此,我在我的 react 本机应用程序中使用了 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 事件类型传递给方法的方式,因为eobject 没有任何endCoordinates.