|
18 | 18 | import com.facebook.infer.annotation.Assertions; |
19 | 19 | import com.facebook.react.bridge.ReadableMap; |
20 | 20 | import com.facebook.react.bridge.ReadableMapKeySetIterator; |
| 21 | +import com.facebook.react.uimanager.events.EventDispatcher; |
21 | 22 |
|
22 | 23 | /** |
23 | 24 | * Base node class for representing virtual tree of React nodes. Shadow nodes are used primarily |
@@ -202,18 +203,37 @@ public void onCollectExtraUpdates(UIViewOperationQueue uiViewOperationQueue) { |
202 | 203 | float absoluteX, |
203 | 204 | float absoluteY, |
204 | 205 | UIViewOperationQueue uiViewOperationQueue, |
205 | | - NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer) { |
| 206 | + NativeViewHierarchyOptimizer nativeViewHierarchyOptimizer, |
| 207 | + EventDispatcher eventDispatcher) { |
206 | 208 | if (mNodeUpdated) { |
207 | 209 | onCollectExtraUpdates(uiViewOperationQueue); |
208 | 210 | } |
209 | 211 |
|
210 | 212 | if (hasNewLayout()) { |
211 | | - mAbsoluteLeft = Math.round(absoluteX + getLayoutX()); |
212 | | - mAbsoluteTop = Math.round(absoluteY + getLayoutY()); |
213 | | - mAbsoluteRight = Math.round(absoluteX + getLayoutX() + getLayoutWidth()); |
214 | | - mAbsoluteBottom = Math.round(absoluteY + getLayoutY() + getLayoutHeight()); |
215 | | - |
216 | | - nativeViewHierarchyOptimizer.handleUpdateLayout(this); |
| 213 | + float absoluteLeft = Math.round(absoluteX + getLayoutX()); |
| 214 | + float absoluteTop = Math.round(absoluteY + getLayoutY()); |
| 215 | + float absoluteRight = Math.round(absoluteX + getLayoutX() + getLayoutWidth()); |
| 216 | + float absoluteBottom = Math.round(absoluteY + getLayoutY() + getLayoutHeight()); |
| 217 | + // If the layout didn't change this should calculate exactly same values, it's fine to compare |
| 218 | + // floats with "==" in this case |
| 219 | + if (absoluteLeft != mAbsoluteLeft || absoluteTop != mAbsoluteTop || |
| 220 | + absoluteRight != mAbsoluteRight || absoluteBottom != mAbsoluteBottom) { |
| 221 | + mAbsoluteLeft = absoluteLeft; |
| 222 | + mAbsoluteTop = absoluteTop; |
| 223 | + mAbsoluteRight = absoluteRight; |
| 224 | + mAbsoluteBottom = absoluteBottom; |
| 225 | + |
| 226 | + nativeViewHierarchyOptimizer.handleUpdateLayout(this); |
| 227 | + if (mShouldNotifyOnLayout) { |
| 228 | + eventDispatcher.dispatchEvent( |
| 229 | + OnLayoutEvent.obtain( |
| 230 | + getReactTag(), |
| 231 | + getScreenX(), |
| 232 | + getScreenY(), |
| 233 | + getScreenWidth(), |
| 234 | + getScreenHeight())); |
| 235 | + } |
| 236 | + } |
217 | 237 | } |
218 | 238 | } |
219 | 239 |
|
@@ -264,10 +284,6 @@ public void setShouldNotifyOnLayout(boolean shouldNotifyOnLayout) { |
264 | 284 | mShouldNotifyOnLayout = shouldNotifyOnLayout; |
265 | 285 | } |
266 | 286 |
|
267 | | - /* package */ boolean shouldNotifyOnLayout() { |
268 | | - return mShouldNotifyOnLayout; |
269 | | - } |
270 | | - |
271 | 287 | /** |
272 | 288 | * Adds a child that the native view hierarchy will have at this index in the native view |
273 | 289 | * corresponding to this node. |
|
0 commit comments