-
-
Save nim23/b793b27214a86714fabc to your computer and use it in GitHub Desktop.
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
#import "MyCustomView.h" | |
@implementation MyCustomView | |
{ | |
UIColor *squareColor; | |
} | |
- (void)setIsRed:(BOOL)isRed | |
{ | |
squareColor= (isRed) ? [UIColor redColor] : [UIColor greenColor]; | |
[self setNeedsDisplay]; | |
} | |
- (void)drawRect:(CGRect)rect | |
{ | |
[squareColor setFill]; | |
CGContextFillRect(UIGraphicsGetCurrentContext(), rect); | |
} |
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 { AppRegistry, Image, Text } = React; | |
var App = React.createClass({ | |
render: function() { | |
return ( | |
<View> | |
<Image src={require('image!hello')}/> | |
<Text>Hello World!</Text> | |
</View> | |
); | |
} | |
}); | |
AppRegistry.registerComponent('helloworld', () => App); |
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
#import "MyCustomView.h" | |
#import <UIKit/UIKit.h> |
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
/** | |
* Example: Native Components in React Native | |
*/ | |
'use strict'; | |
var React = require('react-native'); | |
var { | |
AppRegistry, | |
StyleSheet, | |
Text, | |
View | |
} = React; | |
var createReactIOSNativeComponentClass = require('createReactIOSNativeComponentClass'); | |
var MyCustomView = createReactIOSNativeComponentClass({ | |
validAttributes: {isRed: true}, | |
uiViewClassName: 'MyCustomView', | |
}) | |
var demo = React.createClass({ | |
render: function() { | |
return ( | |
<View style={styles.container}> | |
<Text> | |
Red one | |
</Text> | |
<MyCustomView style={{width: 10, height: 10}} isRed={true}/> | |
<Text> | |
Not red one | |
</Text> | |
<MyCustomView style={{width: 10, height: 10}} isRed={false}/> | |
</View> | |
); | |
} | |
}); | |
var styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
justifyContent: 'center', | |
alignItems: 'center', | |
backgroundColor: '#F5FCFF', | |
}, | |
customView: { | |
width: 10, | |
height: 10 | |
} | |
}); | |
AppRegistry.registerComponent('demo', () => demo); |
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
#import "MyCustomView.h" | |
@implementation MyCustomView | |
{ | |
UIColor *squareColor; | |
} | |
- (void)setIsRed:(BOOL)isRed | |
{ | |
squareColor= (isRed) ? [UIColor redColor] : [UIColor greenColor]; | |
[self setNeedsDisplay]; | |
} | |
- (void)drawRect:(CGRect)rect | |
{ | |
[squareColor setFill]; | |
CGContextFillRect(UIGraphicsGetCurrentContext(), rect); | |
} | |
@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
RCT_EXPORT_VIEW_PROPERTY(setRed, BOOL) |
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
render: function() { | |
return ( | |
<View style={styles.container}> | |
<Text> | |
Red one | |
</Text> | |
<MyCustomView style={{width: 10, height: 10}} isRed={true}/> | |
<Text> | |
Not red one | |
</Text> | |
<MyCustomView style={{width: 10, height: 10}} isRed={false}/> | |
</View> | |
); | |
} |
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 createReactIOSNativeComponentClass = require('createReactIOSNativeComponentClass'); | |
var MyCustomView = createReactIOSNativeComponentClass({ | |
validAttributes: {isRed: true}, | |
uiViewClassName: 'MyCustomView', | |
}) |
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
- (UIView *)view | |
{ | |
MyCustomView * theView; | |
theView = [[MyCustomView alloc] init]; | |
return theView; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment