/*
 * 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.widget;

import static android.widget.ImageView.ScaleType.FIT_XY;
import static com.facebook.litho.annotations.ResType.COLOR;

import android.graphics.drawable.ColorDrawable;
import com.facebook.litho.Component;
import com.facebook.litho.ComponentContext;
import com.facebook.litho.annotations.LayoutSpec;
import com.facebook.litho.annotations.OnCreateLayout;
import com.facebook.litho.annotations.Prop;

/**
 * A component that renders a solid color.
 *
 * @uidocs https://fburl.com/SolidColor:b0df
 * @prop color Color to be shown.
 */
@LayoutSpec
class SolidColorSpec {

  @OnCreateLayout
  static Component onCreateLayout(ComponentContext c, @Prop(resType = COLOR) int color) {
    return Image.create(c)
        .scaleType(FIT_XY)
        .drawable(new ColorDrawable(color))
        .build();
  }
}

@@ -800,16 +800,63 @@
 awable;%0A
+import android.support.v4.graphics.ColorUtils;%0A
 import c
@@ -1075,16 +1075,67 @@
 ns.Prop;
+%0Aimport com.facebook.litho.annotations.PropDefault;
 %0A%0A/**%0A *
@@ -1263,44 +1263,156 @@
 .%0A *
-/%0A@LayoutSpec%0Aclass SolidColorSpec %7B
+ @prop alpha The alpha of the color, in the range %5B0.0, 1.0%5D%0A */%0A@LayoutSpec%0Aclass SolidColorSpec %7B%0A  @PropDefault static final float alpha = -1.0f;
 %0A%0A  
@@ -1461,16 +1461,23 @@
 eLayout(
+%0A      
 Componen
@@ -1487,16 +1487,22 @@
 ntext c,
+%0A     
  @Prop(r
@@ -1530,11 +1530,246 @@
 olor
-) %7B
+,%0A      @Prop(optional = true, isCommonProp = true, overrideCommonPropBehavior = true) float alpha) %7B%0A    if (alpha %3E= 0f) %7B%0A      alpha = Math.min(1f, alpha);%0A      color = ColorUtils.setAlphaComponent(color, (int) (alpha * 255f));%0A    %7D
 %0A   

Optimize setting an alpha on SolidColor