-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from nyura123/master
enhancement - allow custom reusable cells
- Loading branch information
Showing
12 changed files
with
603 additions
and
25 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
#import <foundation/Foundation.h> | ||
@class RCTBridge; | ||
|
||
@interface RNAppGlobals : NSObject { | ||
RCTBridge *appBridge; | ||
} | ||
|
||
@property (nonatomic, retain) RCTBridge *appBridge; | ||
|
||
+ (id)sharedInstance; | ||
|
||
@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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// RNGlobals.m | ||
// RNTableView | ||
// | ||
// Created by Anna Berman on 2/10/16. | ||
// Copyright © 2016 Pavlo Aksonov. All rights reserved. | ||
// | ||
|
||
#import "RNAppGlobals.h" | ||
|
||
@implementation RNAppGlobals | ||
|
||
@synthesize appBridge; | ||
|
||
+ (id)sharedInstance { | ||
static RNAppGlobals *instance = nil; | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
instance = [[self alloc] init]; | ||
}); | ||
return instance; | ||
} | ||
|
||
@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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
//Use react-native root views as reusable cells returned from cellForRowAtIndexPath. | ||
|
||
//App must use the code below to store the app bridge, else cells will be blank | ||
//AppDelegate.m, didFinishLaunchingWithOptions: | ||
// #import <RNTableView/RNAppGlobals.h> | ||
//RCTRootView *rootView = ... | ||
//[[RNAppGlobals sharedInstance] setAppBridge:rootView.bridge]; | ||
|
||
@interface RNReactModuleCell : UITableViewCell { | ||
} | ||
|
||
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier bridge:(RCTBridge*) bridge data:(NSDictionary*)data indexPath:(NSIndexPath*)indexPath reactModule:(NSString*)reactModule; | ||
|
||
-(void)setUpAndConfigure:(NSDictionary*)data bridge:(RCTBridge*)bridge indexPath:(NSIndexPath*)indexPath reactModule:(NSString*)reactModule; | ||
|
||
@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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// RNReactModuleCell.m | ||
// RNTableView | ||
// | ||
// Created by Anna Berman on 2/6/16. | ||
// Copyright © 2016 Pavlo Aksonov. All rights reserved. | ||
// | ||
|
||
#import <RCTRootView.h> | ||
#import "RNReactModuleCell.h" | ||
|
||
@implementation RNReactModuleCell { | ||
RCTRootView *_rootView; | ||
} | ||
|
||
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier bridge:(RCTBridge*) bridge data:(NSDictionary*)data indexPath:(NSIndexPath*)indexPath reactModule:(NSString*)reactModule | ||
{ | ||
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; | ||
if (self) { | ||
[self setUpAndConfigure:data bridge:bridge indexPath:indexPath reactModule:reactModule]; | ||
} | ||
return self; | ||
} | ||
|
||
-(NSDictionary*) toProps:(NSDictionary *)data indexPath:(NSIndexPath*)indexPath { | ||
return @{@"data":data, @"section":[[NSNumber alloc] initWithLong:indexPath.section], @"row":[[NSNumber alloc] initWithLong:indexPath.row]}; | ||
} | ||
|
||
-(void)setUpAndConfigure:(NSDictionary*)data bridge:(RCTBridge*)bridge indexPath:(NSIndexPath*)indexPath reactModule:(NSString*)reactModule{ | ||
NSDictionary *props = [self toProps:data indexPath:indexPath]; | ||
if (_rootView == nil) { | ||
//Create the mini react app that will populate our cell. This will be called from cellForRowAtIndexPath | ||
_rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:reactModule initialProperties:props]; | ||
if (data[@"width"]) { | ||
CGRect contentViewFrame = self.contentView.frame; | ||
contentViewFrame.size.width = ((NSNumber*)data[@"width"]).floatValue; | ||
self.contentView.frame = contentViewFrame; | ||
} | ||
[self.contentView addSubview:_rootView]; | ||
_rootView.frame = self.contentView.frame; | ||
} else { | ||
//Ask react to re-render us with new data | ||
_rootView.appProperties = props; | ||
} | ||
|
||
//The application will be unmounted in javascript when the cell/rootview is destroyed | ||
} | ||
|
||
-(void)prepareForReuse { | ||
[super prepareForReuse]; | ||
//TODO prevent stale data flickering | ||
} | ||
|
||
@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
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
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
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
Oops, something went wrong.