Skip to content

[Layout] Use React view as content view of a native scroll view; how can I measure React components so that I can set the contentSize correctly? #1897

Closed

Description

@hokster7

I'm trying to build a scrollable page of information that has a parallax image header. QMBParallaxScrollViewController looks like a good choice to implement it, and is likely to have native performance. It's agnostic to what the content of the scrollview might be.

Below the parallax header, I have dynamic content that I want to use React Native to lay out for me.

However, in order to plonk a RCTRootView into the scroll view's content view and expect scrolling to work, we need to know how long the content of the RCTRootView is. The only way to measure this right now is outlined here: http://stackoverflow.com/questions/29828971/react-native-measure-a-view (basically #953) but I've not been able to get that to work.

Can anyone give me some guidance here?

Activity

  1. changed the title [-]Use React view as content view of a native scroll view; need to measure React components to set contentSize correctly[/-] [+]Use React view as content view of a native scroll view; how can I measure React components so that I can set the contentSize correctly?[/+] on Jul 7, 2015
  2. nicklockwood commented on Jul 7, 2015

    @nicklockwood
    Contributor
  3. brentvatne commented on Jul 7, 2015

    @brentvatne
    Collaborator

    @fatuhoku - you can use onLayout on a containing view to get the dimensions, check out the LayoutEventsExample

  4. changed the title [-]Use React view as content view of a native scroll view; how can I measure React components so that I can set the contentSize correctly?[/-] [+][Layout] Use React view as content view of a native scroll view; how can I measure React components so that I can set the contentSize correctly?[/+] on Jul 7, 2015
  5. sahrens commented on Jul 8, 2015

    @sahrens
    Contributor

    Sounds like the native component is what needs to know the height? ReactNative hasn't been embedded in this way yet (so far just with a pre-defined root view frame. You'll probably need to wire up your own native hooks to report the size of the content (onLayout should give you that) then use that to update the frame of the root view from your native QMBParallaxScrollViewController.

    But honestly I'd probably just rebuild the parallax logic yourself into a react native ScrollView instead. It's not too hard and will probably save a lot of headache if you can get the feel you want.

  6. sahrens commented on Jul 8, 2015

    @sahrens
    Contributor

    It will be even easier once the Animated API lands - #1900

  7. hokster7 commented on Jul 8, 2015

    @hokster7
    Author

    Thanks for your suggestions. onLayout looks like the next thing to try here. Good to know of the options.

    I don't think I feel confident enough to build the parallax logic quite yet. I've already tried using the attempt here: https://github.com/lelandrichardson/react-native-parallax-view but it's buggy (the image jumps about) and I notice that the scrolling behaviour isn't quite exactly as I expect it.

    EDIT: The parallax view project has been improved since the time of writing to make use of the Animation API. It works quite well now!

  8. locked as resolved and limited conversation to collaborators on Jul 22, 2018
  9. added
    Resolution: Locked
    on Jul 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution: Locked

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions