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

How to make children component height equal to Scroll component's content view height but Scroll component's height #970

Closed
LinkRober opened this issue Feb 28, 2022 · 2 comments

Comments

@LinkRober
Copy link

I create a scroll component

@interface LeMobileScrollComponent()

@property (nonatomic, strong) CKFlexboxComponent *scrollComponent;

@end


@implementation LeMobileScrollComponent

+ (instancetype)newWithListViewAttributes:(const CKViewComponentAttributeValueMap &)viewAttributes
                                     size:(const CKComponentSize &)size
                                    style:(const CKFlexboxComponentStyle &)style
                                 children:(std::vector<CKFlexboxComponentChild>)children {
    CKComponentScope scope(self);
    CKComponentViewConfiguration viewConfiguration = {&scrollViewInstanceFuc,viewAttributes};
    CKFlexboxComponent *scrollComponent = [CKFlexboxComponent newWithView:viewConfiguration size:size style:style children:children];
    LeMobileScrollComponent *c = [super newWithComponent:scrollComponent];
    c.scrollComponent = scrollComponent;
    return c;
}

+ (Class<CKComponentControllerProtocol>)controllerClass {
    return [LeMobileScrollComponentController class];
}

@end

@implementation LeMobileScrollComponentController

- (void)didMount {
    [super didMount];
    //  Get scroll component
    LeMobileScrollComponent *component = (LeMobileScrollComponent*)self.component;
    CKFlexboxComponent *scrollComponent = component.scrollComponent;
    //  Get component size
    CKSizeRange range = CKSizeRange();
    CKComponentLayout layout = [scrollComponent computeLayoutThatFits:range];
    //  Get scroll view
    UIScrollView *scrollView = (UIScrollView *)scrollComponent.viewContext.view;
    //  Set contentSize
    [scrollView setContentSize:layout.size];
}

//  Invoked when the component is updated
- (void)didUpdateComponent{
  [super didUpdateComponent];
}

@end

I hope that first child contain component'height equal to scoll component content view'height rather than scroll component view‘height. example photo below
IMG_0243A8092629-1

@xavierjurado
Copy link
Contributor

Hey @LinkRober, CKFlexboxComponent is not designed to be used like a UIScrollView, it's instead similar to UIKit's UIStackView.

My suggestion is to wrap your items inside a UICollectionView instead . While it requires a bit more code, you'll gain the benefits of component reuse and all the goods from CKDataSource. Take a look at our documentation and our sample code for more details!

@LinkRober
Copy link
Author

@xavierjurado thx I got it

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