Created
March 11, 2022 23:59
-
-
Save fatlinesofcode/418c7d814031f11c5e602444190b258f to your computer and use it in GitHub Desktop.
React Native ios uiview native component
This file contains hidden or 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
#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