react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Resizing native component in native code does not work.

Open jayshah123 opened this issue 10 years ago • 8 comments

I have a custom native component which needs to change its size when some click is provided to it. I use following api but with no effect -

onClick(){
    getLayoutParams().height = 200
    getLayoutParams().width = 200
   requestLayout();
}

but with no effect, it is not able to change its size. How to circumvent such behaviour?

jayshah123 avatar Dec 27 '15 23:12 jayshah123

I am using react-native v0.13rc with android.

jayshah123 avatar Dec 27 '15 23:12 jayshah123

Hey jayshah123, thanks for reporting this issue!

React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.

  • If you don't know how to do something or something is not working as you expect but not sure it's a bug, please ask on StackOverflow with the tag react-native or for more real time interactions, ask on Discord in the #react-native channel.
  • If this is a feature request or a bug that you would like to be fixed, please report it on Product Pains. It has a ranking feature that lets us focus on the most important issues the community is experiencing.
  • We welcome clear issues and PRs that are ready for in-depth discussion. Please provide screenshots where appropriate and always mention the version of React Native you're using. Thank you for your contributions!

facebook-github-bot avatar Dec 27 '15 23:12 facebook-github-bot

Particularly subviews are also not able to change their size, even if the exposed native component is of fixed size or with flex:1 and styled from JS,

onClick(){
    subview.getLayoutParams().height = 200
    subview.getLayoutParams().width = 200
    subview.requestLayout();
    requestLayout();
}

jayshah123 avatar Dec 28 '15 00:12 jayshah123

If somebody happens to know the reason or has faced similar problem I would be glad to know the same. For know it is not a very primary concern for me so closing the issue.

jayshah123 avatar Dec 28 '15 01:12 jayshah123

You can manually trigger layout.

See ReactPicker.java or ReactToolbar.java for example.

 @Override
  public void requestLayout() {
    super.requestLayout();

    // The spinner relies on a measure + layout pass happening after it calls requestLayout().
    // Without this, the widget never actually changes the selection and doesn't call the
    // appropriate listeners. Since we override onLayout in our ViewGroups, a layout pass never
    // happens after a call to requestLayout, so we simulate one here.
    post(measureAndLayout);
  }

realaboo avatar Feb 05 '16 16:02 realaboo

@realaboo Thanks so much for this. I spent days banging my head against the wall but this solved it!

gsavvid avatar Oct 03 '16 19:10 gsavvid

@realaboo Thanks! It's insane that it's not a part of the documentation.

RobertoArtiles avatar Oct 11 '16 23:10 RobertoArtiles

@realaboo thank you so much!

svyatogor avatar Oct 04 '17 23:10 svyatogor