Skip to content

Commit c1081cc

Browse files
fabriziocuccifacebook-github-bot
authored andcommitted
Kotlinify GuardedFrameCallback (#43841)
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
1 parent 13cdd48 commit c1081cc

File tree

3 files changed

+34
-43
lines changed

3 files changed

+34
-43
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4049,7 +4049,7 @@ public final class com/facebook/react/uimanager/FloatUtil {
40494049

40504050
public abstract class com/facebook/react/uimanager/GuardedFrameCallback : android/view/Choreographer$FrameCallback {
40514051
protected fun <init> (Lcom/facebook/react/bridge/ReactContext;)V
4052-
public final fun doFrame (J)V
4052+
public fun doFrame (J)V
40534053
protected abstract fun doFrameGuarded (J)V
40544054
}
40554055

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/GuardedFrameCallback.java

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react.uimanager
9+
10+
import android.view.Choreographer
11+
import com.facebook.react.bridge.ReactContext
12+
13+
/**
14+
* Abstract base for a Choreographer FrameCallback that should have any RuntimeExceptions it throws
15+
* handled by the [JSExceptionHandler] registered if the app is in dev mode.
16+
*/
17+
public abstract class GuardedFrameCallback
18+
protected constructor(private val reactContext: ReactContext) : Choreographer.FrameCallback {
19+
20+
override public fun doFrame(frameTimeNanos: Long) {
21+
try {
22+
doFrameGuarded(frameTimeNanos)
23+
} catch (e: RuntimeException) {
24+
reactContext.handleException(e)
25+
}
26+
}
27+
28+
/**
29+
* Like the standard doFrame but RuntimeExceptions will be caught and passed to
30+
* [ReactContext#handleException(RuntimeException)].
31+
*/
32+
protected abstract fun doFrameGuarded(frameTimeNanos: Long)
33+
}

0 commit comments

Comments
 (0)