mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-06 22:38:37 +08:00
Fix for ViewManager commands being run before view updates.
Summary: Since Nodes' manageChildren doesn't enqueue the child updates immediately, commands were being directed to non-updated views. Previously we applied updates for the shadow node before dispatching the command, but we can instead wait to fire commands until after we update the view hierarchy. Reviewed By: ahmedre Differential Revision: D3568541
This commit is contained in:
committed by
Ahmed El-Helw
parent
7df627f9be
commit
95ae936aa6
@@ -14,6 +14,7 @@ import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.facebook.csslayout.Spacing;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.uimanager.OnLayoutEvent;
|
||||
import com.facebook.react.uimanager.ReactShadowNode;
|
||||
import com.facebook.react.uimanager.ReactStylesDiffMap;
|
||||
@@ -48,6 +49,8 @@ import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
private final ArrayList<OnLayoutEvent> mOnLayoutEvents = new ArrayList<>();
|
||||
private final ArrayList<FlatUIViewOperationQueue.UpdateViewBounds> mUpdateViewBoundsOperations =
|
||||
new ArrayList<>();
|
||||
private final ArrayList<FlatUIViewOperationQueue.ViewManagerCommand> mViewManagerCommands =
|
||||
new ArrayList<>();
|
||||
|
||||
private @Nullable FlatUIViewOperationQueue.DetachAllChildrenFromViews mDetachAllChildrenFromViews;
|
||||
|
||||
@@ -99,6 +102,14 @@ import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
}
|
||||
mUpdateViewBoundsOperations.clear();
|
||||
|
||||
// Process view manager commands after bounds operations, so that any ui operations have already
|
||||
// happened before we actually dispatch the view manager command. This prevents things like
|
||||
// commands going to empty parents and views not yet being created.
|
||||
for (int i = 0, size = mViewManagerCommands.size(); i != size; i++) {
|
||||
mOperationsQueue.enqueueViewManagerCommand(mViewManagerCommands.get(i));
|
||||
}
|
||||
mViewManagerCommands.clear();
|
||||
|
||||
// This could be more efficient if EventDispatcher had a batch mode
|
||||
// to avoid multiple synchronized calls.
|
||||
for (int i = 0, size = mOnLayoutEvents.size(); i != size; ++i) {
|
||||
@@ -134,6 +145,14 @@ import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
mAttachDetachListeners.add(listener);
|
||||
}
|
||||
|
||||
/* package */ void enqueueViewManagerCommand(
|
||||
int reactTag,
|
||||
int commandId,
|
||||
ReadableArray commandArgs) {
|
||||
mViewManagerCommands.add(
|
||||
mOperationsQueue.createViewManagerCommand(reactTag, commandId, commandArgs));
|
||||
}
|
||||
|
||||
/* package */ void enqueueCreateOrUpdateView(
|
||||
FlatShadowNode node,
|
||||
@Nullable ReactStylesDiffMap styles) {
|
||||
|
||||
Reference in New Issue
Block a user