Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit 4863912

Browse files
Akshet Pandeyakshetpandey
Akshet Pandey
authored andcommitted
Upgrade to 0.62 and bump package to 0.5.0
- Upgrade stale packages - Upgrade example app to work with 0.62, it also now targets release RN instead of master making it easier for people to test - Update README to make using the package easier
1 parent 4f895ce commit 4863912

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4876
-6522
lines changed

.eslintrc.js

+96-69
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,99 @@
11
module.exports = {
2-
// Airbnb is the base, prettier is here so that eslint doesn't conflict with prettier
3-
extends: ['airbnb', 'prettier', 'prettier/react'],
4-
parser: '@typescript-eslint/parser',
5-
plugins: ['react', 'react-native', 'import', '@typescript-eslint'],
6-
rules: {
7-
'no-console': 'off',
8-
// Lines will be broken before binary operators
9-
'operator-linebreak': ['error', 'before'],
10-
// Allow imports from dev and peer dependencies
11-
'import/no-extraneous-dependencies': [
12-
'error',
13-
{ devDependencies: true, peerDependencies: true },
14-
],
15-
'react/jsx-filename-extension': ['error', { extensions: ['.tsx'] }],
16-
// This rule doesn't play nice with Prettier
17-
'react/jsx-one-expression-per-line': 'off',
18-
// This rule doesn't play nice with Prettier
19-
'react/jsx-wrap-multilines': 'off',
20-
// Remove this rule because we only destructure props, but never state
21-
'react/destructuring-assignment': 'off',
22-
'react/prop-types': 'off',
23-
'@typescript-eslint/adjacent-overload-signatures': 'error',
24-
'@typescript-eslint/array-type': ['error', {default: 'array'}],
25-
'@typescript-eslint/consistent-type-assertions': 'error',
26-
'@typescript-eslint/generic-type-naming': ['error', '^[a-zA-Z]+$'],
27-
'@typescript-eslint/no-array-constructor': 'error',
28-
'@typescript-eslint/no-empty-interface': 'error',
29-
'@typescript-eslint/no-explicit-any': 'error',
30-
'@typescript-eslint/no-extraneous-class': 'error',
31-
'@typescript-eslint/no-inferrable-types': 'error',
32-
'@typescript-eslint/no-misused-new': 'error',
33-
'@typescript-eslint/no-namespace': 'error',
34-
'@typescript-eslint/no-non-null-assertion': 'error',
35-
'@typescript-eslint/no-parameter-properties': 'error',
36-
'@typescript-eslint/no-this-alias': 'error',
37-
'@typescript-eslint/no-type-alias': [
38-
'error',
39-
{
40-
allowAliases: 'always',
41-
allowCallbacks: 'always',
42-
allowMappedTypes: 'always',
43-
},
44-
],
45-
'@typescript-eslint/no-unused-vars': [
46-
'error',
47-
{ ignoreRestSiblings: true },
48-
],
49-
'@typescript-eslint/prefer-namespace-keyword': 'error',
50-
'@typescript-eslint/type-annotation-spacing': 'error',
51-
},
52-
settings: {
53-
'import/resolver': {
54-
node: {
55-
extensions: [
56-
'.js',
57-
'.android.js',
58-
'.ios.js',
59-
'.jsx',
60-
'.android.jsx',
61-
'.ios.jsx',
62-
'.tsx',
63-
'.ts',
64-
'.android.tsx',
65-
'.android.ts',
66-
'.ios.tsx',
67-
'.ios.ts',
68-
],
69-
},
2+
root: true,
3+
// Airbnb is the base, prettier is here so that eslint doesn't conflict with prettier
4+
extends: ['airbnb', 'prettier', 'prettier/react'],
5+
parser: '@typescript-eslint/parser',
6+
plugins: ['react', 'react-native', 'import', '@typescript-eslint'],
7+
rules: {
8+
'no-console': 'off',
9+
'no-else-return': 'off',
10+
// Lines will be broken before binary operators
11+
'operator-linebreak': ['error', 'before'],
12+
// Allow imports from dev and peer dependencies
13+
'import/no-extraneous-dependencies': [
14+
'error',
15+
{ devDependencies: true, peerDependencies: true },
16+
],
17+
'react/jsx-filename-extension': ['error', { extensions: ['.tsx', '.jsx'] }],
18+
// This rule doesn't play nice with Prettier
19+
'react/jsx-one-expression-per-line': 'off',
20+
// This rule doesn't play nice with Prettier
21+
'react/jsx-wrap-multilines': 'off',
22+
// Remove this rule because we only destructure props, but never state
23+
'react/destructuring-assignment': 'off',
24+
'react/prop-types': 'off',
25+
'react/jsx-props-no-spreading': 'off',
26+
'react/static-property-placement': 'off',
27+
'react/state-in-constructor': 'off',
28+
'@typescript-eslint/adjacent-overload-signatures': 'error',
29+
'@typescript-eslint/array-type': [
30+
'error',
31+
{
32+
default: 'array',
33+
},
34+
],
35+
'@typescript-eslint/generic-type-naming': ['error', '^[a-zA-Z]+$'],
36+
'@typescript-eslint/no-array-constructor': 'error',
37+
'@typescript-eslint/no-empty-interface': 'error',
38+
'@typescript-eslint/no-explicit-any': 'error',
39+
'@typescript-eslint/no-extraneous-class': 'error',
40+
'@typescript-eslint/no-inferrable-types': 'error',
41+
'@typescript-eslint/no-misused-new': 'error',
42+
'@typescript-eslint/no-namespace': 'error',
43+
'@typescript-eslint/no-non-null-assertion': 'error',
44+
'@typescript-eslint/consistent-type-assertions': [
45+
'error',
46+
{
47+
assertionStyle: 'as',
48+
},
49+
],
50+
'@typescript-eslint/no-parameter-properties': 'error',
51+
'@typescript-eslint/no-this-alias': 'error',
52+
'@typescript-eslint/triple-slash-reference': [
53+
'error',
54+
{ path: 'never', types: 'never', lib: 'never' },
55+
],
56+
'@typescript-eslint/no-type-alias': [
57+
'error',
58+
{
59+
allowAliases: 'always',
60+
allowCallbacks: 'always',
61+
allowMappedTypes: 'always',
62+
},
63+
],
64+
'@typescript-eslint/no-unused-vars': [
65+
'error',
66+
{ ignoreRestSiblings: true },
67+
],
68+
'@typescript-eslint/consistent-type-definitions': [
69+
'error',
70+
'interface',
71+
],
72+
'@typescript-eslint/prefer-namespace-keyword': 'error',
73+
'@typescript-eslint/type-annotation-spacing': 'error',
74+
},
75+
settings: {
76+
'import/resolver': {
77+
node: {
78+
extensions: [
79+
'.js',
80+
'.android.js',
81+
'.ios.js',
82+
'.jsx',
83+
'.android.jsx',
84+
'.ios.jsx',
85+
'.tsx',
86+
'.ts',
87+
'.android.tsx',
88+
'.android.ts',
89+
'.ios.tsx',
90+
'.ios.ts',
91+
],
7092
},
7193
},
72-
};
94+
},
95+
globals: {
96+
fetch: false,
97+
HermesInternal: false,
98+
}
99+
};

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
# specific for windows script files
2+
*.bat text eol=crlf
3+
14
*.pbxproj -text

.npmignore

+3
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,6 @@ scripts/examples_postinstall.js
6969
tsconfig.json
7070
yarn.lock
7171
CODE_OF_CONDUCT.md
72+
lib/
73+
android/README.md
74+
src/

README.md

+58-39
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
1-
# react-native-cronet
1+
# react-native-cronet: Chrome's networking stack for your react-native application
2+
3+
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
4+
[![License](https://img.shields.io/github/license/akshetpandey/react-native-cronet)](https://github.com/akshetpandey/react-native-cronet)
5+
[![Known Vulnerabilities](https://snyk.io/test/github/akshetpandey/react-native-cronet/badge.svg?style=flat-square)](https://snyk.io/test/github/akshetpandey/react-native-cronet)
6+
[![NPM Version](https://img.shields.io/npm/v/react-native-cronet.svg?style=flat-square)](https://www.npmjs.com/package/react-native-cronet)
27

38
[Cronet](https://chromium.googlesource.com/chromium/src/+/master/components/cronet) is the [networking stack of Chromium](https://chromium.googlesource.com/chromium/src/+/master/net/docs/life-of-a-url-request.md) put into a library for use on mobile.
49
This is the same networking stack that is used in the Chrome browser by over a billion people.
510
It offers an easy-to-use, high performance, standards-compliant, and secure way to perform HTTP requests.
611
Cronet has support for both Android and iOS.
712

813
This module allows you to use the Cronet stack for your react native apps.
9-
Checkout default android vs cronet comparison when loading many images
14+
Checkout default react-native vs react-native-cronet comparison on android when loading many images on a high lateceny and packetloss network
1015

1116
![Preview](docs/CronetComp.gif)
1217

13-
## NOTE
14-
15-
For iOS, you will have to disable bitcode for your target.
18+
## Support Matrix
1619

17-
In XCode, in the project navigator, select your project. `Build Settings``Enable Bitcode``No`
20+
| React Native | react-native-cronet |
21+
| :----------: | :-----------------: |
22+
| >=0.62 | 0.5.0 |
23+
| >=0.60 | 0.4.0 |
24+
| <0.60 | unsupported |
1825

1926
## Getting started
2027

@@ -30,14 +37,21 @@ or using yarn:
3037
yarn add react-native-cronet
3138
```
3239

40+
### Automatic installation
41+
42+
`react-native-cronet` will link automatically using the autolink.
43+
44+
Make sure to run `pod install` in your iOS folder to get the `Cronet.framework` dependency included.
45+
3346
### Manual installation
3447

3548
#### iOS
3649

3750
1. In XCode, in the project navigator, right click `Libraries``Add Files to [your project's name]`
3851
2. Go to `node_modules``react-native-cronet` and add `RNCronet.xcodeproj`
3952
3. In XCode, in the project navigator, select your project. Add `libRNCronet.a` to your project's `Build Phases``Link Binary With Libraries`
40-
4. Run your project (`Cmd+R`)<
53+
4. Add `pod 'Cronet'` as a dependency in your iOS `Podfile` and run `pod install`, alternatively manaually link [Cronet.framework](https://github.com/akshetpandey/Cronet.framework/releases/latest) to your project
54+
5. Run your project (`Cmd+R`)<
4155

4256
#### Android
4357

@@ -56,27 +70,32 @@ yarn add react-native-cronet
5670
compile project(':react-native-cronet')
5771
```
5872

59-
## Usage
73+
## Basic Usage
74+
75+
### iOS
76+
77+
For iOS, you will have to disable bitcode for your target.
78+
79+
- In XCode, in the project navigator, select your project. `Build Settings``Enable Bitcode``No`
6080

61-
You don't have to do anything else for iOS. Cronet is used automatically for all react-native network request.
62-
For Android, in your `MainApplication.java`, you will have to change how RN initializes `FrescoModule` internally by doing this:
81+
### Android
82+
83+
For Android, in your `MainApplication.java`, you will have to change how RN initializes `FrescoModule` by adding these lines:
6384

6485
```java
65-
import com.akshetpandey.rncronet.RNCronetFrescoImagePipelineConfig;
66-
import com.facebook.imagepipeline.core.ImagePipelineConfig;
67-
import com.facebook.react.shell.MainPackageConfig;
86+
import com.akshetpandey.rncronet.RNCronetFrescoImagePipelineConfig; // <--- ADD THIS
87+
import com.facebook.imagepipeline.core.ImagePipelineConfig; // <--- ADD THIS
88+
import com.facebook.react.shell.MainPackageConfig; // <--- ADD THIS
6889

6990
public class MainApplication extends Application implements ReactApplication {
70-
7191
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
7292
//...
7393
@Override
7494
protected List<ReactPackage> getPackages() {
75-
ImagePipelineConfig pipelineConfig = RNCronetFrescoImagePipelineConfig.build(getApplicationContext());
76-
MainPackageConfig config = new MainPackageConfig.Builder().setFrescoConfig(pipelineConfig).build();
77-
List<ReactPackage> packages = new PackageList(this, config).getPackages();
95+
ImagePipelineConfig pipelineConfig = RNCronetFrescoImagePipelineConfig.build(getApplicationContext()); // <--- ADD THIS
96+
MainPackageConfig config = new MainPackageConfig.Builder().setFrescoConfig(pipelineConfig).build(); // <--- ADD THIS
97+
List<ReactPackage> packages = new PackageList(this, config).getPackages(); // <--- CHANGE THIS TO INCLUDE CONFIG
7898
// Packages that cannot be autolinked yet can be added manually here, for example:
79-
// packages.add(new RNCronetNetworkingPackage());
8099
return packages;
81100
}
82101
//...
@@ -89,12 +108,13 @@ public class MainApplication extends Application implements ReactApplication {
89108
Although the library is capable of automatically configuring itself, you can also initialize the cronet engine based on your use case.
90109
One reason to do this would be to provide QUIC hints for your domain that you know supports QUIC, or to customize cache size and type.
91110

111+
**Make sure this is done before the react native bridge gets initialized.**
112+
92113
Nothing needs to be done on the JS side.
93114

94115
### iOS
95116

96-
Somewhere in your app startup flow, ex. in AppDelegate, you can install an initializer block that can initialize the library for your requirements.
97-
Make sure this is done before the react native bridge gets initialized.
117+
Somewhere in your app startup flow, ex. in `AppDelegate.m`, you can install an initializer block that can initialize the library for your requirements.
98118

99119
iOS documentation for the cronet library initialization is sparse, but you can look at [Cronet/Cronet.h](https://chromium.googlesource.com/chromium/src/+/master/components/cronet/ios/Cronet.h)
100120

@@ -124,33 +144,32 @@ iOS documentation for the cronet library initialization is sparse, but you can l
124144

125145
### Android
126146

127-
Somewhere in your app startup flow, ex in MainActivity, you can install an initializer block that can initialize the library for your requirements.
128-
Make sure this is done before the react native bridge gets initialized.
147+
Somewhere in your app startup flow, ex in `MainActivity.java`, you can install an initializer block that can initialize the library for your requirements.
129148

130149
Android documentation for the cronet library initialization is available in [CronetEngine.Builder](https://developer.android.com/guide/topics/connectivity/cronet/reference/org/chromium/net/CronetEngine.Builder.html)
131150

132151
```java
133152
import org.chromium.net.CronetEngine;
134153

135154
public class MainActivity extends ReactActivity {
136-
@Override
137-
protected void onCreate(Bundle savedInstanceState) {
155+
@Override
156+
protected void onCreate(Bundle savedInstanceState) {
138157
// ...
139-
RNCronetNetworkingModule.setCustomCronetBuilder(context -> {
140-
File cacheDir = new File(context.getCacheDir(), "cronet-cache");
141-
cacheDir.mkdirs();
142-
CronetEngine cronetEngine = new CronetEngine.Builder(context)
143-
.enableBrotli(true)
144-
.enableHttp2(true)
145-
.enableQuic(true)
146-
.setStoragePath(cacheDir.getAbsolutePath())
147-
.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 10 * 1024 * 1024)
148-
.addQuicHint("www.google.com", 443, 443)
149-
.build();
150-
URL.setURLStreamHandlerFactory(cronetEngine.createURLStreamHandlerFactory());
151-
return cronetEngine;
152-
});
158+
RNCronetNetworkingModule.setCustomCronetBuilder(context -> {
159+
File cacheDir = new File(context.getCacheDir(), "cronet-cache");
160+
cacheDir.mkdirs();
161+
CronetEngine cronetEngine = new CronetEngine.Builder(context)
162+
.enableBrotli(true)
163+
.enableHttp2(true)
164+
.enableQuic(true)
165+
.setStoragePath(cacheDir.getAbsolutePath())
166+
.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 10 * 1024 * 1024)
167+
.addQuicHint("www.google.com", 443, 443)
168+
.build();
169+
URL.setURLStreamHandlerFactory(cronetEngine.createURLStreamHandlerFactory());
170+
return cronetEngine;
171+
});
153172
// ...
154-
}
173+
}
155174
}
156175
```

0 commit comments

Comments
 (0)