APSL / react-native-keyboard-aware-scroll-view

A ScrollView component that handles keyboard appearance and automatically scrolls to focused TextInput.
MIT License
5.27k stars 646 forks source link

HOC listenToKeyboardEvents not listed in typing #438

Open AmauryLiet opened 4 years ago

AmauryLiet commented 4 years ago

Hey!

First of all thanks for the great lib, solving painful issues on my projects

I wanted to use the listenToKeyboardEvents HOC to apply it on other components (such as Scrollview from 'react-native-gesture-handler'), but unfortunately the HOC isn't mentionned in index.d.ts, resulting in TS errors

Happy to provide more info if necessary, Thanks!

neiker commented 3 years ago

I'm facing same issue, do you solve it @AmauryLiet ?

This is my "solution":

// FIXME https://github.com/APSL/react-native-keyboard-aware-scroll-view/issues/438
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { listenToKeyboardEvents } from "react-native-keyboard-aware-scroll-view";
import { ScrollView } from "react-native-gesture-handler";

const KeyboardAwareScrollView: typeof ScrollView = listenToKeyboardEvents(
  ScrollView
);
AmauryLiet commented 3 years ago

hey @neiker! I eventually went for a more appropriate solution to my specific issue

Your solution is the most convenient and will indeed resolve TS error but you won't have any autocomplete or type checking

Anyway, thanks for sharing it for future readers ;)

deflexable commented 1 year ago

also having this issue, took me about an hour before figuring out the method was added in the index.js file but wasn't add in the declaration file. Had to create my own declaration file

grifotv commented 2 months ago

Not really sure why I can not get a RNGH KeyboardAwareScrollView to work as a regular KeyboardAwareScrollView (nothing shows up). I have the versions below. Wondering if anyone is facing the same issue.

"react-native-gesture-handler": "^2.17.1"
"react-native-keyboard-aware-scroll-view": "^0.9.5",
grifotv commented 2 months ago

Ended up with an alternative solution:

import { createNativeWrapper } from 'react-native-gesture-handler';
import { KeyboardAwareScrollView as BaseKeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';

type KeyboardAwareScrollViewProps = ComponentProps<
  typeof BaseKeyboardAwareScrollView
>;
const KeyboardAwareScrollView =
  createNativeWrapper<KeyboardAwareScrollViewProps>(
    BaseKeyboardAwareScrollView,
    {
      disallowInterruption: true,
      shouldCancelWhenOutside: false,
    },
  );