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); }
private static int yogaToAndroid(YogaMeasureMode mode, float value) { int m; switch (mode) { case AT_MOST: m = View.MeasureSpec.AT_MOST; break; case EXACTLY: m = View.MeasureSpec.EXACTLY; break; case UNDEFINED: default: m = View.MeasureSpec.UNSPECIFIED; } int v; if (value == Float.NaN) { v = ViewGroup.LayoutParams.WRAP_CONTENT; } else { v = (int) value; } return View.MeasureSpec.makeMeasureSpec(v, m); }
@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()); }
@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); }
@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)); }
@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); }
@Override public long measure( YogaNodeAPI 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()); }
@Override public long measure( YogaNodeAPI 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); }
@Override public long measure( YogaNodeAPI 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)); }
@Override public long measure( YogaNodeAPI 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); }
@Override public long measure( YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { return measure(null, node, width, widthMode, height, heightMode); }
@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"); }
@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()); }
@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()); }
public static int getMeasureSpec(float size, YogaMeasureMode mode) { if (mode == YogaMeasureMode.EXACTLY) { return View.MeasureSpec.makeMeasureSpec((int) size, View.MeasureSpec.EXACTLY); } else if (mode == YogaMeasureMode.AT_MOST) { return View.MeasureSpec.makeMeasureSpec((int) size, View.MeasureSpec.AT_MOST); } else { return View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); } }
@Override public long measure( YogaNodeAPI node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { throw new IllegalStateException("SurfaceView should have explicit width and height set"); }
@Override public long measure( YogaNodeAPI 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()); }
@Override public long measure( YogaNodeAPI 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()); }
@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); }
private static Layout createTextLayout( int width, YogaMeasureMode widthMode, TextUtils.TruncateAt ellipsize, boolean shouldIncludeFontPadding, int maxLines, boolean isSingleLine, CharSequence text, int textSize, float extraSpacing, float spacingMultiplier, int textStyle, Layout.Alignment textAlignment) { Layout newLayout; final @TextLayoutBuilder.MeasureMode int textMeasureMode; switch (widthMode) { case UNDEFINED: textMeasureMode = TextLayoutBuilder.MEASURE_MODE_UNSPECIFIED; break; case EXACTLY: textMeasureMode = TextLayoutBuilder.MEASURE_MODE_EXACTLY; break; case AT_MOST: textMeasureMode = TextLayoutBuilder.MEASURE_MODE_AT_MOST; break; default: throw new IllegalStateException("Unexpected size mode: " + widthMode); } sTextLayoutBuilder .setEllipsize(ellipsize) .setMaxLines(maxLines) .setSingleLine(isSingleLine) .setText(text) .setTextSize(textSize) .setWidth(width, textMeasureMode); sTextLayoutBuilder.setTextStyle(textStyle); sTextLayoutBuilder.setTextDirection(TextDirectionHeuristicsCompat.FIRSTSTRONG_LTR); sTextLayoutBuilder.setIncludeFontPadding(shouldIncludeFontPadding); sTextLayoutBuilder.setTextSpacingExtra(extraSpacing); sTextLayoutBuilder.setTextSpacingMultiplier(spacingMultiplier); sTextLayoutBuilder.setAlignment(textAlignment); newLayout = sTextLayoutBuilder.build(); sTextLayoutBuilder.setText(null); return newLayout; }