Skip to content

Commit

Permalink
Fixed some logic around enabling mvcp
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnarkhede committed Apr 8, 2021
1 parent de70564 commit 3541fb1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,24 @@ public void run() {
final UIManagerModuleListener uiManagerModuleListener = new UIManagerModuleListener() {
@Override
public void willDispatchViewUpdates(final UIManagerModule uiManagerModule) {
ReactViewGroup mContentView = (ReactViewGroup)scrollView.getChildAt(0);
if (mContentView == null) return;

ScrollViewUIHolders.currentScrollY = scrollView.getScrollY();

for (int ii = minIndexForVisible; ii < mContentView.getChildCount(); ++ii) {
View subview = mContentView.getChildAt(ii);
if (subview.getTop() >= ScrollViewUIHolders.currentScrollY) {
ScrollViewUIHolders.prevFirstVisibleTop = subview.getTop();
ScrollViewUIHolders.firstVisibleView = subview;
break;
uiManagerModule.prependUIBlock(new UIBlock() {
@Override
public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
ReactViewGroup mContentView = (ReactViewGroup)scrollView.getChildAt(0);
if (mContentView == null) return;

ScrollViewUIHolders.currentScrollY = scrollView.getScrollY();

for (int ii = minIndexForVisible; ii < mContentView.getChildCount(); ++ii) {
View subview = mContentView.getChildAt(ii);
if (subview.getTop() >= ScrollViewUIHolders.currentScrollY) {
ScrollViewUIHolders.prevFirstVisibleTop = subview.getTop();
ScrollViewUIHolders.firstVisibleView = subview;
break;
}
}
}
}
});
}
};

Expand Down
7 changes: 2 additions & 5 deletions src/FlatList.android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ export default (React.forwardRef(
const propAutoscrollToTopThreshold =
mvcp?.autoscrollToTopThreshold || -Number.MAX_SAFE_INTEGER;
const propMinIndexForVisible = mvcp?.minIndexForVisible || 1;

const hasMvcpChanged =
autoscrollToTopThreshold.current !== propAutoscrollToTopThreshold ||
minIndexForVisible.current !== propMinIndexForVisible;

const enableMvcp = () => {
if (!flRef.current) return;

Expand All @@ -45,9 +43,6 @@ export default (React.forwardRef(
};

const enableMvcpWithRetries = () => {
autoscrollToTopThreshold.current = propAutoscrollToTopThreshold;
minIndexForVisible.current = propMinIndexForVisible;

return enableMvcp()?.catch(() => {
/**
* enableMaintainVisibleContentPosition from native module may throw IllegalViewOperationException,
Expand Down Expand Up @@ -86,6 +81,8 @@ export default (React.forwardRef(
if (isMvcpEnabled.current && !hasMvcpChanged) {
return;
}
autoscrollToTopThreshold.current = propAutoscrollToTopThreshold;
minIndexForVisible.current = propMinIndexForVisible;

isMvcpEnabled.current = true;
disableMvcp().then(enableMvcpWithRetries);
Expand Down

0 comments on commit 3541fb1

Please sign in to comment.