com.facebook.litho.Diff Java Examples

The following examples show how to use com.facebook.litho.Diff. 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: SingleComponentSectionSpecTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoUpdate() {
  Component nextComponent = mock(Component.class);
  Component prevComponent = mock(Component.class);
  when(prevComponent.isEquivalentTo(nextComponent)).thenReturn(true);

  Diff<Component> componentDiff = new Diff<>(prevComponent, nextComponent);
  Diff<Boolean> stickyDiff = new Diff<>(true, true);
  Diff<Integer> spanSizeDiff = new Diff<>(1, 1);
  Diff<Boolean> isFullSpanDiff = new Diff<>(true, true);
  Diff<Map<String, Object>> customAttributesDiff = new Diff<>(null, null);
  Diff<Object> dataDiff = new Diff<>(1, 1);
  SingleComponentSectionSpec.onCreateChangeSet(
      mSectionContext,
      mChangeSet,
      componentDiff,
      stickyDiff,
      spanSizeDiff,
      isFullSpanDiff,
      customAttributesDiff,
      dataDiff);

  assertThat(mChangeSet.getChangeCount()).isEqualTo(0);
}
 
Example #2
Source File: RecyclerBinderUpdateCallback.java    From litho with Apache License 2.0 6 votes vote down vote up
public RecyclerBinderUpdateCallback(
    List<? extends T> prevData,
    List<? extends T> nextData,
    ComponentRenderer<T> componentRenderer,
    OperationExecutor operationExecutor) {
  mPrevData = prevData;
  mOldDataSize = prevData != null ? prevData.size() : 0;
  mNextData = nextData;
  mComponentRenderer = componentRenderer;
  mOperationExecutor = operationExecutor;

  mOperations = new ArrayList<>();
  mPlaceholders = new ArrayList<>();
  mDataHolders = new ArrayList<>();
  for (int i = 0; i < mOldDataSize; i++) {
    mPlaceholders.add(new ComponentContainer(null, false));
    mDataHolders.add(new Diff(mPrevData.get(i), null));
  }
}
 
Example #3
Source File: RecyclerBinderUpdateCallback.java    From litho with Apache License 2.0 6 votes vote down vote up
@Override
public void onInserted(int position, int count) {
  final List<ComponentContainer> placeholders = new ArrayList<>(count);
  final List<Diff> dataHolders = new ArrayList<>(count);
  for (int i = 0; i < count; i++) {
    final int index = position + i;
    final ComponentContainer componentContainer = new ComponentContainer(null, true);
    mPlaceholders.add(index, componentContainer);
    placeholders.add(componentContainer);

    final Diff dataHolder = new Diff(null, null);
    mDataHolders.add(index, dataHolder);
    dataHolders.add(dataHolder);
  }

  mOperations.add(new Operation(Operation.INSERT, position, -1, placeholders, dataHolders));
}
 
Example #4
Source File: SingleComponentSectionSpecTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateIsFullSpan() {
  Component component = mock(Component.class);
  Diff<Component> componentDiff = new Diff<>(component, component);
  Diff<Boolean> stickyDiff = new Diff<>(true, true);
  Diff<Integer> spanSizeDiff = new Diff<>(1, 1);
  Diff<Boolean> isFullSpanDiff = new Diff<>(true, false);
  Diff<Map<String, Object>> customAttributesDiff = new Diff<>(null, null);
  Diff<Object> dataDiff = new Diff<>(null, null);
  SingleComponentSectionSpec.onCreateChangeSet(
      mSectionContext,
      mChangeSet,
      componentDiff,
      stickyDiff,
      spanSizeDiff,
      isFullSpanDiff,
      customAttributesDiff,
      dataDiff);

  Change change = verifyChangeSetAndGetTheChange(mChangeSet);
  assertThat(change.getType()).isEqualTo(Change.UPDATE);
  assertThat(change.getRenderInfo().getComponent()).isEqualTo(component);
  assertThat(change.getRenderInfo().isSticky()).isTrue();
  assertThat(change.getRenderInfo().getSpanSize()).isEqualTo(1);
  assertThat(change.getRenderInfo().isFullSpan()).isFalse();
}
 
