Refactor SKSubDescriptor

Reviewed By: d16r

Differential Revision: D20458337

fbshipit-source-id: e8ea848c6e2f7521c5a6c6eb4110bba0bfe25593
This commit is contained in:
Adam Ernst
2020-03-15 19:39:20 -07:00
committed by Facebook GitHub Bot
parent 19876273a3
commit d9a2167019
7 changed files with 27 additions and 107 deletions

View File

@@ -115,50 +115,17 @@ Sometimes all you need is to extend the functionality of an existing descriptor.
### Subdescriptors
If you want to extend the `SKComponentKitLayoutDescriptor` and add an additional section based on the nodes of the `SKComponentLayoutDescriptor`, you will have to subclass `SKSubDescriptor`.
If you want to extend the `SKComponentKitLayoutDescriptor` and add an additional section based on the nodes of the `SKComponentLayoutDescriptor`, you can use `SKSubDescriptor`.
```objc
#import <FlipperKitLayoutComponentKitSupport/SKSubDescriptor.h>
#import <FlipperKitLayoutComponentKitSupport/SKComponentLayoutWrapper.h>
@interface YourSubDescriptor: SKSubDescriptor
@end
@implementation YourSubDescriptor
- (NSString *) getName {
return @"Section Name";
NSString *YourSubDescriptor(SKComponentLayoutWrapper *)node {
return @"Meta data";
}
- (NSString *)getDataForNode:(SKComponentLayoutWrapper *)node {
return @"Meta data"
}
@end
#endif
// At setup time, you must register it:
[SKComponentLayoutDescriptor registerSubDescriptor:&YourSubDescriptor forName:@"Section Name"];
```
Once you have implemented the descriptor, you will have to setup the Layout plugin as follows.
<!--DOCUSAURUS_CODE_TABS-->
<!--Objective-C-->
```objc
NSArray<SKSubDescriptor *> *registeredSubDescriptors = @[ yourSubDescriptors ];
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
[FlipperKitLayoutComponentKitSupport setUpWithDescriptorMapper: layoutDescriptorMapper subDescriptors: registeredSubDescriptors];
[client addPlugin: [[FlipperKitLayoutPlugin alloc] initWithRootNode: application
withDescriptorMapper: layoutDescriptorMapper]];
```
<!--Swift-->
```swift
let subDescriptors = [ yourSubDescriptors ]
let layoutDescriptorMapper = SKDescriptorMapper(defaults: ())
FlipperKitLayoutComponentKitSupport.setUpWith(layoutDescriptorMapper, subDescriptors: subDescriptors)
client?.add(FlipperKitLayoutPlugin(rootNode: application, with: layoutDescriptorMapper!))
```
<!--END_DOCUSAURUS_CODE_TABS-->
Swift support is not yet available because you must access `SKComponentLayoutWrapper` to implement a subdescriptor.