Created
May 28, 2015 16:24
-
-
Save nicklockwood/85054936f3f19b8590e7 to your computer and use it in GitHub Desktop.
Simple React Native Module for iCarousel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var React = require('react-native'); | |
var { requireNativeComponent } = React; | |
module.exports = requireNativeComponent('Carousel', null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CarouselManager.h | |
// | |
// Created by Nick Lockwood on 19/05/2015. | |
// Copyright (c) 2015 Facebook. All rights reserved. | |
// | |
#import "RCTViewManager.h" | |
@interface CarouselManager : RCTViewManager | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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