Skip to content

Commit 53c4ab1

Browse files
committed
fix(UIManager): Throttle layout from window size change events
Ensure that only the latest window size change event triggers a layout operation. Fixes microsoft#397
1 parent 529bd51 commit 53c4ab1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

ReactWindows/ReactNative/UIManager/UIManagerModule.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,24 @@ public int AddMeasuredRootView(SizeMonitoringCanvas rootView)
102102
var context = new ThemedReactContext(Context);
103103
_uiImplementation.RegisterRootView(rootView, tag, width, height, context);
104104

105+
var resizeCount = 0;
106+
105107
rootView.SetOnSizeChangedListener((sender, args) =>
106108
{
109+
var currentCount = ++resizeCount;
107110
var newWidth = args.NewSize.Width;
108111
var newHeight = args.NewSize.Height;
109112

110113
Context.RunOnNativeModulesQueueThread(() =>
111114
{
112-
Context.AssertOnNativeModulesQueueThread();
113-
_uiImplementation.UpdateRootNodeSize(tag, newWidth, newHeight, _eventDispatcher);
115+
if (currentCount == resizeCount)
116+
{
117+
Context.AssertOnNativeModulesQueueThread();
118+
_uiImplementation.UpdateRootNodeSize(tag, newWidth, newHeight, _eventDispatcher);
119+
}
114120
});
115121
});
116-
122+
117123
return tag;
118124
}
119125

0 commit comments

Comments
 (0)