Skip to content

Commit

Permalink
Allow resolving view from FabricUIManager
Browse files Browse the repository at this point in the history
Summary: Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D30043188

fbshipit-source-id: d8675754b29fb58a28a06777f602098da6dbc27f
  • Loading branch information
javache authored and facebook-github-bot committed Aug 3, 2021
1 parent 228b8e5 commit de25552
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ void updateRootLayoutSpecs(
*/
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,14 @@ public void updateRootLayoutSpecs(
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,18 @@ public void preallocateView(
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,7 @@ public void onConfigurationChanged(Configuration newConfig) {}
public void onLowMemory() {}
}

@Override
public View resolveView(int tag) {
UiThreadUtil.assertOnUiThread();
return mUIImplementation
Expand Down

0 comments on commit de25552

Please sign in to comment.