Skip to content

Instantly share code, notes, and snippets.

@samueljmurray
samueljmurray / MyComponent.jsx
Created August 30, 2017 16:13
Component using HeadingText
/* MyComponent.js */
import HeadingText from "HeadingText";
class MyComponent extends React.Component {
render() {
return (
<View>
<HeadingText>Article heading</HeadingText>
<Text>Article body...</Text>
@samueljmurray
samueljmurray / Button.jsx
Created August 30, 2017 15:58
Button component - with function
/* Button.js */
import styles from "buttonStyles";
class Button extends React.Component {
render() {
const contextualStyles = styles(this.props);
return (
<View style={contextualStyles.button}>
// ...
@samueljmurray
samueljmurray / buttonStyles.js
Last active August 30, 2017 15:57
Button styles - with function
/* buttonStyles.js */
export default (props) => StyleSheet.create({
button: StyleSheet.flatten([
{
backgroundColor: "#DDD",
},
props.colour && {
backgroundColor: props.colour,
},
@samueljmurray
samueljmurray / Button.jsx
Created August 30, 2017 15:56
Button component - without function
/* Button.js */
import styles from "buttonStyles";
class Button extends React.Component {
render() {
return (
<View style={[
styles.button,
this.props.colour && {
@samueljmurray
samueljmurray / buttonStyles.js
Created August 30, 2017 15:50
Button styles - without function
/* buttonStyles.js */
export default StyleSheet.create({
button: {
backgroundColor: "#DDD",
},
button_disabled: {
backgroundColor: "#999",
},
});
@samueljmurray
samueljmurray / styles.js
Created August 30, 2017 15:48
Screen size helper
{
marginHorizontal: screenSize({xs: 8, s: 12}, 16)
}
@samueljmurray
samueljmurray / screenSizeHelper.js
Created August 30, 2017 15:48
A helper function for React Native which returns values based on screen height
import { Dimensions } from "react-native";
// Height
const screenSizes = [
{
name: "xs",
height: 568
},
{
name: "s",
@samueljmurray
samueljmurray / styles.js
Created August 30, 2017 15:42
Screen size ternary inception
{
marginHorizontal: extraSmallScreen ? 8 : (smallScreen ? 12 : 16);
}
@samueljmurray
samueljmurray / styles.js
Created August 30, 2017 15:40
Screen size ternary
const extraSmallScreen = Dimensions.get("window").height < 568;
const smallScreen = Dimensions.get("window").height < 667;
{
marginHorizontal: extraSmallScreen ? 8 : 16,
}
@samueljmurray
samueljmurray / MyComponent.jsx
Created August 30, 2017 15:34
Component using tachyons styles
/* MyComponent.js */
import s from "styles";
class MyComponent extends React.Component {
render() {
return (
<View style={[s.flex1, s.ma1, s.bg_gray_blue]}>
<Text style={[s.teal, s.o_90]}>
Hi.