Skip to content

Commit 795b297

Browse files
ASEditableTextNode.
1 parent 1608a00 commit 795b297

3 files changed

Lines changed: 629 additions & 0 deletions

File tree

AsyncDisplayKit.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
055F1A3C19ABD43F004DAFF1 /* ASCellNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 055F1A3A19ABD43F004DAFF1 /* ASCellNode.h */; settings = {ATTRIBUTES = (Public, ); }; };
2929
055F1A3D19ABD43F004DAFF1 /* ASCellNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 055F1A3B19ABD43F004DAFF1 /* ASCellNode.m */; };
3030
0574D5E219C110940097DC25 /* ASTableViewProtocols.h in Headers */ = {isa = PBXBuildFile; fileRef = 0574D5E119C110610097DC25 /* ASTableViewProtocols.h */; settings = {ATTRIBUTES = (Public, ); }; };
31+
0587F9BD1A7309ED00AFF0BA /* ASEditableTextNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0587F9BB1A7309ED00AFF0BA /* ASEditableTextNode.h */; settings = {ATTRIBUTES = (Public, ); }; };
32+
0587F9BE1A7309ED00AFF0BA /* ASEditableTextNode.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0587F9BC1A7309ED00AFF0BA /* ASEditableTextNode.mm */; };
3133
058D09B0195D04C000B7D73C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 058D09AF195D04C000B7D73C /* Foundation.framework */; };
3234
058D09BE195D04C000B7D73C /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 058D09BD195D04C000B7D73C /* XCTest.framework */; };
3335
058D09BF195D04C000B7D73C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 058D09AF195D04C000B7D73C /* Foundation.framework */; };
@@ -193,6 +195,8 @@
193195
055F1A3A19ABD43F004DAFF1 /* ASCellNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASCellNode.h; sourceTree = "<group>"; };
194196
055F1A3B19ABD43F004DAFF1 /* ASCellNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASCellNode.m; sourceTree = "<group>"; };
195197
0574D5E119C110610097DC25 /* ASTableViewProtocols.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ASTableViewProtocols.h; sourceTree = "<group>"; };
198+
0587F9BB1A7309ED00AFF0BA /* ASEditableTextNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASEditableTextNode.h; sourceTree = "<group>"; };
199+
0587F9BC1A7309ED00AFF0BA /* ASEditableTextNode.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASEditableTextNode.mm; sourceTree = "<group>"; };
196200
058D09AC195D04C000B7D73C /* libAsyncDisplayKit.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libAsyncDisplayKit.a; sourceTree = BUILT_PRODUCTS_DIR; };
197201
058D09AF195D04C000B7D73C /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
198202
058D09B3195D04C000B7D73C /* AsyncDisplayKit-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AsyncDisplayKit-Prefix.pch"; sourceTree = "<group>"; };
@@ -369,6 +373,8 @@
369373
058D09D7195D050800B7D73C /* ASControlNode+Subclasses.h */,
370374
058D09DF195D050800B7D73C /* ASTextNode.h */,
371375
058D09E0195D050800B7D73C /* ASTextNode.mm */,
376+
0587F9BB1A7309ED00AFF0BA /* ASEditableTextNode.h */,
377+
0587F9BC1A7309ED00AFF0BA /* ASEditableTextNode.mm */,
372378
058D09DD195D050800B7D73C /* ASImageNode.h */,
373379
058D09DE195D050800B7D73C /* ASImageNode.mm */,
374380
0516FA3E1A1563D200B4EBED /* ASMultiplexImageNode.h */,
@@ -605,6 +611,7 @@
605611
055B9FA81A1C154B00035D6D /* ASNetworkImageNode.h in Headers */,
606612
054963491A1EA066000F8E56 /* ASBasicImageDownloader.h in Headers */,
607613
AC3C4A541A113EEC00143C57 /* ASCollectionViewProtocols.h in Headers */,
614+
0587F9BD1A7309ED00AFF0BA /* ASEditableTextNode.h in Headers */,
608615
05F20AA41A15733C00DCA68A /* ASImageProtocols.h in Headers */,
609616
058D0A71195D05F800B7D73C /* _AS-objc-internal.h in Headers */,
610617
058D0A72195D05F800B7D73C /* _ASCoreAnimationExtras.h in Headers */,
@@ -761,6 +768,7 @@
761768
058D0A1A195D050800B7D73C /* ASHighlightOverlayLayer.mm in Sources */,
762769
464052231A3F83C40061C0BA /* ASFlowLayoutController.mm in Sources */,
763770
058D0A28195D050800B7D73C /* ASDisplayNode+AsyncDisplay.mm in Sources */,
771+
0587F9BE1A7309ED00AFF0BA /* ASEditableTextNode.mm in Sources */,
764772
058D0A21195D050800B7D73C /* NSMutableAttributedString+TextKitAdditions.m in Sources */,
765773
058D0A25195D050800B7D73C /* UIView+ASConvenience.m in Sources */,
766774
0549634A1A1EA066000F8E56 /* ASBasicImageDownloader.mm in Sources */,
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/* Copyright (c) 2014-present, Facebook, Inc.
2+
* All rights reserved.
3+
*
4+
* This source code is licensed under the BSD-style license found in the
5+
* LICENSE file in the root directory of this source tree. An additional grant
6+
* of patent rights can be found in the PATENTS file in the same directory.
7+
*/
8+
9+
#import <AsyncDisplayKit/ASDisplayNode.h>
10+
11+
@protocol ASEditableTextNodeDelegate;
12+
13+
//! @abstract ASEditableTextNode implements a node that supports text editing.
14+
@interface ASEditableTextNode : ASDisplayNode
15+
16+
//! @abstract The text node's delegate, which must conform to the <ASEditableTextNodeDelegate> protocol.
17+
@property (nonatomic, readwrite, weak) id <ASEditableTextNodeDelegate> delegate;
18+
19+
#pragma mark - Configuration
20+
21+
//! @abstract The attributes to apply to new text being entered by the user.
22+
@property (nonatomic, readwrite, strong) NSDictionary *typingAttributes;
23+
24+
//! @abstract The range of text currently selected. If length is zero, the range is the cursor location.
25+
@property (nonatomic, readwrite, assign) NSRange selectedRange;
26+
27+
#pragma mark - Placeholder
28+
/**
29+
@abstract Indicates if the receiver is displaying the placeholder text.
30+
@discussion To update the placeholder, see the <attributedPlaceholderText> property.
31+
@result YES if the placeholder is currently displayed; NO otherwise.
32+
*/
33+
- (BOOL)isDisplayingPlaceholder;
34+
35+
/**
36+
@abstract The styled placeholder text displayed by the text node while no text is entered
37+
@discussion The placeholder is displayed when the user has not entered any text and the keyboard is not visible.
38+
*/
39+
@property (nonatomic, readwrite, strong) NSAttributedString *attributedPlaceholderText;
40+
41+
#pragma mark - Modifying User Text
42+
/**
43+
@abstract The styled text displayed by the receiver.
44+
@discussion When the placeholder is displayed (as indicated by -isDisplayingPlaceholder), this value is nil. Otherwise, this value is the attributed text the user has entered. This value can be modified regardless of whether the receiver is the first responder (and thus, editing) or not. Changing this value from nil to non-nil will result in the placeholder being hidden, and the new value being displayed.
45+
*/
46+
@property (nonatomic, readwrite, copy) NSAttributedString *attributedText;
47+
48+
#pragma mark - Managing The Keyboard
49+
//! @abstract The text input mode used by the receiver's keyboard, if it is visible. This value is undefined if the receiver is not the first responder.
50+
@property (nonatomic, readonly) UITextInputMode *textInputMode;
51+
52+
/**
53+
@abstract Indicates whether the receiver's text view is the first responder, and thus has the keyboard visible and is prepared for editing by the user.
54+
@result YES if the receiver's text view is the first-responder; NO otherwise.
55+
*/
56+
- (BOOL)isFirstResponder;
57+
58+
//! @abstract Makes the receiver's text view the first responder.
59+
- (void)becomeFirstResponder;
60+
61+
//! @abstract Resigns the receiver's text view from first-responder status, if it has it.
62+
- (void)resignFirstResponder;
63+
64+
#pragma mark - Geometry
65+
/**
66+
@abstract Returns the frame of the given range of characters.
67+
@param textRange A range of characters.
68+
@discussion This method raises an exception if `textRange` is not a valid range of characters within the receiver's attributed text.
69+
@result A CGRect that is the bounding box of the glyphs covered by the given range of characters, in the coordinate system of the receiver.
70+
*/
71+
- (CGRect)frameForTextRange:(NSRange)textRange;
72+
73+
@end
74+
75+
#pragma mark -
76+
@protocol ASEditableTextNodeDelegate <NSObject>
77+
78+
@optional
79+
/**
80+
@abstract Indicates to the delegate that the text node began editing.
81+
@param editableTextNode An editable text node.
82+
@discussion The invocation of this method coincides with the keyboard animating to become visible.
83+
*/
84+
- (void)editableTextNodeDidBeginEditing:(ASEditableTextNode *)editableTextNode;
85+
86+
/**
87+
@abstract Asks the delegate whether the specified text should be replaced in the editable text node.
88+
@param editableTextNode An editable text node.
89+
@param range The current selection range. If the length of the range is 0, range reflects the current insertion point. If the user presses the Delete key, the length of the range is 1 and an empty string object replaces that single character.
90+
@param text The text to insert.
91+
@discussion YES if the old text should be replaced by the new text; NO if the replacement operation should be aborted.
92+
@result The text node calls this method whenever the user types a new character or deletes an existing character. Implementation of this method is optional -- the default implementation returns YES.
93+
*/
94+
- (BOOL)editableTextNode:(ASEditableTextNode *)editableTextNode shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;
95+
96+
/**
97+
@abstract Indicates to the delegate that the text node's selection has changed.
98+
@param editableTextNode An editable text node.
99+
@param fromSelectedRange The previously selected range.
100+
@param toSelectedRange The current selected range. Equvialent to the <selectedRange> property.
101+
@param dueToEditing YES if the selection change was due to editing; NO otherwise.
102+
@discussion You can access the selection of the receiver via <selectedRange>.
103+
*/
104+
- (void)editableTextNodeDidChangeSelection:(ASEditableTextNode *)editableTextNode fromSelectedRange:(NSRange)fromSelectedRange toSelectedRange:(NSRange)toSelectedRange dueToEditing:(BOOL)dueToEditing;
105+
106+
/**
107+
@abstract Indicates to the delegate that the text node's text was updated.
108+
@param editableTextNode An editable text node.
109+
@discussion This method is called each time the user updated the text node's text. It is not called for programmatic changes made to the text via the <attributedText> property.
110+
*/
111+
- (void)editableTextNodeDidUpdateText:(ASEditableTextNode *)editableTextNode;
112+
113+
/**
114+
@abstract Indicates to the delegate that teh text node has finished editing.
115+
@param editableTextNode An editable text node.
116+
@discussion The invocation of this method coincides with the keyboard animating to become hidden.
117+
*/
118+
- (void)editableTextNodeDidFinishEditing:(ASEditableTextNode *)editableTextNode;
119+
120+
121+
@end

0 commit comments

Comments
 (0)