Created
February 5, 2018 06:03
-
-
Save shokimble/f735b19538d3cf47f13a49cde94e4ba2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package com.tshirtdesignernavredux; | |
import java.util.ArrayList; | |
import java.util.List; | |
import com.facebook.react.bridge.ReactApplicationContext; | |
import com.facebook.react.shell.MainReactPackage; | |
import com.facebook.react.bridge.ModuleSpec; | |
import com.facebook.react.modules.network.NetworkingModule; | |
import com.facebook.react.modules.network.NetworkingModuleUtils; | |
import com.facebook.react.bridge.NativeModule; | |
import javax.inject.Provider; | |
//this is to fix awfully messed up fetch() function in android | |
public class MyMainReactPackage extends MainReactPackage { | |
@Override | |
public List<ModuleSpec> getNativeModules(ReactApplicationContext context) { | |
List<ModuleSpec> nativeModules = super.getNativeModules(context); | |
return adjustModules(context, nativeModules); | |
} | |
private List<ModuleSpec> adjustModules(ReactApplicationContext context, List<ModuleSpec> moduleSpecs) { | |
ArrayList<ModuleSpec> modules = new ArrayList<>(moduleSpecs); | |
for (int i = 0; i < modules.size(); i++) { | |
ModuleSpec spec = modules.get(i); | |
if (spec.getType().equals(NetworkingModule.class)) { | |
modules.set(i, getCustomNetworkingModule(context)); | |
break; | |
} | |
} | |
return modules; | |
} | |
private ModuleSpec getCustomNetworkingModule(final ReactApplicationContext context) { | |
return new ModuleSpec(NetworkingModule.class, new Provider<NativeModule>() { | |
@Override | |
public NativeModule get() { | |
return NetworkingModuleUtils.createNetworkingModuleWithCustomClient(context); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment