Skip to content

Commit 4696267

Browse files
Adam Comellaaleclarson
authored andcommitted
iOS: Enable views to be nested within <Text>
Summary: Previously, only Text and Image could be nested within Text. Now, any view can be nested within Text. One restriction of this feature is that developers must give inline views a width and a height via the style prop. Previously, inline Images were supported by using iOS's built-in support for rendering images with an NSAttributedString via NSTextAttachment. However, NSAttributedString doesn't support rendering arbitrary views. This change adds support for nesting views within Text by creating one NSTextAttachment per inline view. The NSTextAttachments act as placeholders. They are set to be the size of the corresponding view. After the text is laid out, we query the text system to find out where it has positioned each NSTextAttachment. We then position the views to be at those locations. This commit also contains a change in `RCTShadowText.m` `_setParagraphStyleOnAttributedString:heightOfTallestSubview:`. It now only sets `lineHeight`, `textAlign`, and `writingDirection` when they've actua Closes facebook#7304 Differential Revision: D3269333 Pulled By: nicklockwood fbshipit-source-id: 2b59f1c5445a4012f9c29df9f10f5010060ea517
1 parent fc99d26 commit 4696267

File tree

15 files changed

+199
-229
lines changed

15 files changed

+199
-229
lines changed

Libraries/Image/ImageView.ios.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,6 @@ var ImageView = React.createClass({
208208
validAttributes: ReactNativeViewAttributes.UIView
209209
},
210210

211-
contextTypes: {
212-
isInAParentText: React.PropTypes.bool
213-
},
214-
215211
render: function() {
216212
var source = resolveAssetSource(this.props.source) || { uri: undefined, width: undefined, height: undefined };
217213
var {width, height, uri} = source;
@@ -236,13 +232,6 @@ var ImageView = React.createClass({
236232
console.warn('The <ImageView> component requires a `source` property rather than `src`.');
237233
}
238234

239-
if (this.context.isInAParentText) {
240-
RawImage = RCTVirtualImage;
241-
if (!width || !height) {
242-
console.warn('You must specify a width and height for the image %s', uri);
243-
}
244-
}
245-
246235
return (
247236
<RawImage
248237
{...this.props}
@@ -263,7 +252,6 @@ var styles = StyleSheet.create({
263252

264253
var RCTImageView = requireNativeComponent('RCTImageView', Image);
265254
var RCTNetworkImageView = NetworkImageViewManager ? requireNativeComponent('RCTNetworkImageView', Image) : RCTImageView;
266-
var RCTVirtualImage = requireNativeComponent('RCTVirtualImage', Image);
267255

268256
/**
269257
* Retrieve the width and height (in pixels) of an image prior to displaying it.

Libraries/Image/RCTImage.xcodeproj/project.pbxproj

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@
4343
134B00A11B54232B00EC8DFB /* RCTImageUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTImageUtils.m; sourceTree = "<group>"; };
4444
139A38821C4D57AD00862840 /* RCTResizeMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTResizeMode.h; sourceTree = "<group>"; };
4545
139A38831C4D587C00862840 /* RCTResizeMode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTResizeMode.m; sourceTree = "<group>"; };
46-
13EF7F071BC42D4E003F47DD /* RCTShadowVirtualImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTShadowVirtualImage.h; sourceTree = "<group>"; };
47-
13EF7F081BC42D4E003F47DD /* RCTShadowVirtualImage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTShadowVirtualImage.m; sourceTree = "<group>"; };
48-
13EF7F091BC42D4E003F47DD /* RCTVirtualImageManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTVirtualImageManager.h; sourceTree = "<group>"; };
49-
13EF7F0A1BC42D4E003F47DD /* RCTVirtualImageManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTVirtualImageManager.m; sourceTree = "<group>"; };
5046
13EF7F7D1BC825B1003F47DD /* RCTXCAssetImageLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTXCAssetImageLoader.h; sourceTree = "<group>"; };
5147
13EF7F7E1BC825B1003F47DD /* RCTXCAssetImageLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTXCAssetImageLoader.m; sourceTree = "<group>"; };
5248
143879361AAD32A300F088A5 /* RCTImageLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTImageLoader.h; sourceTree = "<group>"; };
@@ -90,10 +86,6 @@
9086
35123E6A1B59C99D00EBAD80 /* RCTImageStoreManager.m */,
9187
134B00A01B54232B00EC8DFB /* RCTImageUtils.h */,
9288
134B00A11B54232B00EC8DFB /* RCTImageUtils.m */,
93-
13EF7F071BC42D4E003F47DD /* RCTShadowVirtualImage.h */,
94-
13EF7F081BC42D4E003F47DD /* RCTShadowVirtualImage.m */,
95-
13EF7F091BC42D4E003F47DD /* RCTVirtualImageManager.h */,
96-
13EF7F0A1BC42D4E003F47DD /* RCTVirtualImageManager.m */,
9789
58B5115E1A9E6B3D00147676 /* Products */,
9890
);
9991
indentWidth = 2;
@@ -164,15 +156,13 @@
164156
isa = PBXSourcesBuildPhase;
165157
buildActionMask = 2147483647;
166158
files = (
167-
13EF7F0C1BC42D4E003F47DD /* RCTVirtualImageManager.m in Sources */,
168159
35123E6B1B59C99D00EBAD80 /* RCTImageStoreManager.m in Sources */,
169160
1304D5AC1AA8C4A30002E2BE /* RCTImageViewManager.m in Sources */,
170161
1304D5B21AA8C50D0002E2BE /* RCTGIFImageDecoder.m in Sources */,
171162
143879381AAD32A300F088A5 /* RCTImageLoader.m in Sources */,
172163
354631681B69857700AA0B86 /* RCTImageEditingManager.m in Sources */,
173164
139A38841C4D587C00862840 /* RCTResizeMode.m in Sources */,
174165
1304D5AB1AA8C4A30002E2BE /* RCTImageView.m in Sources */,
175-
13EF7F0B1BC42D4E003F47DD /* RCTShadowVirtualImage.m in Sources */,
176166
13EF7F7F1BC825B1003F47DD /* RCTXCAssetImageLoader.m in Sources */,
177167
134B00A21B54232B00EC8DFB /* RCTImageUtils.m in Sources */,
178168
);

Libraries/Image/RCTImageView.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
*/
99

1010
#import <UIKit/UIKit.h>
11-
#import "RCTImageComponent.h"
1211
#import "RCTResizeMode.h"
1312

1413
@class RCTBridge;
1514
@class RCTImageSource;
1615

17-
@interface RCTImageView : UIImageView <RCTImageComponent>
16+
@interface RCTImageView : UIImageView
1817

1918
- (instancetype)initWithBridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER;
2019

Libraries/Image/RCTShadowVirtualImage.h

Lines changed: 0 additions & 28 deletions
This file was deleted.

Libraries/Image/RCTShadowVirtualImage.m

Lines changed: 0 additions & 86 deletions
This file was deleted.

Libraries/Image/RCTVirtualImageManager.h

Lines changed: 0 additions & 14 deletions
This file was deleted.

Libraries/Image/RCTVirtualImageManager.m

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)