因此,我在我的react本机应用程序中使用recompoose和typescript,并且尝试访问Keyboard的endCoordinates以获取Keyboard高度。我关注了this和这篇post的文章,但是我无法访问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
。
答案 0 :(得分:0)
从KeyboardEvent
导入react-native
const _keyboardDidShow = (props: KeyboardEvent)
const { endCoordinates } = props;