mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Kotlinify AndroidChoreographerProvider (#43839)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43839 Changelog: [Internal] As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)). Reviewed By: cortinico Differential Revision: D55731620 fbshipit-source-id: c75eca4d324fb6761b681f28a9fe65fb2659aa3e
This commit is contained in:
committed by
Facebook GitHub Bot
parent
bc3e3360d1
commit
9d51bfdc14
-41
@@ -1,41 +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.internal;
|
||||
|
||||
import com.facebook.infer.annotation.Nullsafe;
|
||||
import com.facebook.react.bridge.UiThreadUtil;
|
||||
|
||||
/** An implementation of ChoreographerProvider that directly uses android.view.Choreographer. */
|
||||
@Nullsafe(Nullsafe.Mode.LOCAL)
|
||||
public final class AndroidChoreographerProvider implements ChoreographerProvider {
|
||||
|
||||
public static final class AndroidChoreographer implements ChoreographerProvider.Choreographer {
|
||||
private final android.view.Choreographer sInstance = android.view.Choreographer.getInstance();
|
||||
|
||||
public void postFrameCallback(android.view.Choreographer.FrameCallback callback) {
|
||||
sInstance.postFrameCallback(callback);
|
||||
}
|
||||
|
||||
public void removeFrameCallback(android.view.Choreographer.FrameCallback callback) {
|
||||
sInstance.removeFrameCallback(callback);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Holder {
|
||||
private static final AndroidChoreographerProvider INSTANCE = new AndroidChoreographerProvider();
|
||||
}
|
||||
|
||||
public static AndroidChoreographerProvider getInstance() {
|
||||
return Holder.INSTANCE;
|
||||
}
|
||||
|
||||
public Choreographer getChoreographer() {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
return new AndroidChoreographer();
|
||||
}
|
||||
}
|
||||
+33
@@ -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.internal
|
||||
|
||||
import com.facebook.react.bridge.UiThreadUtil
|
||||
|
||||
/** An implementation of ChoreographerProvider that directly uses android.view.Choreographer. */
|
||||
public object AndroidChoreographerProvider : ChoreographerProvider {
|
||||
|
||||
private class AndroidChoreographer : ChoreographerProvider.Choreographer {
|
||||
private val instance: android.view.Choreographer = android.view.Choreographer.getInstance()
|
||||
|
||||
override public fun postFrameCallback(callback: android.view.Choreographer.FrameCallback) {
|
||||
instance.postFrameCallback(callback)
|
||||
}
|
||||
|
||||
override public fun removeFrameCallback(callback: android.view.Choreographer.FrameCallback) {
|
||||
instance.removeFrameCallback(callback)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic public fun getInstance(): AndroidChoreographerProvider = this
|
||||
|
||||
override public fun getChoreographer(): ChoreographerProvider.Choreographer {
|
||||
UiThreadUtil.assertOnUiThread()
|
||||
return AndroidChoreographer()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user