2015-02-19 20:10:52 -08:00
|
|
|
/**
|
2018-09-11 15:27:47 -07:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-03-19 11:24:06 -07:00
|
|
|
*
|
2018-02-16 18:24:55 -08:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-03-19 11:24:06 -07:00
|
|
|
*
|
2018-05-11 13:32:37 -07:00
|
|
|
* @format
|
2018-08-09 08:32:04 -07:00
|
|
|
* @flow strict-local
|
2015-02-19 20:10:52 -08:00
|
|
|
*/
|
2018-05-11 13:32:37 -07:00
|
|
|
|
2015-02-19 20:10:52 -08:00
|
|
|
'use strict';
|
|
|
|
|
2018-10-10 14:36:20 -07:00
|
|
|
const React = require('react');
|
|
|
|
const ReactNative = require('react-native');
|
|
|
|
const {
|
2016-06-13 22:15:47 -07:00
|
|
|
ActivityIndicator,
|
2015-02-19 20:10:52 -08:00
|
|
|
Image,
|
|
|
|
StyleSheet,
|
|
|
|
Text,
|
|
|
|
View,
|
2017-05-24 11:19:31 -07:00
|
|
|
ImageBackground,
|
2016-04-08 20:36:40 -07:00
|
|
|
} = ReactNative;
|
2015-02-19 20:10:52 -08:00
|
|
|
|
2018-10-10 14:36:20 -07:00
|
|
|
const base64Icon =
|
2018-05-11 13:32:37 -07:00
|
|
|
'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-10-19 09:04:54 -07:00
|
|
|
|
2018-10-10 14:36:20 -07:00
|
|
|
const ImageCapInsetsExample = require('./ImageCapInsetsExample');
|
2018-05-11 13:32:37 -07:00
|
|
|
const IMAGE_PREFETCH_URL =
|
|
|
|
'http://origami.design/public/images/bird-logo.png?r=1&t=' + Date.now();
|
2018-10-10 14:36:20 -07:00
|
|
|
const prefetchTask = Image.prefetch(IMAGE_PREFETCH_URL);
|
2015-02-19 20:10:52 -08:00
|
|
|
|
2018-10-10 14:36:20 -07:00
|
|
|
type ImageSource = $ReadOnly<{|
|
|
|
|
uri: string,
|
|
|
|
|}>;
|
|
|
|
|
|
|
|
type NetworkImageCallbackExampleState = {|
|
|
|
|
events: Array<string>,
|
|
|
|
startLoadPrefetched: boolean,
|
|
|
|
mountTime: Date,
|
|
|
|
|};
|
|
|
|
|
|
|
|
type NetworkImageCallbackExampleProps = $ReadOnly<{|
|
|
|
|
source: ImageSource,
|
|
|
|
prefetchedSource: ImageSource,
|
|
|
|
|}>;
|
|
|
|
|
|
|
|
class NetworkImageCallbackExample extends React.Component<
|
|
|
|
NetworkImageCallbackExampleProps,
|
|
|
|
NetworkImageCallbackExampleState,
|
|
|
|
> {
|
|
|
|
state = {
|
|
|
|
events: [],
|
|
|
|
startLoadPrefetched: false,
|
|
|
|
mountTime: new Date(),
|
|
|
|
};
|
2015-11-25 17:06:59 -08:00
|
|
|
|
2018-02-08 10:26:45 -08:00
|
|
|
UNSAFE_componentWillMount() {
|
2015-11-25 17:06:59 -08:00
|
|
|
this.setState({mountTime: new Date()});
|
2018-10-10 14:36:20 -07:00
|
|
|
}
|
2015-11-25 17:06:59 -08:00
|
|
|
|
2018-10-10 14:36:20 -07:00
|
|
|
_loadEventFired = (event: string) => {
|
|
|
|
this.setState(state => ({
|
|
|
|
events: [...state.events, event],
|
|
|
|
}));
|
|
|
|
};
|
2015-11-25 17:06:59 -08:00
|
|
|
|
2018-10-10 14:36:20 -07:00
|
|
|
render() {
|
|
|
|
const {mountTime} = this.state;
|
2015-11-25 17:06:59 -08:00
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<Image
|
|
|
|
source={this.props.source}
|
|
|
|
style={[styles.base, {overflow: 'visible'}]}
|
2018-05-11 13:32:37 -07:00
|
|
|
onLoadStart={() =>
|
|
|
|
this._loadEventFired(`✔ onLoadStart (+${new Date() - mountTime}ms)`)
|
|
|
|
}
|
|
|
|
onLoad={event => {
|
2016-08-22 10:55:20 -07:00
|
|
|
if (event.nativeEvent.source) {
|
|
|
|
const url = event.nativeEvent.source.url;
|
2018-05-11 13:32:37 -07:00
|
|
|
this._loadEventFired(
|
|
|
|
`✔ onLoad (+${new Date() - mountTime}ms) for URL ${url}`,
|
|
|
|
);
|
2016-08-22 10:55:20 -07:00
|
|
|
} else {
|
|
|
|
this._loadEventFired(`✔ onLoad (+${new Date() - mountTime}ms)`);
|
|
|
|
}
|
|
|
|
}}
|
2016-04-13 07:29:10 -07:00
|
|
|
onLoadEnd={() => {
|
|
|
|
this._loadEventFired(`✔ onLoadEnd (+${new Date() - mountTime}ms)`);
|
|
|
|
this.setState({startLoadPrefetched: true}, () => {
|
2018-05-11 13:32:37 -07:00
|
|
|
prefetchTask.then(
|
|
|
|
() => {
|
|
|
|
this._loadEventFired(
|
|
|
|
`✔ Prefetch OK (+${new Date() - mountTime}ms)`,
|
|
|
|
);
|
2018-09-25 19:37:32 -07:00
|
|
|
Image.queryCache([IMAGE_PREFETCH_URL]).then(map => {
|
2018-10-30 14:26:13 -07:00
|
|
|
const result = map.get(IMAGE_PREFETCH_URL);
|
2018-08-20 16:06:18 -07:00
|
|
|
if (result) {
|
|
|
|
this._loadEventFired(
|
2018-09-25 19:37:32 -07:00
|
|
|
`✔ queryCache "${result}" (+${new Date() -
|
|
|
|
mountTime}ms)`,
|
2018-08-20 16:06:18 -07:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this._loadEventFired(
|
|
|
|
`✘ queryCache (+${new Date() - mountTime}ms)`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2018-05-11 13:32:37 -07:00
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this._loadEventFired(
|
|
|
|
`✘ Prefetch failed (+${new Date() - mountTime}ms)`,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2016-04-13 07:29:10 -07:00
|
|
|
});
|
|
|
|
}}
|
2015-11-25 17:06:59 -08:00
|
|
|
/>
|
2018-05-11 13:32:37 -07:00
|
|
|
{this.state.startLoadPrefetched ? (
|
2016-04-13 07:29:10 -07:00
|
|
|
<Image
|
|
|
|
source={this.props.prefetchedSource}
|
|
|
|
style={[styles.base, {overflow: 'visible'}]}
|
2018-05-11 13:32:37 -07:00
|
|
|
onLoadStart={() =>
|
|
|
|
this._loadEventFired(
|
|
|
|
`✔ (prefetched) onLoadStart (+${new Date() - mountTime}ms)`,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
onLoad={event => {
|
2016-08-22 10:55:20 -07:00
|
|
|
// Currently this image source feature is only available on iOS.
|
|
|
|
if (event.nativeEvent.source) {
|
|
|
|
const url = event.nativeEvent.source.url;
|
2018-05-11 13:32:37 -07:00
|
|
|
this._loadEventFired(
|
|
|
|
`✔ (prefetched) onLoad (+${new Date() -
|
|
|
|
mountTime}ms) for URL ${url}`,
|
|
|
|
);
|
2016-08-22 10:55:20 -07:00
|
|
|
} else {
|
2018-05-11 13:32:37 -07:00
|
|
|
this._loadEventFired(
|
|
|
|
`✔ (prefetched) onLoad (+${new Date() - mountTime}ms)`,
|
|
|
|
);
|
2016-08-22 10:55:20 -07:00
|
|
|
}
|
|
|
|
}}
|
2018-05-11 13:32:37 -07:00
|
|
|
onLoadEnd={() =>
|
|
|
|
this._loadEventFired(
|
|
|
|
`✔ (prefetched) onLoadEnd (+${new Date() - mountTime}ms)`,
|
|
|
|
)
|
|
|
|
}
|
2016-04-13 07:29:10 -07:00
|
|
|
/>
|
2018-05-11 13:32:37 -07:00
|
|
|
) : null}
|
|
|
|
<Text style={{marginTop: 20}}>{this.state.events.join('\n')}</Text>
|
2015-11-25 17:06:59 -08:00
|
|
|
</View>
|
|
|
|
);
|
2018-10-10 14:36:20 -07:00
|
|
|
}
|
|
|
|
}
|
2015-11-25 17:06:59 -08:00
|
|
|
|
2018-10-10 14:36:20 -07:00
|
|
|
type NetworkImageExampleState = {|
|
|
|
|
error: boolean,
|
|
|
|
loading: boolean,
|
|
|
|
progress: number,
|
|
|
|
|};
|
2015-11-25 17:06:59 -08:00
|
|
|
|
2018-10-10 14:36:20 -07:00
|
|
|
type NetworkImageExampleProps = $ReadOnly<{|
|
|
|
|
source: ImageSource,
|
|
|
|
|}>;
|
|
|
|
|
|
|
|
class NetworkImageExample extends React.Component<
|
|
|
|
NetworkImageExampleProps,
|
|
|
|
NetworkImageExampleState,
|
|
|
|
> {
|
|
|
|
state = {
|
|
|
|
error: false,
|
|
|
|
loading: false,
|
|
|
|
progress: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2018-10-30 14:26:13 -07:00
|
|
|
const loader = this.state.loading ? (
|
2015-07-14 13:56:55 -07:00
|
|
|
<View style={styles.progress}>
|
|
|
|
<Text>{this.state.progress}%</Text>
|
2018-05-11 13:32:37 -07:00
|
|
|
<ActivityIndicator style={{marginLeft: 5}} />
|
|
|
|
</View>
|
|
|
|
) : null;
|
|
|
|
return this.state.error ? (
|
|
|
|
<Text>{this.state.error}</Text>
|
|
|
|
) : (
|
2017-05-24 11:19:31 -07:00
|
|
|
<ImageBackground
|
2015-07-14 13:56:55 -07:00
|
|
|
source={this.props.source}
|
|
|
|
style={[styles.base, {overflow: 'visible'}]}
|
2018-05-11 13:32:37 -07:00
|
|
|
onLoadStart={e => this.setState({loading: true})}
|
|
|
|
onError={e =>
|
|
|
|
this.setState({error: e.nativeEvent.error, loading: false})
|
|
|
|
}
|
|
|
|
onProgress={e =>
|
|
|
|
this.setState({
|
|
|
|
progress: Math.round(
|
2018-06-06 05:20:40 -07:00
|
|
|
(100 * e.nativeEvent.loaded) / e.nativeEvent.total,
|
2018-05-11 13:32:37 -07:00
|
|
|
),
|
|
|
|
})
|
|
|
|
}
|
2015-07-15 19:17:13 -01:00
|
|
|
onLoad={() => this.setState({loading: false, error: false})}>
|
2015-07-14 13:56:55 -07:00
|
|
|
{loader}
|
2018-05-11 13:32:37 -07:00
|
|
|
</ImageBackground>
|
|
|
|
);
|
2018-10-10 14:36:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type ImageSizeExampleState = {|
|
|
|
|
width: number,
|
|
|
|
height: number,
|
|
|
|
|};
|
2015-07-14 13:56:55 -07:00
|
|
|
|
2018-10-10 14:36:20 -07:00
|
|
|
type ImageSizeExampleProps = $ReadOnly<{|
|
|
|
|
source: ImageSource,
|
|
|
|
|}>;
|
|
|
|
|
|
|
|
class ImageSizeExample extends React.Component<
|
|
|
|
ImageSizeExampleProps,
|
|
|
|
ImageSizeExampleState,
|
|
|
|
> {
|
|
|
|
state = {
|
|
|
|
width: 0,
|
|
|
|
height: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount() {
|
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
2015-12-31 18:50:26 -08:00
|
|
|
Image.getSize(this.props.source.uri, (width, height) => {
|
|
|
|
this.setState({width, height});
|
|
|
|
});
|
2018-10-10 14:36:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
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
2015-12-31 18:50:26 -08:00
|
|
|
return (
|
|
|
|
<View style={{flexDirection: 'row'}}>
|
|
|
|
<Image
|
|
|
|
style={{
|
|
|
|
width: 60,
|
|
|
|
height: 60,
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
marginRight: 10,
|
|
|
|
}}
|
2018-05-11 13:32:37 -07:00
|
|
|
source={this.props.source}
|
|
|
|
/>
|
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
2015-12-31 18:50:26 -08:00
|
|
|
<Text>
|
|
|
|
Actual dimensions:{'\n'}
|
|
|
|
Width: {this.state.width}, Height: {this.state.height}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
2018-10-10 14:36:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type MultipleSourcesExampleState = {|
|
|
|
|
width: number,
|
|
|
|
height: number,
|
|
|
|
|};
|
|
|
|
|
|
|
|
type MultipleSourcesExampleProps = $ReadOnly<{||}>;
|
|
|
|
|
|
|
|
class MultipleSourcesExample extends React.Component<
|
|
|
|
MultipleSourcesExampleProps,
|
|
|
|
MultipleSourcesExampleState,
|
|
|
|
> {
|
|
|
|
state = {
|
|
|
|
width: 30,
|
|
|
|
height: 30,
|
|
|
|
};
|
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
2015-12-31 18:50:26 -08:00
|
|
|
|
2018-10-10 14:36:20 -07:00
|
|
|
increaseImageSize = () => {
|
|
|
|
if (this.state.width >= 100) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
width: this.state.width + 10,
|
|
|
|
height: this.state.height + 10,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
increaseImageSize = () => {
|
|
|
|
if (this.state.width >= 100) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
width: this.state.width + 10,
|
|
|
|
height: this.state.height + 10,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
decreaseImageSize = () => {
|
|
|
|
if (this.state.width <= 10) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
width: this.state.width - 10,
|
|
|
|
height: this.state.height - 10,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2016-06-13 14:04:19 -07:00
|
|
|
return (
|
2016-07-18 23:18:03 -07:00
|
|
|
<View>
|
2016-06-13 14:04:19 -07:00
|
|
|
<View style={{flexDirection: 'row', justifyContent: 'space-between'}}>
|
2018-05-11 13:32:37 -07:00
|
|
|
<Text style={styles.touchableText} onPress={this.decreaseImageSize}>
|
2016-06-13 14:04:19 -07:00
|
|
|
Decrease image size
|
|
|
|
</Text>
|
2018-05-11 13:32:37 -07:00
|
|
|
<Text style={styles.touchableText} onPress={this.increaseImageSize}>
|
2016-06-13 14:04:19 -07:00
|
|
|
Increase image size
|
|
|
|
</Text>
|
|
|
|
</View>
|
2018-05-11 13:32:37 -07:00
|
|
|
<Text>
|
|
|
|
Container image size: {this.state.width}x{this.state.height}{' '}
|
|
|
|
</Text>
|
|
|
|
<View style={{height: this.state.height, width: this.state.width}}>
|
2016-06-13 14:04:19 -07:00
|
|
|
<Image
|
|
|
|
style={{flex: 1}}
|
|
|
|
source={[
|
2018-05-11 13:32:37 -07:00
|
|
|
{
|
|
|
|
uri: 'https://facebook.github.io/react-native/img/favicon.png',
|
|
|
|
width: 38,
|
|
|
|
height: 38,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uri: 'https://facebook.github.io/react-native/img/favicon.png',
|
|
|
|
width: 76,
|
|
|
|
height: 76,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
uri:
|
|
|
|
'https://facebook.github.io/react-native/img/opengraph.png',
|
|
|
|
width: 400,
|
|
|
|
height: 400,
|
|
|
|
},
|
2016-06-13 14:04:19 -07:00
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
2018-10-10 14:36:20 -07:00
|
|
|
}
|
|
|
|
}
|
2016-06-13 14:04:19 -07:00
|
|
|
|
2015-06-22 09:43:30 -07:00
|
|
|
exports.displayName = (undefined: ?string);
|
2015-02-19 20:10:52 -08:00
|
|
|
exports.framework = 'React';
|
|
|
|
exports.title = '<Image>';
|
2018-05-11 13:32:37 -07:00
|
|
|
exports.description =
|
|
|
|
'Base component for displaying different types of images.';
|
2015-02-19 20:10:52 -08:00
|
|
|
|
|
|
|
exports.examples = [
|
|
|
|
{
|
|
|
|
title: 'Plain Network Image',
|
2018-05-11 13:32:37 -07:00
|
|
|
description:
|
|
|
|
'If the `source` prop `uri` property is prefixed with ' +
|
|
|
|
'"http", then it will be downloaded from the network.',
|
2015-02-19 20:10:52 -08:00
|
|
|
render: function() {
|
2018-05-11 13:32:37 -07:00
|
|
|
return <Image source={fullImage} style={styles.base} />;
|
2015-02-19 20:10:52 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Plain Static Image',
|
2018-05-11 13:32:37 -07:00
|
|
|
description:
|
|
|
|
'Static assets should be placed in the source code tree, and ' +
|
|
|
|
'required in the same way as JavaScript modules.',
|
2015-02-19 20:10:52 -08:00
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={styles.horizontal}>
|
2018-05-11 13:32:37 -07: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-19 20:10:52 -08:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
2015-11-25 17:06:59 -08:00
|
|
|
{
|
|
|
|
title: 'Image Loading Events',
|
|
|
|
render: function() {
|
|
|
|
return (
|
2018-05-11 13:32:37 -07:00
|
|
|
<NetworkImageCallbackExample
|
|
|
|
source={{
|
|
|
|
uri:
|
|
|
|
'http://origami.design/public/images/bird-logo.png?r=1&t=' +
|
|
|
|
Date.now(),
|
|
|
|
}}
|
|
|
|
prefetchedSource={{uri: IMAGE_PREFETCH_URL}}
|
|
|
|
/>
|
2015-11-25 17:06:59 -08:00
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
2015-07-14 13:56:55 -07:00
|
|
|
{
|
|
|
|
title: 'Error Handler',
|
|
|
|
render: function() {
|
|
|
|
return (
|
2018-05-11 13:32:37 -07:00
|
|
|
<NetworkImageExample
|
|
|
|
source={{
|
|
|
|
uri: 'https://TYPO_ERROR_facebook.github.io/react/logo-og.png',
|
|
|
|
}}
|
|
|
|
/>
|
2015-07-14 13:56:55 -07:00
|
|
|
);
|
|
|
|
},
|
2015-09-01 14:51:46 -01:00
|
|
|
platform: 'ios',
|
2015-07-14 13:56:55 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Image Download Progress',
|
|
|
|
render: function() {
|
|
|
|
return (
|
2018-05-11 13:32:37 -07:00
|
|
|
<NetworkImageExample
|
|
|
|
source={{
|
|
|
|
uri: 'http://origami.design/public/images/bird-logo.png?r=1',
|
|
|
|
}}
|
|
|
|
/>
|
2015-07-14 13:56:55 -07:00
|
|
|
);
|
|
|
|
},
|
2015-09-01 14:51:46 -01:00
|
|
|
platform: 'ios',
|
2015-07-14 13:56:55 -07:00
|
|
|
},
|
2016-02-01 10:19:56 -08:00
|
|
|
{
|
|
|
|
title: 'defaultSource',
|
|
|
|
description: 'Show a placeholder image when a network image is loading',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<Image
|
|
|
|
defaultSource={require('./bunny.png')}
|
2018-05-11 13:32:37 -07:00
|
|
|
source={{
|
|
|
|
uri: 'https://facebook.github.io/origami/public/images/birds.jpg',
|
|
|
|
}}
|
2016-02-01 10:19:56 -08:00
|
|
|
style={styles.base}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
platform: 'ios',
|
|
|
|
},
|
2017-01-17 16:58:27 -08:00
|
|
|
{
|
|
|
|
title: 'Cache Policy',
|
2018-05-11 13:32:37 -07:00
|
|
|
description:
|
|
|
|
'First image has never been loaded before and is instructed not to load unless in cache.' +
|
|
|
|
'Placeholder image from above will stay. Second image is the same but forced to load regardless of' +
|
|
|
|
' local cache state.',
|
|
|
|
render: function() {
|
2017-01-17 16:58:27 -08:00
|
|
|
return (
|
|
|
|
<View style={styles.horizontal}>
|
|
|
|
<Image
|
|
|
|
defaultSource={require('./bunny.png')}
|
|
|
|
source={{
|
|
|
|
uri: smallImage.uri + '?cacheBust=notinCache' + Date.now(),
|
2018-05-11 13:32:37 -07:00
|
|
|
cache: 'only-if-cached',
|
2017-01-17 16:58:27 -08:00
|
|
|
}}
|
|
|
|
style={styles.base}
|
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
defaultSource={require('./bunny.png')}
|
|
|
|
source={{
|
|
|
|
uri: smallImage.uri + '?cacheBust=notinCache' + Date.now(),
|
2018-05-11 13:32:37 -07:00
|
|
|
cache: 'reload',
|
2017-01-17 16:58:27 -08:00
|
|
|
}}
|
|
|
|
style={styles.base}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
platform: 'ios',
|
|
|
|
},
|
2015-02-19 20:10:52 -08:00
|
|
|
{
|
|
|
|
title: 'Border Color',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={styles.horizontal}>
|
|
|
|
<Image
|
|
|
|
source={smallImage}
|
|
|
|
style={[
|
|
|
|
styles.base,
|
|
|
|
styles.background,
|
2018-05-11 13:32:37 -07:00
|
|
|
{borderWidth: 3, borderColor: '#f099f0'},
|
2015-02-19 20:10:52 -08:00
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Border Width',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={styles.horizontal}>
|
|
|
|
<Image
|
|
|
|
source={smallImage}
|
|
|
|
style={[
|
|
|
|
styles.base,
|
|
|
|
styles.background,
|
2018-05-11 13:32:37 -07:00
|
|
|
{borderWidth: 5, borderColor: '#f099f0'},
|
2015-02-19 20:10:52 -08:00
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Border Radius',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={styles.horizontal}>
|
2018-05-11 13:32:37 -07:00
|
|
|
<Image style={[styles.base, {borderRadius: 5}]} source={fullImage} />
|
2015-02-19 20:10:52 -08:00
|
|
|
<Image
|
2015-09-01 14:51:46 -01:00
|
|
|
style={[styles.base, styles.leftMargin, {borderRadius: 19}]}
|
|
|
|
source={fullImage}
|
2015-02-19 20:10:52 -08:00
|
|
|
/>
|
2018-08-08 14:19:49 -07:00
|
|
|
<Image
|
|
|
|
style={[styles.base, styles.leftMargin, {borderTopLeftRadius: 20}]}
|
|
|
|
source={fullImage}
|
|
|
|
/>
|
|
|
|
<Image
|
2018-09-25 19:37:32 -07:00
|
|
|
style={[
|
|
|
|
styles.base,
|
|
|
|
styles.leftMargin,
|
|
|
|
{
|
|
|
|
borderWidth: 10,
|
|
|
|
borderTopLeftRadius: 10,
|
|
|
|
borderBottomRightRadius: 20,
|
|
|
|
borderColor: 'green',
|
|
|
|
},
|
|
|
|
]}
|
2018-08-08 14:19:49 -07:00
|
|
|
source={fullImage}
|
|
|
|
/>
|
|
|
|
<Image
|
2018-09-25 19:37:32 -07:00
|
|
|
style={[
|
|
|
|
styles.base,
|
|
|
|
styles.leftMargin,
|
|
|
|
{
|
|
|
|
borderWidth: 5,
|
|
|
|
borderTopLeftRadius: 10,
|
|
|
|
borderTopRightRadius: 20,
|
|
|
|
borderBottomRightRadius: 30,
|
|
|
|
borderBottomLeftRadius: 40,
|
|
|
|
borderColor: 'red',
|
|
|
|
},
|
|
|
|
]}
|
2018-08-08 14:19:49 -07:00
|
|
|
source={fullImage}
|
|
|
|
/>
|
2015-02-19 20:10:52 -08:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Background Color',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={styles.horizontal}>
|
|
|
|
<Image source={smallImage} style={styles.base} />
|
|
|
|
<Image
|
|
|
|
style={[
|
|
|
|
styles.base,
|
|
|
|
styles.leftMargin,
|
2018-05-11 13:32:37 -07:00
|
|
|
{backgroundColor: 'rgba(0, 0, 100, 0.25)'},
|
2015-02-19 20:10:52 -08:00
|
|
|
]}
|
|
|
|
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}>
|
2018-05-11 13:32:37 -07:00
|
|
|
<Image style={[styles.base, {opacity: 1}]} source={fullImage} />
|
2015-02-19 20:10:52 -08:00
|
|
|
<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>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2017-09-25 21:55:56 -07:00
|
|
|
title: 'Nesting content inside <Image> component',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={{width: 60, height: 60}}>
|
|
|
|
<Image
|
|
|
|
style={{...StyleSheet.absoluteFillObject}}
|
2018-05-11 13:32:37 -07:00
|
|
|
source={fullImage}
|
|
|
|
/>
|
|
|
|
<Text style={styles.nestedText}>React</Text>
|
2017-09-25 21:55:56 -07:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Nesting content inside <ImageBackground> component',
|
2015-02-19 20:10:52 -08:00
|
|
|
render: function() {
|
|
|
|
return (
|
2017-05-24 11:19:31 -07:00
|
|
|
<ImageBackground
|
2015-02-19 20:10:52 -08:00
|
|
|
style={{width: 60, height: 60, backgroundColor: 'transparent'}}
|
|
|
|
source={fullImage}>
|
2018-05-11 13:32:37 -07:00
|
|
|
<Text style={styles.nestedText}>React</Text>
|
2017-05-24 11:19:31 -07:00
|
|
|
</ImageBackground>
|
2015-02-19 20:10:52 -08:00
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Tint Color',
|
2018-05-11 13:32:37 -07:00
|
|
|
description:
|
|
|
|
'The `tintColor` style prop changes all the non-alpha ' +
|
2015-02-19 20:10:52 -08:00
|
|
|
'pixels to the tint color.',
|
|
|
|
render: function() {
|
|
|
|
return (
|
2015-07-13 10:30:34 -07:00
|
|
|
<View>
|
|
|
|
<View style={styles.horizontal}>
|
|
|
|
<Image
|
2016-01-27 13:21:42 -08:00
|
|
|
source={require('./uie_thumb_normal.png')}
|
2018-05-11 13:32:37 -07:00
|
|
|
style={[styles.icon, {borderRadius: 5, tintColor: '#5ac8fa'}]}
|
2015-07-13 10:30:34 -07:00
|
|
|
/>
|
|
|
|
<Image
|
2016-01-27 13:21:42 -08:00
|
|
|
source={require('./uie_thumb_normal.png')}
|
2018-05-11 13:32:37 -07:00
|
|
|
style={[
|
|
|
|
styles.icon,
|
|
|
|
styles.leftMargin,
|
|
|
|
{borderRadius: 5, tintColor: '#4cd964'},
|
|
|
|
]}
|
2015-07-13 10:30:34 -07:00
|
|
|
/>
|
|
|
|
<Image
|
2016-01-27 13:21:42 -08:00
|
|
|
source={require('./uie_thumb_normal.png')}
|
2018-05-11 13:32:37 -07:00
|
|
|
style={[
|
|
|
|
styles.icon,
|
|
|
|
styles.leftMargin,
|
|
|
|
{borderRadius: 5, tintColor: '#ff2d55'},
|
|
|
|
]}
|
2015-07-13 10:30:34 -07:00
|
|
|
/>
|
|
|
|
<Image
|
2016-01-27 13:21:42 -08:00
|
|
|
source={require('./uie_thumb_normal.png')}
|
2018-05-11 13:32:37 -07:00
|
|
|
style={[
|
|
|
|
styles.icon,
|
|
|
|
styles.leftMargin,
|
|
|
|
{borderRadius: 5, tintColor: '#8e8e93'},
|
|
|
|
]}
|
2015-07-13 10:30:34 -07:00
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
<Text style={styles.sectionText}>
|
|
|
|
It also works with downloaded images:
|
|
|
|
</Text>
|
|
|
|
<View style={styles.horizontal}>
|
|
|
|
<Image
|
|
|
|
source={smallImage}
|
2018-05-11 13:32:37 -07:00
|
|
|
style={[styles.base, {borderRadius: 5, tintColor: '#5ac8fa'}]}
|
2015-07-13 10:30:34 -07:00
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
source={smallImage}
|
2018-05-11 13:32:37 -07:00
|
|
|
style={[
|
|
|
|
styles.base,
|
|
|
|
styles.leftMargin,
|
|
|
|
{borderRadius: 5, tintColor: '#4cd964'},
|
|
|
|
]}
|
2015-07-13 10:30:34 -07:00
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
source={smallImage}
|
2018-05-11 13:32:37 -07:00
|
|
|
style={[
|
|
|
|
styles.base,
|
|
|
|
styles.leftMargin,
|
|
|
|
{borderRadius: 5, tintColor: '#ff2d55'},
|
|
|
|
]}
|
2015-07-13 10:30:34 -07:00
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
source={smallImage}
|
2018-05-11 13:32:37 -07:00
|
|
|
style={[
|
|
|
|
styles.base,
|
|
|
|
styles.leftMargin,
|
|
|
|
{borderRadius: 5, tintColor: '#8e8e93'},
|
|
|
|
]}
|
2015-07-13 10:30:34 -07:00
|
|
|
/>
|
|
|
|
</View>
|
2015-02-19 20:10:52 -08:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Resize Mode',
|
2018-05-11 13:32:37 -07:00
|
|
|
description:
|
|
|
|
'The `resizeMode` style prop controls how the image is ' +
|
2015-02-19 20:10:52 -08:00
|
|
|
'rendered within the frame.',
|
|
|
|
render: function() {
|
|
|
|
return (
|
2016-03-08 12:09:17 -08:00
|
|
|
<View>
|
|
|
|
{[smallImage, fullImage].map((image, index) => {
|
2016-03-19 11:24:06 -07:00
|
|
|
return (
|
2018-05-11 13:32:37 -07:00
|
|
|
<View key={index}>
|
|
|
|
<View style={styles.horizontal}>
|
|
|
|
<View>
|
|
|
|
<Text style={[styles.resizeModeText]}>Contain</Text>
|
|
|
|
<Image
|
|
|
|
style={styles.resizeMode}
|
2018-05-12 23:10:57 -07:00
|
|
|
resizeMode="contain"
|
2018-05-11 13:32:37 -07:00
|
|
|
source={image}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
<View style={styles.leftMargin}>
|
|
|
|
<Text style={[styles.resizeModeText]}>Cover</Text>
|
|
|
|
<Image
|
|
|
|
style={styles.resizeMode}
|
2018-05-12 23:10:57 -07:00
|
|
|
resizeMode="cover"
|
2018-05-11 13:32:37 -07:00
|
|
|
source={image}
|
|
|
|
/>
|
|
|
|
</View>
|
2016-03-19 11:24:06 -07:00
|
|
|
</View>
|
2018-05-11 13:32:37 -07:00
|
|
|
<View style={styles.horizontal}>
|
|
|
|
<View>
|
|
|
|
<Text style={[styles.resizeModeText]}>Stretch</Text>
|
|
|
|
<Image
|
|
|
|
style={styles.resizeMode}
|
2018-05-12 23:10:57 -07:00
|
|
|
resizeMode="stretch"
|
2018-05-11 13:32:37 -07:00
|
|
|
source={image}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
<View style={styles.leftMargin}>
|
|
|
|
<Text style={[styles.resizeModeText]}>Repeat</Text>
|
|
|
|
<Image
|
|
|
|
style={styles.resizeMode}
|
2018-05-12 23:10:57 -07:00
|
|
|
resizeMode="repeat"
|
2018-05-11 13:32:37 -07:00
|
|
|
source={image}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
<View style={styles.leftMargin}>
|
|
|
|
<Text style={[styles.resizeModeText]}>Center</Text>
|
|
|
|
<Image
|
|
|
|
style={styles.resizeMode}
|
2018-05-12 23:10:57 -07:00
|
|
|
resizeMode="center"
|
2018-05-11 13:32:37 -07:00
|
|
|
source={image}
|
|
|
|
/>
|
|
|
|
</View>
|
2016-03-19 11:24:06 -07:00
|
|
|
</View>
|
2016-03-08 12:09:17 -08:00
|
|
|
</View>
|
2018-05-11 13:32:37 -07:00
|
|
|
);
|
|
|
|
})}
|
2015-02-19 20:10:52 -08:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
2015-09-04 04:35:44 -07:00
|
|
|
{
|
|
|
|
title: 'Animated GIF',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<Image
|
|
|
|
style={styles.gif}
|
2018-05-11 13:32:37 -07:00
|
|
|
source={{
|
|
|
|
uri:
|
|
|
|
'https://38.media.tumblr.com/9e9bd08c6e2d10561dd1fb4197df4c4e/tumblr_mfqekpMktw1rn90umo1_500.gif',
|
|
|
|
}}
|
2015-09-04 04:35:44 -07:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
platform: 'ios',
|
|
|
|
},
|
2015-10-19 09:04:54 -07:00
|
|
|
{
|
|
|
|
title: 'Base64 image',
|
|
|
|
render: function() {
|
|
|
|
return (
|
2018-05-11 13:32:37 -07:00
|
|
|
<Image style={styles.base64} source={{uri: base64Icon, scale: 3}} />
|
2015-10-19 09:04:54 -07:00
|
|
|
);
|
|
|
|
},
|
|
|
|
platform: 'ios',
|
|
|
|
},
|
2015-02-19 20:10:52 -08: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 14:51:46 -01:00
|
|
|
platform: 'ios',
|
2015-02-19 20:10:52 -08: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
2015-12-31 18:50:26 -08:00
|
|
|
{
|
|
|
|
title: 'Image Size',
|
|
|
|
render: function() {
|
2016-03-19 11:24:06 -07:00
|
|
|
return <ImageSizeExample source={fullImage} />;
|
2016-01-04 06:37:15 -08: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
2015-12-31 18:50:26 -08:00
|
|
|
},
|
2016-06-13 14:04:19 -07:00
|
|
|
{
|
|
|
|
title: 'MultipleSourcesExample',
|
|
|
|
description:
|
|
|
|
'The `source` prop allows passing in an array of uris, so that native to choose which image ' +
|
|
|
|
'to diplay based on the size of the of the target image',
|
|
|
|
render: function() {
|
|
|
|
return <MultipleSourcesExample />;
|
|
|
|
},
|
|
|
|
},
|
2016-07-21 07:45:54 -07:00
|
|
|
{
|
|
|
|
title: 'Legacy local image',
|
|
|
|
description:
|
|
|
|
'Images shipped with the native bundle, but not managed ' +
|
|
|
|
'by the JS packager',
|
|
|
|
render: function() {
|
2018-05-11 13:32:37 -07:00
|
|
|
return <Image source={{uri: 'legacy_image', width: 120, height: 120}} />;
|
2016-07-21 07:45:54 -07:00
|
|
|
},
|
|
|
|
},
|
2016-08-31 17:30:50 -07:00
|
|
|
{
|
|
|
|
title: 'Bundled images',
|
2018-05-11 13:32:37 -07:00
|
|
|
description: 'Images shipped in a separate native bundle',
|
2016-08-31 17:30:50 -07:00
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={{flexDirection: 'row'}}>
|
|
|
|
<Image
|
|
|
|
source={{
|
2017-04-19 02:53:15 -07:00
|
|
|
uri: 'ImageInBundle',
|
2017-05-05 20:50:47 -07:00
|
|
|
bundle: 'RNTesterBundle',
|
2016-08-31 17:30:50 -07:00
|
|
|
width: 100,
|
|
|
|
height: 100,
|
|
|
|
}}
|
|
|
|
style={{borderColor: 'yellow', borderWidth: 4}}
|
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
source={{
|
2017-04-19 02:53:15 -07:00
|
|
|
uri: 'ImageInAssetCatalog',
|
2017-05-05 20:50:47 -07:00
|
|
|
bundle: 'RNTesterBundle',
|
2016-08-31 17:30:50 -07:00
|
|
|
width: 100,
|
|
|
|
height: 100,
|
|
|
|
}}
|
|
|
|
style={{marginLeft: 10, borderColor: 'blue', borderWidth: 4}}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
2016-09-29 07:23:36 -07:00
|
|
|
platform: 'ios',
|
2016-08-31 17:30:50 -07:00
|
|
|
},
|
2017-03-02 07:32:08 -08:00
|
|
|
{
|
|
|
|
title: 'Blur Radius',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View style={styles.horizontal}>
|
2018-05-11 13:32:37 -07:00
|
|
|
<Image style={[styles.base]} source={fullImage} blurRadius={0} />
|
2017-03-02 07:32:08 -08:00
|
|
|
<Image
|
|
|
|
style={[styles.base, styles.leftMargin]}
|
|
|
|
source={fullImage}
|
|
|
|
blurRadius={5}
|
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
style={[styles.base, styles.leftMargin]}
|
|
|
|
source={fullImage}
|
|
|
|
blurRadius={10}
|
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
style={[styles.base, styles.leftMargin]}
|
|
|
|
source={fullImage}
|
|
|
|
blurRadius={15}
|
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
style={[styles.base, styles.leftMargin]}
|
|
|
|
source={fullImage}
|
|
|
|
blurRadius={20}
|
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
style={[styles.base, styles.leftMargin]}
|
|
|
|
source={fullImage}
|
|
|
|
blurRadius={25}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
2015-02-19 20:10:52 -08:00
|
|
|
];
|
|
|
|
|
2018-10-30 14:26:13 -07:00
|
|
|
const fullImage = {
|
2018-05-11 13:32:37 -07:00
|
|
|
uri: 'https://facebook.github.io/react-native/img/opengraph.png',
|
|
|
|
};
|
2018-10-30 14:26:13 -07:00
|
|
|
const smallImage = {
|
2018-05-11 13:32:37 -07:00
|
|
|
uri: 'https://facebook.github.io/react-native/img/favicon.png',
|
|
|
|
};
|
2015-02-19 20:10:52 -08:00
|
|
|
|
2018-10-30 14:26:13 -07:00
|
|
|
const styles = StyleSheet.create({
|
2015-02-19 20:10:52 -08:00
|
|
|
base: {
|
|
|
|
width: 38,
|
|
|
|
height: 38,
|
|
|
|
},
|
2015-07-14 13:56:55 -07:00
|
|
|
progress: {
|
|
|
|
flex: 1,
|
|
|
|
alignItems: 'center',
|
|
|
|
flexDirection: 'row',
|
2018-05-11 13:32:37 -07:00
|
|
|
width: 100,
|
2015-07-14 13:56:55 -07:00
|
|
|
},
|
2015-02-19 20:10:52 -08:00
|
|
|
leftMargin: {
|
|
|
|
marginLeft: 10,
|
|
|
|
},
|
|
|
|
background: {
|
2018-05-11 13:32:37 -07:00
|
|
|
backgroundColor: '#222222',
|
2015-02-19 20:10:52 -08:00
|
|
|
},
|
2015-07-13 10:30:34 -07:00
|
|
|
sectionText: {
|
|
|
|
marginVertical: 6,
|
|
|
|
},
|
2015-02-19 20:10:52 -08:00
|
|
|
nestedText: {
|
|
|
|
marginLeft: 12,
|
|
|
|
marginTop: 20,
|
|
|
|
backgroundColor: 'transparent',
|
2018-05-11 13:32:37 -07:00
|
|
|
color: 'white',
|
2015-02-19 20:10:52 -08:00
|
|
|
},
|
|
|
|
resizeMode: {
|
|
|
|
width: 90,
|
|
|
|
height: 60,
|
|
|
|
borderWidth: 0.5,
|
2018-05-11 13:32:37 -07:00
|
|
|
borderColor: 'black',
|
2015-02-19 20:10:52 -08:00
|
|
|
},
|
|
|
|
resizeModeText: {
|
|
|
|
fontSize: 11,
|
|
|
|
marginBottom: 3,
|
|
|
|
},
|
|
|
|
icon: {
|
|
|
|
width: 15,
|
|
|
|
height: 15,
|
|
|
|
},
|
|
|
|
horizontal: {
|
|
|
|
flexDirection: 'row',
|
2015-09-04 04:35:44 -07:00
|
|
|
},
|
|
|
|
gif: {
|
|
|
|
flex: 1,
|
|
|
|
height: 200,
|
|
|
|
},
|
2015-10-19 09:04:54 -07:00
|
|
|
base64: {
|
|
|
|
flex: 1,
|
|
|
|
height: 50,
|
|
|
|
resizeMode: 'contain',
|
|
|
|
},
|
2016-06-13 14:04:19 -07:00
|
|
|
touchableText: {
|
|
|
|
fontWeight: '500',
|
|
|
|
color: 'blue',
|
|
|
|
},
|
2015-02-19 20:10:52 -08:00
|
|
|
});
|