-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rn-android | Add abstraction layer between ReactChoreographer and and…
…roid.view.Choreographer that allows substituting current implementation. Summary: We want to have an extension point for choreographer, so we can override default behavior and have either rate-limiting, or testing or other form of manual control. For all those cases allow substitution of choreographer that ReactChoreographer would use by default with a custom one. Changelog: [Android][Added] ReactChoreographer can now use an implementation substitution instead of relying on android.view.Choreographer directly. Reviewed By: javache Differential Revision: D50827975 fbshipit-source-id: 0fd78e1f4f96ffd832e5d8cdc6c805f9a9e272cf
- Loading branch information
1 parent
ae85be3
commit 751f7e9
Showing
7 changed files
with
83 additions
and
10 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
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
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
39 changes: 39 additions & 0 deletions
39
.../ReactAndroid/src/main/java/com/facebook/react/internal/AndroidChoreographerProvider.java
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,39 @@ | ||
/* | ||
* 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 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(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...-native/ReactAndroid/src/main/java/com/facebook/react/internal/ChoreographerProvider.java
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,30 @@ | ||
/* | ||
* 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; | ||
|
||
public interface ChoreographerProvider { | ||
/** | ||
* The interface to a android.view.Choreographer-like object, that can either use the | ||
* android.view.Choreographer or a mock one for testing purposes, or override built-in | ||
* android.view.Choreographer's behaviors. | ||
*/ | ||
interface Choreographer { | ||
|
||
/** Posts a frame callback to run on the next frame. */ | ||
void postFrameCallback(android.view.Choreographer.FrameCallback callback); | ||
/** Removes a previously posted frame callback. */ | ||
void removeFrameCallback(android.view.Choreographer.FrameCallback callback); | ||
} | ||
|
||
/** | ||
* Get an instance of Choreographer. | ||
* | ||
* @return An instance of Choreographer. | ||
*/ | ||
Choreographer getChoreographer(); | ||
} |
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
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