Skip to content

Instantly share code, notes, and snippets.

@renganatha10
Last active October 17, 2024 10:38
Show Gist options
  • Save renganatha10/c983190f1a095a4c58754e773561f915 to your computer and use it in GitHub Desktop.
Save renganatha10/c983190f1a095a4c58754e773561f915 to your computer and use it in GitHub Desktop.
Basic Native UI component Bridging Code
//RCTListViewManger.h
#import <UIKit/UIKit.h>
@interface RCTNativeListView : UIView
@property (nonatomic) NSArray * colors;
@end
--------------------------------------------------------------------------------
//RCTListViewManger.m
#import "RCTNativeListView.h"
#import "UIView+React.h"
@implementation RCTNativeListView
- (instancetype)init {
NSLog(@"init");
self = [super init];
if ( self ) {
[self setUp];
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
return self;
}
- (void) insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex {
NSLog(@"insde");
[super insertReactSubview:subview atIndex:atIndex];
}
- (void)setUp {
UIView * sampleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
sampleView.backgroundColor = [UIColor blackColor];
[self addSubview:sampleView];
}
@end
--------------------------------------------------------------------------------
// RCTListViewManger.h
#import "RCTViewManager.h"
#import "RCTNativeListView.h"
@interface RCTNativeListViewManager : RCTViewManager
@property (nonatomic) RCTNativeListView * nativeListView;
@end
--------------------------------------------------------------------------------
// RCTListViewManger.m
#import "RCTNativeListViewManager.h"
@implementation RCTNativeListViewManager
RCT_EXPORT_MODULE()
- (instancetype)init {
self = [super init];
if ( self ) {
NSLog(@"color picker manager init");
self.nativeListView = [[RCTNativeListView alloc] init];
}
return self;
}
- (UIView *)view {
NSLog(@"color picker manager -view method");
return self.nativeListView;
}
@end
@renganatha10
Copy link
Author

Objective guildline

1)Create a ViewManager and View Class
2)Create A UIView instants (desired one) and its wrapper(again a UIView instance) Line - 45
3)override the insertReactSubviews method line - 40

NativelistView.js

<NativeListView style={{ flex: 1 }}>
       <View style={{ height: 50, width: 50, backgroundColor: 'red' }} />
 </NativeListView>

output

simulator screen shot feb 2 2017 4 11 24 pm

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