Example #5
Source File: SingleComponentSectionSpecTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateSticky() {
  Component component = mock(Component.class);
  Diff<Component> componentDiff = new Diff<>(component, component);
  Diff<Boolean> stickyDiff = new Diff<>(true, false);
  Diff<Integer> spanSizeDiff = new Diff<>(1, 1);
  Diff<Boolean> isFullSpanDiff = new Diff<>(true, true);
  Diff<Map<String, Object>> customAttributesDiff = new Diff<>(null, null);
  Diff<Object> dataDiff = new Diff<>(null, null);
  SingleComponentSectionSpec.onCreateChangeSet(
      mSectionContext,
      mChangeSet,
      componentDiff,
      stickyDiff,
      spanSizeDiff,
      isFullSpanDiff,
      customAttributesDiff,
      dataDiff);

  Change change = verifyChangeSetAndGetTheChange(mChangeSet);
  assertThat(change.getType()).isEqualTo(Change.UPDATE);
  assertThat(change.getRenderInfo().getComponent()).isEqualTo(component);
  assertThat(change.getRenderInfo().isSticky()).isFalse();
  assertThat(change.getRenderInfo().getSpanSize()).isEqualTo(1);
  assertThat(change.getRenderInfo().isFullSpan()).isTrue();
}
 
Example #6
Source File: TestLayout.java    From litho with Apache License 2.0 6 votes vote down vote up
@Override
protected Transition onCreateTransition(ComponentContext c) {
  Transition _result;
  Diff<Integer> _state3Diff =
      new Diff<Integer>(
          mPreviousRenderData == null ? null : mPreviousRenderData.state3,
          mStateContainer.state3);
  _result =
      (Transition)
          TestLayoutSpec.onCreateTransition(
              (ComponentContext) c,
              (Object) prop3,
              (long) mStateContainer.state1,
              (Diff<Integer>) _state3Diff);
  return _result;
}
 
Example #7
Source File: SingleComponentSectionSpecTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateSpanSize() {
  Component component = mock(Component.class);
  Diff<Component> componentDiff = new Diff<>(component, component);
  Diff<Boolean> stickyDiff = new Diff<>(true, true);
  Diff<Integer> spanSizeDiff = new Diff<>(1, 2);
  Diff<Boolean> isFullSpanDiff = new Diff<>(true, true);
  Diff<Map<String, Object>> customAttributesDiff = new Diff<>(null, null);
  Diff<Object> dataDiff = new Diff<>(null, null);
  SingleComponentSectionSpec.onCreateChangeSet(
      mSectionContext,
      mChangeSet,
      componentDiff,
      stickyDiff,
      spanSizeDiff,
      isFullSpanDiff,
      customAttributesDiff,
      dataDiff);

  Change change = verifyChangeSetAndGetTheChange(mChangeSet);
  assertThat(change.getType()).isEqualTo(Change.UPDATE);
  assertThat(change.getRenderInfo().getComponent()).isEqualTo(component);
  assertThat(change.getRenderInfo().isSticky()).isTrue();
  assertThat(change.getRenderInfo().getSpanSize()).isEqualTo(2);
  assertThat(change.getRenderInfo().isFullSpan()).isTrue();
}
 
Example #8
Source File: SingleComponentSectionSpec.java    From litho with Apache License 2.0 6 votes vote down vote up
private static ComponentRenderInfo.Builder addCustomAttributes(
    ComponentRenderInfo.Builder builder,
    @Nullable Map<String, Object> attributes,
    SectionContext c,
    Diff<Component> component) {
  if (ComponentsConfiguration.isRenderInfoDebuggingEnabled()) {
    builder.debugInfo(SONAR_SECTIONS_DEBUG_INFO_TAG, c.getSectionScope());
    builder.debugInfo(SONAR_SINGLE_COMPONENT_SECTION_DATA_PREV, component.getPrevious());
    builder.debugInfo(SONAR_SINGLE_COMPONENT_SECTION_DATA_NEXT, component.getNext());
  }

  if (attributes == null) {
    return builder;
  }

  for (Map.Entry<String, Object> entry : attributes.entrySet()) {
    builder.customAttribute(entry.getKey(), entry.getValue());
  }

  return builder;
}
 
