Java 类com.facebook.yoga.YogaNode 实例源码

项目:react-native-twitterkit    文件:TweetShadowNode.java   
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);
}
项目:RNLearn_Project1    文件:RCTTextInput.java   
@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(mEditText);

  int fontSize = getFontSize();
  editText.setTextSize(
      TypedValue.COMPLEX_UNIT_PX,
      fontSize == UNSET ?
          (int) Math.ceil(PixelUtil.toPixelFromSP(ViewDefaults.FONT_SIZE_SP)) : fontSize);

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

  editText.measure(
      MeasureUtil.getMeasureSpec(width, widthMode),
      MeasureUtil.getMeasureSpec(height, heightMode));
  return YogaMeasureOutput.make(editText.getMeasuredWidth(), editText.getMeasuredHeight());
}
项目:RNLearn_Project1    文件:ReactSwitchManager.java   
@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());
    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);
}
项目:RNLearn_Project1    文件:ProgressBarShadowNode.java   
@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));
}
项目:RNLearn_Project1    文件:ReactSliderManager.java   
@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);
}
项目:react-native-twitterkit    文件:TweetShadowNode.java   
@Override
public long measure(
        YogaNode node,
        float width,
        YogaMeasureMode widthMode,
        float height,
        YogaMeasureMode heightMode) {
  return measure(null, node, width, widthMode, height, heightMode);
}
项目:RNLearn_Project1    文件:FlatARTSurfaceViewManager.java   
@Override
public long measure(
    YogaNode node,
    float width,
    YogaMeasureMode widthMode,
    float height,
    YogaMeasureMode heightMode) {
  throw new IllegalStateException("SurfaceView should have explicit width and height set");
}
项目:RNLearn_Project1    文件:RCTText.java   
@Override
public long measure(
    YogaNode node,
    float width,
    YogaMeasureMode widthMode,
    float height,
    YogaMeasureMode heightMode) {

  CharSequence text = getText();
  if (TextUtils.isEmpty(text)) {
    // to indicate that we don't have anything to display
    mText = null;
    return YogaMeasureOutput.make(0, 0);
  } else {
    mText = text;
  }

  Layout layout = createTextLayout(
      (int) Math.ceil(width),
      widthMode,
      TextUtils.TruncateAt.END,
      true,
      mNumberOfLines,
      mNumberOfLines == 1,
      text,
      getFontSize(),
      mSpacingAdd,
      mSpacingMult,
      getFontStyle(),
      getAlignment());

  if (mDrawCommand != null && !mDrawCommand.isFrozen()) {
    mDrawCommand.setLayout(layout);
  } else {
    mDrawCommand = new DrawTextLayout(layout);
  }

  return YogaMeasureOutput.make(mDrawCommand.getLayoutWidth(), mDrawCommand.getLayoutHeight());
}
项目:RNLearn_Project1    文件:ReactTextInputShadowNode.java   
@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(mEditText);

  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) {
    if (editText.getBreakStrategy() != mTextBreakStrategy) {
      editText.setBreakStrategy(mTextBreakStrategy);
    }
  }

  editText.measure(
      MeasureUtil.getMeasureSpec(width, widthMode),
      MeasureUtil.getMeasureSpec(height, heightMode));

  return YogaMeasureOutput.make(editText.getMeasuredWidth(), editText.getMeasuredHeight());
}
项目:RNLearn_Project1    文件:ARTSurfaceViewManager.java   
@Override
public long measure(
    YogaNode node,
    float width,
    YogaMeasureMode widthMode,
    float height,
    YogaMeasureMode heightMode) {
  throw new IllegalStateException("SurfaceView should have explicit width and height set");
}
项目:RNLearn_Project1    文件:YogaNodePool.java   
public static ClearableSynchronizedPool<YogaNode> get() {
  if (sPool != null) {
    return sPool;
  }

  synchronized (sInitLock) {
    if (sPool == null) {
      sPool = new ClearableSynchronizedPool<YogaNode>(1024);
    }
    return sPool;
  }
}
项目:RNLearn_Project1    文件:ReactShadowNode.java   
public void addChildAt(ReactShadowNode child, int i) {
  if (child.mParent != null) {
    throw new IllegalViewOperationException(
      "Tried to add child that already has a parent! Remove it from its parent first.");
  }
  if (mChildren == null) {
    mChildren = new ArrayList<ReactShadowNode>(4);
  }
  mChildren.add(i, child);
  child.mParent = this;

  // If a CSS node has measure defined, the layout algorithm will not visit its children. Even
  // more, it asserts that you don't add children to nodes with measure functions.
  if (mYogaNode != null && !mYogaNode.isMeasureDefined()) {
    YogaNode childYogaNode = child.mYogaNode;
    if (childYogaNode == null) {
      throw new RuntimeException(
        "Cannot add a child that doesn't have a YogaNode to a parent without a measure " +
          "function! (Trying to add a '" + child.getClass().getSimpleName() + "' to a '" +
          getClass().getSimpleName() + "')");
    }
    mYogaNode.addChildAt(childYogaNode, i);
  }
  markUpdated();

  int increase = child.mIsLayoutOnly ? child.mTotalNativeChildren : 1;
  mTotalNativeChildren += increase;

  updateNativeChildrenCountInParent(increase);
}
项目:RNLearn_Project1    文件:YogaNodePool.java   
public static ClearableSynchronizedPool<YogaNode> get() {
  if (sPool != null) {
    return sPool;
  }

  synchronized (sInitLock) {
    if (sPool == null) {
      sPool = new ClearableSynchronizedPool<YogaNode>(1024);
    }
    return sPool;
  }
}
项目:RNLearn_Project1    文件:ReactShadowNode.java   
public void addChildAt(ReactShadowNode child, int i) {
  if (child.mParent != null) {
    throw new IllegalViewOperationException(
      "Tried to add child that already has a parent! Remove it from its parent first.");
  }
  if (mChildren == null) {
    mChildren = new ArrayList<ReactShadowNode>(4);
  }
  mChildren.add(i, child);
  child.mParent = this;

  // If a CSS node has measure defined, the layout algorithm will not visit its children. Even
  // more, it asserts that you don't add children to nodes with measure functions.
  if (mYogaNode != null && !mYogaNode.isMeasureDefined()) {
    YogaNode childYogaNode = child.mYogaNode;
    if (childYogaNode == null) {
      throw new RuntimeException(
        "Cannot add a child that doesn't have a YogaNode to a parent without a measure " +
          "function! (Trying to add a '" + child.getClass().getSimpleName() + "' to a '" +
          getClass().getSimpleName() + "')");
    }
    mYogaNode.addChildAt(childYogaNode, i);
  }
  markUpdated();

  int increase = child.mIsLayoutOnly ? child.mTotalNativeChildren : 1;
  mTotalNativeChildren += increase;

  updateNativeChildrenCountInParent(increase);
}
项目:react-native-svg    文件:SvgViewManager.java   
@Override
public long measure(
        YogaNode node,
        float width,
        YogaMeasureMode widthMode,
        float height,
        YogaMeasureMode heightMode) {
    throw new IllegalStateException("SurfaceView should have explicit width and height set");
}
项目:react-native-bottom-sheet-behavior    文件:FloatingActionButtonShadowNode.java   
@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);
}