Skip to content

Commit

Permalink
Fixing prop change check
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnarkhede committed Feb 26, 2021
1 parent 2c5ea51 commit 9d5c50e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
Expand Up @@ -109,10 +109,14 @@ public void onLayoutUpdated(ReactShadowNode root) {

@ReactMethod
public void disableMaintainVisibleContentPosition(int key, Promise promise) {
if (key >= 0) {
final UIManagerModule uiManagerModule = this.reactContext.getNativeModule(UIManagerModule.class);
uiManagerModule.removeUIManagerListener(uiManagerModuleListeners.remove(key));
try {
if (key >= 0) {
final UIManagerModule uiManagerModule = this.reactContext.getNativeModule(UIManagerModule.class);
uiManagerModule.removeUIManagerListener(uiManagerModuleListeners.remove(key));
}
promise.resolve(null);
} catch (IllegalViewOperationException e) {
promise.resolve(-1);
}
promise.resolve(null);
}
}
28 changes: 8 additions & 20 deletions src/FlatList.tsx
@@ -1,11 +1,5 @@
import React, { MutableRefObject, useRef } from 'react';
import {
FlatList,
FlatListProps,
findNodeHandle,
NativeModules,
Platform,
} from 'react-native';
import { FlatList, FlatListProps, NativeModules, Platform } from 'react-native';

export const MvcpScrollViewManager = NativeModules.MvcpScrollViewManager;

Expand All @@ -24,19 +18,13 @@ export default (React.forwardRef(
const minIndexForVisible = useRef<number>();
const cleanupPromiseRef = useRef<Promise<any>>();

const getAutoscrollToTopThresholdFromProp = () =>
mvcp?.autoscrollToTopThreshold || -Number.MAX_SAFE_INTEGER;

const getMinIndexForVisibleFromProp = () => mvcp?.minIndexForVisible || 1;

const resetMvcpIfNeeded = (): void => {
if (!mvcp || Platform.OS !== 'android' || !flRef.current) {
return;
}
if (
autoscrollToTopThreshold.current ===
getAutoscrollToTopThresholdFromProp() &&
minIndexForVisible.current === getMinIndexForVisibleFromProp()
autoscrollToTopThreshold.current === mvcp?.autoscrollToTopThreshold &&
minIndexForVisible.current === mvcp?.minIndexForVisible
) {
// Don't do anythinig if the values haven't changed
return;
Expand All @@ -47,14 +35,14 @@ export default (React.forwardRef(
MvcpScrollViewManager.disableMaintainVisibleContentPosition(handle);
});

autoscrollToTopThreshold.current = getAutoscrollToTopThresholdFromProp();
minIndexForVisible.current = getMinIndexForVisibleFromProp();
autoscrollToTopThreshold.current = mvcp?.autoscrollToTopThreshold;
minIndexForVisible.current = mvcp?.minIndexForVisible;

const viewTag = findNodeHandle(flRef.current);
const viewTag = flRef.current.getScrollableNode();
cleanupPromiseRef.current = MvcpScrollViewManager.enableMaintainVisibleContentPosition(
viewTag,
autoscrollToTopThreshold.current,
minIndexForVisible.current
autoscrollToTopThreshold.current || -Number.MAX_SAFE_INTEGER,
minIndexForVisible.current || 1
);
};

Expand Down

0 comments on commit 9d5c50e

Please sign in to comment.