com.facebook.litho.annotations.ResType Java Examples

The following examples show how to use com.facebook.litho.annotations.ResType. 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: CardShadowSpec.java    From litho with Apache License 2.0 6 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext context,
    CardShadowDrawable cardShadowDrawable,
    @Prop(optional = true, resType = ResType.COLOR) int shadowStartColor,
    @Prop(optional = true, resType = ResType.COLOR) int shadowEndColor,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float cornerRadius,
    @Prop(optional = true, resType = ResType.DIMEN_SIZE) float shadowSize,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDx,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDy,
    @Prop(optional = true) boolean hideTopShadow,
    @Prop(optional = true) boolean hideBottomShadow) {

  cardShadowDrawable.setShadowStartColor(shadowStartColor);
  cardShadowDrawable.setShadowEndColor(shadowEndColor);
  cardShadowDrawable.setCornerRadius(cornerRadius);
  cardShadowDrawable.setShadowSize(shadowSize);
  cardShadowDrawable.setHideTopShadow(hideTopShadow);
  cardShadowDrawable.setHideBottomShadow(hideBottomShadow);
  cardShadowDrawable.setShadowDx(shadowDx);
  cardShadowDrawable.setShadowDy(shadowDy);
}
 
Example #2
Source File: PropDefaultsExtractor.java    From litho with Apache License 2.0 6 votes vote down vote up
private static ImmutableList<PropDefaultModel> extractFromField(Element enclosedElement) {
  if (enclosedElement.getKind() != ElementKind.FIELD) {
    return ImmutableList.of();
  }

  final VariableElement variableElement = (VariableElement) enclosedElement;
  final Annotation propDefaultAnnotation = variableElement.getAnnotation(PropDefault.class);
  if (propDefaultAnnotation == null) {
    return ImmutableList.of();
  }

  final ResType propDefaultResType = ((PropDefault) propDefaultAnnotation).resType();
  final int propDefaultResId = ((PropDefault) propDefaultAnnotation).resId();

  return ImmutableList.of(
      new PropDefaultModel(
          TypeName.get(variableElement.asType()),
          variableElement.getSimpleName().toString(),
          ImmutableList.copyOf(new ArrayList<>(variableElement.getModifiers())),
          variableElement,
          propDefaultResType,
          propDefaultResId));
}
 
Example #3
Source File: PsiAnnotationProxyUtilsTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void setValues() {
  testHelper.getPsiClass(
      psiClasses -> {
        assertNotNull(psiClasses);
        PsiClass psiClass = psiClasses.get(0);
        PsiParameter[] parameters =
            PsiTreeUtil.findChildOfType(psiClass, PsiParameterList.class).getParameters();

        Prop prop = PsiAnnotationProxyUtils.findAnnotationInHierarchy(parameters[1], Prop.class);
        assertNotNull(prop);
        assertTrue(prop.optional());
        assertTrue(prop.isCommonProp());
        assertTrue(prop.overrideCommonPropBehavior());
        assertTrue(prop.dynamic());
        assertEquals(ResType.DRAWABLE, prop.resType());

        return true;
      },
      "WithAnnotationClass.java");
}
 
Example #4
Source File: PropModel.java    From litho with Apache License 2.0 6 votes vote down vote up
public PropModel(
    MethodParamModel paramModel,
    boolean isOptional,
    boolean isCommonProp,
    boolean overrideCommonPropBehavior,
    boolean dynamic,
    ResType resType,
    String varArg) {
  mParamModel = paramModel;
  mIsOptional = isOptional || (varArg != null && !varArg.isEmpty());
  mIsCommonProp = isCommonProp;
  mOverrideCommonPropBehavior = overrideCommonPropBehavior;
  mIsDynamic = dynamic;
  mResType = resType;
  mVarArgSingleArgName = varArg;
}
 
Example #5
Source File: PsiAnnotationProxyUtilsTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void defaultValues() {
  testHelper.getPsiClass(
      psiClasses -> {
        assertNotNull(psiClasses);
        PsiClass psiClass = psiClasses.get(0);
        PsiParameter[] parameters =
            PsiTreeUtil.findChildOfType(psiClass, PsiParameterList.class).getParameters();

        Prop prop = PsiAnnotationProxyUtils.findAnnotationInHierarchy(parameters[0], Prop.class);
        assertNotNull(prop);
        assertFalse(prop.optional());
        assertFalse(prop.isCommonProp());
        assertFalse(prop.overrideCommonPropBehavior());
        assertFalse(prop.dynamic());
        assertEquals(ResType.NONE, prop.resType());

        return true;
      },
      "WithAnnotationClass.java");
}
 
Example #6
Source File: CardClipSpec.java    From litho with Apache License 2.0 6 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext c,
    CardClipDrawable cardClipDrawable,
    @Prop(optional = true, resType = ResType.COLOR) int clippingColor,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float cornerRadius,
    @Prop(optional = true) boolean disableClipTopLeft,
    @Prop(optional = true) boolean disableClipTopRight,
    @Prop(optional = true) boolean disableClipBottomLeft,
    @Prop(optional = true) boolean disableClipBottomRight) {
  cardClipDrawable.setClippingColor(clippingColor);
  cardClipDrawable.setCornerRadius(cornerRadius);
  int clipEdge =
      (disableClipTopLeft ? TOP_LEFT : NONE)
          | (disableClipTopRight ? TOP_RIGHT : NONE)
          | (disableClipBottomLeft ? BOTTOM_LEFT : NONE)
          | (disableClipBottomRight ? BOTTOM_RIGHT : NONE);
  cardClipDrawable.setDisableClip(clipEdge);
}
 
Example #7
Source File: PsiPropDefaultsExtractor.java    From litho with Apache License 2.0 6 votes vote down vote up
private static ImmutableList<PropDefaultModel> extractFromField(PsiField psiField) {
  final Annotation propDefaultAnnotation =
      PsiAnnotationProxyUtils.findAnnotationInHierarchy(psiField, PropDefault.class);
  if (propDefaultAnnotation == null) {
    return ImmutableList.of();
  }

  final ResType propDefaultResType = ((PropDefault) propDefaultAnnotation).resType();
  final int propDefaultResId = ((PropDefault) propDefaultAnnotation).resId();

  return ImmutableList.of(
      new PropDefaultModel(
          PsiTypeUtils.getTypeName(psiField.getType()),
          psiField.getName(),
          PsiModifierExtractor.extractModifiers(psiField.getModifierList()),
          psiField,
          propDefaultResType,
          propDefaultResId));
}
 
Example #8
Source File: TestLayoutSpec.java    From litho with Apache License 2.0 6 votes vote down vote up
@OnCreateLayout
static <S extends View> Component onCreateLayout(
    ComponentContext context,
    @Prop @Nullable Object prop3,
    @Prop char[] prop4,
    @Prop EventHandler<ClickEvent> handler,
    @Prop Component child,
    @Prop(optional = true) boolean prop2,
    @Prop(resType = ResType.STRING, optional = true, varArg = "name") List<String> names,
    @State(canUpdateLazily = true) long state1,
    @State S state2,
    @State int state3,
    @TreeProp TestTreeProp treeProp,
    @CachedValue int cached) {
  return null;
}
 
Example #9
Source File: ProgressSpec.java    From litho with Apache License 2.0 6 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext c,
    ProgressBar progressBar,
    @Prop(optional = true, resType = ResType.COLOR) int color,
    @FromPrepare Drawable resolvedIndeterminateDrawable) {

  if (resolvedIndeterminateDrawable != null) {
    progressBar.setIndeterminateDrawable(resolvedIndeterminateDrawable);
  }

  if (color != Color.TRANSPARENT && progressBar.getIndeterminateDrawable() != null) {
    progressBar
        .getIndeterminateDrawable()
        .mutate()
        .setColorFilter(color, PorterDuff.Mode.MULTIPLY);
  }
}
 
Example #10
Source File: PropValidationTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void testIncorrectTypeForResTypeWithVarArg() {
  when(mPropModel1.getResType()).thenReturn(ResType.BOOL);
  when(mPropModel1.hasVarArgs()).thenReturn(true);
  when(mPropModel1.getTypeName())
      .thenReturn(ParameterizedTypeName.get(ClassNames.LIST, TypeName.INT.box()));

  List<SpecModelValidationError> validationErrors =
      PropValidation.validate(
          mSpecModel,
          PropValidation.COMMON_PROP_NAMES,
          PropValidation.VALID_COMMON_PROPS,
          RunMode.normal());
  assertThat(validationErrors).hasSize(1);
  assertThat(validationErrors.get(0).element).isEqualTo(mRepresentedObject1);
  assertThat(validationErrors.get(0).message)
      .isEqualTo(
          "A variable argument declared with resType BOOL must be one of the following types: "
              + "[java.util.List<java.lang.Boolean>].");
}
 
Example #11
Source File: SpinnerSpec.java    From litho with Apache License 2.0 6 votes vote down vote up
@OnCreateLayout
static Component onCreateLayout(
    ComponentContext c,
    @State String selection,
    @State boolean isShowingDropDown,
    @Prop(resType = ResType.DIMEN_TEXT, optional = true) float selectedTextSize,
    @Prop(resType = ResType.COLOR, optional = true) int selectedTextColor,
    @Prop(resType = ResType.DRAWABLE, optional = true) @Nullable Drawable caret) {
  caret = caret == null ? new CaretDrawable(c.getAndroidContext(), DEFAULT_CARET_COLOR) : caret;
  selectedTextSize =
      selectedTextSize == -1
          ? spToPx(c.getAndroidContext(), DEFAULT_TEXT_SIZE_SP)
          : selectedTextSize;

  return Row.create(c)
      .minHeightDip(SPINNER_HEIGHT)
      .justifyContent(YogaJustify.SPACE_BETWEEN)
      .paddingDip(START, MARGIN_SMALL)
      .backgroundAttr(android.R.attr.selectableItemBackground)
      .clickHandler(Spinner.onClick(c))
      .child(createSelectedItemText(c, selection, (int) selectedTextSize, selectedTextColor))
      .child(createCaret(c, caret, isShowingDropDown))
      .accessibilityRole(AccessibilityRole.DROP_DOWN_LIST)
      .build();
}
 
Example #12
Source File: PropValidationTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void testVarArgPropMustHaveParameterizedListType() {
  when(mPropModel1.getResType()).thenReturn(ResType.NONE);
  when(mPropModel1.getVarArgsSingleName()).thenReturn("test");
  when(mPropModel1.hasVarArgs()).thenReturn(true);
  when(mPropModel1.getTypeName())
      .thenReturn(ParameterizedTypeName.get(ArrayList.class, String.class));

  List<SpecModelValidationError> validationErrors =
      PropValidation.validate(
          mSpecModel,
          PropValidation.COMMON_PROP_NAMES,
          PropValidation.VALID_COMMON_PROPS,
          RunMode.normal());
  assertThat(validationErrors).hasSize(1);
  assertThat(validationErrors.get(0).element).isEqualTo(mRepresentedObject1);
  assertThat(validationErrors.get(0).message)
      .isEqualTo("name1 is a variable argument, and thus should be a List<> type.");
}
 
Example #13
Source File: PropValidationTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void testVarArgPropMustHaveListType() {
  when(mPropModel1.getResType()).thenReturn(ResType.NONE);
  when(mPropModel1.getVarArgsSingleName()).thenReturn("test");
  when(mPropModel1.hasVarArgs()).thenReturn(true);
  when(mPropModel1.getTypeName()).thenReturn(TypeName.get(String.class));

  List<SpecModelValidationError> validationErrors =
      PropValidation.validate(
          mSpecModel,
          PropValidation.COMMON_PROP_NAMES,
          PropValidation.VALID_COMMON_PROPS,
          RunMode.normal());
  assertThat(validationErrors).hasSize(1);
  assertThat(validationErrors.get(0).element).isEqualTo(mRepresentedObject1);
  assertThat(validationErrors.get(0).message)
      .isEqualTo("name1 is a variable argument, and thus requires a parameterized List type.");
}
 
Example #14
Source File: TextSpec.java    From litho with Apache License 2.0 6 votes vote down vote up
@OnPopulateAccessibilityNode
static void onPopulateAccessibilityNode(
    View host,
    AccessibilityNodeInfoCompat node,
    @Prop(resType = ResType.STRING) CharSequence text,
    @Prop(optional = true, resType = ResType.BOOL) boolean isSingleLine) {
  if (ViewCompat.getImportantForAccessibility(host)
      == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
    ViewCompat.setImportantForAccessibility(host, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
  }
  CharSequence contentDescription = node.getContentDescription();
  node.setText(contentDescription != null ? contentDescription : text);
  node.setContentDescription(contentDescription != null ? contentDescription : text);

  node.addAction(AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY);
  node.addAction(AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY);
  node.setMovementGranularities(
      AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_CHARACTER
          | AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_WORD
          | AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_PARAGRAPH);

  if (!isSingleLine) {
    node.setMultiLine(true);
  }
}
 
Example #15
Source File: PropValidationTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void testIncorrectTypeForResType() {
  when(mPropModel1.getResType()).thenReturn(ResType.BOOL);
  when(mPropModel1.getTypeName()).thenReturn(TypeName.INT);

  List<SpecModelValidationError> validationErrors =
      PropValidation.validate(
          mSpecModel,
          PropValidation.COMMON_PROP_NAMES,
          PropValidation.VALID_COMMON_PROPS,
          RunMode.normal());
  assertThat(validationErrors).hasSize(1);
  assertThat(validationErrors.get(0).element).isEqualTo(mRepresentedObject1);
  assertThat(validationErrors.get(0).message)
      .isEqualTo(
          "A prop declared with resType BOOL must be one of the following types: "
              + "[boolean, java.lang.Boolean].");
}
 
Example #16
Source File: PropValidationTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void testTwoPropsWithSameNameButDifferentResType() {
  when(mPropModel1.getName()).thenReturn("sameName");
  when(mPropModel2.getName()).thenReturn("sameName");
  when(mPropModel1.getTypeName()).thenReturn(TypeName.INT);
  when(mPropModel2.getTypeName()).thenReturn(TypeName.INT);
  when(mPropModel1.getResType()).thenReturn(ResType.INT);

  List<SpecModelValidationError> validationErrors =
      PropValidation.validate(
          mSpecModel,
          PropValidation.COMMON_PROP_NAMES,
          PropValidation.VALID_COMMON_PROPS,
          RunMode.normal());
  assertThat(validationErrors).hasSize(1);
  assertThat(validationErrors.get(0).element).isEqualTo(mRepresentedObject1);
  assertThat(validationErrors.get(0).message)
      .isEqualTo(
          "The prop sameName is defined differently in different methods. Ensure that each "
              + "instance of this prop is declared in the same way (this means having the same type, "
              + "resType and values for isOptional, isCommonProp and overrideCommonPropBehavior).");
}
 
Example #17
Source File: PropValidationTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
  when(mPropModel1.getName()).thenReturn("name1");
  when(mPropModel2.getName()).thenReturn("name2");
  when(mPropModel1.getTypeName()).thenReturn(TypeName.BOOLEAN);
  when(mPropModel2.getTypeName()).thenReturn(TypeName.INT);
  when(mPropModel1.getTypeSpec()).thenReturn(new TypeSpec(TypeName.BOOLEAN));
  when(mPropModel2.getTypeSpec()).thenReturn(new TypeSpec(TypeName.INT));
  when(mPropModel1.isOptional()).thenReturn(false);
  when(mPropModel2.isOptional()).thenReturn(false);
  when(mPropModel1.getResType()).thenReturn(ResType.NONE);
  when(mPropModel2.getResType()).thenReturn(ResType.NONE);
  when(mPropModel1.getRepresentedObject()).thenReturn(mRepresentedObject1);
  when(mPropModel2.getRepresentedObject()).thenReturn(mRepresentedObject2);
  when(mSpecModel.getProps()).thenReturn(ImmutableList.of(mPropModel1, mPropModel2));
  when(mSpecModel.getPropDefaults()).thenReturn(ImmutableList.<PropDefaultModel>of());
}
 
Example #18
Source File: PropDefaultModel.java    From litho with Apache License 2.0 5 votes vote down vote up
public PropDefaultModel(
    TypeName type,
    String name,
    ImmutableList<Modifier> modifiers,
    Object representedObject,
    ResType resType,
    int resId) {
  mType = type;
  mName = name;
  mModifiers = modifiers;
  mRepresentedObject = representedObject;
  mResType = resType;
  mResId = resId;
}
 
Example #19
Source File: InjectPropModel.java    From litho with Apache License 2.0 5 votes vote down vote up
/** Convert to a regular prop model. */
public PropModel toPropModel() {
  final String localName = getName();
  return new PropModel(mParamModel, false, false, false, false, ResType.NONE, "") {
    @Override
    public String getName() {
      return localName;
    }
  };
}
 
Example #20
Source File: PropNameInterStageStoreTest.java    From litho with Apache License 2.0 5 votes vote down vote up
static PropModel makePropModel(String name) {
  return new PropModel(
      MockMethodParamModel.newBuilder().name(name).build(),
      false,
      false,
      false,
      false,
      ResType.BOOL,
      "");
}
 
Example #21
Source File: TestLayoutSpecModelFactoryTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnCreateLayout
public static Component onCreateLayout(
    ComponentContext c,
    @Prop String s,
    @Prop Component child,
    @Prop(resType = ResType.DIMEN_SIZE) float size,
    @Prop(optional = true) int i) {
  return Row.create(c).build();
}
 
Example #22
Source File: FrescoVitoImage2Spec.java    From fresco with MIT License 5 votes vote down vote up
@OnMeasure
static void onMeasure(
    ComponentContext c,
    ComponentLayout layout,
    int widthSpec,
    int heightSpec,
    Size size,
    @Prop(optional = true, resType = ResType.FLOAT) float imageAspectRatio) {
  MeasureUtils.measureWithAspectRatio(widthSpec, heightSpec, imageAspectRatio, size);
}
 
Example #23
Source File: FullGroupSectionSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnCreateChildren
protected static <T> Children onCreateChildren(
    SectionContext c,
    @Prop Component prop3,
    @Prop(resType = ResType.STRING) String prop4,
    @Prop Section prop5,
    @State T state1) {
  return null;
}
 
Example #24
Source File: PropValidationTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void testResTypeDimenMustNotHavePxOrDimensionAnnotations() {
  when(mPropModel1.getResType()).thenReturn(ResType.DIMEN_OFFSET);
  when(mPropModel1.getTypeName()).thenReturn(TypeName.INT);
  when(mPropModel1.getExternalAnnotations())
      .thenReturn(ImmutableList.of(AnnotationSpec.builder(ClassNames.PX).build()));

  when(mPropModel2.getResType()).thenReturn(ResType.DIMEN_SIZE);
  when(mPropModel2.getTypeName()).thenReturn(TypeName.INT);
  when(mPropModel2.getExternalAnnotations())
      .thenReturn(ImmutableList.of(AnnotationSpec.builder(ClassNames.DIMENSION).build()));

  List<SpecModelValidationError> validationErrors =
      PropValidation.validate(
          mSpecModel,
          PropValidation.COMMON_PROP_NAMES,
          PropValidation.VALID_COMMON_PROPS,
          RunMode.normal());
  assertThat(validationErrors).hasSize(2);
  assertThat(validationErrors.get(0).element).isEqualTo(mRepresentedObject1);
  assertThat(validationErrors.get(0).message)
      .isEqualTo(
          "Props with resType DIMEN_OFFSET should not be annotated with "
              + "androidx.annotation.Px or androidx.annotation.Dimension, since "
              + "these annotations will automatically be added to the relevant builder methods "
              + "in the generated code.");
  assertThat(validationErrors.get(1).element).isEqualTo(mRepresentedObject2);
  assertThat(validationErrors.get(1).message)
      .isEqualTo(
          "Props with resType DIMEN_SIZE should not be annotated with "
              + "androidx.annotation.Px or androidx.annotation.Dimension, since "
              + "these annotations will automatically be added to the relevant builder methods "
              + "in the generated code.");
}
 
Example #25
Source File: FrescoImageSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnMeasure
protected static void onMeasure(
    ComponentContext c,
    ComponentLayout layout,
    int widthSpec,
    int heightSpec,
    Size size,
    @Prop(optional = true, resType = ResType.FLOAT) float imageAspectRatio) {
  MeasureUtils.measureWithAspectRatio(widthSpec, heightSpec, imageAspectRatio, size);
}
 
Example #26
Source File: JavadocGeneratorTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenerateJavadocProps() {
  final MethodParamModel requiredMethodParam =
      MockMethodParamModel.newBuilder().name("propName1").type(TypeName.INT).build();
  final MethodParamModel optionalMethodParam =
      MockMethodParamModel.newBuilder().name("propName2").type(TypeName.BOOLEAN).build();
  final SpecModel specModel =
      MockSpecModel.newBuilder()
          .classJavadoc("Test Javadoc")
          .propJavadocs(
              ImmutableList.of(
                  new PropJavadocModel("propName1", "test prop1 javadoc"),
                  new PropJavadocModel("propName2", "test prop2 javadoc")))
          .props(
              ImmutableList.of(
                  new PropModel(requiredMethodParam, false, false, false, false, ResType.INT, ""),
                  new PropModel(
                      optionalMethodParam, true, false, false, false, ResType.BOOL, "")))
          .build();

  final TypeSpecDataHolder dataHolder = JavadocGenerator.generate(specModel);
  assertThat(dataHolder.getJavadocSpecs()).hasSize(4);

  assertThat(getJavadocsString(dataHolder))
      .isEqualTo(
          "Test Javadoc<p>\n"
              + "@prop-required propName1 int test prop1 javadoc\n"
              + "@prop-optional propName2 boolean test prop2 javadoc\n");
}
 
Example #27
Source File: TileComponentSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnCreateLayout
static Component onCreateLayout(
    ComponentContext c, @Prop String text, @Prop(resType = ResType.COLOR) int bgColor) {
  return Column.create(c)
      .alignContent(YogaAlign.CENTER)
      .alignItems(YogaAlign.CENTER)
      .justifyContent(YogaJustify.CENTER)
      .widthDip(50)
      .heightDip(50)
      .backgroundColor(bgColor)
      .child(Text.create(c).textSizeSp(30).text(text))
      .build();
}
 
Example #28
Source File: CircleSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnCreateLayout
static Component onCreateLayout(
    ComponentContext c,
    @Prop(resType = ResType.DIMEN_SIZE) int radius,
    @Prop(resType = ResType.COLOR) int color) {
  final int dim = 2 * radius;
  return Row.create(c)
      .heightPx(dim)
      .widthPx(dim)
      .background(buildRoundedRect(radius, color))
      .build();
}
 
Example #29
Source File: VerticalScrollSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext context,
    final LithoScrollView lithoScrollView,
    @Prop(optional = true) boolean scrollbarEnabled,
    @Prop(optional = true) boolean scrollbarFadingEnabled,
    @Prop(optional = true) boolean nestedScrollingEnabled,
    @Prop(optional = true) boolean incrementalMountEnabled,
    @Prop(optional = true) boolean verticalFadingEdgeEnabled,
    @Prop(optional = true, resType = ResType.DIMEN_SIZE) int fadingEdgeLength,
    @Prop(optional = true) @Nullable OnScrollChangeListener onScrollChangeListener,
    // NOT THE SAME AS LITHO'S interceptTouchHandler COMMON PROP, see class javadocs
    @Prop(optional = true) @Nullable OnInterceptTouchListener onInterceptTouchListener,
    @State ComponentTree childComponentTree,
    @State final ScrollPosition scrollPosition) {
  lithoScrollView.mount(childComponentTree, scrollPosition, incrementalMountEnabled);
  lithoScrollView.setScrollbarFadingEnabled(scrollbarFadingEnabled);
  lithoScrollView.setNestedScrollingEnabled(nestedScrollingEnabled);
  lithoScrollView.setVerticalFadingEdgeEnabled(verticalFadingEdgeEnabled);
  lithoScrollView.setFadingEdgeLength(fadingEdgeLength);

  // On older versions we need to disable the vertical scroll bar as otherwise we run into an NPE
  // that was only fixed in Lollipop - see
  // https://github.com/aosp-mirror/platform_frameworks_base/commit/6c8fef7fb866d244486a962dd82f4a6f26505f16#diff-7c8b4c8147fbbbf69293775bca384f31.
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    lithoScrollView.setVerticalScrollBarEnabled(false);
  } else {
    lithoScrollView.setVerticalScrollBarEnabled(scrollbarEnabled);
  }
  lithoScrollView.setOnScrollChangeListener(onScrollChangeListener);
  lithoScrollView.setOnInterceptTouchListener(onInterceptTouchListener);
}
 
Example #30
Source File: FrescoVitoImage2Spec.java    From fresco with MIT License 5 votes vote down vote up
@ShouldUpdate(onMount = true)
static boolean shouldUpdate(
    @Prop(optional = true) Diff<Uri> uri,
    @Prop(optional = true) Diff<ImageSource> imageSource,
    @Prop(optional = true) Diff<ImageOptions> imageOptions,
    @Prop(optional = true, resType = ResType.FLOAT) Diff<Float> imageAspectRatio,
    @Prop(optional = true) Diff<ImageListener> imageListener) {
  return !ObjectsCompat.equals(uri.getPrevious(), uri.getNext())
      || !ObjectsCompat.equals(imageSource.getPrevious(), imageSource.getNext())
      || !ObjectsCompat.equals(imageOptions.getPrevious(), imageOptions.getNext())
      || !ObjectsCompat.equals(imageAspectRatio.getPrevious(), imageAspectRatio.getNext())
      || !ObjectsCompat.equals(imageListener.getPrevious(), imageListener.getNext());
}