Skip to content

Commit

Permalink
Add way to compile out ASTextNode + TextKit dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
maicki committed Nov 18, 2018
1 parent 8029632 commit 7863840
Show file tree
Hide file tree
Showing 30 changed files with 158 additions and 6 deletions.
10 changes: 10 additions & 0 deletions Source/ASTextNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@
//

#import <AsyncDisplayKit/ASAvailability.h>

#import <AsyncDisplayKit/ASControlNode.h>
#import <AsyncDisplayKit/ASTextNodeCommon.h>

#if (!AS_ENABLE_TEXTNODE)

// Pull in ASTextNode2 to replace ASTextNode with ASTextNode2
#import <AsyncDisplayKit/ASTextNode2.h>

#else

NS_ASSUME_NONNULL_BEGIN

/**
Expand Down Expand Up @@ -251,3 +259,5 @@ NS_ASSUME_NONNULL_BEGIN
@end

NS_ASSUME_NONNULL_END

#endif
5 changes: 5 additions & 0 deletions Source/ASTextNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
//

#import <AsyncDisplayKit/ASTextNode.h>

#if AS_ENABLE_TEXTNODE

#import <AsyncDisplayKit/ASTextNode2.h>

#import <AsyncDisplayKit/ASTextNode+Beta.h>
Expand Down Expand Up @@ -1427,3 +1430,5 @@ - (NSAttributedString *)truncationAttributedString
}

@end

#endif
8 changes: 8 additions & 0 deletions Source/ASTextNode2.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ NS_ASSUME_NONNULL_BEGIN
@abstract Draws interactive rich text.
@discussion Backed by the code in TextExperiment folder, on top of CoreText.
*/
#if AS_ENABLE_TEXTNODE
@interface ASTextNode2 : ASControlNode
#else
@interface ASTextNode : ASControlNode
#endif

/**
@abstract The styled text displayed by the node.
Expand Down Expand Up @@ -215,7 +219,11 @@ NS_ASSUME_NONNULL_BEGIN

@end

#if AS_ENABLE_TEXTNODE
@interface ASTextNode2 (Unavailable)
#else
@interface ASTextNode (Unavailable)
#endif

- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(nullable ASDisplayNodeDidLoadBlock)didLoadBlock NS_UNAVAILABLE;

Expand Down
8 changes: 8 additions & 0 deletions Source/ASTextNode2.mm
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,19 @@ @implementation ASTextCacheValue
static const CGFloat ASTextNodeHighlightDarkOpacity = 0.22;
static NSString *ASTextNodeTruncationTokenAttributeName = @"ASTextNodeTruncationAttribute";

#if AS_ENABLE_TEXTNODE
@interface ASTextNode2 () <UIGestureRecognizerDelegate>
#else
@interface ASTextNode () <UIGestureRecognizerDelegate>
#endif

@end

#if AS_ENABLE_TEXTNODE
@implementation ASTextNode2 {
#else
@implementation ASTextNode {
#endif
ASTextContainer *_textContainer;

CGSize _shadowOffset;
Expand Down
2 changes: 2 additions & 0 deletions Source/ASTextNodeCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import <Foundation/Foundation.h>

#import <AsyncDisplayKit/ASAvailability.h>

@class ASTextNode;

#define AS_TEXT_ALERT_UNIMPLEMENTED_FEATURE() { \
Expand Down
4 changes: 4 additions & 0 deletions Source/Base/ASAvailability.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#define AS_TLS_AVAILABLE 1
#endif

#ifndef AS_ENABLE_TEXTNODE
#define AS_ENABLE_TEXTNODE 1 // Enable old TextNode by default
#endif

#ifndef AS_USE_PHOTOS
#define AS_USE_PHOTOS 0
#endif
Expand Down
7 changes: 7 additions & 0 deletions Source/TextKit/ASTextKitAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
#pragma once

#import <UIKit/UIKit.h>

#import <AsyncDisplayKit/ASAvailability.h>

#if AS_ENABLE_TEXTNODE

#import <AsyncDisplayKit/ASEqualityHelpers.h>

AS_EXTERN NSString *const ASTextKitTruncationAttributeName;
Expand Down Expand Up @@ -119,3 +124,5 @@ struct ASTextKitAttributes {

size_t hash() const;
};

#endif
4 changes: 4 additions & 0 deletions Source/TextKit/ASTextKitAttributes.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#import <AsyncDisplayKit/ASTextKitAttributes.h>

#if AS_ENABLE_TEXTNODE

#import <AsyncDisplayKit/ASHashing.h>

NSString *const ASTextKitTruncationAttributeName = @"ck_truncation";
Expand Down Expand Up @@ -44,3 +46,5 @@
};
return ASHashBytes(&data, sizeof(data));
}

#endif
1 change: 1 addition & 0 deletions Source/TextKit/ASTextKitComponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//

#import <UIKit/UIKit.h>

#import <AsyncDisplayKit/ASBaseDefines.h>

NS_ASSUME_NONNULL_BEGIN
Expand Down
7 changes: 7 additions & 0 deletions Source/TextKit/ASTextKitContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
//

#import <UIKit/UIKit.h>

#import <AsyncDisplayKit/ASAvailability.h>

#if AS_ENABLE_TEXTNODE

#import <AsyncDisplayKit/ASBaseDefines.h>

/**
Expand Down Expand Up @@ -44,3 +49,5 @@ AS_SUBCLASSING_RESTRICTED
NSTextContainer *textContainer))block;

@end

#endif
5 changes: 5 additions & 0 deletions Source/TextKit/ASTextKitContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
//

#import <AsyncDisplayKit/ASTextKitContext.h>

#if AS_ENABLE_TEXTNODE

#import <AsyncDisplayKit/ASLayoutManager.h>
#import <AsyncDisplayKit/ASThread.h>

Expand Down Expand Up @@ -73,3 +76,5 @@ - (void)performBlockWithLockedTextKitComponents:(NS_NOESCAPE void (^)(NSLayoutMa
}

@end

#endif
7 changes: 6 additions & 1 deletion Source/TextKit/ASTextKitCoreTextAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#import <AsyncDisplayKit/ASAvailability.h>

#if AS_ENABLE_TEXTNODE

#import <AsyncDisplayKit/ASBaseDefines.h>

NS_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -82,3 +85,5 @@ AS_EXTERN NSAttributedString *ASCleanseAttributedStringOfCoreTextAttributes(NSAt
@end

NS_ASSUME_NONNULL_END

#endif
4 changes: 4 additions & 0 deletions Source/TextKit/ASTextKitCoreTextAdditions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#import <AsyncDisplayKit/ASTextKitCoreTextAdditions.h>

#if AS_ENABLE_TEXTNODE

#import <CoreText/CTFont.h>
#import <CoreText/CTStringAttributes.h>

Expand Down Expand Up @@ -333,3 +335,5 @@ + (NSParagraphStyle *)paragraphStyleWithCTParagraphStyle:(CTParagraphStyleRef)co
}

@end

#endif
7 changes: 7 additions & 0 deletions Source/TextKit/ASTextKitEntityAttribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
//

#import <Foundation/Foundation.h>

#import <AsyncDisplayKit/ASAvailability.h>

#if AS_ENABLE_TEXTNODE

#import <AsyncDisplayKit/ASBaseDefines.h>

/**
Expand All @@ -27,3 +32,5 @@ AS_SUBCLASSING_RESTRICTED
- (instancetype)initWithEntity:(id<NSObject>)entity;

@end

#endif
4 changes: 4 additions & 0 deletions Source/TextKit/ASTextKitEntityAttribute.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#import <AsyncDisplayKit/ASTextKitEntityAttribute.h>

#if AS_ENABLE_TEXTNODE

@implementation ASTextKitEntityAttribute

- (instancetype)initWithEntity:(id<NSObject>)entity
Expand Down Expand Up @@ -37,3 +39,5 @@ - (BOOL)isEqual:(id)object
}

@end

#endif
8 changes: 7 additions & 1 deletion Source/TextKit/ASTextKitFontSizeAdjuster.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
//

#import <UIKit/UIKit.h>

#import <AsyncDisplayKit/ASAvailability.h>

#if AS_ENABLE_TEXTNODE

#import <AsyncDisplayKit/ASTextKitAttributes.h>
#import <AsyncDisplayKit/ASBaseDefines.h>

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -50,3 +54,5 @@ AS_SUBCLASSING_RESTRICTED
@end

NS_ASSUME_NONNULL_END

#endif
4 changes: 4 additions & 0 deletions Source/TextKit/ASTextKitFontSizeAdjuster.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#import <AsyncDisplayKit/ASTextKitFontSizeAdjuster.h>

#if AS_ENABLE_TEXTNODE

#import <tgmath.h>
#import <mutex>

Expand Down Expand Up @@ -235,3 +237,5 @@ - (CGFloat)scaleFactor
}

@end

#endif
4 changes: 4 additions & 0 deletions Source/TextKit/ASTextKitRenderer+Positioning.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#import <AsyncDisplayKit/ASTextKitRenderer.h>

#if AS_ENABLE_TEXTNODE

typedef void (^as_text_component_index_block_t)(NSUInteger characterIndex,
CGRect glyphBoundingRect,
BOOL *stop);
Expand Down Expand Up @@ -100,3 +102,5 @@ typedef NS_ENUM(NSUInteger, ASTextKitRendererMeasureOption) {
- (CGRect)trailingRect;

@end

#endif
4 changes: 4 additions & 0 deletions Source/TextKit/ASTextKitRenderer+Positioning.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#import <AsyncDisplayKit/ASTextKitRenderer+Positioning.h>

#if AS_ENABLE_TEXTNODE

#import <CoreText/CoreText.h>
#import <tgmath.h>

Expand Down Expand Up @@ -380,3 +382,5 @@ - (CGRect)frameForTextRange:(NSRange)textRange
}

@end

#endif
4 changes: 4 additions & 0 deletions Source/TextKit/ASTextKitRenderer+TextChecking.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#import <AsyncDisplayKit/ASTextKitRenderer.h>

#if AS_ENABLE_TEXTNODE

/**
Application extensions to NSTextCheckingType. We're allowed to do this (see NSTextCheckingAllCustomTypes).
*/
Expand All @@ -26,3 +28,5 @@ static uint64_t const ASTextKitTextCheckingTypeTruncation = 1ULL << 34
- (NSTextCheckingResult *)textCheckingResultAtPoint:(CGPoint)point;

@end

#endif
4 changes: 4 additions & 0 deletions Source/TextKit/ASTextKitRenderer+TextChecking.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#import <AsyncDisplayKit/ASTextKitRenderer+TextChecking.h>

#if AS_ENABLE_TEXTNODE

#import <AsyncDisplayKit/ASTextKitEntityAttribute.h>
#import <AsyncDisplayKit/ASTextKitRenderer+Positioning.h>
#import <AsyncDisplayKit/ASTextKitTailTruncater.h>
Expand Down Expand Up @@ -98,3 +100,5 @@ - (NSTextCheckingResult *)textCheckingResultAtPoint:(CGPoint)point
}

@end

#endif
10 changes: 8 additions & 2 deletions Source/TextKit/ASTextKitRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//

#import <vector>

#import <UIKit/UIKit.h>

#import <AsyncDisplayKit/ASAvailability.h>

#if AS_ENABLE_TEXTNODE

#import <AsyncDisplayKit/ASTextKitAttributes.h>

#import <vector>

@class ASTextKitContext;
@class ASTextKitShadower;
@class ASTextKitFontSizeAdjuster;
Expand Down Expand Up @@ -100,3 +104,5 @@
@property (nonatomic, readonly) NSRange firstVisibleRange;

@end

#endif
4 changes: 4 additions & 0 deletions Source/TextKit/ASTextKitRenderer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#import <AsyncDisplayKit/ASTextKitRenderer.h>

#if AS_ENABLE_TEXTNODE

#import <AsyncDisplayKit/ASAssert.h>

#import <AsyncDisplayKit/ASTextKitContext.h>
Expand Down Expand Up @@ -289,3 +291,5 @@ - (NSRange)firstVisibleRange
}

@end

#endif
7 changes: 7 additions & 0 deletions Source/TextKit/ASTextKitShadower.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
//

#import <UIKit/UIKit.h>

#import <AsyncDisplayKit/ASAvailability.h>

#if AS_ENABLE_TEXTNODE

#import <AsyncDisplayKit/ASBaseDefines.h>

/**
Expand Down Expand Up @@ -69,3 +74,5 @@ AS_SUBCLASSING_RESTRICTED
- (void)setShadowInContext:(CGContextRef)context;

@end

#endif
Loading

0 comments on commit 7863840

Please sign in to comment.