Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import com.facebook.react.bridge.ReactNoCrashSoftException;

public class SurfaceMountingManager {
public static final String TAG = SurfaceMountingManager.class.getSimpleName();
Expand Down Expand Up @@ -338,7 +339,16 @@ public void addViewAt(final int parentTag, final int tag, final int index) {
return;
}

ViewState parentViewState = getViewState(parentTag);

ViewState parentViewState = getNullableViewState(parentTag);
if (parentViewState == null) {
// ReactSoftExceptionLogger.logSoftException(
// TAG,
// new ReactNoCrashSoftException(
// "Unable to find viewState for parent tag " + parentTag + ". Surface stopped: " + isStopped()));
return;
}

if (!(parentViewState.mView instanceof ViewGroup)) {
String message =
"Unable to add a view into a view that is not a ViewGroup. ParentTag: "
Expand All @@ -351,11 +361,22 @@ public void addViewAt(final int parentTag, final int tag, final int index) {
throw new IllegalStateException(message);
}
final ViewGroup parentView = (ViewGroup) parentViewState.mView;
ViewState viewState = getViewState(tag);
ViewState viewState = getNullableViewState(tag);
if (viewState == null) {
// ReactSoftExceptionLogger.logSoftException(
// TAG,
// new ReactNoCrashSoftException(
// "Unable to find viewState for tag " + tag + ". Surface stopped: " + isStopped()));
return;
}

final View view = viewState.mView;
if (view == null) {
throw new IllegalStateException(
"Unable to find view for viewState " + viewState + " and tag " + tag);
// ReactSoftExceptionLogger.logSoftException(
// TAG,
// new ReactNoCrashSoftException(
// "Unable to find view for viewState " + viewState + " and tag " + tag));
return;
}

// Display children before inserting
Expand Down Expand Up @@ -685,6 +706,9 @@ public void updateProps(int reactTag, ReadableMap props) {
}

ViewState viewState = getViewState(reactTag);
if (viewState == null) {
return;
}
viewState.mCurrentProps = new ReactStylesDiffMap(props);
View view = viewState.mView;

Expand All @@ -709,17 +733,20 @@ public void receiveCommand(int reactTag, int commandId, @Nullable ReadableArray
// disappearing. Throw `ReactNoCrashSoftException` so they're logged but don't crash in dev
// for now.
if (viewState == null) {
throw new RetryableMountingLayerException(
"Unable to find viewState for tag: [" + reactTag + "] for commandId: " + commandId);
return;
// throw new RetryableMountingLayerException(
// "Unable to find viewState for tag: [" + reactTag + "] for commandId: " + commandId);
}

if (viewState.mViewManager == null) {
throw new RetryableMountingLayerException("Unable to find viewManager for tag " + reactTag);
return;
// throw new RetryableMountingLayerException("Unable to find viewManager for tag " + reactTag);
}

if (viewState.mView == null) {
throw new RetryableMountingLayerException(
"Unable to find viewState view for tag " + reactTag);
return;
// throw new RetryableMountingLayerException(
// "Unable to find viewState view for tag " + reactTag);
}

viewState.mViewManager.receiveCommand(viewState.mView, commandId, commandArgs);
Expand All @@ -738,18 +765,21 @@ public void receiveCommand(
// disappearing. Throw `ReactNoCrashSoftException` so they're logged but don't crash in dev
// for now.
if (viewState == null) {
throw new RetryableMountingLayerException(
"Unable to find viewState for tag: " + reactTag + " for commandId: " + commandId);
return;
// throw new RetryableMountingLayerException(
// "Unable to find viewState for tag: " + reactTag + " for commandId: " + commandId);
}

if (viewState.mViewManager == null) {
throw new RetryableMountingLayerException(
"Unable to find viewState manager for tag " + reactTag);
return;
// throw new RetryableMountingLayerException(
// "Unable to find viewState manager for tag " + reactTag);
}

if (viewState.mView == null) {
throw new RetryableMountingLayerException(
"Unable to find viewState view for tag " + reactTag);
return;
// throw new RetryableMountingLayerException(
// "Unable to find viewState view for tag " + reactTag);
}

viewState.mViewManager.receiveCommand(viewState.mView, commandId, commandArgs);
Expand All @@ -761,15 +791,20 @@ public void sendAccessibilityEvent(int reactTag, int eventType) {
}

ViewState viewState = getViewState(reactTag);
if (viewState == null) {
return;
}

if (viewState.mViewManager == null) {
throw new RetryableMountingLayerException(
"Unable to find viewState manager for tag " + reactTag);
return;
// throw new RetryableMountingLayerException(
// "Unable to find viewState manager for tag " + reactTag);
}

if (viewState.mView == null) {
throw new RetryableMountingLayerException(
"Unable to find viewState view for tag " + reactTag);
return;
// throw new RetryableMountingLayerException(
// "Unable to find viewState view for tag " + reactTag);
}

viewState.mView.sendAccessibilityEvent(eventType);
Expand All @@ -790,6 +825,9 @@ public void updateLayout(
}

ViewState viewState = getViewState(reactTag);
if (viewState == null) {
return;
}
// Do not layout Root Views
if (viewState.mIsRoot) {
return;
Expand Down Expand Up @@ -834,7 +872,7 @@ public void updateLayout(

ViewState parentViewState = getViewState(parentTag);
IViewGroupManager<?> parentViewManager = null;
if (parentViewState.mViewManager != null) {
if (parentViewState != null && parentViewState.mViewManager != null) {
parentViewManager = (IViewGroupManager) parentViewState.mViewManager;
}
if (parentViewManager == null || !parentViewManager.needsCustomLayoutForChildren()) {
Expand All @@ -856,6 +894,9 @@ public void updatePadding(int reactTag, int left, int top, int right, int bottom
}

ViewState viewState = getViewState(reactTag);
if (viewState == null) {
return;
}
// Do not layout Root Views
if (viewState.mIsRoot) {
return;
Expand Down Expand Up @@ -887,6 +928,9 @@ public void updateOverflowInset(
}

ViewState viewState = getViewState(reactTag);
if (viewState == null) {
return;
}
// Do not layout Root Views
if (viewState.mIsRoot) {
return;
Expand All @@ -912,6 +956,9 @@ public void updateState(final int reactTag, @Nullable StateWrapper stateWrapper)
}

ViewState viewState = getViewState(reactTag);
if (viewState == null) {
return;
}

StateWrapper prevStateWrapper = viewState.mStateWrapper;
viewState.mStateWrapper = stateWrapper;
Expand Down Expand Up @@ -981,6 +1028,9 @@ public synchronized void setJSResponder(
}

ViewState viewState = getViewState(reactTag);
if (viewState == null) {
return;
}
View view = viewState.mView;
if (initialReactTag != reactTag && view instanceof ViewParent) {
// In this case, initialReactTag corresponds to a virtual/layout-only View, and we already
Expand Down Expand Up @@ -1096,11 +1146,14 @@ public View getView(int reactTag) {
return view;
}

private @NonNull ViewState getViewState(int tag) {
private @Nullable ViewState getViewState(int tag) {
ViewState viewState = mTagToViewState.get(tag);
if (viewState == null) {
throw new RetryableMountingLayerException(
"Unable to find viewState for tag " + tag + ". Surface stopped: " + isStopped());
return null;
// ReactSoftExceptionLogger.logSoftException(
// TAG,
// new ReactNoCrashSoftException(
// "Unable to find viewState for parent tag " + tag + ". Surface stopped: " + isStopped()));
}
return viewState;
}
Expand Down
Loading