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

Create api to acquire Views for measuring #71

Open
emilsjolander opened this issue Apr 12, 2017 · 3 comments
Open

Create api to acquire Views for measuring #71

emilsjolander opened this issue Apr 12, 2017 · 3 comments

Comments

@emilsjolander
Copy link
Contributor

We need an API for acquiring Views for measuring. This api would allow us to do things like:

@OnMeasure
protected static void onMeasure(
        ComponentContext c, 
        ComponentLayout layout, 
        int widthSpec, 
        int heightSpec, 
        Size size) {
    View toMeasure = c.acquireMeasurableView();
    toMeasure.measure(...)
    ...
    c.releaseMeasurableView(toMeasure);
}

This way we might cache the views by context and thread and make this thread safe and consistent with theming. The acquire being a Component level api could simply call ComponentLifecycle.createMountContent under the hood (and create appropriate LayoutParams).

Point of contact: @IanChilds

@mmm111mmm
Copy link

mmm111mmm commented May 2, 2017

I've come across this problem too.

I want to use an Android EditText (It has properties that litho's doesn't) wrapped in a MountSpec.

I want to measure the height of the EditText like this: https://stackoverflow.com/questions/24359538/how-to-find-the-text-areaheight-width-of-textview-programmatically-in-android/24359594#24359594

textView.setText("bla");
textView.measure(0, 0);
textView.getMeasuredWidth();
textView.getMeasuredHeight();

But currently there is no way to access the Android EditText in the onMeasure function.

@IanChilds @emilsjolander Does this touch on the same issue in this ticket or shall I make a new one? This one hasn't been touched for 20 days.

@IanChilds
Copy link
Contributor

Not sure what you mean here:

But currently there is no way to access the Android EditText in the onMeasure function.

If you look at https://github.com/facebook/litho/blob/master/litho-widget/src/main/java/com/facebook/litho/widget/EditTextSpec.java#L229 you see that it does actually access the Android EditText in the onMeasure method.

@ar-g
Copy link

ar-g commented Feb 13, 2018

@IanChilds API for measuring custom views such as EditText is unclear. Moreover, in EditText example to measure EditTextSpec we create a new instance of EditText each time. Is this a common approach to implement onMeasure for MountSpec with view capable to resize itself dynamically?

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

No branches or pull requests

5 participants