簡體   English   中英

反應原生 | 如何使用 Typescript 訪問鍵盤的 endCoordinates 並重構

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM