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?
I am using react-native v0.13rc with android.
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.
react-native or for more real time interactions, ask on Discord in the #react-native channel.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();
}
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.
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 Thanks so much for this. I spent days banging my head against the wall but this solved it!
@realaboo Thanks! It's insane that it's not a part of the documentation.
@realaboo thank you so much!
Most helpful comment
You can manually trigger layout.
See ReactPicker.java or ReactToolbar.java for example.