Created
December 24, 2017 14:27
-
-
Save guyca/5b2980e7b91bce1af807bf2ae94d635b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.support.annotation.Nullable; | |
import com.facebook.react.uimanager.NativeViewHierarchyManager; | |
import com.facebook.react.uimanager.UIBlock; | |
import com.facebook.react.uimanager.UIManagerModule; | |
import com.facebook.react.uimanager.UIViewOperationQueue; | |
/** | |
* ¯\_(ツ)_/¯ | |
*/ | |
public class ReactHacks { | |
/** | |
* {@link NativeViewHierarchyManager} is used to resolve a native view by RN tag ({@link NativeViewHierarchyManager#resolveView}). The only way of obtaining it is by | |
* posting {@link UIBlock} which can take a noticeable amount of time to execute. | |
*/ | |
@Nullable | |
public static NativeViewHierarchyManager getNativeViewHierarchyManager(UIManagerModule uiManager) { | |
try { | |
UIViewOperationQueue mOperationsQueue = (UIViewOperationQueue) ReflectionUtils.getDeclaredField(uiManager.getUIImplementation(), "mOperationsQueue"); | |
return (NativeViewHierarchyManager) ReflectionUtils.getDeclaredField(mOperationsQueue, "mNativeViewHierarchyManager"); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment