Skip to content

Commit

Permalink
The Great File Renaming in RCTText
Browse files Browse the repository at this point in the history
Summary:
The previous file/class name convention seemed cool... but now it drives me BANANAS! It makes all this code really hard to maintain.
So, evething were renamed following common modern RN convention.

Reviewed By: mmmulani

Differential Revision: D6605090

fbshipit-source-id: 88ca13d793a5d2adaac2b7922ec6bd4654aacec5
  • Loading branch information
shergin authored and facebook-github-bot committed Dec 20, 2017
1 parent 5c8481e commit 19a9c5e
Show file tree
Hide file tree
Showing 40 changed files with 385 additions and 251 deletions.
4 changes: 2 additions & 2 deletions Libraries/Components/ScrollResponder.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ function isTagInstanceOfTextInput(tag) {
var instance = getInstanceFromNode(tag);
return instance && instance.viewConfig && (
instance.viewConfig.uiViewClassName === 'AndroidTextInput' ||
instance.viewConfig.uiViewClassName === 'RCTTextView' ||
instance.viewConfig.uiViewClassName === 'RCTTextField'
instance.viewConfig.uiViewClassName === 'RCTMultilineTextInputView' ||
instance.viewConfig.uiViewClassName === 'RCTSinglelineTextInputView'
);
}