Example #9
Source File: FullDiffSection.java    From litho with Apache License 2.0 6 votes vote down vote up
@Override
protected void generateChangeSet(
    SectionContext c, ChangeSet changeSet, Section _prevAbstractImpl, Section _nextAbstractImpl) {
  FullDiffSection _prevImpl = (FullDiffSection) _prevAbstractImpl;
  FullDiffSection _nextImpl = (FullDiffSection) _nextAbstractImpl;
  Diff<List<T>> data =
      new Diff<List<T>>(
          _prevImpl == null ? null : _prevImpl.data, _nextImpl == null ? null : _nextImpl.data);
  Diff<Component> prop3 =
      new Diff<Component>(
          _prevImpl == null ? null : _prevImpl.prop3, _nextImpl == null ? null : _nextImpl.prop3);
  Diff<Object> state1 =
      new Diff<Object>(
          _prevImpl == null ? null : _prevImpl.mStateContainer.state1,
          _nextImpl == null ? null : _nextImpl.mStateContainer.state1);
  FullDiffSectionSpec.onDiff(
      (SectionContext) c,
      (ChangeSet) changeSet,
      (Diff<List<T>>) data,
      (Diff<Component>) prop3,
      (Diff<Object>) state1);
}
 
Example #10
Source File: SingleComponentSectionSpecTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteComponent() {
  Diff<Component> componentDiff = new Diff<>(mock(Component.class), null);
  Diff<Boolean> stickyDiff = new Diff<>(null, null);
  Diff<Integer> spanSizeDiff = new Diff<>(null, null);
  Diff<Boolean> isFullSpanDiff = new Diff<>(null, null);
  Diff<Map<String, Object>> customAttributesDiff = new Diff<>(null, null);
  Diff<Object> dataDiff = new Diff<>(1, null);
  SingleComponentSectionSpec.onCreateChangeSet(
      mSectionContext,
      mChangeSet,
      componentDiff,
      stickyDiff,
      spanSizeDiff,
      isFullSpanDiff,
      customAttributesDiff,
      dataDiff);

  Change change = verifyChangeSetAndGetTheChange(mChangeSet);
  assertThat(change.getType()).isEqualTo(Change.DELETE);
  assertThat(change.getPrevData()).isEqualTo(ImmutableList.of(1));
  assertThat(change.getNextData()).isNull();
}
 
Example #11
Source File: SingleComponentSectionSpecTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void testNullComponentWithPrevRenderInfo() {
  Diff<Component> componentDiff = new Diff<>(null, null);
  Diff<Boolean> stickyDiff = new Diff<>(true, true);
  Diff<Integer> spanSizeDiff = new Diff<>(2, 1);
  Diff<Boolean> isFullSpanDiff = new Diff<>(false, true);
  Diff<Map<String, Object>> customAttributesDiff =
      new Diff<>(null, new HashMap<String, Object>());
  Diff<Object> dataDiff = new Diff<>(1, null);
  SingleComponentSectionSpec.onCreateChangeSet(
      mSectionContext,
      mChangeSet,
      componentDiff,
      stickyDiff,
      spanSizeDiff,
      isFullSpanDiff,
      customAttributesDiff,
      dataDiff);

  assertThat(mChangeSet.getChangeCount()).isEqualTo(0);
}
 
Example #12
Source File: SingleComponentSectionSpecTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void testNullComponent() {
  Diff<Component> componentDiff = new Diff<>(null, null);
  Diff<Boolean> stickyDiff = new Diff<>(null, null);
  Diff<Integer> spanSizeDiff = new Diff<>(null, null);
  Diff<Boolean> isFullSpanDiff = new Diff<>(null, null);
  Diff<Map<String, Object>> customAttributesDiff = new Diff<>(null, null);
  Diff<Object> dataDiff = new Diff<>(null, null);
  SingleComponentSectionSpec.onCreateChangeSet(
      mSectionContext,
      mChangeSet,
      componentDiff,
      stickyDiff,
      spanSizeDiff,
      isFullSpanDiff,
      customAttributesDiff,
      dataDiff);

  assertThat(mChangeSet.getChangeCount()).isEqualTo(0);
}
 
