-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix IllegalArgumentException when dismissing ReactModalHostView
Summary: This diff fixes an IllegalArgumentException when dismissing ReactModalHostView. I wasn't able to reproduce this error because this is likely created by a race condition. Reviewed By: axe-fb Differential Revision: D12916787 fbshipit-source-id: b071ffc4c251f2a613bb1270de005def56818376
- Loading branch information
Showing
4 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
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
37 changes: 37 additions & 0 deletions
37
ReactAndroid/src/main/java/com/facebook/react/views/common/ContextUtils.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.facebook.react.views.common; | ||
|
||
import android.content.Context; | ||
import android.content.ContextWrapper; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Class containing static methods involving manipulations of Contexts and their related subclasses. | ||
*/ | ||
public class ContextUtils { | ||
|
||
/** | ||
* Returns the nearest context in the chain (as defined by ContextWrapper.getBaseContext()) which | ||
* is an instance of the specified type, or null if one could not be found | ||
* | ||
* @param context Initial context | ||
* @param clazz Class instance to look for | ||
* @param <T> | ||
* @return the first context which is an instance of the specified class, or null if none exists | ||
*/ | ||
public static @Nullable <T> T findContextOfType( | ||
@Nullable Context context, Class<? extends T> clazz) { | ||
while (!(clazz.isInstance(context))) { | ||
if (context instanceof ContextWrapper) { | ||
Context baseContext = ((ContextWrapper) context).getBaseContext(); | ||
if (context == baseContext) { | ||
return null; | ||
} else { | ||
context = baseContext; | ||
} | ||
} else { | ||
return null; | ||
} | ||
} | ||
return (T) context; | ||
} | ||
} |
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
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