11
11
import androidx .recyclerview .widget .RecyclerView ;
12
12
import androidx .recyclerview .widget .StaggeredGridLayoutManager ;
13
13
14
+ import com .facebook .rebound .SimpleSpringListener ;
15
+ import com .facebook .rebound .Spring ;
16
+ import com .facebook .rebound .SpringConfig ;
17
+ import com .facebook .rebound .SpringSystem ;
18
+
14
19
import ceui .lisa .utils .Common ;
15
20
import ceui .lisa .utils .DensityUtil ;
16
21
@@ -34,19 +39,25 @@ protected int getVerticalSnapPreference() {
34
39
35
40
@ Override
36
41
protected void onTargetFound (View targetView , RecyclerView .State state , Action action ) {
37
- Rect rect = new Rect ();
38
- recyclerView .getLocalVisibleRect (rect );
39
-
40
- int parentHeight = rect .bottom - rect .top ;
41
- int childHeight = targetView .getHeight ();
42
- int offset = (parentHeight - childHeight ) / 2 ;
43
-
44
- final int dx = calculateDxToMakeVisible (targetView , getHorizontalSnapPreference ());
45
- final int dy = calculateDyToMakeVisible (targetView , getVerticalSnapPreference ()) + offset ;
46
- final int distance = (int ) Math .sqrt (dx * dx + dy * dy );
47
- final int time = calculateTimeForDeceleration (distance );
48
- if (time > 0 ) {
49
- action .update (-dx , -dy , time , mDecelerateInterpolator );
42
+ try {
43
+ if (!targetView .getGlobalVisibleRect (new Rect ())) {
44
+ Rect rect = new Rect ();
45
+ recyclerView .getGlobalVisibleRect (rect );
46
+
47
+ int parentHeight = rect .bottom - rect .top ;
48
+ int childHeight = targetView .getHeight ();
49
+ int offset = (parentHeight - childHeight ) / 2 ;
50
+
51
+ final int dx = calculateDxToMakeVisible (targetView , getHorizontalSnapPreference ());
52
+ final int dy = calculateDyToMakeVisible (targetView , getVerticalSnapPreference ()) + offset ;
53
+ final int distance = (int ) Math .sqrt (dx * dx + dy * dy );
54
+ final int time = calculateTimeForDeceleration (distance );
55
+ if (time > 0 ) {
56
+ action .update (-dx , -dy , time , mDecelerateInterpolator );
57
+ }
58
+ }
59
+ } catch (Exception e ) {
60
+ e .printStackTrace ();
50
61
}
51
62
}
52
63
0 commit comments