简体   繁体   English

反应原生 | 如何使用 Typescript 访问键盘的 endCoordinates 并重构

[英]React Native | How access to endCoordinates of Keyboard using Typescript and recompose

So I use recompoose and typescript in my react native app, and I trying to access to endCoordinates for Keyboard the get the Keyboard height.所以我在我的本机应用程序中使用 recompose 和 typescript,我尝试访问键盘的 endCoordinates 以获取键盘高度。 I followed this article and this post but I am not able to access to endCoordinates, it's always undefined.我关注了这篇文章和这篇文章,但我无法访问 endCoordinates,它始终未定义。

This is what I tried :这是我试过的:

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
);

I think the problem is the way I need to pass the keyboardDidShow event type to the method, because e object does not have any endCoordinates .我认为问题在于我需要将 keyboardDidShow 事件类型传递给方法的方式,因为e对象没有任何endCoordinates

react-native导入KeyboardEvent

const _keyboardDidShow = (props: KeyboardEvent)

const { endCoordinates } = props;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM