Skip to content

Instantly share code, notes, and snippets.

@nicklockwood
Created May 28, 2015 16:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicklockwood/85054936f3f19b8590e7 to your computer and use it in GitHub Desktop.
Save nicklockwood/85054936f3f19b8590e7 to your computer and use it in GitHub Desktop.
Simple React Native Module for iCarousel
//
// CarouselManager.h
//
// Created by Nick Lockwood on 19/05/2015.
// Copyright (c) 2015 Facebook. All rights reserved.
//
#import "RCTViewManager.h"
@interface CarouselManager : RCTViewManager
@end
//
// CarouselManager.m
//
// Created by Nick Lockwood on 19/05/2015.
// Copyright (c) 2015 Facebook. All rights reserved.
//
#import "CarouselManager.h"
#import "iCarousel.h"
#import "UIView+React.h"
@interface Carousel: iCarousel <iCarouselDataSource>
@end
@implementation Carousel
{
NSMutableArray *_items;
}
- (instancetype)init
{
if ((self = [super init])) {
_items = [NSMutableArray array];
self.dataSource = self;
self.type = iCarouselTypeCylinder;
self.vertical = YES;
}
return self;
}
- (void)insertReactSubview:(id<RCTViewNodeProtocol>)subview atIndex:(NSInteger)atIndex
{
[_items insertObject:subview atIndex:atIndex];
[self reloadData];
}
- (void)removeReactSubview:(id<RCTViewNodeProtocol>)subview
{
[_items removeObject:subview];
[self reloadData];
}
- (NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return _items.count;
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{
return _items[index];
}
@end
@implementation CarouselManager
RCT_EXPORT_MODULE()
- (UIView *)view
{
return [[Carousel alloc] init];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment