com.facebook.yoga.YogaNode Java Examples
The following examples show how to use
com.facebook.yoga.YogaNode.
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: 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 #3
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 #4
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 #5
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 #6
Source File: DefaultInternalNode.java From litho with Apache License 2.0 | 6 votes |
@Override public DefaultInternalNode deepClone() { // 1. Return the null layout. if (this == NULL_LAYOUT) { return this; } // 2. Clone this layout. final DefaultInternalNode copy = clone(); // 3. Clone the YogaNode of this layout and set it on the cloned layout. YogaNode node = mYogaNode.cloneWithoutChildren(); copy.mYogaNode = node; node.setData(copy); // 4. Deep clone all children and add it to the cloned YogaNode final int count = getChildCount(); for (int i = 0; i < count; i++) { copy.child(getChildAt(i).deepClone()); } copy.resetResolvedLayoutProperties(); return copy; }
Example #7
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 #8
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 #9
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 #10
Source File: InternalNodeTest.java From litho with Apache License 2.0 | 5 votes |
@Test public void testPaddingIsSetFromDrawable() { YogaNode yogaNode = mock(YogaNode.class); InternalNode node = new DefaultInternalNode(new ComponentContext(getApplicationContext()), yogaNode); node.backgroundRes(background_with_padding); assertThat(isFlagSet(node, "PFLAG_PADDING_IS_SET")).isTrue(); verify(yogaNode).setPadding(LEFT, 48); verify(yogaNode).setPadding(TOP, 0); verify(yogaNode).setPadding(RIGHT, 0); verify(yogaNode).setPadding(BOTTOM, 0); }
Example #11
Source File: NodeConfig.java From litho with Apache License 2.0 | 5 votes |
@Nullable static YogaNode createYogaNode() { final InternalYogaNodeFactory factory = sYogaNodeFactory; return factory != null ? factory.create(sYogaConfig) : LithoYogaFactory.createYogaNode(sYogaConfig); }
Example #12
Source File: DefaultInternalNode.java From litho with Apache License 2.0 | 5 votes |
/** * Convenience method to create a shallow copy of the InternalNode, set a new YogaNode, update all * components and ComponentContext, release all the unnecessary properties from the new * InternalNode. */ private static DefaultInternalNode getCleanUpdatedShallowCopy( final DefaultInternalNode current, final Component head, final YogaNode node) { final boolean isTracing = ComponentsSystrace.isTracing(); if (isTracing) { ComponentsSystrace.beginSection("clone:" + head.getSimpleName()); } // 1. Shallow copy this layout. final DefaultInternalNode layout = current.clone(); if (isTracing) { ComponentsSystrace.endSection(); ComponentsSystrace.beginSection("clean:" + head.getSimpleName()); } // 2. Reset and release properties layout.clean(); if (isTracing) { ComponentsSystrace.endSection(); ComponentsSystrace.beginSection("update:" + head.getSimpleName()); } // 3. Get updated components List<Component> updated = current.getUpdatedComponents(head); // 4. Update the layout with the updated context, components, and YogaNode. layout.updateWith(head.getScopedContext(), node, updated, null); if (isTracing) { ComponentsSystrace.endSection(); } return layout; }
Example #13
Source File: DefaultInternalNode.java From litho with Apache License 2.0 | 5 votes |
@Override public void useHeightAsBaseline(boolean useHeightAsBaselineFunction) { if (useHeightAsBaselineFunction) { mYogaNode.setBaselineFunction( new YogaBaselineFunction() { @Override public float baseline(YogaNode yogaNode, float width, float height) { return height; } }); } }
Example #14
Source File: DefaultInternalNode.java From litho with Apache License 2.0 | 5 votes |
/** Continually walks the node hierarchy until a node returns a non inherited layout direction */ @Override public YogaDirection recursivelyResolveLayoutDirection() { YogaNode yogaNode = mYogaNode; while (yogaNode != null && yogaNode.getLayoutDirection() == YogaDirection.INHERIT) { yogaNode = yogaNode.getOwner(); } return yogaNode == null ? YogaDirection.INHERIT : yogaNode.getLayoutDirection(); }
Example #15
Source File: ReactShadowNodeImpl.java From react-native-GPay with MIT License | 5 votes |
public ReactShadowNodeImpl() { mDefaultPadding = new Spacing(0); if (!isVirtual()) { YogaNode node = YogaNodePool.get().acquire(); mYogaNode = node == null ? new YogaNode(sYogaConfig) : node; mYogaNode.setData(this); Arrays.fill(mPadding, YogaConstants.UNDEFINED); } else { mYogaNode = null; } }
Example #16
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 #17
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 #18
Source File: YogaNodePool.java From react-native-GPay with MIT License | 5 votes |
public static ClearableSynchronizedPool<YogaNode> get() { if (sPool != null) { return sPool; } synchronized (sInitLock) { if (sPool == null) { sPool = new ClearableSynchronizedPool<>(1024); } return sPool; } }
Example #19
Source File: ReactShadowNodeImpl.java From react-native-GPay with MIT License | 5 votes |
@Override public YogaNode cloneNode(YogaNode oldYogaNode, YogaNode parent, int childIndex) { SystraceMessage.beginSection( Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricReconciler.YogaNodeCloneFunction") .flush(); try { ReactShadowNodeImpl parentReactShadowNode = (ReactShadowNodeImpl) parent.getData(); Assertions.assertNotNull(parentReactShadowNode); ReactShadowNodeImpl oldReactShadowNode = (ReactShadowNodeImpl) oldYogaNode.getData(); Assertions.assertNotNull(oldReactShadowNode); if (DEBUG) { FLog.d( TAG, "YogaNode started cloning: oldYogaNode: " + oldReactShadowNode + " - parent: " + parentReactShadowNode + " index: " + childIndex); } ReactShadowNodeImpl newNode = oldReactShadowNode.mutableCopy(oldReactShadowNode.getInstanceHandle()); parentReactShadowNode.replaceChild(newNode, childIndex); return newNode.mYogaNode; } finally{ Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); } }
Example #20
Source File: DefaultInternalNode.java From litho with Apache License 2.0 | 5 votes |
protected DefaultInternalNode( ComponentContext componentContext, YogaNode yogaNode, boolean createDebugComponentsInCtor) { super(); mComponentContext = componentContext; if (yogaNode != null) { yogaNode.setData(this); } mYogaNode = yogaNode; if (createDebugComponentsInCtor) { mDebugComponents = new HashSet<>(); } }
Example #21
Source File: ReactShadowNodeImpl.java From react-native-GPay with MIT License | 5 votes |
@Override public void addChildAt(ReactShadowNodeImpl child, int i) { assertNotSealed(); if (mChildren == null) { mChildren = new ArrayList<>(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 && !isYogaLeafNode()) { 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.toString() + "' to a '" + toString() + "')"); } mYogaNode.addChildAt(childYogaNode, i); } markUpdated(); int increase = child.isLayoutOnly() ? child.getTotalNativeChildren() : 1; mTotalNativeChildren += increase; updateNativeChildrenCountInParent(increase); }
Example #22
Source File: NodeConfig.java From litho with Apache License 2.0 | 4 votes |
@Nullable YogaNode create(YogaConfig config);
Example #23
Source File: DefaultInternalNode.java From litho with Apache License 2.0 | 4 votes |
/** * Internal method to reconcile the {@param current} InternalNode with a new {@link * ComponentContext} and an updated head {@link Component} and a {@link ReconciliationMode}. * * @param current The current InternalNode which should be updated. * @param next The updated component to be used to reconcile this InternalNode. * @param keys The keys of mutated components. * @param mode {@link ReconciliationMode#RECONCILE} or {@link ReconciliationMode#COPY}. * @return A new updated InternalNode. */ private static InternalNode reconcile( final DefaultInternalNode current, final Component next, final Set<String> keys, final @ReconciliationMode int mode) { final boolean isTracing = ComponentsSystrace.isTracing(); if (isTracing) { ComponentsSystrace.beginSection( (mode == ReconciliationMode.COPY ? "copy:" : "reconcile:") + next.getSimpleName()); } // 1. Shallow copy this layouts's YogaNode. final YogaNode currentNode = current.getYogaNode(); if (isTracing) { ComponentsSystrace.beginSection("cloneYogaNode:" + next.getSimpleName()); } final YogaNode copiedNode = currentNode.cloneWithoutChildren(); if (isTracing) { ComponentsSystrace.endSection(); } // 2. Shallow copy this layout. final DefaultInternalNode layout = getCleanUpdatedShallowCopy(current, next, copiedNode); ComponentContext parentContext = layout.getTailComponent().getScopedContext(); // 3. Clear the nested tree if (layout.getNestedTree() != null) { layout.getOrCreateNestedTreeProps().mNestedTree = null; } // 4. Iterate over children. int count = currentNode.getChildCount(); for (int i = 0; i < count; i++) { final DefaultInternalNode child = (DefaultInternalNode) currentNode.getChildAt(i).getData(); // 4.1 Get the head component of the child layout. List<Component> components = child.getComponents(); final Component component = components.get(Math.max(0, components.size() - 1)); // 4.2 Update the head component of the child layout. final Component updated = component.makeUpdatedShallowCopy(parentContext); // 4.3 Reconcile child layout. final InternalNode copy; if (mode == ReconciliationMode.COPY) { copy = reconcile(child, updated, keys, ReconciliationMode.COPY); } else { copy = reconcile(parentContext, child, updated, keys); } // 4.3 Add the child to the cloned yoga node layout.child(copy); } if (isTracing) { ComponentsSystrace.endSection(); } return layout; }
Example #24
Source File: LithoYogaFactory.java From litho with Apache License 2.0 | 4 votes |
public static YogaNode createYogaNode(YogaConfig config) { return YogaNodeFactory.create(config); }
Example #25
Source File: LithoYogaBaselineFunction.java From litho with Apache License 2.0 | 4 votes |
@Override public float baseline(YogaNode cssNode, float width, float height) { final InternalNode node = (InternalNode) cssNode.getData(); return node.getTailComponent().onMeasureBaseline(node.getContext(), (int) width, (int) height); }
Example #26
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); }
Example #27
Source File: ComponentLifecycleTest.java From litho with Apache License 2.0 | 4 votes |
@Before public void setUp() { mockStatic(Layout.class); NodeConfig.sInternalNodeFactory = new NodeConfig.InternalNodeFactory() { @Override public InternalNode create(ComponentContext componentContext) { InternalNode layout = spy(new DefaultInternalNode(componentContext)); YogaNode node = YogaNodeFactory.create(); node.setData(layout); return layout; } }; when(Layout.onCreateLayout((ComponentContext) any(), (Component) any())).thenCallRealMethod(); when(Layout.create((ComponentContext) any(), (Component) any(), anyBoolean(), anyBoolean())) .thenCallRealMethod(); when(Layout.create((ComponentContext) any(), (Component) any(), anyBoolean())) .thenCallRealMethod(); when(Layout.create((ComponentContext) any(), (Component) any())).thenCallRealMethod(); when(Layout.update((ComponentContext) any(), (Component) any(), anyBoolean())) .thenCallRealMethod(); mDiffNode = mock(DiffNode.class); mNode = mock(DefaultInternalNode.class); mYogaNode = YogaNodeFactory.create(); mYogaNode.setData(mNode); when(mNode.getLastWidthSpec()).thenReturn(-1); when(mNode.getDiffNode()).thenReturn(mDiffNode); when(mDiffNode.getLastMeasuredWidth()).thenReturn(-1f); when(mDiffNode.getLastMeasuredHeight()).thenReturn(-1f); StateHandler stateHandler = mock(StateHandler.class); final ComponentContext c = new ComponentContext(getApplicationContext(), stateHandler); c.setLayoutStateContextForTesting(); mContext = spy(c); when(mNode.getContext()).thenReturn(mContext); mNestedTreeWidthSpec = SizeSpec.makeSizeSpec(400, SizeSpec.EXACTLY); mNestedTreeHeightSpec = SizeSpec.makeSizeSpec(200, SizeSpec.EXACTLY); }
Example #28
Source File: NoOpInternalNode.java From litho with Apache License 2.0 | 4 votes |
@Override public @Nullable YogaNode getYogaNode() { return null; }
Example #29
Source File: DefaultInternalNode.java From litho with Apache License 2.0 | 4 votes |
protected DefaultInternalNode(ComponentContext componentContext, YogaNode yogaNode) { this(componentContext, yogaNode, true); }
Example #30
Source File: DefaultInternalNode.java From litho with Apache License 2.0 | 4 votes |
@Override public YogaNode getYogaNode() { return mYogaNode; }