mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-06-12 03:14:32 +08:00
Summary: fixes #19073 Changelog: ---------- [Android] [Fixed] - Add error description to Image onError callback Pull Request resolved: https://github.com/facebook/react-native/pull/22737 Differential Revision: D13676224 Pulled By: hramos fbshipit-source-id: 0dea7e97ae6517b8980ad02827f19d22cd3ef933
59 lines
1.3 KiB
JavaScript
59 lines
1.3 KiB
JavaScript
/**
|
|
* 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;
|