2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2015-03-28 05:18:47 +00:00
|
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
|
|
* evaluation purposes only.
|
2015-03-23 20:35:08 +00:00
|
|
|
*
|
2015-03-28 05:18:47 +00:00
|
|
|
* Facebook reserves all rights not expressly granted.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2015-03-24 20:25:39 +00:00
|
|
|
*
|
|
|
|
* @flow
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var React = require('react-native');
|
|
|
|
var {
|
|
|
|
Image,
|
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
View,
|
2015-07-14 20:56:55 +00:00
|
|
|
ActivityIndicatorIOS
|
2015-02-20 04:10:52 +00:00
|
|
|
} = React;
|
|
|
|
|
2015-10-19 16:04:54 +00:00
|
|
|
var base64Icon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEsAAABLCAQAAACSR7JhAAADtUlEQVR4Ac3YA2Bj6QLH0XPT1Fzbtm29tW3btm3bfLZtv7e2ObZnms7d8Uw098tuetPzrxv8wiISrtVudrG2JXQZ4VOv+qUfmqCGGl1mqLhoA52oZlb0mrjsnhKpgeUNEs91Z0pd1kvihA3ULGVHiQO2narKSHKkEMulm9VgUyE60s1aWoMQUbpZOWE+kaqs4eLEjdIlZTcFZB0ndc1+lhB1lZrIuk5P2aib1NBpZaL+JaOGIt0ls47SKzLC7CqrlGF6RZ09HGoNy1lYl2aRSWL5GuzqWU1KafRdoRp0iOQEiDzgZPnG6DbldcomadViflnl/cL93tOoVbsOLVM2jylvdWjXolWX1hmfZbGR/wjypDjFLSZIRov09BgYmtUqPQPlQrPapecLgTIy0jMgPKtTeob2zWtrGH3xvjUkPCtNg/tm1rjwrMa+mdUkPd3hWbH0jArPGiU9ufCsNNWFZ40wpwn+62/66R2RUtoso1OB34tnLOcy7YB1fUdc9e0q3yru8PGM773vXsuZ5YIZX+5xmHwHGVvlrGPN6ZSiP1smOsMMde40wKv2VmwPPVXNut4sVpUreZiLBHi0qln/VQeI/LTMYXpsJtFiclUN+5HVZazim+Ky+7sAvxWnvjXrJFneVtLWLyPJu9K3cXLWeOlbMTlrIelbMDlrLenrjEQOtIF+fuI9xRp9ZBFp6+b6WT8RrxEpdK64BuvHgDk+vUy+b5hYk6zfyfs051gRoNO1usU12WWRWL73/MMEy9pMi9qIrR4ZpV16Rrvduxazmy1FSvuFXRkqTnE7m2kdb5U8xGjLw/spRr1uTov4uOgQE+0N/DvFrG/Jt7i/FzwxbA9kDanhf2w+t4V97G8lrT7wc08aA2QNUkuTfW/KimT01wdlfK4yEw030VfT0RtZbzjeMprNq8m8tnSTASrTLti64oBNdpmMQm0eEwvfPwRbUBywG5TzjPCsdwk3IeAXjQblLCoXnDVeoAz6SfJNk5TTzytCNZk/POtTSV40NwOFWzw86wNJRpubpXsn60NJFlHeqlYRbslqZm2jnEZ3qcSKgm0kTli3zZVS7y/iivZTweYXJ26Y+RTbV1zh3hYkgyFGSTKPfRVbRqWWVReaxYeSLarYv1Qqsmh1s95S7G+eEWK0f3jYKTbV6bOwepjfhtafsvUsqrQvrGC8YhmnO9cSCk3yuY984F1vesdHYhWJ5FvASlacshUsajFt2mUM9pqzvKGcyNJW0arTKN1GGGzQlH0tXwLDgQTurS8eIQAAAABJRU5ErkJggg==';
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
var ImageCapInsetsExample = require('./ImageCapInsetsExample');
|
|
|
|
|
2015-11-26 01:06:59 +00:00
|
|
|
var NetworkImageCallbackExample = React.createClass({
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
events: [],
|
2015-12-02 03:09:01 +00:00
|
|
|
mountTime: new Date(),
|
2015-11-26 01:06:59 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
|
|
this.setState({mountTime: new Date()});
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
var { mountTime } = this.state;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<Image
|
|
|
|
source={this.props.source}
|
|
|
|
style={[styles.base, {overflow: 'visible'}]}
|
|
|
|
onLoadStart={() => this._loadEventFired(`✔ onLoadStart (+${new Date() - mountTime}ms)`)}
|
|
|
|
onLoad={() => this._loadEventFired(`✔ onLoad (+${new Date() - mountTime}ms)`)}
|
|
|
|
onLoadEnd={() => this._loadEventFired(`✔ onLoadEnd (+${new Date() - mountTime}ms)`)}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Text style={{marginTop: 20}}>
|
|
|
|
{this.state.events.join('\n')}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
_loadEventFired(event) {
|
|
|
|
this.setState((state) => {
|
|
|
|
return state.events = [...state.events, event];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-07-14 20:56:55 +00:00
|
|
|
var NetworkImageExample = React.createClass({
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
error: false,
|
2015-07-15 20:17:13 +00:00
|
|
|
loading: false,
|
2015-07-14 20:56:55 +00:00
|
|
|
progress: 0
|
|
|
|
};
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
var loader = this.state.loading ?
|
|
|
|
<View style={styles.progress}>
|
|
|
|
<Text>{this.state.progress}%</Text>
|
|
|
|
<ActivityIndicatorIOS style={{marginLeft:5}}/>
|
|
|
|
</View> : null;
|
|
|
|
return this.state.error ?
|
|
|
|
<Text>{this.state.error}</Text> :
|
|
|
|
<Image
|
|
|
|
source={this.props.source}
|
|
|
|
style={[styles.base, {overflow: 'visible'}]}
|
2015-07-15 20:17:13 +00:00
|
|
|
onLoadStart={(e) => this.setState({loading: true})}
|
|
|
|
onError={(e) => this.setState({error: e.nativeEvent.error, loading: false})}
|
|
|
|
onProgress={(e) => this.setState({progress: Math.round(100 * e.nativeEvent.loaded / e.nativeEvent.total)})}
|
|
|
|
onLoad={() => this.setState({loading: false, error: false})}>
|
2015-07-14 20:56:55 +00:00
|
|
|
{loader}
|
|
|
|
</Image>;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
Added getImageSize method
Summary:
public
This diff adds a `getSize()` method to `Image` to retrieve the width and height of an image prior to displaying it. This is useful when working with images from uncontrolled sources, and has been a much-requested feature.
In order to retrieve the image dimensions, the image may first need to be loaded or downloaded, after which it will be cached. This means that in principle you could use this method to preload images, however it is not optimized for that purpose, and may in future be implemented in a way that does not fully load/download the image data.
A fully supported way to preload images will be provided in a future diff.
The API (separate success and failure callbacks) is far from ideal, but until we agree on a unified standard, this was the most conventional way I could think of to implement it. If it returned a promise or something similar, it would be unique among all such APIS in the framework.
Please note that this has been a long time coming, in part due to much bikeshedding about what the API should look like, so while it's not unlikely that the API may change in future, I think having *some* way to do this is better than waiting until we can define the "perfect" way.
Reviewed By: vjeux
Differential Revision: D2797365
fb-gh-sync-id: 11eb1b8547773b1f8be0bc55ddf6dfedebf7fc0a
2016-01-01 02:50:26 +00:00
|
|
|
var ImageSizeExample = React.createClass({
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
width: 0,
|
|
|
|
height: 0,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
componentDidMount: function() {
|
|
|
|
Image.getSize(this.props.source.uri, (width, height) => {
|
|
|
|
this.setState({width, height});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={{flexDirection: 'row'}}>
|
|
|
|
<Image
|
|
|
|
style={{
|
|
|
|
width: 60,
|
|
|
|
height: 60,
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
marginRight: 10,
|
|
|
|
}}
|
|
|
|
source={this.props.source} />
|
|
|
|
<Text>
|
|
|
|
Actual dimensions:{'\n'}
|
|
|
|
Width: {this.state.width}, Height: {this.state.height}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2015-06-22 16:43:30 +00:00
|
|
|
exports.displayName = (undefined: ?string);
|
2015-02-20 04:10:52 +00:00
|
|
|
exports.framework = 'React';
|
|
|
|
exports.title = '<Image>';
|
|
|
|
exports.description = 'Base component for displaying different types of images.';
|
|
|
|
|
|
|
|
exports.examples = [
|
|
|
|
{
|
|
|
|
title: 'Plain Network Image',
|
|
|
|
description: 'If the `source` prop `uri` property is prefixed with ' +
|
|
|
|
'"http", then it will be downloaded from the network.',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<Image
|
|
|
|
source={{uri: 'http://facebook.github.io/react/img/logo_og.png'}}
|
|
|
|
style={styles.base}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Plain Static Image',
|
2016-01-27 21:21:42 +00:00
|
|
|
description: 'Static assets should be placed in the source code tree, and ' +
|
|
|
|
'required in the same way as JavaScript modules.',
|
2015-02-20 04:10:52 +00:00
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={styles.horizontal}>
|
2016-01-27 21:21:42 +00:00
|
|
|
<Image source={require('./uie_thumb_normal.png')} style={styles.icon} />
|
|
|
|
<Image source={require('./uie_thumb_selected.png')} style={styles.icon} />
|
|
|
|
<Image source={require('./uie_comment_normal.png')} style={styles.icon} />
|
|
|
|
<Image source={require('./uie_comment_highlighted.png')} style={styles.icon} />
|
2015-02-20 04:10:52 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
2015-11-26 01:06:59 +00:00
|
|
|
{
|
|
|
|
title: 'Image Loading Events',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<NetworkImageCallbackExample source={{uri: 'http://facebook.github.io/origami/public/images/blog-hero.jpg?r=1'}}/>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
2015-07-14 20:56:55 +00:00
|
|
|
{
|
|
|
|
title: 'Error Handler',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<NetworkImageExample source={{uri: 'http://TYPO_ERROR_facebook.github.io/react/img/logo_og.png'}} />
|
|
|
|
);
|
|
|
|
},
|
2015-09-01 15:51:46 +00:00
|
|
|
platform: 'ios',
|
2015-07-14 20:56:55 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Image Download Progress',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<NetworkImageExample source={{uri: 'http://facebook.github.io/origami/public/images/blog-hero.jpg?r=1'}}/>
|
|
|
|
);
|
|
|
|
},
|
2015-09-01 15:51:46 +00:00
|
|
|
platform: 'ios',
|
2015-07-14 20:56:55 +00:00
|
|
|
},
|
2015-02-20 04:10:52 +00:00
|
|
|
{
|
|
|
|
title: 'Border Color',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={styles.horizontal}>
|
|
|
|
<Image
|
|
|
|
source={smallImage}
|
|
|
|
style={[
|
|
|
|
styles.base,
|
|
|
|
styles.background,
|
|
|
|
{borderWidth: 3, borderColor: '#f099f0'}
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Border Width',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={styles.horizontal}>
|
|
|
|
<Image
|
|
|
|
source={smallImage}
|
|
|
|
style={[
|
|
|
|
styles.base,
|
|
|
|
styles.background,
|
|
|
|
{borderWidth: 5, borderColor: '#f099f0'}
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Border Radius',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={styles.horizontal}>
|
|
|
|
<Image
|
2015-09-01 15:51:46 +00:00
|
|
|
style={[styles.base, {borderRadius: 5}]}
|
|
|
|
source={fullImage}
|
2015-02-20 04:10:52 +00:00
|
|
|
/>
|
|
|
|
<Image
|
2015-09-01 15:51:46 +00:00
|
|
|
style={[styles.base, styles.leftMargin, {borderRadius: 19}]}
|
|
|
|
source={fullImage}
|
2015-02-20 04:10:52 +00:00
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Background Color',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={styles.horizontal}>
|
|
|
|
<Image source={smallImage} style={styles.base} />
|
|
|
|
<Image
|
|
|
|
style={[
|
|
|
|
styles.base,
|
|
|
|
styles.leftMargin,
|
|
|
|
{backgroundColor: 'rgba(0, 0, 100, 0.25)'}
|
|
|
|
]}
|
|
|
|
source={smallImage}
|
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
style={[styles.base, styles.leftMargin, {backgroundColor: 'red'}]}
|
|
|
|
source={smallImage}
|
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
style={[styles.base, styles.leftMargin, {backgroundColor: 'black'}]}
|
|
|
|
source={smallImage}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Opacity',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={styles.horizontal}>
|
|
|
|
<Image
|
|
|
|
style={[styles.base, {opacity: 1}]}
|
|
|
|
source={fullImage}
|
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
style={[styles.base, styles.leftMargin, {opacity: 0.8}]}
|
|
|
|
source={fullImage}
|
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
style={[styles.base, styles.leftMargin, {opacity: 0.6}]}
|
|
|
|
source={fullImage}
|
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
style={[styles.base, styles.leftMargin, {opacity: 0.4}]}
|
|
|
|
source={fullImage}
|
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
style={[styles.base, styles.leftMargin, {opacity: 0.2}]}
|
|
|
|
source={fullImage}
|
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
style={[styles.base, styles.leftMargin, {opacity: 0}]}
|
|
|
|
source={fullImage}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Nesting',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<Image
|
|
|
|
style={{width: 60, height: 60, backgroundColor: 'transparent'}}
|
|
|
|
source={fullImage}>
|
|
|
|
<Text style={styles.nestedText}>
|
|
|
|
React
|
|
|
|
</Text>
|
|
|
|
</Image>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Tint Color',
|
|
|
|
description: 'The `tintColor` style prop changes all the non-alpha ' +
|
|
|
|
'pixels to the tint color.',
|
|
|
|
render: function() {
|
|
|
|
return (
|
2015-07-13 17:30:34 +00:00
|
|
|
<View>
|
|
|
|
<View style={styles.horizontal}>
|
|
|
|
<Image
|
2016-01-27 21:21:42 +00:00
|
|
|
source={require('./uie_thumb_normal.png')}
|
2015-09-01 15:51:46 +00:00
|
|
|
style={[styles.icon, {borderRadius: 5, tintColor: '#5ac8fa' }]}
|
2015-07-13 17:30:34 +00:00
|
|
|
/>
|
|
|
|
<Image
|
2016-01-27 21:21:42 +00:00
|
|
|
source={require('./uie_thumb_normal.png')}
|
2015-09-01 15:51:46 +00:00
|
|
|
style={[styles.icon, styles.leftMargin, {borderRadius: 5, tintColor: '#4cd964' }]}
|
2015-07-13 17:30:34 +00:00
|
|
|
/>
|
|
|
|
<Image
|
2016-01-27 21:21:42 +00:00
|
|
|
source={require('./uie_thumb_normal.png')}
|
2015-09-01 15:51:46 +00:00
|
|
|
style={[styles.icon, styles.leftMargin, {borderRadius: 5, tintColor: '#ff2d55' }]}
|
2015-07-13 17:30:34 +00:00
|
|
|
/>
|
|
|
|
<Image
|
2016-01-27 21:21:42 +00:00
|
|
|
source={require('./uie_thumb_normal.png')}
|
2015-09-01 15:51:46 +00:00
|
|
|
style={[styles.icon, styles.leftMargin, {borderRadius: 5, tintColor: '#8e8e93' }]}
|
2015-07-13 17:30:34 +00:00
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
<Text style={styles.sectionText}>
|
|
|
|
It also works with downloaded images:
|
|
|
|
</Text>
|
|
|
|
<View style={styles.horizontal}>
|
|
|
|
<Image
|
|
|
|
source={smallImage}
|
2015-09-01 15:51:46 +00:00
|
|
|
style={[styles.base, {borderRadius: 5, tintColor: '#5ac8fa' }]}
|
2015-07-13 17:30:34 +00:00
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
source={smallImage}
|
2015-09-01 15:51:46 +00:00
|
|
|
style={[styles.base, styles.leftMargin, {borderRadius: 5, tintColor: '#4cd964' }]}
|
2015-07-13 17:30:34 +00:00
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
source={smallImage}
|
2015-09-01 15:51:46 +00:00
|
|
|
style={[styles.base, styles.leftMargin, {borderRadius: 5, tintColor: '#ff2d55' }]}
|
2015-07-13 17:30:34 +00:00
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
source={smallImage}
|
2015-09-01 15:51:46 +00:00
|
|
|
style={[styles.base, styles.leftMargin, {borderRadius: 5, tintColor: '#8e8e93' }]}
|
2015-07-13 17:30:34 +00:00
|
|
|
/>
|
|
|
|
</View>
|
2015-02-20 04:10:52 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Resize Mode',
|
|
|
|
description: 'The `resizeMode` style prop controls how the image is ' +
|
|
|
|
'rendered within the frame.',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={styles.horizontal}>
|
|
|
|
<View>
|
|
|
|
<Text style={[styles.resizeModeText]}>
|
|
|
|
Contain
|
|
|
|
</Text>
|
|
|
|
<Image
|
2015-04-17 01:17:19 +00:00
|
|
|
style={styles.resizeMode}
|
|
|
|
resizeMode={Image.resizeMode.contain}
|
2015-02-20 04:10:52 +00:00
|
|
|
source={fullImage}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
<View style={styles.leftMargin}>
|
|
|
|
<Text style={[styles.resizeModeText]}>
|
|
|
|
Cover
|
|
|
|
</Text>
|
|
|
|
<Image
|
2015-04-17 01:17:19 +00:00
|
|
|
style={styles.resizeMode}
|
|
|
|
resizeMode={Image.resizeMode.cover}
|
2015-02-20 04:10:52 +00:00
|
|
|
source={fullImage}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
<View style={styles.leftMargin}>
|
|
|
|
<Text style={[styles.resizeModeText]}>
|
|
|
|
Stretch
|
|
|
|
</Text>
|
|
|
|
<Image
|
2015-04-17 01:17:19 +00:00
|
|
|
style={styles.resizeMode}
|
|
|
|
resizeMode={Image.resizeMode.stretch}
|
2015-02-20 04:10:52 +00:00
|
|
|
source={fullImage}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
2015-09-04 11:35:44 +00:00
|
|
|
{
|
|
|
|
title: 'Animated GIF',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<Image
|
|
|
|
style={styles.gif}
|
|
|
|
source={{uri: 'http://38.media.tumblr.com/9e9bd08c6e2d10561dd1fb4197df4c4e/tumblr_mfqekpMktw1rn90umo1_500.gif'}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
platform: 'ios',
|
|
|
|
},
|
2015-10-19 16:04:54 +00:00
|
|
|
{
|
|
|
|
title: 'Base64 image',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<Image
|
|
|
|
style={styles.base64}
|
|
|
|
source={{uri: base64Icon, scale: 3}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
platform: 'ios',
|
|
|
|
},
|
2015-02-20 04:10:52 +00:00
|
|
|
{
|
|
|
|
title: 'Cap Insets',
|
|
|
|
description:
|
|
|
|
'When the image is resized, the corners of the size specified ' +
|
|
|
|
'by capInsets will stay a fixed size, but the center content and ' +
|
|
|
|
'borders of the image will be stretched. This is useful for creating ' +
|
|
|
|
'resizable rounded buttons, shadows, and other resizable assets.',
|
|
|
|
render: function() {
|
|
|
|
return <ImageCapInsetsExample />;
|
|
|
|
},
|
2015-09-01 15:51:46 +00:00
|
|
|
platform: 'ios',
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
Added getImageSize method
Summary:
public
This diff adds a `getSize()` method to `Image` to retrieve the width and height of an image prior to displaying it. This is useful when working with images from uncontrolled sources, and has been a much-requested feature.
In order to retrieve the image dimensions, the image may first need to be loaded or downloaded, after which it will be cached. This means that in principle you could use this method to preload images, however it is not optimized for that purpose, and may in future be implemented in a way that does not fully load/download the image data.
A fully supported way to preload images will be provided in a future diff.
The API (separate success and failure callbacks) is far from ideal, but until we agree on a unified standard, this was the most conventional way I could think of to implement it. If it returned a promise or something similar, it would be unique among all such APIS in the framework.
Please note that this has been a long time coming, in part due to much bikeshedding about what the API should look like, so while it's not unlikely that the API may change in future, I think having *some* way to do this is better than waiting until we can define the "perfect" way.
Reviewed By: vjeux
Differential Revision: D2797365
fb-gh-sync-id: 11eb1b8547773b1f8be0bc55ddf6dfedebf7fc0a
2016-01-01 02:50:26 +00:00
|
|
|
{
|
|
|
|
title: 'Image Size',
|
|
|
|
render: function() {
|
|
|
|
return <ImageSizeExample source={fullImage} />;
|
2016-01-04 14:37:15 +00:00
|
|
|
},
|
|
|
|
platform: 'ios',
|
Added getImageSize method
Summary:
public
This diff adds a `getSize()` method to `Image` to retrieve the width and height of an image prior to displaying it. This is useful when working with images from uncontrolled sources, and has been a much-requested feature.
In order to retrieve the image dimensions, the image may first need to be loaded or downloaded, after which it will be cached. This means that in principle you could use this method to preload images, however it is not optimized for that purpose, and may in future be implemented in a way that does not fully load/download the image data.
A fully supported way to preload images will be provided in a future diff.
The API (separate success and failure callbacks) is far from ideal, but until we agree on a unified standard, this was the most conventional way I could think of to implement it. If it returned a promise or something similar, it would be unique among all such APIS in the framework.
Please note that this has been a long time coming, in part due to much bikeshedding about what the API should look like, so while it's not unlikely that the API may change in future, I think having *some* way to do this is better than waiting until we can define the "perfect" way.
Reviewed By: vjeux
Differential Revision: D2797365
fb-gh-sync-id: 11eb1b8547773b1f8be0bc55ddf6dfedebf7fc0a
2016-01-01 02:50:26 +00:00
|
|
|
},
|
2015-02-20 04:10:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
var fullImage = {uri: 'http://facebook.github.io/react/img/logo_og.png'};
|
2015-08-21 16:50:12 +00:00
|
|
|
var smallImage = {uri: 'http://facebook.github.io/react/img/logo_small_2x.png'};
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
|
|
|
base: {
|
|
|
|
width: 38,
|
|
|
|
height: 38,
|
|
|
|
},
|
2015-07-14 20:56:55 +00:00
|
|
|
progress: {
|
|
|
|
flex: 1,
|
|
|
|
alignItems: 'center',
|
|
|
|
flexDirection: 'row',
|
|
|
|
width: 100
|
|
|
|
},
|
2015-02-20 04:10:52 +00:00
|
|
|
leftMargin: {
|
|
|
|
marginLeft: 10,
|
|
|
|
},
|
|
|
|
background: {
|
|
|
|
backgroundColor: '#222222'
|
|
|
|
},
|
2015-07-13 17:30:34 +00:00
|
|
|
sectionText: {
|
|
|
|
marginVertical: 6,
|
|
|
|
},
|
2015-02-20 04:10:52 +00:00
|
|
|
nestedText: {
|
|
|
|
marginLeft: 12,
|
|
|
|
marginTop: 20,
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
color: 'white'
|
|
|
|
},
|
|
|
|
resizeMode: {
|
|
|
|
width: 90,
|
|
|
|
height: 60,
|
|
|
|
borderWidth: 0.5,
|
|
|
|
borderColor: 'black'
|
|
|
|
},
|
|
|
|
resizeModeText: {
|
|
|
|
fontSize: 11,
|
|
|
|
marginBottom: 3,
|
|
|
|
},
|
|
|
|
icon: {
|
|
|
|
width: 15,
|
|
|
|
height: 15,
|
|
|
|
},
|
|
|
|
horizontal: {
|
|
|
|
flexDirection: 'row',
|
2015-09-04 11:35:44 +00:00
|
|
|
},
|
|
|
|
gif: {
|
|
|
|
flex: 1,
|
|
|
|
height: 200,
|
|
|
|
},
|
2015-10-19 16:04:54 +00:00
|
|
|
base64: {
|
|
|
|
flex: 1,
|
|
|
|
height: 50,
|
|
|
|
resizeMode: 'contain',
|
|
|
|
},
|
2015-02-20 04:10:52 +00:00
|
|
|
});
|