/*
 * Copyright 2014-present Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.facebook.litho.annotations;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * This indicates that the annotated method will be called when the component's checks if it can use
 * the last cached layout returned from the Layout Spec with a new Size Spec. This is used in
 * conjunction with {@link OnCreateLayoutWithSizeSpec}. The annotated method must have the following
 * signature:
 *
 * <pre><code>
 *  static boolean onShouldCreateLayoutWithNewSizeSpec(
 *    ComponentContext context,
 *    int newWidthSpec,
 *    int newHeightSpec, ...)
 * </code></pre>
 *
 * <p>The annotated method should return {@code true} iff the Layout Spec should create a new layout
 * for this new size spec. If the method returns {@code false} then the Component will use the last
 * cached layout.
 */
@Retention(RetentionPolicy.SOURCE)
public @interface OnShouldCreateLayoutWithNewSizeSpec {}

@@ -1437,16 +1437,2016 @@
 layout.%0A
+ *%0A * %3Cp%3EFor example: %3Cbr%3E%0A *%0A * %3Cpre%3E%3Ccode%3E%7B@literal @LayoutSpec%7D%0A * class MyComponentSpec %7B%0A *%0A *  %7B@literal @OnCreateLayoutWithSizeSpec%7D%0A *   static Component onCreateLayoutWithSizeSpec(%0A *       ComponentContext c,%0A *       int widthSpec,%0A *       int heightSpec) %7B%0A *%0A *     final Component textComponent =%0A *         Text.create(c).textSizeSp(16).text(%22Some text to measure.%22).build();%0A *%0A *     // UNSPECIFIED sizeSpecs will measure the text as being one line only,%0A *     // having unlimited width.%0A *     final Size textOutputSize = new Size();%0A *     textComponent.measure(%0A *         c,%0A *         SizeSpec.makeSizeSpec(0, UNSPECIFIED),%0A *         SizeSpec.makeSizeSpec(0, UNSPECIFIED),%0A *         textOutputSize);%0A *%0A *     // Small component to use in case textComponent does not fit within the current layout.%0A *     final Component imageComponent = Image.create(c).drawableRes(R.drawable.ic_launcher).build();%0A *%0A *     // Assuming SizeSpec.getMode(widthSpec) == EXACTLY or AT_MOST.%0A *     final int layoutWidth = SizeSpec.getSize(widthSpec);%0A *     final boolean textFits = (textOutputSize.width &lt;= layoutWidth);%0A *%0A *     return textFits ? textComponent : imageComponent;%0A *   %7D%0A *%0A *  %7B@literal @OnShouldCreateLayoutWithNewSizeSpec%7D%0A *   static boolean onShouldCreateLayoutWithNewSizeSpec(%0A *       ComponentContext context,%0A *       int newWidthSpec,%0A *       int newHeightSpec,%0A *      %7B@literal @FromCreateLayout%7D int textWidth,%0A *      %7B@literal @FromCreateLayout%7D boolean didItFit) %7B%0A *%0A *     final int newLayoutWidth = SizeSpec.getSize(newWidthSpec);%0A *     final boolean doesItStillFit = (textWidth &lt;= newLayoutWidth);%0A *%0A *     // false if it still fits or if still doesn't fit%0A *     return doesItStillFit %5E didItFit;%0A *   %7D%0A * %7D%3C/code%3E%3C/pre%3E%0A *%0A * %3Cimg alt=%22On Should Create Layout With New Size Spec flow chart%22%0A * src=%22https://fblitho.com/static/images/flow-chart-v0.22.1-layout-with-size-spec.svg%22%3E%0A *%0A * @see FromCreateLayout%0A * @see OnCreateLayoutWithSizeSpec%0A
  */%0A@Ret

Update JavaDoc for OnShouldCreateLayoutWithNewSizeSpec