Skip to content

Commit

Permalink
* reverted clip-to-padding
Browse files Browse the repository at this point in the history
  • Loading branch information
Beloo authored and Beloo committed Dec 23, 2016
1 parent 9b271a8 commit b09191e
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .idea/runConfigurations/functional_tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -793,11 +793,11 @@ private void fill(RecyclerView.Recycler recycler, ILayouter backwardLayouter, IL
/* there is no sense to perform backward layouting when anchor is null.
null anchor means that layout will be performed from absolutely top corner with start at anchor position
*/
if (anchorView.getAnchorViewRect() != null) {
// if (anchorView.getAnchorViewRect() != null) {
//up layouter should be invoked earlier than down layouter, because views with lower positions positioned above anchorView
//start from anchor position
fillWithLayouter(recycler, backwardLayouter, startingPos - 1);
}
fillWithLayouter(recycler, backwardLayouter, startingPos - 1);
// }

logger.onStartLayouter(startingPos);

Expand Down
@@ -1,7 +1,6 @@
package com.beloo.widget.chipslayoutmanager.layouter;

import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;

import com.beloo.widget.chipslayoutmanager.ChipsLayoutManager;
Expand All @@ -21,14 +20,13 @@ class LTRRowsCreator implements ILayouterCreator {
}

@Override
public Rect createOffsetRectForBackwardLayouter(@NonNull Rect anchorRect) {
//for backward layouting anchor can't be null, because it doesn't have sense
public Rect createOffsetRectForBackwardLayouter(Rect anchorRect) {
return new Rect(
0,
anchorRect.top,
anchorRect == null ? layoutManager.getPaddingTop() : anchorRect.top,
//we shouldn't include anchor view here, so anchorLeft is a rightOffset
anchorRect.left,
anchorRect.bottom);
anchorRect == null ? layoutManager.getPaddingRight() : anchorRect.left,
anchorRect == null ? layoutManager.getPaddingBottom() : anchorRect.bottom);
}

@Override
Expand Down
Expand Up @@ -81,7 +81,6 @@ private AbstractLayouter.Builder fillBasicBuilder(AbstractLayouter.Builder build

@Nullable
public final ILayouter getBackwardLayouter(Rect anchorRect) {
if (anchorRect == null) return null;
return fillBasicBuilder(createBackwardBuilder())
.offsetRect(createOffsetRectForBackwardLayouter(anchorRect))
.breaker(breakerFactory.createBackwardRowBreaker())
Expand Down
Expand Up @@ -3,17 +3,20 @@
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.ViewInteraction;
import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.beloo.chipslayoutmanager.sample.ui.LayoutManagerFactory;
import com.beloo.chipslayoutmanager.sample.ui.ChipsFacade;
import com.beloo.chipslayoutmanager.sample.ui.TestActivity;
import com.beloo.chipslayoutmanager.sample.ui.adapter.ChipsAdapter;
import com.beloo.widget.chipslayoutmanager.util.Action;
import com.beloo.widget.chipslayoutmanager.util.InstrumentalUtil;

import org.junit.Before;
Expand All @@ -33,6 +36,7 @@
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -73,6 +77,7 @@ public void setUp() throws Throwable {
TestActivity.setLmFactory(layoutManagerFactory);

activityTestRule.getActivity().initialize();

}

@Test
Expand Down Expand Up @@ -258,6 +263,57 @@ public void setAdapterTwice_ChipsLayoutManagerHaveSetToRecyclerView_NoException(
assertNotEquals(RecyclerView.NO_POSITION, pos);
}

@Test
public void clipToPadding_IsTrue_paddingStaySame() throws Exception {
//arrange
ViewInteraction recyclerView = onView(withId(R.id.rvTest)).check(matches(isDisplayed()));

ViewAction viewAction = new Action<RecyclerView>() {
@Override
public void performAction(UiController uiController, RecyclerView view) {
view.setClipToPadding(true);
view.setPadding(50, 50, 50, 50);
view.requestLayout();
}
};

//act
recyclerView.perform(viewAction);
recyclerView.perform(RecyclerViewActions.scrollToPosition(12));
InstrumentalUtil.waitForIdle();

//assert
View view = layoutManager.getChildAt(0);
int padding = layoutManager.getDecoratedTop(view);
assertEquals(50, padding);
}


@Test
public void clipToPadding_IsFalse_paddingOfScrolledViewIsLowerThanInitial() throws Exception {
//arrange
ViewInteraction recyclerView = onView(withId(R.id.rvTest)).check(matches(isDisplayed()));

ViewAction viewAction = new Action<RecyclerView>() {
@Override
public void performAction(UiController uiController, RecyclerView view) {
view.setClipToPadding(false);
view.setPadding(50, 50, 50, 50);
view.requestLayout();
}
};

//act
recyclerView.perform(viewAction);
recyclerView.perform(RecyclerViewActions.scrollToPosition(12));
InstrumentalUtil.waitForIdle();

//assert
View view = layoutManager.getChildAt(0);
int padding = layoutManager.getDecoratedTop(view);
assertTrue(padding < 0);
}

@Ignore
@Test
public void deleteItem_ItemHasMaximumHeight_SamePadding() throws Exception {
Expand Down
@@ -0,0 +1,32 @@
package com.beloo.widget.chipslayoutmanager.util;

import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.view.View;

import org.hamcrest.Matcher;

import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static org.hamcrest.Matchers.allOf;

public abstract class Action<T extends View> implements ViewAction {
@Override
public Matcher<View> getConstraints() {
return allOf(isAssignableFrom(View.class), isDisplayed());
}

@Override
public String getDescription() {
return "action " + this.getClass().getSimpleName();
}

@Override
public final void perform(UiController uiController, View view) {
performAction(uiController, (T) view);
}

public void performAction(UiController uiController, T view) {

}
}
Expand Up @@ -18,6 +18,10 @@
import static org.hamcrest.Matchers.allOf;

public class RecyclerViewActionFactory {
///////////////////////////////////////////////////////////////////////////
// Actions factory
///////////////////////////////////////////////////////////////////////////

public ViewAction scrollBy(int x, int y) {
return new ScrollByRecyclerViewAction(x, y);
}
Expand All @@ -26,27 +30,29 @@ public ViewAction smoothScrollToPosition(int position) {
return new SmoothScrollToPositionRecyclerViewAction(position);
}


public ViewAction setAdapter(RecyclerView.Adapter<? extends RecyclerView.ViewHolder> adapter) {
return new SetAdapterAction(adapter);
}

///////////////////////////////////////////////////////////////////////////
// Matcher factory
///////////////////////////////////////////////////////////////////////////

public Matcher<View> correctOrder() {
return orderMatcher();
}

private static final class SetAdapterAction implements ViewAction {
///////////////////////////////////////////////////////////////////////////
// Actions
///////////////////////////////////////////////////////////////////////////

private static final class SetAdapterAction extends RecyclerViewAction {
private final RecyclerView.Adapter<? extends RecyclerView.ViewHolder> adapter;

private SetAdapterAction(RecyclerView.Adapter<? extends RecyclerView.ViewHolder> adapter) {
this.adapter = adapter;
}

@Override
public Matcher<View> getConstraints() {
return allOf(isAssignableFrom(RecyclerView.class), isDisplayed());
}

@Override
public String getDescription() {
return"set adapter to recycler view";
Expand All @@ -59,18 +65,13 @@ public void perform(UiController uiController, View view) {
}
}

private static final class SmoothScrollToPositionRecyclerViewAction implements ViewAction {
private static final class SmoothScrollToPositionRecyclerViewAction extends RecyclerViewAction {
private final int position;

private SmoothScrollToPositionRecyclerViewAction(int position) {
this.position = position;
}

@Override
public Matcher<View> getConstraints() {
return allOf(isAssignableFrom(RecyclerView.class), isDisplayed());
}

@Override
public String getDescription() {
return String.format(Locale.getDefault(), "smooth scroll RecyclerView to position %d", position);
Expand All @@ -96,7 +97,7 @@ private synchronized void onScrollStateChanged(RecyclerView recyclerView, int ne
}
}

private static final class ScrollByRecyclerViewAction implements ViewAction {
private static final class ScrollByRecyclerViewAction extends RecyclerViewAction {
private final int x;
private final int y;

Expand All @@ -105,11 +106,6 @@ private ScrollByRecyclerViewAction(int x, int y) {
this.y = y;
}

@Override
public Matcher<View> getConstraints() {
return allOf(isAssignableFrom(RecyclerView.class), isDisplayed());
}

@Override
public String getDescription() {
return String.format(Locale.getDefault(), "scroll RecyclerView with offsets: x = %d, y = %d ", x, y);
Expand All @@ -122,6 +118,23 @@ public void perform(UiController uiController, View view) {
}
}

private abstract static class RecyclerViewAction implements ViewAction {

@Override
public Matcher<View> getConstraints() {
return allOf(isAssignableFrom(RecyclerView.class), isDisplayed());
}

@Override
public String getDescription() {
return "RecyclerView action " + this.getClass().getSimpleName();
}
}

///////////////////////////////////////////////////////////////////////////
// Matcher
///////////////////////////////////////////////////////////////////////////

private Matcher<View> orderMatcher() {
return new TypeSafeMatcher<View>() {
@Override
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/layout/fragment_items.xml
Expand Up @@ -12,7 +12,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottomContainer"
android:padding="12dp"
android:padding="50dp"
android:clipToPadding="false"
/>

Expand Down

0 comments on commit b09191e

Please sign in to comment.