Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Demo/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default class App extends Component {
<Image
style={{width: width - 50, height: height - 100, backgroundColor: 'black'}}
source={{uri: this.state.uri}}
showLoading={true} //show loading
//pixels={{width: 1920, height: 1080}}
/>
</View>
Expand Down Expand Up @@ -81,7 +82,9 @@ export default class App extends Component {
/>
<Image
style={{width: width, height: height}}
source={{uri: 'http://p10.qhimg.com/t019e9cf51692f735be.jpg'}}/>
source={{uri: 'http://p10.qhimg.com/t019e9cf51692f735be.jpg'}}
/>

</ScrollView>
);
}
Expand Down
6 changes: 3 additions & 3 deletions Demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"start": "node_modules/react-native/packager/packager.sh"
},
"dependencies": {
"react": "15.2.1",
"react-native": "^0.29.2",
"react-native-transformable-image": "0.0.18"
"react-native-transformable-image": "0.0.18",
"react": "15.4.1",
"react-native": "0.39.2"
}
}
41 changes: 27 additions & 14 deletions library/TransformableImage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import React, { Component, PropTypes } from 'react';
import { Image } from 'react-native';
import { Image, ActivityIndicator,View } from 'react-native';

import ViewTransformer from 'react-native-view-transformer';

Expand All @@ -24,13 +24,15 @@ export default class TransformableImage extends Component {
enableTranslate: PropTypes.bool,
onSingleTapConfirmed: PropTypes.func,
onTransformGestureReleased: PropTypes.func,
onViewTransformed: PropTypes.func
onViewTransformed: PropTypes.func,
showLoading:PropTypes.bool
};

static defaultProps = {
enableTransform: true,
enableScale: true,
enableTranslate: true
enableTranslate: true,
showLoading:false
};

constructor(props) {
Expand Down Expand Up @@ -99,23 +101,34 @@ export default class TransformableImage extends Component {
contentAspectRatio={contentAspectRatio}
onLayout={this.onLayout.bind(this)}
style={this.props.style}>
<Image
{...this.props}
style={[this.props.style, {backgroundColor: 'transparent'}]}
resizeMode={'contain'}
onLoadStart={this.onLoadStart.bind(this)}
onLoad={this.onLoad.bind(this)}
capInsets={{left: 0.1, top: 0.1, right: 0.1, bottom: 0.1}} //on iOS, use capInsets to avoid image downsampling
/>
<Image
{...this.props}
style={[this.props.style, {backgroundColor: 'transparent'}]}
resizeMode={'contain'}
onLoadStart={this.onLoadStart.bind(this)}
onLoad={this.onLoad.bind(this)}
capInsets={{left: 0.1, top: 0.1, right: 0.1, bottom: 0.1}} //on iOS, use capInsets to avoid image downsampling
>
{/* loading activityIndicator (android & ios) before image onLoaded */}
{this.props.showLoading && !this.state.imageLoaded &&
<View style={{position: 'absolute',
justifyContent: 'center',
alignItems: 'center',
left: 0,
right: 0,
top: 0,
bottom: 0,}}>
<ActivityIndicator animating={!this.state.imageLoaded} size={"large"}/>
</View>
}
</Image>
</ViewTransformer>
);
}

onLoadStart(e) {
this.props.onLoadStart && this.props.onLoadStart(e);
this.setState({
imageLoaded: false
});
this.state.imageLoaded = false //solve (react-native 0.44.3 android) multiple update views
}

onLoad(e) {
Expand Down