Skip to content
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

Custom Enumerated Property definition #16

Closed
tbrannam opened this issue Nov 12, 2014 · 2 comments
Closed

Custom Enumerated Property definition #16

tbrannam opened this issue Nov 12, 2014 · 2 comments

Comments

@tbrannam
Copy link
Contributor

While it is easy to support custom string properties by way of registerCustomProperty, it seems less clear how to support custom properties with enumerated types - as the implementation to create these is private and the the returned ISSPropertyDefinition consists of readonly fields. should these be promoted to a public interface? Should registerCustomProperty have a implementation that accepts a ISSPropertyDescription?

// Private initializer
- (id) initWithName:(NSString *)name aliases:(NSArray*)aliases type:(ISSPropertyType)type enumBlock:(NSDictionary*)enumValues enumBitMaskType:(BOOL)enumBitMaskType;
@tbrannam
Copy link
Contributor Author

By importing the private category

#import <InterfaCSS/ISSPropertyDefinition+Private.h> 

and adding to ISSPropertyRegistery

- (void) registerCustomPropertyDefinition:(ISSPropertyDefinition *)propertyDefinition {
      if (propertyDefinition)
          self.propertyDefinitions = [self.propertyDefinitions setByAddingObject:propertyDefinition];
}

I was able to add an enumerated type to support a custom view

ISSPropertyDefinition *imageViewContentMode =
        [[ISSPropertyDefinition alloc] initWithName:@"imageAlign"
                                          aliases:nil
                                         type:ISSPropertyTypeEnumType
                                   enumValues:@{ @"center" : @(UIImageViewAlignmentMaskCenter),
                                                 @"left" : @(UIImageViewAlignmentMaskLeft),
                                                 @"right" : @(UIImageViewAlignmentMaskRight),
                                                 @"top" : @(UIImageViewAlignmentMaskTop),
                                                 @"bottom" : @(UIImageViewAlignmentMaskBottom)}
                                enumBitMaskType:YES
                                    setterBlock:^(ISSPropertyDefinition* property, id viewObject, id value, NSArray* parameters) {
                                                     if( [viewObject isKindOfClass:UIImageViewAligned.class] ) {
                                                         UIImageViewAligned* v = viewObject;
                                                         v.alignment = (UIImageViewAlignmentMask)[value unsignedIntegerValue];
                                                     }
                                                 } parameterEnumValues:nil];

[[[InterfaCSS interfaCSS] propertyRegistry] registerCustomPropertyDefinition:imageViewContentMode];

@tolo
Copy link
Owner

tolo commented Nov 14, 2014

Fixed in 0162ed5 - exposed full interface of ISSPropertyDefinition in ISSPropertyDefinition.h and added method to register a property definition directly to ISSPropertyRegistery.

@tolo tolo closed this as completed Nov 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants