Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you expose ref property? #13

Open
borisjwork opened this issue Mar 5, 2024 · 1 comment
Open

Can you expose ref property? #13

borisjwork opened this issue Mar 5, 2024 · 1 comment

Comments

@borisjwork
Copy link

Hello,

I am migrating one project and I find this library very useful. I need to use scrollTo function from native ScrollView. Because of that, I need the possibility to set ref and use scrollTo function. Can you do this?

@Bialson
Copy link

Bialson commented Jun 13, 2024

You can expose ref by yourself in your local package files.

Inside package files in KeyboardAvoiderScrollView.tsx add the following line in props type definition:

// * node_modules/@good-react-native/keyboard-avoider/src/components/KeyboardAvoiderScrollView.tsx

type Props = ScrollViewProps & CommonProps & {
    /**
     * What to do when the keyboard hides on iOS.
     * @option 'stay' - *Default* scroll view will not move when the keyboard hides (it will stay where it is.)
     * @option 'revert' - Scroll view will return to its original position when the keyboard hides. 
     */
    iosHideBehavior?: 'stay' | 'revert',
    scrollViewRef?: AnimatedRef<AnimatedScrollView>; //<- this line
}

Then change the ref to be passed prop in line 39:

const scrollviewRef = props.scrollViewRef;

To create ref in parent component write the code as below and then pass it to KeyboardAvoiderScrollView component:

const scrollViewRef = useAnimatedRef<ScrollView>();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants