com.facebook.yoga.YogaMeasureMode Java Examples
The following examples show how to use
com.facebook.yoga.YogaMeasureMode.
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 |
@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 |
@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 |
@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 |
@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 |
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: TweetShadowNode.java From react-native-twitterkit with MIT License | 6 votes |
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); }
Example #7
Source File: ARTSurfaceViewManager.java From art with MIT License | 5 votes |
@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"); }
Example #8
Source File: ReactTextInputShadowNode.java From react-native-GPay with MIT License | 5 votes |
@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 #9
Source File: ARTSurfaceViewManager.java From react-native-GPay with MIT License | 5 votes |
@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"); }
Example #10
Source File: MeasureUtil.java From react-native-GPay with MIT License | 5 votes |
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); } }
Example #11
Source File: SizeSpec.java From litho with Apache License 2.0 | 5 votes |
public static int makeSizeSpecFromCssSpec(float cssSize, YogaMeasureMode cssMode) { switch (cssMode) { case EXACTLY: return makeSizeSpec(FastMath.round(cssSize), SizeSpec.EXACTLY); case UNDEFINED: return makeSizeSpec(0, SizeSpec.UNSPECIFIED); case AT_MOST: return makeSizeSpec(FastMath.round(cssSize), SizeSpec.AT_MOST); default: throw new IllegalArgumentException("Unexpected YogaMeasureMode: " + cssMode); } }
Example #12
Source File: TweetShadowNode.java From react-native-twitterkit with MIT License | 5 votes |
@Override public long measure( YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) { return measure(null, node, width, widthMode, height, heightMode); }
Example #13
Source File: FloatingActionButtonShadowNode.java From react-native-bottom-sheet-behavior with MIT License | 5 votes |
@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 #14
Source File: LithoYogaMeasureFunction.java From litho with Apache License 2.0 | 4 votes |
@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); }