Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resizing whole recycler with no views removing and inflating. #166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,10 @@ public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State
//won't be cleared until onLayoutCompleted
if (!isFirstOrEmptyLayout) {
isFirstOrEmptyLayout = recyclerViewProxy.getChildCount() == 0;
if (isFirstOrEmptyLayout) {
initChildDimensions(recycler);
}
}

initChildDimensions(recycler);

recyclerViewProxy.detachAndScrapAttachedViews(recycler);

fill(recycler);
Expand Down Expand Up @@ -145,7 +144,7 @@ public void onLayoutCompleted(RecyclerView.State state) {
}

protected void initChildDimensions(RecyclerView.Recycler recycler) {
View viewToMeasure = recyclerViewProxy.getMeasuredChildForAdapterPosition(0, recycler);
View viewToMeasure = recyclerViewProxy.getMeasuredChildForAdapterPosition(currentPosition, recycler);

int childViewWidth = recyclerViewProxy.getMeasuredWidthWithMargin(viewToMeasure);
int childViewHeight = recyclerViewProxy.getMeasuredHeightWithMargin(viewToMeasure);
Expand All @@ -158,8 +157,6 @@ protected void initChildDimensions(RecyclerView.Recycler recycler) {
childViewHeight);

extraLayoutSpace = scrollToChangeCurrent * offscreenItems;

recyclerViewProxy.detachAndScrapView(viewToMeasure, recycler);
}

protected void updateRecyclerDimensions(RecyclerView.State state) {
Expand All @@ -169,7 +166,6 @@ protected void updateRecyclerDimensions(RecyclerView.State state) {
if (dimensionsChanged) {
viewWidth = recyclerViewProxy.getWidth();
viewHeight = recyclerViewProxy.getHeight();
recyclerViewProxy.removeAllViews();
}
recyclerCenter.set(
recyclerViewProxy.getWidth() / 2,
Expand Down Expand Up @@ -224,7 +220,7 @@ protected void layoutView(RecyclerView.Recycler recycler, int position, Point vi
if (position < 0) return;
View v = detachedCache.get(position);
if (v == null) {
v = recyclerViewProxy.getMeasuredChildForAdapterPosition(position, recycler);
v = recyclerViewProxy.addMeasuredChildForAdapterPosition(position, recycler);
recyclerViewProxy.layoutDecoratedWithMargins(v,
viewCenter.x - childHalfWidth, viewCenter.y - childHalfHeight,
viewCenter.x + childHalfWidth, viewCenter.y + childHalfHeight);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.yarolegovich.discretescrollview;

import android.support.annotation.NonNull;
import android.support.v7.widget.LinearSmoothScroller;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -49,13 +48,22 @@ public int getItemCount() {
return layoutManager.getItemCount();
}

public View getMeasuredChildForAdapterPosition(int position, RecyclerView.Recycler recycler) {
public View addMeasuredChildForAdapterPosition(int position, RecyclerView.Recycler recycler) {
View view = recycler.getViewForPosition(position);
layoutManager.addView(view);
layoutManager.measureChildWithMargins(view, 0, 0);
return view;
}

public View getMeasuredChildForAdapterPosition(int position, RecyclerView.Recycler recycler) {
View view = layoutManager.findViewByPosition(position);
if (view == null) {
view = recycler.getViewForPosition(position);
}
layoutManager.measureChildWithMargins(view, 0, 0);
return view;
}

public void layoutDecoratedWithMargins(View v, int left, int top, int right, int bottom) {
layoutManager.layoutDecoratedWithMargins(v, left, top, right, bottom);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ public int getItemCount() {
return adapterItemCount;
}

@Override
public View addMeasuredChildForAdapterPosition(int position, RecyclerView.Recycler recycler) {
if (position < adapterItemCount) {
return new StubChildInfo(0, position).view;
}
throw new IndexOutOfBoundsException();
}

@Override
public View getMeasuredChildForAdapterPosition(int position, RecyclerView.Recycler recycler) {
if (position < adapterItemCount) {
Expand Down