Skip to content

Commit

Permalink
Kotlinify GuardedFrameCallback (#43841)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #43841

Changelog: [Internal]

As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)).

Reviewed By: cortinico

Differential Revision: D55732555

fbshipit-source-id: baab9a33be7d963dfe0fe765211de3d5abaebaca
  • Loading branch information
fabriziocucci authored and facebook-github-bot committed Apr 4, 2024
1 parent 13cdd48 commit c1081cc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 43 deletions.
2 changes: 1 addition & 1 deletion packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> (Lcom/facebook/react/bridge/ReactContext;)V
public final fun doFrame (J)V
public fun doFrame (J)V
protected abstract fun doFrameGuarded (J)V
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit c1081cc

Please sign in to comment.