mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Native implementation of <Image> intrinsic content size on iOS
Summary: Now intrinsic content size of <Image> is implemented natively on iOS and now it is actually `intrinsicContentSize`, not just overrided `height` and `width` styles (which was incorrect and hacky). This change also removes support of nested content inside <Image>. This is a first commit in the row where we improve <Image> implementation. Reviewed By: mmmulani Differential Revision: D5189017 fbshipit-source-id: eab3defa3d86a5d4219b4f4925ab7460b58d760f
This commit is contained in:
committed by
Facebook Github Bot
parent
c47759a9ae
commit
7bd0855650
@@ -352,13 +352,11 @@ const Image = createReactClass({
|
||||
const source = resolveAssetSource(this.props.source) || { uri: undefined, width: undefined, height: undefined };
|
||||
|
||||
let sources;
|
||||
let style;
|
||||
let style = flattenStyle([styles.base, this.props.style]) || {};
|
||||
if (Array.isArray(source)) {
|
||||
style = flattenStyle([styles.base, this.props.style]) || {};
|
||||
sources = source;
|
||||
} else {
|
||||
const {width, height, uri} = source;
|
||||
style = flattenStyle([{width, height}, styles.base, this.props.style]) || {};
|
||||
const {uri} = source;
|
||||
sources = [source];
|
||||
|
||||
if (uri === '') {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#import <React/RCTConvert.h>
|
||||
#import <React/RCTEventDispatcher.h>
|
||||
#import <React/RCTImageSource.h>
|
||||
#import <React/RCTUIManager.h>
|
||||
#import <React/RCTUtils.h>
|
||||
#import <React/UIView+React.h>
|
||||
|
||||
@@ -107,6 +108,22 @@ static NSDictionary *onLoadParamsForSource(RCTImageSource *source)
|
||||
|
||||
RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
|
||||
- (CGSize)intrinsicContentSize
|
||||
{
|
||||
// The first `imageSource` defines intrinsic content size.
|
||||
RCTImageSource *imageSource = _imageSources.firstObject;
|
||||
if (!imageSource) {
|
||||
return CGSizeZero;
|
||||
}
|
||||
|
||||
return imageSource.size;
|
||||
}
|
||||
|
||||
- (void)updateIntrinsicContentSize
|
||||
{
|
||||
[_bridge.uiManager setIntrinsicContentSize:self.intrinsicContentSize forView:self];
|
||||
}
|
||||
|
||||
- (void)updateWithImage:(UIImage *)image
|
||||
{
|
||||
if (!image) {
|
||||
@@ -176,6 +193,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
{
|
||||
if (![imageSources isEqual:_imageSources]) {
|
||||
_imageSources = [imageSources copy];
|
||||
[self updateIntrinsicContentSize];
|
||||
_needsReload = YES;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user