forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreact-native+0.76.3+002+fixMVCPAndroid.patch
175 lines (159 loc) · 7.35 KB
/
react-native+0.76.3+002+fixMVCPAndroid.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
diff --git a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/MaintainVisibleScrollPositionHelper.java b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/MaintainVisibleScrollPositionHelper.java
index 26c9aeb..b2cff8b 100644
--- a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/MaintainVisibleScrollPositionHelper.java
+++ b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/MaintainVisibleScrollPositionHelper.java
@@ -86,6 +86,7 @@ class MaintainVisibleScrollPositionHelper<ScrollViewT extends ViewGroup & HasSmo
return;
}
mListening = false;
+ mFirstVisibleView = null;
getUIManagerModule().removeUIManagerEventListener(this);
}
@@ -93,20 +94,19 @@ class MaintainVisibleScrollPositionHelper<ScrollViewT extends ViewGroup & HasSmo
* Update the scroll position of the managed ScrollView. This should be called after layout has
* been updated.
*/
- public void updateScrollPosition() {
+ public void onLayout() {
// On Fabric this will be called internally in `didMountItems`.
- if (ViewUtil.getUIManagerType(mScrollView.getId()) == UIManagerType.FABRIC) {
- return;
+ if (ViewUtil.getUIManagerType(mScrollView.getId()) != UIManagerType.FABRIC) {
+ didMountItemsInternal();
}
- updateScrollPositionInternal();
}
- private void updateScrollPositionInternal() {
- if (mConfig == null || mFirstVisibleView == null || mPrevFirstVisibleFrame == null) {
+ private void didMountItemsInternal() {
+ if (mConfig == null || mPrevFirstVisibleFrame == null) {
return;
}
- View firstVisibleView = mFirstVisibleView.get();
+ View firstVisibleView = getFirstVisibleView();
if (firstVisibleView == null) {
return;
}
@@ -150,7 +150,7 @@ class MaintainVisibleScrollPositionHelper<ScrollViewT extends ViewGroup & HasSmo
ViewUtil.getUIManagerType(mScrollView.getId())));
}
- private void computeTargetView() {
+ public void onScroll() {
if (mConfig == null) {
return;
}
@@ -160,6 +160,12 @@ class MaintainVisibleScrollPositionHelper<ScrollViewT extends ViewGroup & HasSmo
}
int currentScroll = mHorizontal ? mScrollView.getScrollX() : mScrollView.getScrollY();
+ View firstVisibleView = null;
+ // We cannot assume that the views will be in position order because of things like z-index
+ // which will change the order of views in their parent. This means we need to iterate through
+ // the full children array and find the view with the smallest position that is bigger than
+ // the scroll position.
+ float firstVisibleViewPosition = Float.MAX_VALUE;
for (int i = mConfig.minIndexForVisible; i < contentView.getChildCount(); i++) {
View child = contentView.getChildAt(i);
@@ -168,14 +174,36 @@ class MaintainVisibleScrollPositionHelper<ScrollViewT extends ViewGroup & HasSmo
mHorizontal ? child.getX() + child.getWidth() : child.getY() + child.getHeight();
// If the child is partially visible or this is the last child, select it as the anchor.
- if (position > currentScroll || i == contentView.getChildCount() - 1) {
- mFirstVisibleView = new WeakReference<>(child);
- Rect frame = new Rect();
- child.getHitRect(frame);
- mPrevFirstVisibleFrame = frame;
- break;
+ if ((position > currentScroll && position < firstVisibleViewPosition) ||
+ (firstVisibleView == null && i == contentView.getChildCount() - 1)) {
+ firstVisibleView = child;
+ firstVisibleViewPosition = position;
+ }
+ }
+ mFirstVisibleView = new WeakReference<>(firstVisibleView);
+ }
+
+ private View getFirstVisibleView() {
+ return mFirstVisibleView != null ? mFirstVisibleView.get() : null;
+ }
+
+ private void willMountItemsInternal() {
+ View firstVisibleView = getFirstVisibleView();
+
+ // If we don't have a first visible view because no scroll happened call onScroll
+ // to update it.
+ if (firstVisibleView == null) {
+ onScroll();
+ firstVisibleView = getFirstVisibleView();
+
+ // There are cases where it is possible for this to still be null so just bail out.
+ if (firstVisibleView == null) {
+ return;
}
}
+ Rect frame = new Rect();
+ firstVisibleView.getHitRect(frame);
+ mPrevFirstVisibleFrame = frame;
}
// UIManagerListener
@@ -186,19 +214,19 @@ class MaintainVisibleScrollPositionHelper<ScrollViewT extends ViewGroup & HasSmo
new Runnable() {
@Override
public void run() {
- computeTargetView();
+ willMountItemsInternal();
}
});
}
@Override
public void willMountItems(UIManager uiManager) {
- computeTargetView();
+ willMountItemsInternal();
}
@Override
public void didMountItems(UIManager uiManager) {
- updateScrollPositionInternal();
+ didMountItemsInternal();
}
@Override
diff --git a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java
index 1d7800d..b612029 100644
--- a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java
+++ b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java
@@ -508,6 +508,10 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
mOnScrollDispatchHelper.getYFlingVelocity(),
mEnableSyncOnScroll);
mPreventReentry = false;
+
+ if (mMaintainVisibleContentPositionHelper != null) {
+ mMaintainVisibleContentPositionHelper.onScroll();
+ }
}
}
@@ -1459,7 +1463,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
if (layoutDirection == LAYOUT_DIRECTION_RTL) {
adjustPositionForContentChangeRTL(left, right, oldLeft, oldRight);
} else if (mMaintainVisibleContentPositionHelper != null) {
- mMaintainVisibleContentPositionHelper.updateScrollPosition();
+ mMaintainVisibleContentPositionHelper.onLayout();
}
}
diff --git a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java
index e49a25a..0eb79ed 100644
--- a/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java
+++ b/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java
@@ -432,6 +432,10 @@ public class ReactScrollView extends ScrollView
mOnScrollDispatchHelper.getYFlingVelocity(),
mEnableSyncOnScroll);
mPreventReentry = false;
+
+ if (mMaintainVisibleContentPositionHelper != null) {
+ mMaintainVisibleContentPositionHelper.onScroll();
+ }
}
}
@@ -1235,7 +1239,7 @@ public class ReactScrollView extends ScrollView
}
if (mMaintainVisibleContentPositionHelper != null) {
- mMaintainVisibleContentPositionHelper.updateScrollPosition();
+ mMaintainVisibleContentPositionHelper.onLayout();
}
if (isShown() && isContentReady()) {