Example #13
Source File: SingleComponentSectionSpecTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void testNullComponentWithRenderInfo() {
  Diff<Component> componentDiff = new Diff<>(null, null);
  Diff<Boolean> stickyDiff = new Diff<>(null, true);
  Diff<Integer> spanSizeDiff = new Diff<>(null, 1);
  Diff<Boolean> isFullSpanDiff = new Diff<>(null, true);
  Diff<Map<String, Object>> customAttributesDiff =
      new Diff<>(null, new HashMap<String, Object>());
  Diff<Object> dataDiff = new Diff<>(null, 1);
  SingleComponentSectionSpec.onCreateChangeSet(
      mSectionContext,
      mChangeSet,
      componentDiff,
      stickyDiff,
      spanSizeDiff,
      isFullSpanDiff,
      customAttributesDiff,
      dataDiff);

  assertThat(mChangeSet.getChangeCount()).isEqualTo(0);
}
 
Example #14
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());
}
 
Example #15
Source File: ImageSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@ShouldUpdate(onMount = true)
static boolean shouldUpdate(
    @Prop(optional = true) Diff<ScaleType> scaleType,
    @Prop(resType = ResType.DRAWABLE) Diff<Drawable> drawable) {
  return scaleType.getNext() != scaleType.getPrevious()
      || !DrawableUtils.isEquivalentTo(drawable.getNext(), drawable.getPrevious());
}
 
Example #16
Source File: FullGroupSection.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean shouldUpdate(Section _prevAbstractImpl, Section _nextAbstractImpl) {
  FullGroupSection _prevImpl = (FullGroupSection) _prevAbstractImpl;
  FullGroupSection _nextImpl = (FullGroupSection) _nextAbstractImpl;
  boolean _result;
  Diff<Integer> prop1 =
      new Diff<Integer>(
          _prevImpl == null ? null : _prevImpl.prop1, _nextImpl == null ? null : _nextImpl.prop1);
  _result = (boolean) FullGroupSectionSpec.shouldUpdate((Diff<Integer>) prop1);
  return _result;
}
 
Example #17
Source File: FullDiffSectionSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnDiff
protected static <T> void onDiff(
    SectionContext c,
    ChangeSet changeSet,
    @Prop Diff<List<T>> data,
    @Prop Diff<Component> prop3,
    @State Diff<Object> state1) {}
 
Example #18
Source File: SingleComponentSectionSpecTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateComponent() {
  Component nextComponent = mock(Component.class);
  Component prevComponent = mock(Component.class);
  when(prevComponent.isEquivalentTo(nextComponent)).thenReturn(false);

  Diff<Component> componentDiff = new Diff<>(prevComponent, nextComponent);
  Diff<Boolean> stickyDiff = new Diff<>(true, true);
  Diff<Integer> spanSizeDiff = new Diff<>(2, 2);
  Diff<Boolean> isFullSpanDiff = new Diff<>(true, true);
  Diff<Map<String, Object>> customAttributesDiff = new Diff<>(null, null);
  Diff<Object> dataDiff = new Diff<>(1, 2);
  SingleComponentSectionSpec.onCreateChangeSet(
      mSectionContext,
      mChangeSet,
      componentDiff,
      stickyDiff,
      spanSizeDiff,
      isFullSpanDiff,
      customAttributesDiff,
      dataDiff);

  Change change = verifyChangeSetAndGetTheChange(mChangeSet);
  assertThat(change.getType()).isEqualTo(Change.UPDATE);
  assertThat(change.getRenderInfo().getComponent()).isEqualTo(nextComponent);
  assertThat(change.getRenderInfo().isSticky()).isTrue();
  assertThat(change.getRenderInfo().getSpanSize()).isEqualTo(2);
  assertThat(change.getRenderInfo().isFullSpan()).isTrue();
  assertThat(change.getPrevData()).isEqualTo(ImmutableList.of(1));
  assertThat(change.getNextData()).isEqualTo(ImmutableList.of(2));
}
 
Example #19
Source File: FullDiffSection.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean shouldUpdate(Section _prevAbstractImpl, Section _nextAbstractImpl) {
  FullDiffSection _prevImpl = (FullDiffSection) _prevAbstractImpl;
  FullDiffSection _nextImpl = (FullDiffSection) _nextAbstractImpl;
  boolean _result;
  Diff<Integer> prop1 =
      new Diff<Integer>(
          _prevImpl == null ? null : _prevImpl.prop1, _nextImpl == null ? null : _nextImpl.prop1);
  _result = (boolean) FullDiffSectionSpec.shouldUpdate((Diff<Integer>) prop1);
  return _result;
}
 
