Skip to content

Commit

Permalink
Fix isRootVisible not working with non-Venice
Browse files Browse the repository at this point in the history
Summary:
## Context
```isRootViewVisible``` doesn't work as expected for non-Venice: when enter Marketplace tab, ```isRootViewVisible```  should returns true with Marketplace tab's rootViewTag, but it returns false.

## Root cause
```rootViewTag``` is added to "mVisibleRootTags" in "FbReactRootVisibilityTracker" when ```BaseFbReactFragment.onViewDidAppear()``` gets called, but ```BaseFbReactFragment.onViewDidAppear()``` is called earlier than when the ```rootViewTag``` is set.

## Fix
Move setRootViewTag to earlier when RootView is created instead of in startSurface or mounting.

Changelog:
[Android][Changed] - Move setRootViewTag to earlier when RootView is created

Reviewed By: RSNara

Differential Revision: D38586584

fbshipit-source-id: aec3ed37eb62289a19794e68b1a6b5ca213cb14a
  • Loading branch information
luluwu2032 authored and facebook-github-bot committed Aug 30, 2022
1 parent 8c882b4 commit 4d642a2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,6 @@ private void attachRootViewToInstance(final ReactRoot reactRoot) {
: Arguments.fromBundle(initialProperties),
reactRoot.getWidthMeasureSpec(),
reactRoot.getHeightMeasureSpec());
reactRoot.setRootViewTag(rootTag);
reactRoot.setShouldLogContentAppeared(true);
} else {
rootTag =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.ReactClippingProhibitedView;
import com.facebook.react.uimanager.ReactRoot;
import com.facebook.react.uimanager.ReactRootViewTagGenerator;
import com.facebook.react.uimanager.RootView;
import com.facebook.react.uimanager.RootViewUtil;
import com.facebook.react.uimanager.UIManagerHelper;
Expand Down Expand Up @@ -131,6 +132,7 @@ public ReactRootView(Context context, AttributeSet attrs, int defStyle) {
}

private void init() {
setRootViewTag(ReactRootViewTagGenerator.getNextRootViewTag());
setClipChildren(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ public <T extends View> int addRootView(
new IllegalViewOperationException(
"Do not call addRootView in Fabric; it is unsupported. Call startSurface instead."));

final int rootTag = ReactRootViewTagGenerator.getNextRootViewTag();
ReactRoot reactRootView = (ReactRoot) rootView;
final int rootTag = reactRootView.getRootViewTag();

ThemedReactContext reactContext =
new ThemedReactContext(
Expand Down Expand Up @@ -322,7 +322,7 @@ public <T extends View> int startSurface(
final WritableMap initialProps,
int widthMeasureSpec,
int heightMeasureSpec) {
final int rootTag = ReactRootViewTagGenerator.getNextRootViewTag();
final int rootTag = ((ReactRoot) rootView).getRootViewTag();
Context context = rootView.getContext();
ThemedReactContext reactContext =
new ThemedReactContext(mReactApplicationContext, context, moduleName, rootTag);
Expand Down

0 comments on commit 4d642a2

Please sign in to comment.