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 create a component that contains a collection view ? #806

Closed
sxgfxm opened this issue May 4, 2017 · 6 comments
Closed

How to create a component that contains a collection view ? #806

sxgfxm opened this issue May 4, 2017 · 6 comments

Comments

@sxgfxm
Copy link

sxgfxm commented May 4, 2017

I can use ComponentKit to create a collection view whose cells display simple views. However, I get into trouble when I create a component which contains a collection view. Is there any demo or tips to do that ? Thanks a lot .

@ryanrhee
Copy link
Contributor

ryanrhee commented May 4, 2017

That should work as expected. What do you mean by "get into trouble"?

@sxgfxm
Copy link
Author

sxgfxm commented May 5, 2017

I initialize the dataSource with one section and insert multiple items. When I scroll the collection view, it works correctly. Then I scroll up and down few times, the cells which contain a collection view show content in the wrong order. When the cell will appear, I check the model that is correct. But when the cell did appear, it shows different content randomly. I think maybe there is something wrong with reusing. I worked on it for a few days but cannot find out the solution. Could you show me how to create a component that contains a collection view ?
Here is my CollectionComponent, the FixedCollectionView is a UIView with a collection view on it.

+(instancetype)newWithMovieListModel:(MovieListModel *)movieListModel{
  CKComponentScope scope(self);
  //  layout
  UICollectionViewFlowLayout *flowLayout =
  [[UICollectionViewFlowLayout alloc] init];
  [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
  [flowLayout setMinimumLineSpacing:0];
  [flowLayout setMinimumInteritemSpacing:0];
  //  size
  CGSize itemSize = CGSizeMake(100, 150);
  CGSize viewSize = CGSizeMake(355, 150);
  //  items
  NSMutableDictionary<NSIndexPath *, NSObject *> *items =
  [NSMutableDictionary new];
  for (int i = 0; i < movieListModel.movieList.count; i++) {
       [items setObject:movieListModel.movieList[i]
              forKey:[NSIndexPath indexPathForRow:i inSection:0]];
  }
  //  component
  return [super newWithComponent:[CKInsetComponent
                                  newWithView:{[UIView class],{{@selector(setBackgroundColor:),[UIColor grayColor]}}}
                                  insets:{.left = 10,.top = 10,.right = 10,.bottom = 10}
                                  component:[CKComponent newWithView:{
    [FixedCollectionView class],
    {
      {@selector(setupAll:),@(YES)},
      {@selector(setupFlowLayout:),flowLayout},
      {@selector(setupCollectionViewWithViewSize:),[NSValue valueWithCGSize:viewSize]},
      {@selector(setupItemSize:),[NSValue valueWithCGSize:itemSize]},
      {@selector(setupItems:),items},
      {@selector(setupComponentName:),NSStringFromClass([MovieComponent class])},
      {@selector(setupSelector:),NSStringFromSelector(@selector(newWithMovieModel:))},
      {@selector(setupModel:),NSStringFromClass([MovieModel class])}
    }
  } size:{viewSize.width,viewSize.height}]]];
}

Thank you for your help

@ryanrhee
Copy link
Contributor

ryanrhee commented May 8, 2017

Just glancing at it, things look fine. If you think there's a bug with the core framework can you show it with a breaking unit test? Thanks!

@ocrickard
Copy link
Contributor

This seems likely an issue inside your collection view code.

cc @gkassabli @lucasr we get requests to have an open-source collection view example every once in awhile. Any interest in providing an example?

@ocrickard
Copy link
Contributor

I opened #810 to track providing an example. Closing this issue since the specific issue here with the code needs more information to be actionable. If you get a failing unit test, feel free to open a new issue!

@sxgfxm
Copy link
Author

sxgfxm commented May 10, 2017

Thank you for your help. I'm looking forward for the example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants