Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Usbergo committed Nov 22, 2019
1 parent 39e7dcb commit 6d842e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repositoryURL": "https://github.com/alexdrone/CoreRender",
"state": {
"branch": "master",
"revision": "be1885f15efed24347c985b90cb8e6813c8ac538",
"revision": "39e7dcb443bc9a618678f15d0b3b439d019c6954",
"version": null
}
}
Expand Down
42 changes: 15 additions & 27 deletions Sources/CoreRenderObjC/CRNodeBuilder+Modifiers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,15 @@
#import "CRNodeLayoutSpec.h"
#import "YGLayout.h"

@interface CRNodeBuilder (Private)
- (instancetype)_unsafeSetSpec:(CRNodeLayoutSpec *)spec keyPath:(NSString *)keyPath value:(id)value;
- (instancetype)_unsafeSet:(NSString *)keyPath value:(id)value;
@end

@implementation CRNodeBuilder (Private)

- (instancetype)_unsafeSetSpec:(CRNodeLayoutSpec *)spec
keyPath:(NSString *)keyPath
value:(id)value {
void _CRUnsafeSet(CRNodeLayoutSpec * spec, NSString *keyPath, id value) {
const auto selector = NSSelectorFromString(keyPath);
if (![spec.view respondsToSelector:selector]) {
NSLog(@"warning: %@ cannot find keyPath %@ in class %@", NSStringFromSelector(_cmd), keyPath,
spec.view.class);
NSLog(@"warning: cannot find keyPath %@ in class %@", keyPath, spec.view.class);
} else {
[spec set:keyPath value:value];
}
}

- (instancetype)_unsafeSet:(NSString *)keyPath value:(id)value {
return [self withLayoutSpec:^(CRNodeLayoutSpec *spec) {
[self _unsafeSetSpec:spec keyPath:keyPath value:value];
}];
}

@end

@implementation CRNodeBuilder (Modifiers)

- (instancetype)padding:(CGFloat)padding {
Expand Down Expand Up @@ -289,7 +271,7 @@ - (instancetype)text:(nullable NSString *)text {
if (button) {
[button setTitle:text forState:UIControlStateNormal];
} else {
[self _unsafeSetSpec:spec keyPath:CR_UNSAFE_KEYPATH(text) value:text];
_CRUnsafeSet(spec, CR_UNSAFE_KEYPATH(text), text);
}
}];
}
Expand All @@ -300,7 +282,7 @@ - (instancetype)attributedText:(nullable NSAttributedString *)attributedText {
if (button) {
[button setAttributedTitle:attributedText forState:UIControlStateNormal];
} else {
[self _unsafeSetSpec:spec keyPath:CR_UNSAFE_KEYPATH(attributedText) value:attributedText];
_CRUnsafeSet(spec, CR_UNSAFE_KEYPATH(attributedText), attributedText);
}
}];
}
Expand All @@ -311,7 +293,7 @@ - (instancetype)font:(UIFont *)font {
if (button) {
[spec set:CR_KEYPATH(button, titleLabel.font) value:font];
} else {
[self _unsafeSetSpec:spec keyPath:CR_UNSAFE_KEYPATH(font) value:font];
_CRUnsafeSet(spec, CR_UNSAFE_KEYPATH(font), font);
}
}];
}
Expand All @@ -322,21 +304,27 @@ - (instancetype)textColor:(UIColor *)textColor {
if (button) {
[button setTitleColor:textColor forState:UIControlStateNormal];
} else {
[self _unsafeSetSpec:spec keyPath:CR_UNSAFE_KEYPATH(textColor) value:textColor];
_CRUnsafeSet(spec, CR_UNSAFE_KEYPATH(textColor), textColor);
}
}];
}

- (instancetype)textAlignment:(NSTextAlignment)textAlignment {
return [self _unsafeSet:CR_UNSAFE_KEYPATH(textAlignment) value:@(textAlignment)];
return [self withLayoutSpec:^(CRNodeLayoutSpec *spec) {
_CRUnsafeSet(spec, CR_UNSAFE_KEYPATH(textAlignment), @(textAlignment));
}];
}

- (instancetype)lineBreakMode:(NSLineBreakMode)lineBreakMode {
return [self _unsafeSet:CR_UNSAFE_KEYPATH(lineBreakMode) value:@(lineBreakMode)];
return [self withLayoutSpec:^(CRNodeLayoutSpec *spec) {
_CRUnsafeSet(spec, CR_UNSAFE_KEYPATH(lineBreakMode), @(lineBreakMode));
}];
}

- (instancetype)numberOfLines:(NSUInteger)numberOfLines {
return [self _unsafeSet:CR_UNSAFE_KEYPATH(numberOfLines) value:@(numberOfLines)];
return [self withLayoutSpec:^(CRNodeLayoutSpec *spec) {
_CRUnsafeSet(spec, CR_UNSAFE_KEYPATH(numberOfLines), @(numberOfLines));
}];
}

@end

0 comments on commit 6d842e0

Please sign in to comment.