Skip to content

Commit 7109564

Browse files
committed
fixed scroll behavior for payment selection
1 parent dc9f321 commit 7109564

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

ui/src/main/java/io/snabble/sdk/ui/checkout/PaymentMethodView.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import android.content.res.Resources;
55
import android.graphics.drawable.ColorDrawable;
66
import android.support.v4.content.res.ResourcesCompat;
7+
import android.support.v4.widget.NestedScrollView;
78
import android.support.v7.widget.DividerItemDecoration;
89
import android.support.v7.widget.LinearLayoutManager;
910
import android.support.v7.widget.RecyclerView;
1011
import android.util.AttributeSet;
1112
import android.view.LayoutInflater;
1213
import android.view.View;
1314
import android.view.ViewGroup;
15+
import android.view.ViewTreeObserver;
1416
import android.widget.FrameLayout;
1517
import android.widget.ImageView;
1618
import android.widget.TextView;
@@ -40,6 +42,7 @@ class PaymentMethodView extends FrameLayout {
4042

4143
private Checkout checkout;
4244
private List<PaymentMethod> availablePaymentMethods;
45+
private RecyclerView recyclerView;
4346

4447
public PaymentMethodView(Context context) {
4548
super(context);
@@ -74,16 +77,34 @@ private void inflateView() {
7477
}
7578
}
7679

77-
RecyclerView recyclerView = findViewById(R.id.payment_methods);
80+
recyclerView = findViewById(R.id.payment_methods);
7881
recyclerView.setAdapter(new Adapter());
7982

80-
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
81-
layoutManager.setStackFromEnd(true);
82-
layoutManager.scrollToPosition(0);
83+
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()) {
84+
@Override
85+
public boolean canScrollVertically() {
86+
return false;
87+
}
88+
};
89+
90+
final NestedScrollView scrollView = findViewById(R.id.scroller);
8391

8492
recyclerView.setLayoutManager(layoutManager);
8593
recyclerView.setItemAnimator(null);
8694

95+
scrollView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
96+
@Override
97+
public void onGlobalLayout() {
98+
scrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
99+
100+
scrollView.post(new Runnable() {
101+
public void run() {
102+
scrollView.fullScroll(View.FOCUS_DOWN);
103+
}
104+
});
105+
}
106+
});
107+
87108
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL);
88109
int dividerColor = ResourcesCompat.getColor(getResources(), R.color.snabble_dividerColor, null);
89110
dividerItemDecoration.setDrawable(new ColorDrawable(dividerColor));

ui/src/main/res/layout/view_payment_method.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818

1919
<android.support.v4.widget.NestedScrollView
2020
android:layout_width="match_parent"
21-
android:layout_height="match_parent"
21+
android:layout_height="wrap_content"
22+
android:layout_alignParentBottom="true"
23+
android:layout_marginTop="64dp"
24+
android:scrollbars="none"
2225
android:padding="16dp"
23-
android:layout_below="@+id/choose_payment_title">
26+
android:id="@+id/scroller">
2427
<android.support.v7.widget.CardView
2528
android:layout_width="match_parent"
2629
android:layout_height="wrap_content"
27-
android:layout_gravity="bottom"
2830
app:cardCornerRadius="15dp"
2931
app:cardElevation="3dp"
3032
app:cardUseCompatPadding="true">

0 commit comments

Comments
 (0)