PerfMonitor - Fix enable/disable states (#53957)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/53957

There are cases where the overlay can get enabled multiple times, creating more than one view. This change no-ops enabling if the overlay is already enabled and just uses enable/disable for showing/hiding the view.
{F1982272836}

Changelog: [Internal]

Reviewed By: hoxyq

Differential Revision: D83275253

fbshipit-source-id: 4b468171a582e134071875f718c66d1659d67782
This commit is contained in:
Devan Buggay
2025-09-26 12:28:25 -07:00
committed by Facebook GitHub Bot
parent 8bc133c6c1
commit 456e01bf3f
@@ -20,18 +20,25 @@ internal class PerfMonitorOverlayManager(
/** Enable the Perf Monitor overlay. */
fun enable() {
if (enabled) {
return
}
enabled = true
UiThreadUtil.runOnUiThread {
val context = devHelper.currentActivity ?: return@runOnUiThread
view = PerfMonitorOverlayView(context, ::handleRecordingButtonPress)
if (view == null) {
view = PerfMonitorOverlayView(context, ::handleRecordingButtonPress)
}
view?.show()
}
}
/** Disable the Perf Monitor overlay. Will remain hidden when updates are received. */
fun disable() {
UiThreadUtil.runOnUiThread { view?.hide() }
view = null
enabled = false
UiThreadUtil.runOnUiThread { view?.hide() }
}
/** Start background trace recording. */