-
Notifications
You must be signed in to change notification settings - Fork 66
feat(iOS): custom style #641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
8016f73
fb8cdc0
e4f4804
2c29d83
c2c0613
ce12b57
18ca4bd
ec7521b
9c0c095
f34fbf0
cf3739e
4ab7531
0e37c0d
e29cdfa
1c1933b
1d2aa4a
eeaa4ac
595ba1d
dc48a57
f1c7a1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the way we decide the style value over a range is a bit wrong. IMO:
This would at least align with how we decide it for other styles, e.g. an inline style is shown as active only if it spans the whole selected range without any exceptions.
|
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd move both the header and implementation files to |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #pragma once | ||
| #import <UIKit/UIKit.h> | ||
|
|
||
| @interface CustomStyleData : NSObject <NSCopying> | ||
|
|
||
| @property(nonatomic, strong, nullable) UIColor *foregroundColor; | ||
| @property(nonatomic, strong, nullable) UIColor *backgroundColor; | ||
|
|
||
| - (BOOL)isEmpty; | ||
|
|
||
| // Applies a partial update from a dict (keys: "foregroundColor", | ||
| // "backgroundColor"). A key absent from the dict leaves the field unchanged; | ||
| // NSNull or any non-UIColor value clears it; a UIColor value sets it. | ||
| - (void)mergeFromDict:(NSDictionary *)dict; | ||
|
|
||
| @end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #import "CustomStyleData.h" | ||
|
|
||
| @implementation CustomStyleData | ||
|
|
||
| - (BOOL)isEmpty { | ||
| return _foregroundColor == nil && _backgroundColor == nil; | ||
| } | ||
|
|
||
| - (void)mergeFromDict:(NSDictionary *)dict { | ||
| id fgVal = dict[@"foregroundColor"]; | ||
| if (fgVal != nil) { | ||
| self.foregroundColor = | ||
| [fgVal isKindOfClass:[UIColor class]] ? (UIColor *)fgVal : nil; | ||
| } | ||
| id bgVal = dict[@"backgroundColor"]; | ||
| if (bgVal != nil) { | ||
| self.backgroundColor = | ||
| [bgVal isKindOfClass:[UIColor class]] ? (UIColor *)bgVal : nil; | ||
| } | ||
| } | ||
|
|
||
| - (BOOL)isEqual:(id)object { | ||
| if (self == object) | ||
| return YES; | ||
| if (![object isKindOfClass:[CustomStyleData class]]) | ||
| return NO; | ||
| CustomStyleData *other = (CustomStyleData *)object; | ||
| BOOL fgEqual = (_foregroundColor == other.foregroundColor) || | ||
| [_foregroundColor isEqual:other.foregroundColor]; | ||
| BOOL bgEqual = (_backgroundColor == other.backgroundColor) || | ||
| [_backgroundColor isEqual:other.backgroundColor]; | ||
| return fgEqual && bgEqual; | ||
| } | ||
|
|
||
| - (NSUInteger)hash { | ||
| return [_foregroundColor hash] ^ [_backgroundColor hash]; | ||
| } | ||
|
|
||
| - (id)copyWithZone:(NSZone *)zone { | ||
| CustomStyleData *copy = [[CustomStyleData allocWithZone:zone] init]; | ||
| copy.foregroundColor = self.foregroundColor; | ||
| copy.backgroundColor = self.backgroundColor; | ||
| return copy; | ||
| } | ||
|
|
||
| @end |


Uh oh!
There was an error while loading. Please reload this page.