Skip to content

Commit d06b79b

Browse files
zeyapfacebook-github-bot
authored andcommitted
make sure view width and height are non 0 before calling createBitmap() (#56627)
Summary: ## Changelog: [Android] [Fixed] - make sure view width and height are non 0 before calling createBitmap() Differential Revision: D102657602
1 parent 44a4b1b commit d06b79b

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/ViewTransitionSnapshotManager.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,11 @@ internal class ViewTransitionSnapshotManager(
106106
val location = IntArray(2)
107107
view.getLocationInWindow(location)
108108

109+
val viewWidth = view.width
110+
val viewHeight = view.height
111+
109112
// The view's rect in window coordinates.
110-
val viewRect =
111-
Rect(location[0], location[1], location[0] + view.width, location[1] + view.height)
113+
val viewRect = Rect(location[0], location[1], location[0] + viewWidth, location[1] + viewHeight)
112114

113115
// Clamp to window bounds — PixelCopy only captures what's visible on the
114116
// window surface. Without clamping, off-screen portions are black/empty
@@ -144,23 +146,28 @@ internal class ViewTransitionSnapshotManager(
144146
if (copyResult == PixelCopy.SUCCESS) {
145147
// Compose the clamped capture into a full-size bitmap at the
146148
// correct offset so it aligns with the pseudo-element's bounds.
147-
val fullBitmap = createBitmap(view.width, view.height)
149+
val fullBitmap = createBitmap(viewWidth, viewHeight)
148150
Canvas(fullBitmap)
149151
.drawBitmap(clampedBitmap, offsetX.toFloat(), offsetY.toFloat(), null)
150152
clampedBitmap.recycle()
151153
onBitmapCaptured(reactTag, fullBitmap)
152154
} else {
155+
// Fall back to software rendering if the view is still valid.
153156
clampedBitmap.recycle()
154-
onBitmapCaptured(reactTag, captureSoftwareBitmap(view))
157+
if (view.width > 0 && view.height > 0) {
158+
onBitmapCaptured(reactTag, captureSoftwareBitmap(view))
159+
}
155160
}
156161
},
157162
mainHandler,
158163
)
159164
} catch (e: IllegalArgumentException) {
160165
// Window surface may have been destroyed (e.g., device idle/sleep).
161-
// Fall back to software rendering.
166+
// Fall back to software rendering if the view is still valid.
162167
clampedBitmap.recycle()
163-
onBitmapCaptured(reactTag, captureSoftwareBitmap(view))
168+
if (view.width > 0 && view.height > 0) {
169+
onBitmapCaptured(reactTag, captureSoftwareBitmap(view))
170+
}
164171
}
165172
}
166173

0 commit comments

Comments
 (0)