Expand Down
12 changes: 6 additions & 6 deletions Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const onlyMultiline = {
if (Platform.OS === 'android') {
var AndroidTextInput = requireNativeComponent('AndroidTextInput', null);
} else if (Platform.OS === 'ios') {
var RCTTextView = requireNativeComponent('RCTTextView', null);
var RCTTextField = requireNativeComponent('RCTTextField', null);
var RCTMultilineTextInputView = requireNativeComponent('RCTMultilineTextInputView', null);
var RCTSinglelineTextInputView = requireNativeComponent('RCTSinglelineTextInputView', null);
}

type Event = Object;
Expand Down Expand Up @@ -707,7 +707,7 @@ const TextInput = createReactClass({
}
}
textContainer =
<RCTTextField
<RCTSinglelineTextInputView
ref={this._setNativeRef}
{...props}
onFocus={this._onFocus}
Expand All @@ -733,7 +733,7 @@ const TextInput = createReactClass({
}
props.style.unshift(styles.multilineInput);
textContainer =
<RCTTextView
<RCTMultilineTextInputView
ref={this._setNativeRef}
{...props}
children={children}
Expand Down Expand Up @@ -926,8 +926,8 @@ const TextInput = createReactClass({

var styles = StyleSheet.create({
multilineInput: {
// This default top inset makes RCTTextView seem as close as possible
// to single-line RCTTextField defaults, using the system defaults
// This default top inset makes RCTMultilineTextInputView seem as close as possible
// to single-line RCTSinglelineTextInputView defaults, using the system defaults
// of font size 17 and a height of 31 points.
paddingTop: 5,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#import <React/RCTShadowView.h>

@interface RCTShadowRawText : RCTShadowView
@interface RCTRawTextShadowView : RCTShadowView

@property (nonatomic, copy) NSString *text;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import "RCTShadowRawText.h"
#import "RCTRawTextShadowView.h"

#import <React/RCTUIManager.h>

@implementation RCTShadowRawText
@implementation RCTRawTextShadowView

- (instancetype)init
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

#import <React/RCTViewManager.h>

@interface RCTRawTextManager : RCTViewManager
@interface RCTRawTextViewManager : RCTViewManager

@end
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import "RCTRawTextManager.h"
#import "RCTRawTextViewManager.h"

#import "RCTShadowRawText.h"
#import "RCTRawTextShadowView.h"

@implementation RCTRawTextManager
@implementation RCTRawTextViewManager

RCT_EXPORT_MODULE()
RCT_EXPORT_MODULE(RCTRawText)

- (RCTShadowView *)shadowView
{
return [RCTShadowRawText new];
return [RCTRawTextShadowView new];
}

RCT_EXPORT_SHADOW_PROPERTY(text, NSString)
Expand Down
386 changes: 248 additions & 138 deletions Libraries/Text/RCTText.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typedef NS_ENUM(NSInteger, RCTSizeComparison)
extern NSString *const RCTIsHighlightedAttributeName;
extern NSString *const RCTReactTagAttributeName;

@interface RCTShadowText : RCTShadowView
@interface RCTTextShadowView : RCTShadowView

@property (nonatomic, strong) UIColor *color;
@property (nonatomic, strong) UIColor *backgroundColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import "RCTShadowText.h"
#import "RCTTextShadowView.h"

#import <React/RCTAccessibilityManager.h>
#import <React/RCTBridge.h>
Expand All @@ -18,9 +18,9 @@
#import <React/RCTUIManager.h>
#import <React/RCTUtils.h>

#import "RCTShadowRawText.h"
#import "RCTText.h"
#import "RCTRawTextShadowView.h"
#import "RCTTextView.h"
#import "RCTMultilineTextInputView.h"

NSString *const RCTIsHighlightedAttributeName = @"IsHighlightedAttributeName";
NSString *const RCTReactTagAttributeName = @"ReactTagAttributeName";
Expand All @@ -31,7 +31,7 @@
static CGFloat const kAutoSizeHeightErrorMargin = 0.025f;
static CGFloat const kAutoSizeGranularity = 0.001f;

@implementation RCTShadowText
@implementation RCTTextShadowView
{
NSTextStorage *_cachedTextStorage;
CGFloat _cachedTextStorageWidth;
Expand All @@ -43,7 +43,7 @@ @implementation RCTShadowText

static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode)
{
RCTShadowText *shadowText = (__bridge RCTShadowText *)YGNodeGetContext(node);
RCTTextShadowView *shadowText = (__bridge RCTTextShadowView *)YGNodeGetContext(node);
NSTextStorage *textStorage = [shadowText buildTextStorageForWidth:width widthMode:widthMode];
[shadowText calculateTextFrame:textStorage];
NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject;
Expand Down Expand Up @@ -109,7 +109,7 @@ - (void)contentSizeMultiplierDidChange:(NSNotification *)note
- (NSDictionary<NSString *, id> *)processUpdatedProperties:(NSMutableSet<RCTApplierBlock> *)applierBlocks
parentProperties:(NSDictionary<NSString *, id> *)parentProperties
{
if ([[self reactSuperview] isKindOfClass:[RCTShadowText class]]) {
if ([[self reactSuperview] isKindOfClass:[RCTTextShadowView class]]) {
return parentProperties;
}

Expand All @@ -122,22 +122,22 @@ - (void)contentSizeMultiplierDidChange:(NSNotification *)note
CGRect textFrame = [self calculateTextFrame:textStorage];
BOOL selectable = _selectable;
[applierBlocks addObject:^(NSDictionary<NSNumber *, UIView *> *viewRegistry) {
RCTText *view = (RCTText *)viewRegistry[self.reactTag];
RCTTextView *view = (RCTTextView *)viewRegistry[self.reactTag];
view.textFrame = textFrame;
view.textStorage = textStorage;
view.selectable = selectable;

/**
* NOTE: this logic is included to support rich text editing inside multiline
* `<TextInput>` controls. It is required in order to ensure that the
* textStorage (aka attributed string) is copied over from the RCTShadowText
* to the RCTText view in time to be used to update the editable text content.
* TODO: we should establish a delegate relationship betweeen RCTTextView
* and its contaned RCTText element when they get inserted and get rid of this
* textStorage (aka attributed string) is copied over from the RCTTextShadowView
* to the RCTTextView view in time to be used to update the editable text content.
* TODO: we should establish a delegate relationship betweeen RCTMultilineTextInputView
* and its contaned RCTTextView element when they get inserted and get rid of this
*/
UIView *parentView = viewRegistry[parentTag];
if ([parentView respondsToSelector:@selector(performTextUpdate)]) {
[(RCTTextView *)parentView performTextUpdate];
[(RCTMultilineTextInputView *)parentView performTextUpdate];
}
}];

Expand Down Expand Up @@ -308,8 +308,8 @@ - (NSAttributedString *)_attributedStringWithFontFamily:(NSString *)fontFamily
CGFloat heightOfTallestSubview = 0.0;
NSMutableAttributedString *attributedString = [NSMutableAttributedString new];
for (RCTShadowView *child in [self reactSubviews]) {
if ([child isKindOfClass:[RCTShadowText class]]) {
RCTShadowText *shadowText = (RCTShadowText *)child;
if ([child isKindOfClass:[RCTTextShadowView class]]) {
RCTTextShadowView *shadowText = (RCTTextShadowView *)child;
[attributedString appendAttributedString:
[shadowText _attributedStringWithFontFamily:fontFamily
fontSize:fontSize
Expand All @@ -321,8 +321,8 @@ - (NSAttributedString *)_attributedStringWithFontFamily:(NSString *)fontFamily
backgroundColor:shadowText.backgroundColor ?: backgroundColor
opacity:opacity * shadowText.opacity]];
[child setTextComputed];
} else if ([child isKindOfClass:[RCTShadowRawText class]]) {
RCTShadowRawText *shadowRawText = (RCTShadowRawText *)child;
} else if ([child isKindOfClass:[RCTRawTextShadowView class]]) {
RCTRawTextShadowView *shadowRawText = (RCTRawTextShadowView *)child;
[attributedString appendAttributedString:[[NSAttributedString alloc] initWithString:shadowRawText.text ?: @""]];
[child setTextComputed];
} else {
Expand All @@ -340,7 +340,7 @@ - (NSAttributedString *)_attributedStringWithFontFamily:(NSString *)fontFamily
if (height > heightOfTallestSubview) {
heightOfTallestSubview = height;
}
// Don't call setTextComputed on this child. RCTTextManager takes care of
// Don't call setTextComputed on this child. RCTTextViewManager takes care of
// processing inline UIViews.
}
}
Expand Down Expand Up @@ -653,8 +653,8 @@ - (void)setAllowFontScaling:(BOOL)allowFontScaling
{
_allowFontScaling = allowFontScaling;
for (RCTShadowView *child in [self reactSubviews]) {
if ([child isKindOfClass:[RCTShadowText class]]) {
((RCTShadowText *)child).allowFontScaling = allowFontScaling;
if ([child isKindOfClass:[RCTTextShadowView class]]) {
((RCTTextShadowView *)child).allowFontScaling = allowFontScaling;
}
}
[self dirtyText];
Expand All @@ -668,8 +668,8 @@ - (void)setFontSizeMultiplier:(CGFloat)fontSizeMultiplier
_fontSizeMultiplier = 1.0;
}
for (RCTShadowView *child in [self reactSubviews]) {
if ([child isKindOfClass:[RCTShadowText class]]) {
((RCTShadowText *)child).fontSizeMultiplier = fontSizeMultiplier;
if ([child isKindOfClass:[RCTTextShadowView class]]) {
((RCTTextShadowView *)child).fontSizeMultiplier = fontSizeMultiplier;
}
}
[self dirtyText];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#import <UIKit/UIKit.h>

@interface RCTText : UIView
@interface RCTTextView : UIView

@property (nonatomic, assign) UIEdgeInsets contentInset;
@property (nonatomic, strong) NSTextStorage *textStorage;
Expand Down
12 changes: 6 additions & 6 deletions Libraries/Text/RCTText.m → Libraries/Text/Text/RCTTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import "RCTText.h"
#import "RCTTextView.h"

#import <MobileCoreServices/UTCoreTypes.h>

#import <React/RCTUtils.h>
#import <React/UIView+React.h>

#import "RCTShadowText.h"
#import "RCTTextShadowView.h"

static void collectNonTextDescendants(RCTText *view, NSMutableArray *nonTextDescendants)
static void collectNonTextDescendants(RCTTextView *view, NSMutableArray *nonTextDescendants)
{
for (UIView *child in view.reactSubviews) {
if ([child isKindOfClass:[RCTText class]]) {
collectNonTextDescendants((RCTText *)child, nonTextDescendants);
if ([child isKindOfClass:[RCTTextView class]]) {
collectNonTextDescendants((RCTTextView *)child, nonTextDescendants);
} else if (!CGRectEqualToRect(child.frame, CGRectZero)) {
[nonTextDescendants addObject:child];
}
}
}

@implementation RCTText
@implementation RCTTextView
{
NSTextStorage *_textStorage;
CAShapeLayer *_highlightLayer;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import "RCTTextManager.h"
#import "RCTTextViewManager.h"

#import <React/RCTAccessibilityManager.h>
#import <React/RCTAssert.h>
Expand All @@ -17,42 +17,42 @@
#import <React/UIView+React.h>
#import <yoga/Yoga.h>

#import "RCTShadowRawText.h"
#import "RCTShadowText.h"
#import "RCTText.h"
#import "RCTRawTextShadowView.h"
#import "RCTTextShadowView.h"
#import "RCTTextView.h"
#import "RCTMultilineTextInputView.h"

static void collectDirtyNonTextDescendants(RCTShadowText *shadowView, NSMutableArray *nonTextDescendants) {
static void collectDirtyNonTextDescendants(RCTTextShadowView *shadowView, NSMutableArray *nonTextDescendants) {
for (RCTShadowView *child in shadowView.reactSubviews) {
if ([child isKindOfClass:[RCTShadowText class]]) {
collectDirtyNonTextDescendants((RCTShadowText *)child, nonTextDescendants);
} else if ([child isKindOfClass:[RCTShadowRawText class]]) {
if ([child isKindOfClass:[RCTTextShadowView class]]) {
collectDirtyNonTextDescendants((RCTTextShadowView *)child, nonTextDescendants);
} else if ([child isKindOfClass:[RCTRawTextShadowView class]]) {
// no-op
} else if ([child isTextDirty]) {
[nonTextDescendants addObject:child];
}
}
}

@interface RCTShadowText (Private)
@interface RCTTextShadowView (Private)

- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(YGMeasureMode)widthMode;

@end


@implementation RCTTextManager
@implementation RCTTextViewManager

RCT_EXPORT_MODULE()
RCT_EXPORT_MODULE(RCTText)

- (UIView *)view
{
return [RCTText new];
return [RCTTextView new];
}

- (RCTShadowView *)shadowView
{
return [RCTShadowText new];
return [RCTTextShadowView new];
}

#pragma mark - Shadow properties
Expand Down Expand Up @@ -101,13 +101,13 @@ - (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(NSDictionary<NSNu
RCTShadowView *shadowView = queue[i];
RCTAssert([shadowView isTextDirty], @"Don't process any nodes that don't have dirty text");

if ([shadowView isKindOfClass:[RCTShadowText class]]) {
((RCTShadowText *)shadowView).fontSizeMultiplier = self.bridge.accessibilityManager.multiplier;
[(RCTShadowText *)shadowView recomputeText];
collectDirtyNonTextDescendants((RCTShadowText *)shadowView, queue);
} else if ([shadowView isKindOfClass:[RCTShadowRawText class]]) {
if ([shadowView isKindOfClass:[RCTTextShadowView class]]) {
((RCTTextShadowView *)shadowView).fontSizeMultiplier = self.bridge.accessibilityManager.multiplier;
[(RCTTextShadowView *)shadowView recomputeText];
collectDirtyNonTextDescendants((RCTTextShadowView *)shadowView, queue);
} else if ([shadowView isKindOfClass:[RCTRawTextShadowView class]]) {
RCTLogError(@"Raw text cannot be used outside of a <Text> tag. Not rendering string: '%@'",
[(RCTShadowRawText *)shadowView text]);
[(RCTRawTextShadowView *)shadowView text]);
} else {
for (RCTShadowView *child in [shadowView reactSubviews]) {
if ([child isTextDirty]) {
Expand All @@ -123,13 +123,13 @@ - (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(NSDictionary<NSNu
return nil;
}

- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowView:(RCTShadowText *)shadowView
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowView:(RCTTextShadowView *)shadowView
{
NSNumber *reactTag = shadowView.reactTag;
UIEdgeInsets padding = shadowView.paddingAsInsets;

return ^(RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTText *> *viewRegistry) {
RCTText *text = viewRegistry[reactTag];
return ^(RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTTextView *> *viewRegistry) {
RCTTextView *text = viewRegistry[reactTag];
text.contentInset = padding;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

#import <React/RCTShadowView.h>

@interface RCTShadowTextView : RCTShadowView
@interface RCTMultilineTextInputShadowView : RCTShadowView

@end
Loading

0 comments on commit 19a9c5e

Please sign in to comment.