Skip to content

Commit bd8bb5f

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() Reviewed By: Abbondanzo Differential Revision: D102657602
1 parent 44a4b1b commit bd8bb5f

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,30 @@ internal class ViewTransitionSnapshotManager(
144144
if (copyResult == PixelCopy.SUCCESS) {
145145
// Compose the clamped capture into a full-size bitmap at the
146146
// correct offset so it aligns with the pseudo-element's bounds.
147-
val fullBitmap = createBitmap(view.width, view.height)
148-
Canvas(fullBitmap)
149-
.drawBitmap(clampedBitmap, offsetX.toFloat(), offsetY.toFloat(), null)
150-
clampedBitmap.recycle()
151-
onBitmapCaptured(reactTag, fullBitmap)
147+
if (view.width > 0 && view.height > 0) {
148+
val fullBitmap = createBitmap(view.width, view.height)
149+
Canvas(fullBitmap)
150+
.drawBitmap(clampedBitmap, offsetX.toFloat(), offsetY.toFloat(), null)
151+
clampedBitmap.recycle()
152+
onBitmapCaptured(reactTag, fullBitmap)
153+
}
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)