Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to override NetworkingModule? #15283

Closed
huanghaiyang opened this issue Jul 31, 2017 · 3 comments
Closed

How to override NetworkingModule? #15283

huanghaiyang opened this issue Jul 31, 2017 · 3 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@huanghaiyang
Copy link

huanghaiyang commented Jul 31, 2017

Is this a bug report?

No

Environment

react-native-cli: 2.0.1
react-native: 0.46.4
node: v7.10.0
npm: 5.0.1

  • Target Platform:
    Android

  • Development Operating System:
    win10

  • Build tools:
    Androind SDK 23

Steps to Reproduce

  1. create a new LazyPackage
  2. override getNativeModules
  3. override getReactModuleInfoProvider

my code below:
`
public class UEMPackage extends LazyReactPackage {

@Override
public List<ModuleSpec> getNativeModules(final ReactApplicationContext reactContext) {
    final List list = Arrays.asList(new NetworkInterceptorCreator() {
        @Override
        public Interceptor create() {
            return new UEMNetworkInterceptor();
        }
    });
    return Arrays.asList(
        new ModuleSpec(UEMModule.class, new Provider<NativeModule>(){
            @Override
            public NativeModule get() {
                return new UEMModule(reactContext);
            }
        }), new ModuleSpec(NetworkingModule.class, new Provider<NativeModule>() {
            @Override
            public NativeModule get() {
                return new NetworkingModule(reactContext, list);
            }
        })
    );
}



@Override
public ReactModuleInfoProvider getReactModuleInfoProvider() {
    return new ReactModuleInfoProvider() {
        @Override
        public Map<Class, ReactModuleInfo> getReactModuleInfos() {
            Map<Class, ReactModuleInfo> map = new HashMap<Class, ReactModuleInfo>();
            map.put(UEMModule.class, new ReactModuleInfo(UEMModule.MODULE_NAME, true, false, false));
            map.put(NetworkingModule.class, new ReactModuleInfo("Networking", true, false, false));
            return map;
        }
    };
}

@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
    return Collections.emptyList();
}

@Override
public List<ViewManager> createViewManagers(
        ReactApplicationContext reactContext) {
    return Collections.emptyList();
}

}
`

Expected Behavior

I want use XMLHttpRequest or fetch to requeset a resourse by custom NetworkingModule, but it happend a waring or error

Actual Behavior

image

@huanghaiyang huanghaiyang changed the title How to override Networking module? How to override NetworkingModule? Jul 31, 2017
@lostaloneesk
Copy link

lostaloneesk commented Jul 31, 2017

add

   @Override
    public boolean canOverrideExistingModule() {
        return true;
    }

in NetworkingModule

@huanghaiyang
Copy link
Author

@lostaloneesk I want to extends the NetworkModule , but it is a final class

public final class NetworkingModule extends ReactContextBaseJavaModule {}

@hramos
Copy link
Contributor

hramos commented Jul 31, 2017

This issue looks like a question that would be best asked on StackOverflow.

StackOverflow is amazing for Q&A: it has a reputation system, voting, the ability to mark a question as answered. Because of the reputation system it is likely the community will see and answer your question there. This also helps us use the GitHub bug tracker for bugs only.

Will close this as this is really a question that should be asked on StackOverflow.

@hramos hramos closed this as completed Jul 31, 2017
@facebook facebook locked as resolved and limited conversation to collaborators Jul 31, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants