Java Code Examples for com.facebook.litho.ComponentLayout#getPaddingLeft()

The following examples show how to use com.facebook.litho.ComponentLayout#getPaddingLeft() . 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: HorizontalScrollSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnBoundsDefined
static void onBoundsDefined(
    ComponentContext context,
    ComponentLayout layout,
    @Prop Component contentProps,
    @Prop(optional = true) boolean fillViewport,
    @State ComponentTree childComponentTree,
    @FromMeasure Integer measuredComponentWidth,
    @FromMeasure Integer measuredComponentHeight,
    Output<Integer> componentWidth,
    Output<Integer> componentHeight,
    Output<YogaDirection> layoutDirection) {

  final int layoutWidth = layout.getWidth() - layout.getPaddingLeft() - layout.getPaddingRight();

  // If onMeasure() has been called, this means the content component already
  // has a defined size, no need to calculate it again.
  if (measuredComponentWidth != null && measuredComponentHeight != null) {
    componentWidth.set(Math.max(measuredComponentWidth, fillViewport ? layoutWidth : 0));
    componentHeight.set(measuredComponentHeight);
  } else {
    final int measuredWidth;
    final int measuredHeight;

    Size contentSize = new Size();
    childComponentTree.setRootAndSizeSpec(
        contentProps,
        SizeSpec.makeSizeSpec(0, UNSPECIFIED),
        SizeSpec.makeSizeSpec(layout.getHeight(), EXACTLY),
        contentSize);

    measuredWidth = Math.max(contentSize.width, fillViewport ? layoutWidth : 0);
    measuredHeight = contentSize.height;

    componentWidth.set(measuredWidth);
    componentHeight.set(measuredHeight);
  }

  layoutDirection.set(layout.getResolvedLayoutDirection());
}
 
Example 2
Source File: ImageSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnBoundsDefined
static void onBoundsDefined(
    ComponentContext c,
    ComponentLayout layout,
    @Prop(resType = ResType.DRAWABLE) Drawable drawable,
    @Prop(optional = true) ScaleType scaleType,
    Output<DrawableMatrix> drawableMatrix,
    Output<Integer> drawableWidth,
    Output<Integer> drawableHeight) {

  final int horizontalPadding = layout.getPaddingLeft() + layout.getPaddingRight();
  final int verticalPadding = layout.getPaddingTop() + layout.getPaddingBottom();

  if (ScaleType.FIT_XY == scaleType
      || drawable == null
      || drawable.getIntrinsicWidth() <= 0
      || drawable.getIntrinsicHeight() <= 0) {
    drawableMatrix.set(null);
    drawableWidth.set(layout.getWidth() - horizontalPadding);
    drawableHeight.set(layout.getHeight() - verticalPadding);
  } else {
    final DrawableMatrix matrix =
        DrawableMatrix.create(
            drawable,
            scaleType,
            layout.getWidth() - horizontalPadding,
            layout.getHeight() - verticalPadding);

    drawableMatrix.set(matrix);
    drawableWidth.set(drawable.getIntrinsicWidth());
    drawableHeight.set(drawable.getIntrinsicHeight());
  }
}
 
Example 3
Source File: VerticalScrollSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnBoundsDefined
static void onBoundsDefined(
    ComponentContext c,
    ComponentLayout layout,
    @Prop Component childComponent,
    @Prop(optional = true) boolean fillViewport,
    @State ComponentTree childComponentTree,
    @FromMeasure Integer measuredWidth,
    @FromMeasure Integer measuredHeight) {

  final int layoutWidth = layout.getWidth() - layout.getPaddingLeft() - layout.getPaddingRight();
  final int layoutHeight =
      layout.getHeight() - layout.getPaddingTop() - layout.getPaddingBottom();

  if (measuredWidth != null
      && measuredWidth == layoutWidth
      && (!fillViewport || (measuredHeight != null && measuredHeight == layoutHeight))) {
    // If we're not filling the viewport, then we always measure the height with unspecified, so
    // we just need to check that the width matches.
    return;
  }

  measureVerticalScroll(
      c,
      SizeSpec.makeSizeSpec(layout.getWidth(), EXACTLY),
      SizeSpec.makeSizeSpec(layout.getHeight(), EXACTLY),
      new Size(),
      childComponentTree,
      childComponent,
      fillViewport);
}
 
Example 4
Source File: FrescoVitoImage2Spec.java    From fresco with MIT License 5 votes vote down vote up
@OnBoundsDefined
static void onBoundsDefined(
    ComponentContext c, ComponentLayout layout, Output<Rect> viewportDimensions) {
  final int width = layout.getWidth();
  final int height = layout.getHeight();
  int paddingX = 0, paddingY = 0;
  if (layout.isPaddingSet()) {
    paddingX = layout.getPaddingLeft() + layout.getPaddingRight();
    paddingY = layout.getPaddingTop() + layout.getPaddingBottom();
  }

  viewportDimensions.set(new Rect(0, 0, width - paddingX, height - paddingY));
}