com.facebook.litho.utils.MeasureUtils Java Examples
The following examples show how to use
com.facebook.litho.utils.MeasureUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FrescoImageSpec.java From litho with Apache License 2.0 | 5 votes |
@OnMeasure protected static void onMeasure( ComponentContext c, ComponentLayout layout, int widthSpec, int heightSpec, Size size, @Prop(optional = true, resType = ResType.FLOAT) float imageAspectRatio) { MeasureUtils.measureWithAspectRatio(widthSpec, heightSpec, imageAspectRatio, size); }
Example #2
Source File: ImageSpec.java From litho with Apache License 2.0 | 5 votes |
@OnMeasure static void onMeasure( ComponentContext c, ComponentLayout layout, int widthSpec, int heightSpec, Size size, @Prop(resType = ResType.DRAWABLE) Drawable drawable) { if (drawable == null || drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) { size.width = 0; size.height = 0; return; } final int intrinsicHeight = drawable.getIntrinsicHeight(); final int intrinsicWidth = drawable.getIntrinsicWidth(); if (SizeSpec.getMode(widthSpec) == UNSPECIFIED && SizeSpec.getMode(heightSpec) == UNSPECIFIED) { size.width = intrinsicWidth; size.height = intrinsicHeight; return; } final float aspectRatio = intrinsicWidth / (float) intrinsicHeight; MeasureUtils.measureWithAspectRatio( widthSpec, heightSpec, intrinsicWidth, intrinsicHeight, aspectRatio, size); }
Example #3
Source File: ProgressSpec.java From litho with Apache License 2.0 | 5 votes |
@OnMeasure static void onMeasure( ComponentContext c, ComponentLayout layout, int widthSpec, int heightSpec, Size size) { if (SizeSpec.getMode(widthSpec) == SizeSpec.UNSPECIFIED && SizeSpec.getMode(heightSpec) == SizeSpec.UNSPECIFIED) { size.width = DEFAULT_SIZE; size.height = DEFAULT_SIZE; } else { MeasureUtils.measureWithEqualDimens(widthSpec, heightSpec, size); } }
Example #4
Source File: ClockComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@OnMeasure static void onMeasure( ComponentContext c, ComponentLayout layout, int widthSpec, int heightSpec, Size size) { final ClockView clockView = new ClockView(c.getAndroidContext()); clockView.measure( MeasureUtils.getViewMeasureSpec(widthSpec), MeasureUtils.getViewMeasureSpec(heightSpec)); size.width = clockView.getMeasuredWidth(); size.height = clockView.getMeasuredHeight(); }
Example #5
Source File: FrescoVitoImage2Spec.java From fresco with MIT License | 5 votes |
@OnMeasure static void onMeasure( ComponentContext c, ComponentLayout layout, int widthSpec, int heightSpec, Size size, @Prop(optional = true, resType = ResType.FLOAT) float imageAspectRatio) { MeasureUtils.measureWithAspectRatio(widthSpec, heightSpec, imageAspectRatio, size); }
Example #6
Source File: TextInputSpec.java From litho with Apache License 2.0 | 4 votes |
@OnMeasure static void onMeasure( ComponentContext c, ComponentLayout layout, int widthSpec, int heightSpec, Size size, @Prop(optional = true, resType = ResType.STRING) CharSequence hint, @Prop(optional = true, resType = ResType.DRAWABLE) Drawable inputBackground, @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowRadius, @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDx, @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDy, @Prop(optional = true, resType = ResType.COLOR) int shadowColor, @Prop(optional = true) ColorStateList textColorStateList, @Prop(optional = true) ColorStateList hintColorStateList, @Prop(optional = true, resType = ResType.COLOR) Integer highlightColor, @Prop(optional = true, resType = ResType.DIMEN_TEXT) int textSize, @Prop(optional = true) Typeface typeface, @Prop(optional = true) int textAlignment, @Prop(optional = true) int gravity, @Prop(optional = true) boolean editable, @Prop(optional = true) int inputType, @Prop(optional = true) int imeOptions, @Prop(optional = true, varArg = "inputFilter") List<InputFilter> inputFilters, @Prop(optional = true) boolean multiline, @Prop(optional = true) TextUtils.TruncateAt ellipsize, @Prop(optional = true) int minLines, @Prop(optional = true) int maxLines, @Prop(optional = true) int cursorDrawableRes, @Prop(optional = true, resType = ResType.STRING) CharSequence error, @Prop(optional = true, resType = ResType.DRAWABLE) Drawable errorDrawable, @State AtomicReference<CharSequence> savedText, @State int measureSeqNumber) { // The height should be the measured height of EditText with relevant params final EditText forMeasure = new ForMeasureEditText(c.getAndroidContext()); // If text contains Spans, we don't want it to be mutable for the measurement case CharSequence text = savedText.get(); if (text instanceof Spannable) { text = text.toString(); } setParams( forMeasure, hint, getBackgroundOrDefault( c, inputBackground == UNSET_DRAWABLE ? forMeasure.getBackground() : inputBackground), shadowRadius, shadowDx, shadowDy, shadowColor, textColorStateList, hintColorStateList, highlightColor, textSize, typeface, textAlignment, gravity, editable, inputType, imeOptions, inputFilters, multiline, ellipsize, minLines, maxLines, cursorDrawableRes, forMeasure.getMovementMethod(), // onMeasure happens: // 1. After initState before onMount: savedText = initText. // 2. After onMount before onUnmount: savedText preserved from underlying editText. text, error, errorDrawable); forMeasure.measure( MeasureUtils.getViewMeasureSpec(widthSpec), MeasureUtils.getViewMeasureSpec(heightSpec)); size.height = forMeasure.getMeasuredHeight(); // For width we always take all available space, or collapse to 0 if unspecified. if (SizeSpec.getMode(widthSpec) == SizeSpec.UNSPECIFIED) { size.width = 0; } else { size.width = Math.min(SizeSpec.getSize(widthSpec), forMeasure.getMeasuredWidth()); } }
Example #7
Source File: GlideImageSpec.java From litho-glide with MIT License | 4 votes |
@OnMeasure static void onMeasureLayout(ComponentContext c, ComponentLayout layout, int widthSpec, int heightSpec, Size size, @Prop(optional = true, resType = ResType.FLOAT) float imageAspectRatio) { MeasureUtils.measureWithAspectRatio(widthSpec, heightSpec, imageAspectRatio, size); }
Example #8
Source File: PicassoImageSpec.java From litho-picasso with MIT License | 4 votes |
@OnMeasure static void onMeasureLayout(ComponentContext c, ComponentLayout layout, int widthSpec, int heightSpec, Size size) { MeasureUtils.measureWithEqualDimens(widthSpec, heightSpec, size); }