Example #20
Source File: TestLayoutSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnCreateTransition
static Transition onCreateTransition(
    ComponentContext c,
    @Prop @Nullable Object prop3,
    @State(canUpdateLazily = true) long state1,
    @State Diff<Integer> state3) {
  return Transition.parallel(Transition.create(Transition.TransitionKeyType.GLOBAL, "testKey"));
}
 
Example #21
Source File: TestMount.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean shouldUpdate(Component _prevAbstractImpl, Component _nextAbstractImpl) {
  TestMount _prevImpl = (TestMount) _prevAbstractImpl;
  TestMount _nextImpl = (TestMount) _nextAbstractImpl;
  boolean _result;
  Diff<Integer> prop1 =
      new Diff<Integer>(
          _prevImpl == null ? null : _prevImpl.prop1, _nextImpl == null ? null : _nextImpl.prop1);
  _result = (boolean) TestMountSpec.shouldUpdate((Diff<Integer>) prop1);
  return _result;
}
 
Example #22
Source File: DataDiffSectionSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
private static List<Object> extractNextData(List<Diff> dataHolders) {
  final List<Object> data = new ArrayList<>(dataHolders.size());
  for (Diff diff : dataHolders) {
    data.add(diff.getNext());
  }
  return data;
}
 
Example #23
Source File: DataDiffSectionSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * @return true if duplicates detection should be enabled when performing the Diff. Always on on
 *     debug. Default to false on release.
 */
private static boolean isDetectDuplicatesEnabled(@Nullable Diff<Boolean> alwaysDetectDuplicates) {
  if (alwaysDetectDuplicates == null || alwaysDetectDuplicates.getNext() == null) {
    return ComponentsConfiguration.isDebugModeEnabled;
  }
  return alwaysDetectDuplicates.getNext();
}
 
Example #24
Source File: DataDiffSectionSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
private static List<Object> extractPrevData(List<Diff> dataHolders) {
  final List<Object> data = new ArrayList<>(dataHolders.size());
  for (Diff diff : dataHolders) {
    data.add(diff.getPrevious());
  }
  return data;
}
 
Example #25
Source File: SingleComponentSectionSpecTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void testInsertComponent() {
  Component component = mock(Component.class);
  Diff<Component> componentDiff = new Diff<>(null, component);
  Diff<Boolean> stickyDiff = new Diff<>(null, true);
  Diff<Integer> spanSizeDiff = new Diff<>(null, 2);
  Diff<Boolean> isFullSpanDiff = new Diff<>(null, true);
  Diff<Map<String, Object>> customAttributesDiff = new Diff<>(null, null);
  Diff<Object> dataDiff = new Diff<>(null, 1);
  SingleComponentSectionSpec.onCreateChangeSet(
      mSectionContext,
      mChangeSet,
      componentDiff,
      stickyDiff,
      spanSizeDiff,
      isFullSpanDiff,
      customAttributesDiff,
      dataDiff);

  Change change = verifyChangeSetAndGetTheChange(mChangeSet);
  assertThat(change.getType()).isEqualTo(Change.INSERT);
  assertThat(change.getRenderInfo().getComponent()).isEqualTo(component);
  assertThat(change.getRenderInfo().isSticky()).isTrue();
  assertThat(change.getRenderInfo().getSpanSize()).isEqualTo(2);
  assertThat(change.getRenderInfo().isFullSpan()).isTrue();
  assertThat(change.getPrevData()).isNull();
  assertThat(change.getNextData()).isEqualTo(ImmutableList.of(1));
}
 
Example #26
Source File: BaseImageSpecTest.java    From fresco with MIT License 5 votes vote down vote up
public boolean invokeShouldUpdate(
    Diff<Uri> uri,
    Diff<MultiUri> multiUriDiff,
    Diff<ImageOptions> imageOptions,
    Diff<FrescoContext> frescoContext,
    Diff<Float> imageAspectRatio)
    throws InvocationTargetException, IllegalAccessException {
  return (boolean)
      mShouldUpdateMethod.invoke(
          null, uri, multiUriDiff, imageOptions, frescoContext, imageAspectRatio);
}
 
Example #27
Source File: BaseImageSpecTest.java    From fresco with MIT License 5 votes vote down vote up
@Test
public void test_shouldUpdate_whenUriChanged_thenUpdate()
    throws InvocationTargetException, IllegalAccessException {
  Uri uri1 = mock(Uri.class);
  Uri uri2 = mock(Uri.class);

  Diff<Uri> diff = new Diff<>(null, uri1);

  boolean shouldUpdate =
      invokeShouldUpdate(
          diff,
          NULL_MULTI_URI_DIFF,
          NULL_IMAGE_OPTIONS_DIFF,
          NULL_FRESCO_CONTEXT_DIFF,
          NULL_ASPECT_RATIO_DIFF);

  assertThat(shouldUpdate).isTrue();

  diff = new Diff<>(uri1, uri2);

  shouldUpdate =
      invokeShouldUpdate(
          diff,
          NULL_MULTI_URI_DIFF,
          NULL_IMAGE_OPTIONS_DIFF,
          NULL_FRESCO_CONTEXT_DIFF,
          NULL_ASPECT_RATIO_DIFF);

  assertThat(shouldUpdate).isTrue();
}
 
Example #28
Source File: BaseImageSpecTest.java    From fresco with MIT License 5 votes vote down vote up
@Test
public void test_shouldUpdate_whenImageOptionsChanged_thenUpdate()
    throws InvocationTargetException, IllegalAccessException {
  ImageOptions options1 = ImageOptions.create().build();
  ImageOptions options2 = ImageOptions.create().placeholderRes(123).build();

  Diff<ImageOptions> diff = new Diff<>(null, options1);

  boolean shouldUpdate =
      invokeShouldUpdate(
          NULL_URI_DIFF,
          NULL_MULTI_URI_DIFF,
          diff,
          NULL_FRESCO_CONTEXT_DIFF,
          NULL_ASPECT_RATIO_DIFF);

  assertThat(shouldUpdate).isTrue();

  diff = new Diff<>(ImageOptions.create().build(), options2);

  shouldUpdate =
      invokeShouldUpdate(
          NULL_URI_DIFF,
          NULL_MULTI_URI_DIFF,
          diff,
          NULL_FRESCO_CONTEXT_DIFF,
          NULL_ASPECT_RATIO_DIFF);

  assertThat(shouldUpdate).isTrue();
}
 
Example #29
Source File: StoryFooterComponentSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnCreateTransition
static Transition onCreateTransition(ComponentContext c, @State Diff<Boolean> commentText) {
  if (commentText.getPrevious() == null) {
    return null;
  }

  return Transition.parallel(
      Transition.create("comment_editText")
          .animate(AnimatedProperties.ALPHA)
          .appearFrom(0)
          .disappearTo(0)
          .animate(AnimatedProperties.X)
          .appearFrom(DimensionValue.widthPercentageOffset(-50))
          .disappearTo(DimensionValue.widthPercentageOffset(-50)),
      Transition.create("cont_comment")
          .animate(AnimatedProperties.ALPHA)
          .appearFrom(0)
          .disappearTo(0),
      Transition.create("icon_like", "icon_share").animate(AnimatedProperties.X),
      Transition.create("text_like", "text_share")
          .animate(AnimatedProperties.ALPHA)
          .appearFrom(0)
          .disappearTo(0)
          .animate(AnimatedProperties.X)
          .appearFrom(DimensionValue.widthPercentageOffset(50))
          .disappearTo(DimensionValue.widthPercentageOffset(50)));
}
 
Example #30
Source File: VerticalScrollSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@ShouldUpdate(onMount = true)
static boolean shouldUpdate(
    @Prop Diff<Component> childComponent,
    @Prop(optional = true) Diff<Boolean> scrollbarEnabled,
    @Prop(optional = true) Diff<Boolean> scrollbarFadingEnabled,
    @Prop(optional = true) Diff<Boolean> fillViewport,
    @Prop(optional = true) Diff<Boolean> nestedScrollingEnabled,
    @Prop(optional = true) Diff<Boolean> incrementalMountEnabled) {
  return !childComponent.getPrevious().isEquivalentTo(childComponent.getNext())
      || !scrollbarEnabled.getPrevious().equals(scrollbarEnabled.getNext())
      || !scrollbarFadingEnabled.getPrevious().equals(scrollbarFadingEnabled.getNext())
      || !fillViewport.getPrevious().equals(fillViewport.getNext())
      || !nestedScrollingEnabled.getPrevious().equals(nestedScrollingEnabled.getNext())
      || !incrementalMountEnabled.getPrevious().equals(incrementalMountEnabled.getNext());
}