Java Code Examples for com.facebook.litho.Diff#getNext()
The following examples show how to use
com.facebook.litho.Diff#getNext() .
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: ImageSpec.java From litho with Apache License 2.0 | 5 votes |
@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 2
Source File: DataDiffSectionSpec.java From litho with Apache License 2.0 | 5 votes |
/** * @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 3
Source File: RecyclerSpec.java From litho with Apache License 2.0 | 4 votes |
@ShouldUpdate(onMount = true) protected static boolean shouldUpdate( @Prop Diff<Binder<RecyclerView>> binder, @Prop(optional = true) Diff<Boolean> hasFixedSize, @Prop(optional = true) Diff<Boolean> clipToPadding, @Prop(optional = true) Diff<Integer> leftPadding, @Prop(optional = true) Diff<Integer> rightPadding, @Prop(optional = true) Diff<Integer> topPadding, @Prop(optional = true) Diff<Integer> bottomPadding, @Prop(optional = true, resType = ResType.COLOR) Diff<Integer> refreshProgressBarBackgroundColor, @Prop(optional = true, resType = ResType.COLOR) Diff<Integer> refreshProgressBarColor, @Prop(optional = true) Diff<Boolean> clipChildren, @Prop(optional = true) Diff<Integer> scrollBarStyle, @Prop(optional = true) Diff<RecyclerView.ItemDecoration> itemDecoration, @Prop(optional = true) Diff<Boolean> horizontalFadingEdgeEnabled, @Prop(optional = true) Diff<Boolean> verticalFadingEdgeEnabled, @Prop(optional = true, resType = ResType.DIMEN_SIZE) Diff<Integer> fadingEdgeLength, @Prop(optional = true) Diff<ItemAnimator> itemAnimator, @State Diff<Integer> measureVersion) { if (measureVersion.getPrevious().intValue() != measureVersion.getNext().intValue()) { return true; } if (binder.getPrevious() != binder.getNext()) { return true; } if (!hasFixedSize.getPrevious().equals(hasFixedSize.getNext())) { return true; } if (!clipToPadding.getPrevious().equals(clipToPadding.getNext())) { return true; } if (!leftPadding.getPrevious().equals(leftPadding.getNext())) { return true; } if (!rightPadding.getPrevious().equals(rightPadding.getNext())) { return true; } if (!topPadding.getPrevious().equals(topPadding.getNext())) { return true; } if (!bottomPadding.getPrevious().equals(bottomPadding.getNext())) { return true; } if (!clipChildren.getPrevious().equals(clipChildren.getNext())) { return true; } if (!scrollBarStyle.getPrevious().equals(scrollBarStyle.getNext())) { return true; } if (!horizontalFadingEdgeEnabled.getPrevious().equals(horizontalFadingEdgeEnabled.getNext())) { return true; } if (!verticalFadingEdgeEnabled.getPrevious().equals(verticalFadingEdgeEnabled.getNext())) { return true; } if (!fadingEdgeLength.getPrevious().equals(fadingEdgeLength.getNext())) { return true; } Integer previousRefreshBgColor = refreshProgressBarBackgroundColor.getPrevious(); Integer nextRefreshBgColor = refreshProgressBarBackgroundColor.getNext(); if (previousRefreshBgColor == null ? nextRefreshBgColor != null : !previousRefreshBgColor.equals(nextRefreshBgColor)) { return true; } if (!refreshProgressBarColor.getPrevious().equals(refreshProgressBarColor.getNext())) { return true; } final ItemAnimator previousItemAnimator = itemAnimator.getPrevious(); final ItemAnimator nextItemAnimator = itemAnimator.getNext(); if (previousItemAnimator == null ? nextItemAnimator != null : !previousItemAnimator.getClass().equals(nextItemAnimator.getClass())) { return true; } final RecyclerView.ItemDecoration previous = itemDecoration.getPrevious(); final RecyclerView.ItemDecoration next = itemDecoration.getNext(); final boolean itemDecorationIsEqual = (previous == null) ? (next == null) : previous.equals(next); return !itemDecorationIsEqual; }
Example 4
Source File: DataDiffSectionSpec.java From litho with Apache License 2.0 | 4 votes |
@OnDiff public static <T> void onCreateChangeSet( SectionContext c, ChangeSet changeSet, @Prop Diff<List<? extends T>> data, @Prop(optional = true) @Nullable Diff<Boolean> detectMoves, @Prop(optional = true) @Nullable Diff<Boolean> alwaysDetectDuplicates) { final List<? extends T> previousData = data.getPrevious(); final List<? extends T> nextData = data.getNext(); final ComponentRenderer componentRenderer = new ComponentRenderer(DataDiffSection.getRenderEventHandler(c), c); final DiffSectionOperationExecutor operationExecutor = new DiffSectionOperationExecutor(changeSet); final RecyclerBinderUpdateCallback<T> updatesCallback; final boolean isTracing = ComponentsSystrace.isTracing(); final Callback<T> callback = new Callback<>(c, data.getPrevious(), data.getNext()); final ComponentsLogger logger = c.getLogger(); final PerfEvent logEvent = logger == null ? null : LogTreePopulator.populatePerfEventFromLogger( c, logger, logger.newPerformanceEvent(c, EVENT_SECTIONS_DATA_DIFF_CALCULATE_DIFF)); if (nextData != null && isDetectDuplicatesEnabled(alwaysDetectDuplicates)) { detectDuplicates(c, nextData, callback); } if (isTracing) { ComponentsSystrace.beginSection("DiffUtil.calculateDiff"); } final DiffUtil.DiffResult result = DiffUtil.calculateDiff(callback, isDetectMovesEnabled(detectMoves)); if (isTracing) { ComponentsSystrace.endSection(); } if (logEvent != null) { logger.logPerfEvent(logEvent); } updatesCallback = new RecyclerBinderUpdateCallback<>( previousData, nextData, componentRenderer, operationExecutor); result.dispatchUpdatesTo(updatesCallback); updatesCallback.applyChangeset(c); }
Example 5
Source File: SingleComponentSectionSpec.java From litho with Apache License 2.0 | 4 votes |
@OnDiff public static void onCreateChangeSet( SectionContext context, ChangeSet changeSet, @Prop Diff<Component> component, @Prop(optional = true) Diff<Boolean> sticky, @Prop(optional = true) Diff<Integer> spanSize, @Prop(optional = true) Diff<Boolean> isFullSpan, @Prop(optional = true) Diff<Map<String, Object>> customAttributes, @Prop(optional = true) Diff<Object> data) { final Object prevData = data.getPrevious(); final Object nextData = data.getNext(); final Component prevComponent = component.getPrevious(); final Component nextComponent = component.getNext(); if (prevComponent == null && nextComponent == null) { return; } if (prevComponent != null && nextComponent == null) { changeSet.delete(0, prevData); return; } boolean isNextSticky = false; if (sticky != null && sticky.getNext() != null) { isNextSticky = sticky.getNext(); } int nextSpanSize = 1; if (spanSize != null && spanSize.getNext() != null) { nextSpanSize = spanSize.getNext(); } boolean isNextFullSpan = false; if (isFullSpan != null && isFullSpan.getNext() != null) { isNextFullSpan = isFullSpan.getNext(); } if (prevComponent == null && nextComponent != null) { changeSet.insert( 0, addCustomAttributes( ComponentRenderInfo.create(), customAttributes.getNext(), context, component) .component(nextComponent) .isSticky(isNextSticky) .spanSize(nextSpanSize) .isFullSpan(isNextFullSpan) .build(), context.getTreePropsCopy(), nextData); return; } // Both previous and next components are non-null -- check if an update is required. boolean isPrevSticky = false; if (sticky != null && sticky.getPrevious() != null) { isPrevSticky = sticky.getPrevious(); } int prevSpanSize = 1; if (spanSize != null && spanSize.getPrevious() != null) { prevSpanSize = spanSize.getPrevious(); } boolean isPrevFullSpan = false; if (isFullSpan != null && isFullSpan.getPrevious() != null) { isPrevFullSpan = isFullSpan.getPrevious(); } final boolean customAttributesEqual = MapDiffUtils.areMapsEqual(customAttributes.getPrevious(), customAttributes.getNext()); if (isPrevSticky != isNextSticky || prevSpanSize != nextSpanSize || isPrevFullSpan != isNextFullSpan || !customAttributesEqual || !prevComponent.isEquivalentTo(nextComponent)) { changeSet.update( 0, addCustomAttributes( ComponentRenderInfo.create(), customAttributes.getNext(), context, component) .component(nextComponent) .isSticky(isNextSticky) .spanSize(nextSpanSize) .isFullSpan(isNextFullSpan) .build(), context.getTreePropsCopy(), prevData, nextData); } }
Example 6
Source File: PicassoImageSpec.java From litho-picasso with MIT License | 4 votes |
@ShouldUpdate(onMount = true) static boolean shouldUpdate( @Prop(optional = true) Diff<String> imageUrl, @Prop(optional = true) Diff<File> file, @Prop(optional = true) Diff<Uri> uri, @Prop(optional = true) Diff<Integer> resourceId, @Prop(optional = true, resType = DRAWABLE) Diff<Drawable> errorDrawable, @Prop(optional = true, resType = DRAWABLE) Diff<Drawable> placeholderImage, @Prop(optional = true) Diff<Boolean> noPlaceholder, @Prop(optional = true) Diff<Bitmap.Config> config, @Prop(optional = true) Diff<Boolean> fit, @Prop(optional = true) Diff<Boolean> centerCrop, @Prop(optional = true) Diff<Boolean> centerInside, @Prop(optional = true) Diff<Boolean> noFade, @Prop(optional = true) Diff<Boolean> onlyScaleDown, @Prop(optional = true) Diff<Picasso.Priority> priority, @Prop(optional = true) Diff<Integer> resizeTargetWidth, @Prop(optional = true) Diff<Integer> resizeTargetHeight, @Prop(optional = true, resType = INT) Diff<Integer> resizeTargetWidthResId, @Prop(optional = true, resType = INT) Diff<Integer> resizeTargetHeightResId, @Prop(optional = true) Diff<Float> rotateDegrees, @Prop(optional = true) Diff<Integer> pivotX, @Prop(optional = true) Diff<Integer> pivotY, @Prop(optional = true) Diff<String> stableKey, @Prop(optional = true) Diff<Object> tag, @Prop(optional = true) Diff<Transformation> transformation, @Prop(optional = true) Diff<List<? extends Transformation>> transformations ) { return imageUrl.getNext() != imageUrl.getPrevious() || file.getNext() != file.getPrevious() || uri.getNext() != uri.getPrevious() || resourceId.getNext() != resourceId.getPrevious() || errorDrawable.getNext() != errorDrawable.getPrevious() || placeholderImage.getNext() != placeholderImage.getPrevious() || noPlaceholder.getNext() != noPlaceholder.getPrevious() || config.getNext() != config.getPrevious() || fit.getNext() != fit.getPrevious() || centerCrop.getNext() != centerCrop.getPrevious() || centerInside.getNext() != centerInside.getPrevious() || noFade.getNext() != noFade.getPrevious() || onlyScaleDown.getNext() != onlyScaleDown.getPrevious() || priority.getNext() != priority.getPrevious() || resizeTargetWidth.getNext() != resizeTargetWidth.getPrevious() || resizeTargetHeight.getNext() != resizeTargetHeight.getPrevious() || resizeTargetWidthResId.getNext() != resizeTargetWidthResId.getPrevious() || resizeTargetHeightResId.getNext() != resizeTargetHeightResId.getPrevious() || rotateDegrees.getNext() != rotateDegrees.getPrevious() || pivotX.getNext() != pivotX.getPrevious() || pivotY.getNext() != pivotY.getPrevious() || stableKey.getNext() != stableKey.getPrevious() || tag.getNext() != tag.getPrevious() || transformation.getNext() != transformation.getPrevious() || transformations.getNext() != transformations.getPrevious(); }
Example 7
Source File: DataDiffSectionSpec.java From litho with Apache License 2.0 | 2 votes |
/** * @return true if detect moves should be enabled when performing the Diff. Detect moves is * enabled by default */ private static boolean isDetectMovesEnabled(@Nullable Diff<Boolean> detectMoves) { return detectMoves == null || detectMoves.getNext() == null || detectMoves.getNext(); }