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 React, { Component } from 'react'; | |
import { Text, View, StyleSheet, Dimensions } from 'react-native'; | |
const { width } = Dimensions.get("window"); | |
export default class App extends Component { | |
render() { | |
const tileDimensions = calcTileDimensions(width, 2) // -> change this number and see! | |
const tiles = 'Lorem Ipsum Dolor Sit Amet'.split(' ') | |
return ( | |
<View style={styles.container}> |
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
// tpr = tiles per row | |
const calcTileDimensions = (deviceWidth, tpr) => { | |
const margin = deviceWidth / (tpr * 10); | |
const size = (deviceWidth - margin * (tpr * 2)) / tpr; | |
return { size, margin }; | |
}; |
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
// Recursive funcion with Tail Call Optimization | |
flatten = ([first, ...rest], work = []) => { | |
if (first === undefined) { | |
return work; | |
} | |
else if (!Array.isArray(first)) { | |
return flatten(rest, [...work, first]); | |
} | |
else { |
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
// -- BEFORE -- | |
// In this first exmaple, the action dispatching and flow would be hard to test, because its highly coupled with | |
// the component and the way it interacts with the Linking API. | |
// login.js | |
import {Linking} from 'react-native' | |
export default class Login extends Component { | |
constructor(props) { | |
super(props); | |
this.handleDeepLink = this.handleDeepLink.bind(this); |
NewerOlder