Skip to content

Commit

Permalink
Fix createObjectURL (#267)
Browse files Browse the repository at this point in the history
* Add tests for Blob

* Configure Blob on Android

* Use BlobModule instead of NativeBlobModule

Co-authored-by: André Costa Lima <[email protected]>
Co-authored-by: Kenny Meyer <[email protected]>
  • Loading branch information
3 people authored Mar 2, 2021
1 parent 1395226 commit 5985d7e
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 12 deletions.
9 changes: 9 additions & 0 deletions detox/rn-0.60/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ const App: () => React$Node = () => {
).href
}
</Text>
<Text testID="url-test-3">
{URL.createObjectURL({
data: {
blobId: 1,
offset: 32,
},
size: 64,
})}
</Text>
</SafeAreaView>
</>
);
Expand Down
5 changes: 5 additions & 0 deletions detox/rn-0.60/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<provider
android:name="com.facebook.react.modules.blob.BlobProvider"
android:authorities="@string/blob_provider_authority"
android:exported="false"
/>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
Expand Down
1 change: 1 addition & 0 deletions detox/rn-0.60/android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">Detox</string>
<string name="blob_provider_authority">com.detox.blob</string>
</resources>
6 changes: 6 additions & 0 deletions detox/rn-0.60/e2e/url-polyfill.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ describe('URL Polyfill', () => {
'https://facebook.github.io/react-native/img/header_logo.png',
);
});

it('should handle test 3', async () => {
await expect(element(by.id('url-test-3'))).toHaveText(
'blob:1?offset=32&size=64',
);
});
});
9 changes: 9 additions & 0 deletions detox/rn-0.61/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ const App: () => React$Node = () => {
).href
}
</Text>
<Text testID="url-test-3">
{URL.createObjectURL({
data: {
blobId: 1,
offset: 32,
},
size: 64,
})}
</Text>
</SafeAreaView>
</>
);
Expand Down
6 changes: 6 additions & 0 deletions detox/rn-0.61/e2e/url-polyfill.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ describe('URL Polyfill', () => {
'https://facebook.github.io/react-native/img/header_logo.png',
);
});

it('should handle test 3', async () => {
await expect(element(by.id('url-test-3'))).toHaveText(
'blob:1?offset=32&size=64',
);
});
});
9 changes: 9 additions & 0 deletions detox/rn-0.62/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ const App: () => React$Node = () => {
).href
}
</Text>
<Text testID="url-test-3">
{URL.createObjectURL({
data: {
blobId: 1,
offset: 32,
},
size: 64,
})}
</Text>
</SafeAreaView>
</>
);
Expand Down
6 changes: 6 additions & 0 deletions detox/rn-0.62/e2e/url-polyfill.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ describe('URL Polyfill', () => {
'https://facebook.github.io/react-native/img/header_logo.png',
);
});

it('should handle test 3', async () => {
await expect(element(by.id('url-test-3'))).toHaveText(
'blob:1?offset=32&size=64',
);
});
});
9 changes: 9 additions & 0 deletions detox/rn-0.63/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ const App: () => React$Node = () => {
).href
}
</Text>
<Text testID="url-test-3">
{URL.createObjectURL({
data: {
blobId: 1,
offset: 32,
},
size: 64,
})}
</Text>
</SafeAreaView>
</>
);
Expand Down
5 changes: 5 additions & 0 deletions detox/rn-0.63/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<provider
android:name="com.facebook.react.modules.blob.BlobProvider"
android:authorities="@string/blob_provider_authority"
android:exported="false"
/>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
Expand Down
1 change: 1 addition & 0 deletions detox/rn-0.63/android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">Detox</string>
<string name="blob_provider_authority">com.detox.blob</string>
</resources>
6 changes: 6 additions & 0 deletions detox/rn-0.63/e2e/url-polyfill.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ describe('URL Polyfill', () => {
'https://facebook.github.io/react-native/img/header_logo.png',
);
});

it('should handle test 3', async () => {
await expect(element(by.id('url-test-3'))).toHaveText(
'blob:1?offset=32&size=64',
);
});
});
19 changes: 7 additions & 12 deletions js/URL.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import {URL as whatwgUrl} from 'whatwg-url-without-unicode';

import {NativeModules} from 'react-native';

const {NativeBlobModule} = NativeModules;
import {URL as whatwgUrl} from 'whatwg-url-without-unicode';

let BLOB_URL_PREFIX = null;

if (
NativeBlobModule &&
typeof NativeBlobModule.getConstants().BLOB_URI_SCHEME === 'string'
) {
const constants = NativeBlobModule.getConstants();
BLOB_URL_PREFIX = constants.BLOB_URI_SCHEME + ':';
if (typeof constants.BLOB_URI_HOST === 'string') {
BLOB_URL_PREFIX += `//${constants.BLOB_URI_HOST}/`;
const {BlobModule} = NativeModules;

if (BlobModule && typeof BlobModule.BLOB_URI_SCHEME === 'string') {
BLOB_URL_PREFIX = BlobModule.BLOB_URI_SCHEME + ':';
if (typeof BlobModule.BLOB_URI_HOST === 'string') {
BLOB_URL_PREFIX += `//${BlobModule.BLOB_URI_HOST}/`;
}
}

Expand Down

0 comments on commit 5985d7e

Please sign in to comment.