Allow resolving view from FabricUIManager

Summary: Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D30043188

fbshipit-source-id: d8675754b29fb58a28a06777f602098da6dbc27f
This commit is contained in:
Pieter De Baets
2021-08-03 10:55:47 -07:00
committed by Facebook GitHub Bot
parent 228b8e5529
commit de255528e0
4 changed files with 31 additions and 2 deletions
@@ -117,6 +117,16 @@ public interface UIManager extends JSIModule, PerformanceCounter {
*/
void removeUIManagerEventListener(UIManagerListener listener);
/**
* Resolves a view based on its reactTag. Do not mutate properties on this view that are already
* managed by React, as there are no guarantees this changes will be preserved.
*
* @throws IllegalViewOperationException if tag could not be resolved.
* @param reactTag tag
* @return view if found
*/
View resolveView(int reactTag);
/**
* This method dispatches events from RN Android code to JS. The delivery of this event will not
* be queued in EventDispatcher class.
@@ -804,6 +804,14 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
doLeftAndRightSwapInRTL);
}
@Override
public View resolveView(int reactTag) {
UiThreadUtil.assertOnUiThread();
SurfaceMountingManager surfaceManager = mMountingManager.getSurfaceManagerForView(reactTag);
return surfaceManager == null ? null : surfaceManager.getView(reactTag);
}
@Override
public void receiveEvent(int reactTag, String eventName, @Nullable WritableMap params) {
receiveEvent(View.NO_ID, reactTag, eventName, params);
@@ -928,8 +928,18 @@ public class SurfaceMountingManager {
return viewState == null ? null : viewState.mEventEmitter;
}
@NonNull
private ViewState getViewState(int tag) {
@UiThread
public View getView(int reactTag) {
ViewState state = getNullableViewState(reactTag);
View view = state == null ? null : state.mView;
if (view == null) {
throw new IllegalViewOperationException(
"Trying to resolve view with tag " + reactTag + " which doesn't exist");
}
return view;
}
private @NonNull ViewState getViewState(int tag) {
ViewState viewState = mTagToViewState.get(tag);
if (viewState == null) {
throw new RetryableMountingLayerException("Unable to find viewState for tag " + tag);
@@ -955,6 +955,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule
public void onLowMemory() {}
}
@Override
public View resolveView(int tag) {
UiThreadUtil.assertOnUiThread();
return mUIImplementation