Skip to content

Instantly share code, notes, and snippets.

@fatlinesofcode
Created March 11, 2022 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fatlinesofcode/418c7d814031f11c5e602444190b258f to your computer and use it in GitHub Desktop.
Save fatlinesofcode/418c7d814031f11c5e602444190b258f to your computer and use it in GitHub Desktop.
React Native ios uiview native component
#import <React/RCTViewManager.h>
@interface RCTComponentViewManager : RCTViewManager
@property (nonatomic, strong) UIView *wrapper;
@end
@implementation RCTComponentViewManager
/*
* //export UIView as component
* export const RCTComponentView = requireNativeComponent('RCTComponentView', null)
*
* // ususage in react
* // <RCTComponentView title="test 01" />
*/
RCT_EXPORT_MODULE(RCTComponentView)
- (UIView *)view
{
UIView *wrapper = [[UIView alloc] init];
self.wrapper = wrapper;
return wrapper;
}
RCT_CUSTOM_VIEW_PROPERTY(title, NSString, UIView)
{
NSString *title = [RCTConvert NSString:json];
NSLog(@"title: %@", title);
UILabel *label = [[UILabel alloc] init];
[label setTextColor:[UIColor redColor]];
[label setText: title];
[label sizeToFit];
[self.wrapper addSubview:label];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment