mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-04 02:56:42 +00:00
Image: fix example code
This commit is contained in:
@@ -75,7 +75,7 @@ const { Component, PropTypes } = React;
|
|||||||
class Avatar extends Component {
|
class Avatar extends Component {
|
||||||
constructor(props, context) {
|
constructor(props, context) {
|
||||||
super(props, context)
|
super(props, context)
|
||||||
this.state = { isLoaded: false }
|
this.state = { loading: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
@@ -90,12 +90,12 @@ class Avatar extends Component {
|
|||||||
|
|
||||||
_onLoad(e) {
|
_onLoad(e) {
|
||||||
console.log('Avatar.onLoad', e)
|
console.log('Avatar.onLoad', e)
|
||||||
this.setState({ isLoaded: true })
|
this.setState({ loading: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { size, testID, user } = this.props
|
const { size, testID, user } = this.props
|
||||||
const { isLoaded } = this.state
|
const loadingStyle = this.state.loading ? { styles.loading } : { }
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Image
|
<Image
|
||||||
@@ -104,18 +104,20 @@ class Avatar extends Component {
|
|||||||
onLoad={this._onLoad.bind(this)}
|
onLoad={this._onLoad.bind(this)}
|
||||||
resizeMode='cover'
|
resizeMode='cover'
|
||||||
source={{ uri: user.avatarUrl }}
|
source={{ uri: user.avatarUrl }}
|
||||||
style={ ...style.base, ...style[size], ...style[isLoaded] }
|
style={{ ...styles.base, ...styles[size], ...loadingStyle }}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const style = {
|
const styles = {
|
||||||
base: {
|
base: {
|
||||||
borderColor: 'white',
|
borderColor: 'white',
|
||||||
borderRadius: '5px',
|
borderRadius: '5px',
|
||||||
borderWidth: '5px',
|
borderWidth: '5px'
|
||||||
opacity: 0.5,
|
},
|
||||||
|
loading: {
|
||||||
|
opacity: 0.5
|
||||||
},
|
},
|
||||||
small: {
|
small: {
|
||||||
height: '32px',
|
height: '32px',
|
||||||
@@ -129,8 +131,5 @@ const style = {
|
|||||||
height: '64px',
|
height: '64px',
|
||||||
width: '64px'
|
width: '64px'
|
||||||
}
|
}
|
||||||
isLoaded: {
|
|
||||||
opacity: 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ const imageStyleKeys = Object.keys(ImageStylePropTypes)
|
|||||||
const styles = {
|
const styles = {
|
||||||
initial: {
|
initial: {
|
||||||
alignSelf: 'flex-start',
|
alignSelf: 'flex-start',
|
||||||
|
backgroundColor: 'lightgray',
|
||||||
backgroundPosition: 'center',
|
backgroundPosition: 'center',
|
||||||
backgroundRepeat: 'no-repeat',
|
backgroundRepeat: 'no-repeat',
|
||||||
backgroundSize: '100% 100%'
|
backgroundSize: '100% 100%'
|
||||||
@@ -112,8 +113,8 @@ class Image extends React.Component {
|
|||||||
|
|
||||||
this._destroyImageLoader()
|
this._destroyImageLoader()
|
||||||
this.setState({ status: STATUS_ERRORED })
|
this.setState({ status: STATUS_ERRORED })
|
||||||
if (onError) onError(event)
|
|
||||||
this._onLoadEnd()
|
this._onLoadEnd()
|
||||||
|
if (onError) onError(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
_onLoad(e) {
|
_onLoad(e) {
|
||||||
@@ -122,8 +123,8 @@ class Image extends React.Component {
|
|||||||
|
|
||||||
this._destroyImageLoader()
|
this._destroyImageLoader()
|
||||||
this.setState({ status: STATUS_LOADED })
|
this.setState({ status: STATUS_LOADED })
|
||||||
if (onLoad) onLoad(event)
|
|
||||||
this._onLoadEnd()
|
this._onLoadEnd()
|
||||||
|
if (onLoad) onLoad(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
_onLoadEnd() {
|
_onLoadEnd() {
|
||||||
|
|||||||
Reference in New Issue
Block a user