Java Code Examples for com.facebook.yoga.YogaMeasureOutput#make()

The following examples show how to use com.facebook.yoga.YogaMeasureOutput#make() . 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: ProgressBarShadowNode.java    From progress-bar-android with MIT License 6 votes vote down vote up
@Override
public long measure(
    YogaNode node,
    float width,
    YogaMeasureMode widthMode,
    float height,
    YogaMeasureMode heightMode) {
  final int style = ReactProgressBarViewManager.getStyleFromString(getStyle());
  if (!mMeasured.contains(style)) {
    ProgressBar progressBar = ReactProgressBarViewManager.createProgressBar(getThemedContext(), style);
    final int spec = View.MeasureSpec.makeMeasureSpec(
        ViewGroup.LayoutParams.WRAP_CONTENT,
        View.MeasureSpec.UNSPECIFIED);
    progressBar.measure(spec, spec);
    mHeight.put(style, progressBar.getMeasuredHeight());
    mWidth.put(style, progressBar.getMeasuredWidth());
    mMeasured.add(style);
  }

  return YogaMeasureOutput.make(mWidth.get(style), mHeight.get(style));
}
 
Example 2
Source File: ReactSwitchManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
public long measure(
    YogaNode node,
    float width,
    YogaMeasureMode widthMode,
    float height,
    YogaMeasureMode heightMode) {
  if (!mMeasured) {
    // Create a switch with the default config and measure it; since we don't (currently)
    // support setting custom switch text, this is fine, as all switches will measure the same
    // on a specific device/theme/locale combination.
    ReactSwitch reactSwitch = new ReactSwitch(getThemedContext());
    reactSwitch.setShowText(false);
    final int spec = View.MeasureSpec.makeMeasureSpec(
        ViewGroup.LayoutParams.WRAP_CONTENT,
        View.MeasureSpec.UNSPECIFIED);
    reactSwitch.measure(spec, spec);
    mWidth = reactSwitch.getMeasuredWidth();
    mHeight = reactSwitch.getMeasuredHeight();
    mMeasured = true;
  }

  return YogaMeasureOutput.make(mWidth, mHeight);
}
 
Example 3
Source File: ProgressBarShadowNode.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
public long measure(
    YogaNode node,
    float width,
    YogaMeasureMode widthMode,
    float height,
    YogaMeasureMode heightMode) {
  final int style = ReactProgressBarViewManager.getStyleFromString(getStyle());
  if (!mMeasured.contains(style)) {
    ProgressBar progressBar = ReactProgressBarViewManager.createProgressBar(getThemedContext(), style);
    final int spec = View.MeasureSpec.makeMeasureSpec(
        ViewGroup.LayoutParams.WRAP_CONTENT,
        View.MeasureSpec.UNSPECIFIED);
    progressBar.measure(spec, spec);
    mHeight.put(style, progressBar.getMeasuredHeight());
    mWidth.put(style, progressBar.getMeasuredWidth());
    mMeasured.add(style);
  }

  return YogaMeasureOutput.make(mWidth.get(style), mHeight.get(style));
}
 
Example 4
Source File: ReactSliderManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@Override
public long measure(
    YogaNode node,
    float width,
    YogaMeasureMode widthMode,
    float height,
    YogaMeasureMode heightMode) {
  if (!mMeasured) {
    SeekBar reactSlider = new ReactSlider(getThemedContext(), null, STYLE);
    final int spec = View.MeasureSpec.makeMeasureSpec(
        ViewGroup.LayoutParams.WRAP_CONTENT,
        View.MeasureSpec.UNSPECIFIED);
    reactSlider.measure(spec, spec);
    mWidth = reactSlider.getMeasuredWidth();
    mHeight = reactSlider.getMeasuredHeight();
    mMeasured = true;
  }

  return YogaMeasureOutput.make(mWidth, mHeight);
}
 
Example 5
Source File: TweetShadowNode.java    From react-native-twitterkit with MIT License 6 votes vote down vote up
public synchronized long measure(
        Tweet tweet,
        YogaNode node,
        float width,
        YogaMeasureMode widthMode,
        float height,
        YogaMeasureMode heightMode
) {
  if (mTweetView == null) {
    mTweetView = ReactTweetViewManager.createTweetView(getThemedContext());
  }

  if (tweet != null) {
    mTweetView.setTweet(tweet);
  }
  mTweetView.measure(yogaToAndroid(widthMode, width), yogaToAndroid(heightMode, height));

  int measuredWidth = mTweetView.getMeasuredWidth();
  int measuredHeight = mTweetView.getMeasuredHeight();
  return YogaMeasureOutput.make(measuredWidth, measuredHeight);
}
 
Example 6
Source File: ReactTextInputShadowNode.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public long measure(
    YogaNode node,
    float width,
    YogaMeasureMode widthMode,
    float height,
    YogaMeasureMode heightMode) {
  // measure() should never be called before setThemedContext()
  EditText editText = Assertions.assertNotNull(mDummyEditText);

  if (mLocalData != null) {
    mLocalData.apply(editText);
  } else {
    editText.setTextSize(
        TypedValue.COMPLEX_UNIT_PX,
        mFontSize == UNSET ?
            (int) Math.ceil(PixelUtil.toPixelFromSP(ViewDefaults.FONT_SIZE_SP)) : mFontSize);

    if (mNumberOfLines != UNSET) {
      editText.setLines(mNumberOfLines);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
        editText.getBreakStrategy() != mTextBreakStrategy) {
      editText.setBreakStrategy(mTextBreakStrategy);
    }
  }

   // make sure the placeholder content is also being measured
   editText.setHint(getPlaceholder());
   editText.measure(
      MeasureUtil.getMeasureSpec(width, widthMode),
      MeasureUtil.getMeasureSpec(height, heightMode));

  return YogaMeasureOutput.make(editText.getMeasuredWidth(), editText.getMeasuredHeight());
}
 
Example 7
Source File: FloatingActionButtonShadowNode.java    From react-native-bottom-sheet-behavior with MIT License 5 votes vote down vote up
@Override
public long measure(YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) {
    if(!mMeasured) {
        FloatingActionButtonView nodeView = new FloatingActionButtonView(getThemedContext());
        final int spec = View.MeasureSpec.makeMeasureSpec(
                ViewGroup.LayoutParams.WRAP_CONTENT,
                View.MeasureSpec.UNSPECIFIED);
        nodeView.measure(spec, spec);
        mWidth = nodeView.getMeasuredWidth();
        mHeight = nodeView.getMeasuredHeight();
        mMeasured = true;
    }

    return YogaMeasureOutput.make(mWidth, mHeight);
}
 
Example 8
Source File: LithoYogaMeasureFunction.java    From litho with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressLint("WrongCall")
@SuppressWarnings("unchecked")
public long measure(
    YogaNode cssNode,
    float width,
    YogaMeasureMode widthMode,
    float height,
    YogaMeasureMode heightMode) {
  final InternalNode node = (InternalNode) cssNode.getData();
  final Component component = node.getTailComponent();
  final ComponentContext componentScopedContext = component.getScopedContext();

  if (componentScopedContext != null && componentScopedContext.wasLayoutCanceled()) {
    return 0;
  }

  final DiffNode diffNode = node.areCachedMeasuresValid() ? node.getDiffNode() : null;

  final int widthSpec;
  final int heightSpec;
  final boolean isTracing = ComponentsSystrace.isTracing();

  widthSpec = SizeSpec.makeSizeSpecFromCssSpec(width, widthMode);
  heightSpec = SizeSpec.makeSizeSpecFromCssSpec(height, heightMode);

  if (isTracing) {
    ComponentsSystrace.beginSectionWithArgs("measure:" + component.getSimpleName())
        .arg("widthSpec", SizeSpec.toString(widthSpec))
        .arg("heightSpec", SizeSpec.toString(heightSpec))
        .arg("componentId", component.getId())
        .flush();
  }

  node.setLastWidthSpec(widthSpec);
  node.setLastHeightSpec(heightSpec);

  int outputWidth = 0;
  int outputHeight = 0;

  ComponentContext context = node.getContext();

  if (Component.isNestedTree(context, component) || node.hasNestedTree()) {

    // Find the nearest parent component context.
    final Component head = node.getHeadComponent();
    final Component parent;

    if (component != head) { // If the head and tail are different, use the head.
      parent = head;
    } else if (node.getParent() != null) { // Otherwise use the tail of the parent node.
      parent = node.getParent().getTailComponent();
    } else {
      parent = null;
    }

    if (parent != null) {
      context = parent.getScopedContext();
    }

    final InternalNode nestedTree = Layout.create(context, node, widthSpec, heightSpec);

    outputWidth = nestedTree.getWidth();
    outputHeight = nestedTree.getHeight();
  } else if (diffNode != null
      && diffNode.getLastWidthSpec() == widthSpec
      && diffNode.getLastHeightSpec() == heightSpec
      && !component.shouldAlwaysRemeasure()) {
    outputWidth = (int) diffNode.getLastMeasuredWidth();
    outputHeight = (int) diffNode.getLastMeasuredHeight();
  } else {
    final Size size = acquireSize(Integer.MIN_VALUE /* initialValue */);

    component.onMeasure(componentScopedContext, node, widthSpec, heightSpec, size);

    if (size.width < 0 || size.height < 0) {
      throw new IllegalStateException(
          "MeasureOutput not set, ComponentLifecycle is: " + component);
    }

    outputWidth = size.width;
    outputHeight = size.height;

    if (node.getDiffNode() != null) {
      node.getDiffNode().setLastWidthSpec(widthSpec);
      node.getDiffNode().setLastHeightSpec(heightSpec);
      node.getDiffNode().setLastMeasuredWidth(outputWidth);
      node.getDiffNode().setLastMeasuredHeight(outputHeight);
    }
  }

  node.setLastMeasuredWidth(outputWidth);
  node.setLastMeasuredHeight(outputHeight);

  if (isTracing) {
    ComponentsSystrace.endSection();
  }

  return YogaMeasureOutput.make(outputWidth, outputHeight);
}