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

Set ScrollView manually #10

Open
diegolmello opened this issue Feb 6, 2018 · 3 comments
Open

Set ScrollView manually #10

diegolmello opened this issue Feb 6, 2018 · 3 comments

Comments

@diegolmello
Copy link

I need the ability to set scrollview with ref.
The same way react-native-keyboard-input does on kbInputRef.

I found that the iteration below finds the wrong scrollview when using react-navigation.
https://github.com/wix/react-native-keyboard-tracking-view/blob/master/lib/KeyboardTrackingViewManager.m#L127

So it would be awesome to set scrollview inside the code.
Also it would be unnecessary to do that loop.

@artald
Copy link
Collaborator

artald commented Feb 7, 2018

Hi @diegolmello

Initially we had some synchronization issues when we attempted to set the scroll-view from a ref, so this is the solution we ended up with.

As you noticed, this issue can happen when you use a JS based navigation. With native solutions like react-native-navigation this can't happen because each screen has it's own root view.

As a solution you can try to use the requiresSameParentToManageScrollView prop and set it to true. This will force the loop to hook to a scrollview which has the same parent (superview) as the tracking view. If you're using a view hierarchy where the KeyboardTrackingView and the ScrollView have the same container view - it should solve your problem.

@diegolmello
Copy link
Author

@artald I am already using requiresSameParentToManageScrollView prop, but the loop finds react-navigation's sidebar scroll.

@jedt
Copy link

jedt commented Jun 24, 2020

I am using Navigator from react-native-deprecated-custom-components as mentioned by @artald it will not work with js based. But the fix below works for me:

KeyboardTrackingViewManager.m

-(UIView*)getRootView
{
    UIView *view = self;
    while (view.superview != nil)
    {
        view = view.superview;
        if ([view isKindOfClass:[UIView class]])
            break;
    }
    
    if ([view isKindOfClass:[UIView class]])
    {
        return (UIView*)view;
    }
    return nil;
}

Hope this helps

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

3 participants