Use context from view when resolving platform color if activity doesn't exist

Summary:
There are cases where the activity may not exist (such as for VRShell panel apps). In this case we will search for a view associated with a PropsAnimatedNode to get the context.

Changelog:
[Internal][Fixed] - Use context from view when resolving platform color if activity doesn't exist

Reviewed By: javache

Differential Revision: D34022882

fbshipit-source-id: c316935af1034ea770f3ef9334f77d6dc783fb27
This commit is contained in:
Genki Kondo
2022-02-08 11:42:27 -08:00
committed by Facebook GitHub Bot
parent cd79317672
commit 1a044123fc
2 changed files with 56 additions and 12 deletions
@@ -7,12 +7,14 @@
package com.facebook.react.animated;
import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.JavaOnlyMap;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.facebook.react.bridge.UIManager;
import com.facebook.react.uimanager.IllegalViewOperationException;
import com.facebook.react.uimanager.common.UIManagerType;
import com.facebook.react.uimanager.common.ViewUtil;
import java.util.HashMap;
@@ -116,6 +118,16 @@ import java.util.Map;
mUIManager.synchronouslyUpdateViewOnUIThread(mConnectedViewTag, mPropMap);
}
public View getConnectedView() {
try {
return mUIManager.resolveView(mConnectedViewTag);
} catch (IllegalViewOperationException ex) {
// resolveView throws an {@link IllegalViewOperationException} when the view doesn't exist
// (this can happen if the surface is being deallocated).
return null;
}
}
public String prettyPrint() {
return "PropsAnimatedNode["
+ mTag