diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index d375baa1e414a5..c785e33afe8b4c 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -4049,7 +4049,7 @@ public final class com/facebook/react/uimanager/FloatUtil { public abstract class com/facebook/react/uimanager/GuardedFrameCallback : android/view/Choreographer$FrameCallback { protected fun (Lcom/facebook/react/bridge/ReactContext;)V - public final fun doFrame (J)V + public fun doFrame (J)V protected abstract fun doFrameGuarded (J)V } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/GuardedFrameCallback.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/GuardedFrameCallback.java deleted file mode 100644 index 9ed8000da172f2..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/GuardedFrameCallback.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.uimanager; - -import android.view.Choreographer; -import com.facebook.infer.annotation.Nullsafe; -import com.facebook.react.bridge.JSExceptionHandler; -import com.facebook.react.bridge.ReactContext; - -/** - * Abstract base for a Choreographer FrameCallback that should have any RuntimeExceptions it throws - * handled by the {@link JSExceptionHandler} registered if the app is in dev mode. - */ -@Nullsafe(Nullsafe.Mode.LOCAL) -public abstract class GuardedFrameCallback implements Choreographer.FrameCallback { - - private final ReactContext mReactContext; - - protected GuardedFrameCallback(ReactContext reactContext) { - mReactContext = reactContext; - } - - @Override - public final void doFrame(long frameTimeNanos) { - try { - doFrameGuarded(frameTimeNanos); - } catch (RuntimeException e) { - mReactContext.handleException(e); - } - } - - /** - * Like the standard doFrame but RuntimeExceptions will be caught and passed to {@link - * com.facebook.react.bridge.ReactContext#handleException(RuntimeException)}. - */ - protected abstract void doFrameGuarded(long frameTimeNanos); -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/GuardedFrameCallback.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/GuardedFrameCallback.kt new file mode 100644 index 00000000000000..7b29fe123cc1b5 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/GuardedFrameCallback.kt @@ -0,0 +1,33 @@ +/* + * 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.uimanager + +import android.view.Choreographer +import com.facebook.react.bridge.ReactContext + +/** + * Abstract base for a Choreographer FrameCallback that should have any RuntimeExceptions it throws + * handled by the [JSExceptionHandler] registered if the app is in dev mode. + */ +public abstract class GuardedFrameCallback +protected constructor(private val reactContext: ReactContext) : Choreographer.FrameCallback { + + override public fun doFrame(frameTimeNanos: Long) { + try { + doFrameGuarded(frameTimeNanos) + } catch (e: RuntimeException) { + reactContext.handleException(e) + } + } + + /** + * Like the standard doFrame but RuntimeExceptions will be caught and passed to + * [ReactContext#handleException(RuntimeException)]. + */ + protected abstract fun doFrameGuarded(frameTimeNanos: Long) +}