Skip to content

Instantly share code, notes, and snippets.

@spencercarli
Created March 30, 2016 00:34
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 spencercarli/023de9335a35e5b83e1799d5c845aed8 to your computer and use it in GitHub Desktop.
Save spencercarli/023de9335a35e5b83e1799d5c845aed8 to your computer and use it in GitHub Desktop.
Sharing Code between Android and iOS in React Native - button.android.js
// app/components/button.android.js
import React, { Component, TouchableOpacity, Text, StyleSheet } from 'react-native';
import reactMixin from 'react-mixin';
import ButtonCommon from './button.common';
class Button extends Component {
render() {
const buttonStyle = [styles.button];
if (this.state.pressed) buttonStyle.push(styles.buttonPress);
return (
<TouchableOpacity onPress={this.handlePress.bind(this)} style={buttonStyle}>
<Text style={styles.text}>{this.props.text}</Text>
</TouchableOpacity>
)
}
}
reactMixin.onClass(Button, ButtonCommon);
export default Button;
const styles = StyleSheet.create({
button: {
borderRadius: 20,
backgroundColor: '#F44336',
paddingHorizontal: 16,
paddingVertical: 10,
position: 'absolute',
right: 16,
bottom: 16
},
buttonPress: {
backgroundColor: '#C7C7C7'
},
text: {
color: '#fff'
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment