forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert FpsDebugFrameCallback/AnimationsDebugModule to Kotlin (facebo…
…ok#44475) Summary: Pull Request resolved: facebook#44475 # Changelog: [Internal] - As the title says, this is preparing to complete the conversion of the whole corresponding module to Kotlin. Reviewed By: christophpurrer Differential Revision: D57095896 fbshipit-source-id: 87fe08aec974f5f1327189d0e74c3782c4391e85
- Loading branch information
Showing
7 changed files
with
386 additions
and
457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 0 additions & 104 deletions
104
packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/FpsView.java
This file was deleted.
Oops, something went wrong.
101 changes: 101 additions & 0 deletions
101
packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/FpsView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.devsupport | ||
|
||
import android.view.View | ||
import android.widget.FrameLayout | ||
import android.widget.TextView | ||
import com.facebook.common.logging.FLog | ||
import com.facebook.react.R | ||
import com.facebook.react.bridge.ReactContext | ||
import com.facebook.react.common.ReactConstants | ||
import com.facebook.react.modules.debug.FpsDebugFrameCallback | ||
import java.util.Locale | ||
|
||
/** | ||
* View that automatically monitors and displays the current app frame rate. Also logs the current | ||
* FPS to logcat while active. | ||
* | ||
* NB: Requires API 16 for use of FpsDebugFrameCallback. | ||
*/ | ||
internal class FpsView(reactContext: ReactContext?) : FrameLayout(reactContext!!) { | ||
private val textView: TextView | ||
private val frameCallback: FpsDebugFrameCallback | ||
private val fpsMonitorRunnable: FPSMonitorRunnable | ||
|
||
init { | ||
inflate(reactContext, R.layout.fps_view, this) | ||
textView = findViewById<View>(R.id.fps_text) as TextView | ||
frameCallback = FpsDebugFrameCallback(reactContext!!) | ||
fpsMonitorRunnable = FPSMonitorRunnable() | ||
setCurrentFPS(0.0, 0.0, 0, 0) | ||
} | ||
|
||
override fun onAttachedToWindow() { | ||
super.onAttachedToWindow() | ||
frameCallback.reset() | ||
frameCallback.start() | ||
fpsMonitorRunnable.start() | ||
} | ||
|
||
override fun onDetachedFromWindow() { | ||
super.onDetachedFromWindow() | ||
frameCallback.stop() | ||
fpsMonitorRunnable.stop() | ||
} | ||
|
||
private fun setCurrentFPS( | ||
currentFPS: Double, | ||
currentJSFPS: Double, | ||
droppedUIFrames: Int, | ||
total4PlusFrameStutters: Int | ||
) { | ||
val fpsString = | ||
String.format( | ||
Locale.US, | ||
"UI: %.1f fps\n%d dropped so far\n%d stutters (4+) so far\nJS: %.1f fps", | ||
currentFPS, | ||
droppedUIFrames, | ||
total4PlusFrameStutters, | ||
currentJSFPS) | ||
textView.text = fpsString | ||
FLog.d(ReactConstants.TAG, fpsString) | ||
} | ||
|
||
/** Timer that runs every UPDATE_INTERVAL_MS ms and updates the currently displayed FPS. */ | ||
private inner class FPSMonitorRunnable : Runnable { | ||
private var shouldStop = false | ||
private var totalFramesDropped = 0 | ||
private var total4PlusFrameStutters = 0 | ||
|
||
override fun run() { | ||
if (shouldStop) { | ||
return | ||
} | ||
totalFramesDropped += frameCallback.expectedNumFrames - frameCallback.numFrames | ||
total4PlusFrameStutters += frameCallback.get4PlusFrameStutters() | ||
setCurrentFPS( | ||
frameCallback.fps, frameCallback.jsFPS, totalFramesDropped, total4PlusFrameStutters) | ||
frameCallback.reset() | ||
postDelayed(this, UPDATE_INTERVAL_MS.toLong()) | ||
} | ||
|
||
fun start() { | ||
shouldStop = false | ||
post(this) | ||
} | ||
|
||
fun stop() { | ||
shouldStop = true | ||
} | ||
} | ||
|
||
companion object { | ||
private const val UPDATE_INTERVAL_MS = 500 | ||
} | ||
} |
106 changes: 0 additions & 106 deletions
106
...ve/ReactAndroid/src/main/java/com/facebook/react/modules/debug/AnimationsDebugModule.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.