-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Allow app to init an OkHttpClientProvider.IProvider with custom settings(FrescoModule and NetworkingModule) #14675
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
…tings(FrescoModule and NetworkingModule)
…tings(FrescoModule and NetworkingModule)
@thotegowda Good job. This solution is more lightweight. |
@leon087 I tried to find reviewers for this pull request and wanted to ping them to take another look. However, based on the blame information for the files in this pull request I couldn't find any reviewers. This sometimes happens when the files in the pull request are new or don't exist on master anymore. Is this pull request still relevant? If yes could you please rebase? In case you know who has context on this code feel free to mention them in a comment (one person is fine). Thanks for reading and hope you will continue contributing to the project. |
good job , Hope to take effect as soon as possible @leon087 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions. |
Summary: Prior to 0a71f48, users could customise the OkHttp client used by React Native on Android by calling replaceOkHttpClient in OkHttpClientProvider. This functionality has a variety of legitimate applications from changing connection timeouts or pool size to Stetho integration. The challenge is to add back support for replacing the client without causing a breaking change or reintroducing the problems olegbl sought to address in his original commit. Introducing a client factory archives these aims, it adds a new, backwards compatible interface and is called each time a client is requested rather than re-using the same instance (unless you explicitly want this behaviour, in which case you could replicate it using a static class property inside your custom factory). A number of PRs have been opened to add this functionality: #14675, #14068. I don't have a lot of Java experience so I'm open to better/more idiomatic ways to achieve this :) Create React Native application and set a custom factory in the constructor, e.g. `OkHttpClientProvider.setOkHttpClientFactory(new CustomNetworkModule());` Where a custom factory would look like: ``` class CustomNetworkModule implements OkHttpClientFactory { public OkHttpClient createNewNetworkModuleClient() { return new OkHttpClient.Builder().build(); } } ``` Remove the existing replace client method to prevent accident use and alert existing users that its functionality has changed: #16972 [Android] [Minor] [Networking] - | Provide interface for customising the OkHttp client used by React Native | Closes #17237 Differential Revision: D6837734 Pulled By: hramos fbshipit-source-id: 81e63df7716e6f9039ea12e99233f6336c6dd7ef
Summary: Prior to 0a71f48, users could customise the OkHttp client used by React Native on Android by calling replaceOkHttpClient in OkHttpClientProvider. This functionality has a variety of legitimate applications from changing connection timeouts or pool size to Stetho integration. The challenge is to add back support for replacing the client without causing a breaking change or reintroducing the problems olegbl sought to address in his original commit. Introducing a client factory archives these aims, it adds a new, backwards compatible interface and is called each time a client is requested rather than re-using the same instance (unless you explicitly want this behaviour, in which case you could replicate it using a static class property inside your custom factory). A number of PRs have been opened to add this functionality: facebook#14675, facebook#14068. I don't have a lot of Java experience so I'm open to better/more idiomatic ways to achieve this :) Create React Native application and set a custom factory in the constructor, e.g. `OkHttpClientProvider.setOkHttpClientFactory(new CustomNetworkModule());` Where a custom factory would look like: ``` class CustomNetworkModule implements OkHttpClientFactory { public OkHttpClient createNewNetworkModuleClient() { return new OkHttpClient.Builder().build(); } } ``` Remove the existing replace client method to prevent accident use and alert existing users that its functionality has changed: facebook#16972 [Android] [Minor] [Networking] - | Provide interface for customising the OkHttp client used by React Native | Closes facebook#17237 Differential Revision: D6837734 Pulled By: hramos fbshipit-source-id: 81e63df7716e6f9039ea12e99233f6336c6dd7ef
Summary: Prior to 0a71f48, users could customise the OkHttp client used by React Native on Android by calling replaceOkHttpClient in OkHttpClientProvider. This functionality has a variety of legitimate applications from changing connection timeouts or pool size to Stetho integration. The challenge is to add back support for replacing the client without causing a breaking change or reintroducing the problems olegbl sought to address in his original commit. Introducing a client factory archives these aims, it adds a new, backwards compatible interface and is called each time a client is requested rather than re-using the same instance (unless you explicitly want this behaviour, in which case you could replicate it using a static class property inside your custom factory). A number of PRs have been opened to add this functionality: facebook#14675, facebook#14068. I don't have a lot of Java experience so I'm open to better/more idiomatic ways to achieve this :) Create React Native application and set a custom factory in the constructor, e.g. `OkHttpClientProvider.setOkHttpClientFactory(new CustomNetworkModule());` Where a custom factory would look like: ``` class CustomNetworkModule implements OkHttpClientFactory { public OkHttpClient createNewNetworkModuleClient() { return new OkHttpClient.Builder().build(); } } ``` Remove the existing replace client method to prevent accident use and alert existing users that its functionality has changed: facebook#16972 [Android] [Minor] [Networking] - | Provide interface for customising the OkHttp client used by React Native | Closes facebook#17237 Differential Revision: D6837734 Pulled By: hramos fbshipit-source-id: 81e63df7716e6f9039ea12e99233f6336c6dd7ef
Motivation
This allows app to init an OkHttpClientProvider.IProvider with custom settings(FrescoModule and NetworkingModule).