com.facebook.litho.annotations.OnUnmount Java Examples

The following examples show how to use com.facebook.litho.annotations.OnUnmount. 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: HorizontalScrollSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnUnmount
static void onUnmount(
    ComponentContext context,
    HorizontalScrollLithoView mountedView,
    @Prop(optional = true) @Nullable HorizontalScrollEventsController eventsController) {

  mountedView.unmount();

  if (eventsController != null) {
    eventsController.setScrollableView(null);
  }
}
 
Example #2
Source File: FrescoVitoImage2Spec.java    From fresco with MIT License 5 votes vote down vote up
@OnUnmount
static void onUnmount(
    ComponentContext c,
    FrescoDrawable2 frescoDrawable,
    @FromPrepare DataSource<Void> prefetchDataSource) {
  FrescoVitoProvider.getController().release(frescoDrawable);
  if (prefetchDataSource != null) {
    prefetchDataSource.close();
  }
}
 
Example #3
Source File: MountSpecWithShouldUpdateSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnUnmount
static void onUnmount(
    ComponentContext c,
    View v,
    @Prop List<LifecycleStep> operationsOutput,
    @Prop Object objectForShouldUpdate) {
  operationsOutput.add(LifecycleStep.ON_UNMOUNT);
}
 
Example #4
Source File: EditTextSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnUnmount
static void onUnmount(
    ComponentContext c,
    EditTextWithEventHandlers editText,
    @State AtomicReference<EditTextWithEventHandlers> mountedView) {
  mountedView.set(null);
}
 
Example #5
Source File: TextInputSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnUnmount
static void onUnmount(
    ComponentContext c,
    EditTextWithEventHandlers editText,
    @State AtomicReference<EditTextWithEventHandlers> mountedView) {
  editText.setTextState(null);
  mountedView.set(null);
}
 
Example #6
Source File: TextSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnUnmount
static void onUnmount(
    ComponentContext c,
    TextDrawable textDrawable,
    @Prop(resType = ResType.STRING) CharSequence text) {
  textDrawable.unmount();

  if (text instanceof MountableCharSequence) {
    ((MountableCharSequence) text).onUnmount(textDrawable);
  }
}
 
Example #7
Source File: RecyclerSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnUnmount
static void onUnmount(
    ComponentContext context,
    SectionsRecyclerView sectionsRecycler,
    @Prop Binder<RecyclerView> binder,
    @Prop(optional = true) RecyclerView.ItemDecoration itemDecoration,
    @Prop(optional = true, resType = ResType.COLOR) @Nullable
        Integer refreshProgressBarBackgroundColor,
    @Prop(optional = true) SnapHelper snapHelper) {
  final RecyclerView recyclerView = sectionsRecycler.getRecyclerView();

  if (recyclerView == null) {
    throw new IllegalStateException(
        "RecyclerView not found, it should not be removed from SwipeRefreshLayout "
            + "before unmounting");
  }

  recyclerView.setId(RecyclerSpec.recyclerViewId);

  if (refreshProgressBarBackgroundColor != null) {
    sectionsRecycler.setProgressBackgroundColorSchemeColor(
        DEFAULT_REFRESH_SPINNER_BACKGROUND_COLOR);
  }

  if (itemDecoration != null) {
    recyclerView.removeItemDecoration(itemDecoration);
  }

  binder.unmount(recyclerView);

  if (snapHelper != null) {
    snapHelper.attachToRecyclerView(null);
  }

  sectionsRecycler.resetItemAnimator();
}
 
Example #8
Source File: ImageSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnUnmount
static void onUnmount(
    ComponentContext c,
    MatrixDrawable convertDrawable,
    @Prop(resType = ResType.DRAWABLE) Drawable drawable) {
  convertDrawable.unmount();
}
 
Example #9
Source File: ProgressSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnUnmount
static void onUnmount(
    ComponentContext c,
    ProgressBar progressBar,
    @Prop(optional = true, resType = ResType.COLOR) int color,
    @FromPrepare Drawable resolvedIndeterminateDrawable) {

  // restore the color first, since it acts on the indeterminateDrawable
  if (color != Color.TRANSPARENT && progressBar.getIndeterminateDrawable() != null) {
    progressBar.getIndeterminateDrawable().mutate().clearColorFilter();
  }

  progressBar.setIndeterminateDrawable(null);
}
 
Example #10
Source File: MountSpecLifecycleTesterSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@UiThread
@OnUnmount
static void onUnmount(
    ComponentContext context, View view, @Prop LifecycleTracker lifecycleTracker) {
  lifecycleTracker.addStep(LifecycleStep.ON_UNMOUNT);
}
 
Example #11
Source File: FrescoImageSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnUnmount
protected static void onUnmount(
    ComponentContext c, DraweeDrawable<GenericDraweeHierarchy> mountedDrawable) {
  mountedDrawable.unmount();
}
 
Example #12
Source File: PicassoImageSpec.java    From litho-picasso with MIT License 4 votes vote down vote up
@OnUnmount
static void onUnmount(ComponentContext c, ImageView imageView) {
  Picasso.with(imageView.getContext()).cancelRequest(imageView);
}
 
Example #13
Source File: GlideImageSpec.java    From litho-glide with MIT License 4 votes vote down vote up
@OnUnmount
static void onUnmount(ComponentContext c, ImageView imageView) {
  Glide.clear(imageView);
}
 
Example #14
Source File: DelegateMethodValidation.java    From litho with Apache License 2.0 4 votes vote down vote up
static List<SpecModelValidationError> validateMountSpecModel(MountSpecModel specModel) {
  List<SpecModelValidationError> validationErrors = new ArrayList<>();
  validationErrors.addAll(
      validateMethods(
          specModel,
          DelegateMethodDescriptions.MOUNT_SPEC_DELEGATE_METHODS_MAP,
          DelegateMethodDescriptions.INTER_STAGE_INPUTS_MAP));

  final SpecMethodModel<DelegateMethod, Void> onCreateMountContentModel =
      SpecModelUtils.getMethodModelWithAnnotation(specModel, OnCreateMountContent.class);
  if (onCreateMountContentModel == null) {
    validationErrors.add(
        new SpecModelValidationError(
            specModel.getRepresentedObject(),
            "All MountSpecs need to have a method annotated with @OnCreateMountContent."));
  } else {
    final TypeName mountType = onCreateMountContentModel.returnType;
    ImmutableList<Class<? extends Annotation>> methodsAcceptingMountTypeAsSecondParam =
        ImmutableList.of(OnMount.class, OnBind.class, OnUnbind.class, OnUnmount.class);
    for (Class<? extends Annotation> annotation : methodsAcceptingMountTypeAsSecondParam) {
      final SpecMethodModel<DelegateMethod, Void> method =
          SpecModelUtils.getMethodModelWithAnnotation(specModel, annotation);
      if (method != null
          && (method.methodParams.size() < 2
              || !method.methodParams.get(1).getTypeName().equals(mountType))) {
        validationErrors.add(
            new SpecModelValidationError(
                method.representedObject,
                "The second parameter of a method annotated with "
                    + annotation
                    + " must "
                    + "have the same type as the return type of the method annotated with "
                    + "@OnCreateMountContent (i.e. "
                    + mountType
                    + ")."));
      }
    }
  }

  return validationErrors;
}
 
Example #15
Source File: TestMountSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnUnmount
static void onUnmount(ComponentContext c, Drawable v, @Prop long prop8) {}
 
Example #16
Source File: MountSpecModelFactoryTest.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnUnmount
static void onUnmount() {}
 
Example #17
Source File: DelegateMethodValidationTest.java    From litho with Apache License 2.0 4 votes vote down vote up
@Test
public void testInterStageInputParamAnnotationNotValid() {
  final InterStageInputParamModel interStageInputParamModel =
      mock(InterStageInputParamModel.class);
  when(interStageInputParamModel.getAnnotations())
      .thenReturn(ImmutableList.of((Annotation) () -> FromBind.class));
  when(interStageInputParamModel.getRepresentedObject()).thenReturn(mMethodParamObject3);
  when(mMountSpecModel.getDelegateMethods())
      .thenReturn(
          ImmutableList.of(
              mOnCreateMountContent,
              SpecMethodModel.<DelegateMethod, Void>builder()
                  .annotations(ImmutableList.of((Annotation) () -> OnUnmount.class))
                  .modifiers(ImmutableList.of(Modifier.STATIC))
                  .name("onUnmount")
                  .returnTypeSpec(new TypeSpec(TypeName.VOID))
                  .typeVariables(ImmutableList.of())
                  .methodParams(
                      ImmutableList.of(
                          MockMethodParamModel.newBuilder()
                              .type(ClassNames.COMPONENT_CONTEXT)
                              .representedObject(mMethodParamObject1)
                              .build(),
                          MockMethodParamModel.newBuilder()
                              .type(ClassName.bestGuess("java.lang.MadeUpClass"))
                              .representedObject(mMethodParamObject2)
                              .build(),
                          interStageInputParamModel))
                  .representedObject(mDelegateMethodObject1)
                  .typeModel(null)
                  .build()));

  final List<SpecModelValidationError> validationErrors =
      DelegateMethodValidation.validateMountSpecModel(mMountSpecModel);
  assertThat(validationErrors).hasSize(1);
  assertThat(validationErrors.get(0).element).isEqualTo(mMethodParamObject3);
  assertThat(validationErrors.get(0).message)
      .isEqualTo(
          "Inter-stage input annotation is not valid for methods annotated with interface "
              + "com.facebook.litho.annotations.OnUnmount; please use one of the "
              + "following: [interface com.facebook.litho.annotations.FromPrepare, "
              + "interface com.facebook.litho.annotations.FromMeasure, "
              + "interface com.facebook.litho.annotations.FromMeasureBaseline, "
              + "interface com.facebook.litho.annotations.FromBoundsDefined]");
}
 
Example #18
Source File: TestCrasherOnMountSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnUnmount
static void onUnmount(ComponentContext c, LithoView mountedView) {
  mountedView.setComponentTree(null);
}
 
Example #19
Source File: PreallocatedMountSpecLifecycleTesterSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@UiThread
@OnUnmount
static void onUnmount(
    ComponentContext context, View view, @Prop List<LifecycleStep.StepInfo> steps) {
  steps.add(new StepInfo(LifecycleStep.ON_UNMOUNT));
}
 
Example #20
Source File: SizeSpecMountWrapperComponentSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@UiThread
@OnUnmount
static void onUnmount(ComponentContext c, FrameLayout wrapperView) {
  ((LithoView) wrapperView.getChildAt(0)).setComponentTree(null);
}
 
Example #21
Source File: VerticalScrollSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnUnmount
static void onUnmount(ComponentContext context, LithoScrollView lithoScrollView) {
  lithoScrollView.setOnScrollChangeListener((OnScrollChangeListener) null);
  lithoScrollView.setOnInterceptTouchListener(null);
  lithoScrollView.unmount();
}
 
Example #22
Source File: CardClipSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnUnmount
static void onUnmount(ComponentContext c, CardClipDrawable cardClipDrawable) {
  cardClipDrawable.setCornerRadius(0);
  cardClipDrawable.setClippingColor(Color.WHITE);
  cardClipDrawable.setDisableClip(NONE);
}
 
Example #23
Source File: TransparencyEnabledCardClipSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnUnmount
static void onUnmount(ComponentContext c, TransparencyEnabledCardClipDrawable cardClipDrawable) {
  cardClipDrawable.setCornerRadius(0);
  cardClipDrawable.setBackgroundColor(Color.WHITE);
}