-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android: Add error description to Image onError callback (#22737)
Summary: fixes #19073 Changelog: ---------- [Android] [Fixed] - Add error description to Image onError callback Pull Request resolved: #22737 Differential Revision: D13676224 Pulled By: hramos fbshipit-source-id: 0dea7e97ae6517b8980ad02827f19d22cd3ef933
- Loading branch information
1 parent
527fc9d
commit 7795a67
Showing
7 changed files
with
134 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
46 changes: 46 additions & 0 deletions
46
ReactAndroid/src/androidTest/java/com/facebook/react/tests/ImageErrorTestCase.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.tests; | ||
|
||
import android.view.View; | ||
import com.facebook.react.testing.ReactAppInstrumentationTestCase; | ||
import com.facebook.react.testing.ReactInstanceSpecForTest; | ||
import com.facebook.react.testing.StringRecordingModule; | ||
|
||
/** | ||
* Simple test case to check that onError does not get called with undefined | ||
*/ | ||
public class ImageErrorTestCase extends ReactAppInstrumentationTestCase { | ||
|
||
private StringRecordingModule mStringRecordingModule; | ||
|
||
@Override | ||
protected String getReactApplicationKeyUnderTest() { | ||
return "ImageErrorTestApp"; | ||
} | ||
|
||
public void testErrorHasCause() throws Exception { | ||
assertNotNull(getViewByTestId("image-1")); | ||
assertNotNull(getViewByTestId("image-2")); | ||
assertNotNull(getViewByTestId("image-3")); | ||
|
||
Thread.sleep(3000); | ||
|
||
assertEquals(3, mStringRecordingModule.getCalls().size()); | ||
assertEquals("Got error: Unsupported uri scheme! Uri is: ", mStringRecordingModule.getCalls().get(0)); | ||
assertEquals("Got error: /does/not/exist: open failed: ENOENT (No such file or directory)", mStringRecordingModule.getCalls().get(1)); | ||
assertEquals("Got error: Unexpected HTTP code Response{protocol=http/1.1, code=404, message=Not Found, url=https://typo_error_facebook.github.io/react/logo-og.png}", mStringRecordingModule.getCalls().get(2)); | ||
} | ||
|
||
@Override | ||
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() { | ||
mStringRecordingModule = new StringRecordingModule(); | ||
return super.createReactInstanceSpecForTest() | ||
.addNativeModule(mStringRecordingModule); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const React = require('React'); | ||
const Image = require('Image'); | ||
const StyleSheet = require('StyleSheet'); | ||
const View = require('View'); | ||
|
||
const RecordingModule = require('NativeModules').Recording; | ||
|
||
class ImageErrorTestApp extends React.Component { | ||
onError = e => { | ||
RecordingModule.record('Got error: ' + e.nativeEvent.error); | ||
}; | ||
|
||
render() { | ||
// For some reason image-2 needs explicit height. Without it onError is not triggered. | ||
return ( | ||
<View> | ||
<Image | ||
testID="image-1" | ||
source={{uri: '/does/not/exist'}} | ||
onError={this.onError} | ||
/> | ||
<Image | ||
testID="image-2" | ||
source={{uri: 'file:///does/not/exist'}} | ||
style={styles.image} | ||
onError={this.onError} | ||
/> | ||
<Image | ||
testID="image-3" | ||
source={{ | ||
uri: 'https://TYPO_ERROR_facebook.github.io/react/logo-og.png', | ||
}} | ||
onError={this.onError} | ||
/> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
image: { | ||
height: 50, | ||
width: 50, | ||
}, | ||
}); | ||
|
||
module.exports = ImageErrorTestApp; |
This file contains 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
This file contains 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
This file contains 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