Skip to content

Commit

Permalink
Fix crash when destroying catalyst
Browse files Browse the repository at this point in the history
Reviewed By: fromcelticpark

Differential Revision: D6373275

fbshipit-source-id: c36b53f023800097b301d530250b05e5b2a4dfca
  • Loading branch information
Dmitry Zakharov authored and facebook-github-bot committed Nov 20, 2017
1 parent 0ff5760 commit f101566
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,14 @@ public List<ViewManager> createAllViewManagers(
}

public @Nullable ViewManager createViewManager(String viewManagerName) {
ReactApplicationContext context =
Assertions.assertNotNull((ReactApplicationContext) getCurrentReactContext());
ReactApplicationContext context;
synchronized (mReactContextLock) {
context = (ReactApplicationContext) getCurrentReactContext();
if (context == null || !context.hasActiveCatalystInstance()) {
return null;
}
}

synchronized (mPackages) {
for (ReactPackage reactPackage : mPackages) {
if (reactPackage instanceof ViewManagerOnDemandReactPackage) {
Expand All @@ -781,9 +787,15 @@ public List<ViewManager> createAllViewManagers(
return null;
}

public List<String> getViewManagerNames() {
ReactApplicationContext context =
Assertions.assertNotNull((ReactApplicationContext) getCurrentReactContext());
public @Nullable List<String> getViewManagerNames() {
ReactApplicationContext context;
synchronized(mReactContextLock) {
context = (ReactApplicationContext) getCurrentReactContext();
if (context == null || !context.hasActiveCatalystInstance()) {
return null;
}
}

synchronized (mPackages) {
Set<String> uniqueNames = new HashSet<>();
for (ReactPackage reactPackage : mPackages) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface ViewManagerOnDemandReactPackage {
*
* @param loadClasses defines if View Managers classes should be loaded or be avoided.
*/
List<String> getViewManagerNames(ReactApplicationContext reactContext, boolean loadClasses);
@Nullable List<String> getViewManagerNames(ReactApplicationContext reactContext, boolean loadClasses);
/**
* Creates and returns a ViewManager with a specific name {@param viewManagerName}. It's up to an
* implementing package how to interpret the name.
Expand Down

0 comments on commit f101566

Please sign in to comment.