Back out "[RN] Layout Animation fix for normalized indices"

Summary:
Original commit changeset: 43e57dffa807

[Errors are growing and very ominious](https://our.intern.facebook.com/intern/logview/details/facebook_android_crashes/6acac038d7dd9d8ca95d1b9bccc4dfaa/?trace_key=39c72364f916998602bd55f091b04682)
I don't have a good idea what's going on.
This will re-introduce this bug: T44343673

Next steps:
* Would be great to try and get a repro to fix.
* Refactor this logic out to its own class and write actual tests.

Reviewed By: mdvacca

Differential Revision: D15822555

fbshipit-source-id: 0a2ec3d5c73420ca56aad93a4323a34cff1cc9c7
This commit is contained in:
Luna Wei
2019-06-14 07:43:06 -07:00
committed by Facebook Github Bot
parent 6c5ddb027d
commit 545b084cc8
@@ -338,52 +338,17 @@ public class NativeViewHierarchyManager {
}
/**
* Given an index, normalize against pending view deletion indices in the native view hierarchy
* @param index the index in the view operation under the assumption all view operations are synchronous
* @param pendingIndicesToDelete sparse array of view tags at normalized indices
* Given an index to action on under synchronous deletes, return an updated index factoring in
* asynchronous deletes (where the async delete operations have not yet been performed)
*/
private int normalizeIndex(int index, SparseIntArray pendingIndicesToDelete) {
int normalizedIndex = -1;
while (index >= 0) {
normalizedIndex += 1;
if (pendingIndicesToDelete.get(normalizedIndex, -1) == -1) { // assuming we never have negative tag
index--;
}
private int normalizeIndex(int index, SparseIntArray pendingIndices) {
int normalizedIndex = index;
for (int i = 0; i <= index; i++) {
normalizedIndex += pendingIndices.get(i);
}
return normalizedIndex;
}
/**
* Add view tag to pendingIndicesToDelete. Views in pendingIndicesToDelete are marked for deletion but have not been deleted yet
* @param index the index in the view to be deleted as provided by the view operation
* @param tag the view tag
* @param pendingIndicesToDelete sparse array of normalizedIndices to view tags marked for deletion
*/
private void addPendingIndex(int index, int tag, SparseIntArray pendingIndicesToDelete) {
int normalizedIndex = normalizeIndex(index, pendingIndicesToDelete);
if (pendingIndicesToDelete.get(normalizedIndex) > 0) {
throw new IllegalViewOperationException("Invalid!!");
}
pendingIndicesToDelete.put(normalizedIndex, tag);
}
/**
* When delete is completed, remove view from pendingIndicesToDelete
* @param tag tag of the view to be removed
* @param pendingIndicesToDelete sparse array of normalizedIndices to view tags marked for deletion
*/
private void removePendingIndex(int tag, SparseIntArray pendingIndicesToDelete) {
// indexAt refers to index within pendingIndicesToDelete sparse array, not the normalized index
int indexAt = pendingIndicesToDelete.indexOfValue(tag);
pendingIndicesToDelete.removeAt(indexAt);
for (indexAt = indexAt + 1; indexAt < pendingIndicesToDelete.size(); indexAt ++) {
int nextTag = pendingIndicesToDelete.valueAt(indexAt);
int nextKey = pendingIndicesToDelete.keyAt(indexAt);
pendingIndicesToDelete.removeAt(indexAt);
pendingIndicesToDelete.put(nextKey - 1, nextTag);
}
}
/**
* Given React tag, return sparse array of direct child indices that are pending deletion (due to
* async view deletion)
@@ -506,8 +471,8 @@ public class NativeViewHierarchyManager {
if (mLayoutAnimationEnabled &&
mLayoutAnimator.shouldAnimateLayout(viewToDestroy)) {
addPendingIndex(indexToDelete, tagToDelete, pendingIndicesToDelete);
int updatedCount = pendingIndicesToDelete.get(indexToDelete, 0) + 1;
pendingIndicesToDelete.put(indexToDelete, updatedCount);
mLayoutAnimator.deleteView(
viewToDestroy,
new LayoutAnimationListener() {
@@ -516,7 +481,8 @@ public class NativeViewHierarchyManager {
viewManager.removeView(viewToManage, viewToDestroy);
dropView(viewToDestroy);
removePendingIndex(viewToDestroy.getId(), pendingIndicesToDelete);
int count = pendingIndicesToDelete.get(indexToDelete, 0);
pendingIndicesToDelete.put(indexToDelete, Math.max(0, count - 1));
}
});
} else {