Date post: | 24-Jan-2018 |
Category: |
Software |
Upload: | corneliu-chitanu |
View: | 390 times |
Download: | 2 times |
Improving View Performance with
ComponentKit
1. Caracteristici ComponentKit 2. De tinut cont in utilizarea
ComponentKit 3. Code:
1.Sintaxa 2.Componente de bază 3.Good practices
Caracteristicile
ComponentKit
Facebook și-a dorit să mute complexitatea în
infrastructură
Immutability
Immutability
E declarativ
pentru specificarea 1. ierarhiei de view-uri 2. layout 3. modificarilor de stare
@implementation DCCTextComponent
+(instancetype)newWithText:(NSString *)postText context:(id)context { CGFloat componentWidth = [[context objectForKey:@"componentWidth"] doubleValue]; return [super newWithComponent: [CKStackLayoutComponent newWithView:{} size:{.width = componentWidth - 20} style:{} children:{ {[CKTextComponent newWithTextAttributes:{ .attributedString = [[NSAttributedString alloc] initWithString:postText attributes:@{NSFontAttributeName:[UIFont preferredFontForTextStyle:UIFontTextStyleBody], NSForegroundColorAttributeName:[UIColor blackColor]}], } viewAttributes:{ } accessibilityContext:{}]} }]];}
@end
Componentele = functii pure@implementation DCCTextComponent
+(instancetype)newWithText:(NSString *)postText context:(id)context { CGFloat componentWidth = [[context objectForKey:@"componentWidth"] doubleValue]; return [super newWithComponent: [CKStackLayoutComponent newWithView:{} size:{.width = componentWidth - 20} style:{} children:{ {[CKTextComponent newWithTextAttributes:{ .attributedString = [[NSAttributedString alloc] initWithString:postText attributes:@{NSFontAttributeName:[UIFont preferredFontForTextStyle:UIFontTextStyleBody], NSForegroundColorAttributeName:[UIColor blackColor]}], } viewAttributes:{ } accessibilityContext:{}]} }]];}
@end
Composable & Reusable@implementation DCCTextComponent
+(instancetype)newWithText:(NSString *)postText context:(id)context { CGFloat componentWidth = [[context objectForKey:@"componentWidth"] doubleValue]; return [super newWithComponent: [CKStackLayoutComponent newWithView:{} size:{.width = componentWidth - 20} style:{} children:{ {[CKTextComponent newWithTextAttributes:{ .attributedString = [[NSAttributedString alloc] initWithString:postText attributes:@{NSFontAttributeName:[UIFont preferredFontForTextStyle:UIFontTextStyleBody], NSForegroundColorAttributeName:[UIColor blackColor]}], } viewAttributes:{ } accessibilityContext:{}]} }]];}
@end
De tinut cont cand utilizam
ComponentKit
Tipuri de view potrivite pentru ComponentKit:
Liste care au un continut
complex
Puncte forte:
1.Performanta la scroll 2.Reciclarea view-urilor 3.Putin cod pentru o componentă
(if done right)
Puncte slabe:
1.Animațiile sunt mai greu de implementat
2.Nu e potrivit pentru view-uri dinamice, care se modifica des la interactiunea cu utilizatorul
3.Nu se poate integra cu Swift (Swift nu poate conlucra cu C++)
Code