Last active
May 1, 2019 17:14
-
-
Save OwenMelbz/8730a7557a2f37cd516daecf45dfb28d to your computer and use it in GitHub Desktop.
Twitter Clone Helpers
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 faker from 'faker'; | |
export default class Api | |
{ | |
data = []; | |
_generateTweets(number = null) { | |
number = number || faker.random.number({ min: 1, max: 5 }); | |
const items = []; | |
let n = 0; | |
while (n < number) { | |
items.push(this._generateTweet()) | |
n++ | |
} | |
return items; | |
} | |
_generateTweet() { | |
const comments = new Array(faker.random.number({ min: 0, max: 10 })).fill(true).map(() => { | |
return { | |
user: { | |
name: faker.name.findName(), | |
handle: '@' + faker.internet.userName(), | |
avatar: faker.internet.avatar() | |
}, | |
key: faker.random.uuid(), | |
body: faker.lorem.paragraph(), | |
} | |
}); | |
return { | |
user: { | |
name: faker.name.findName(), | |
handle: '@' + faker.internet.userName(), | |
avatar: faker.internet.avatar() | |
}, | |
key: faker.random.uuid(), | |
body: faker.lorem.paragraph(), | |
likes: faker.random.number({ min: 0, max: 200 }), | |
comments, | |
} | |
} | |
refresh() { | |
const startCount = this.data.length ? null : 10; | |
const newTweets = this._generateTweets(startCount); | |
this.data = newTweets.concat(this.data); | |
return this.data; | |
} | |
loadMore() { | |
const oldTweets = this._generateTweets(); | |
this.data = this.data.concat(oldTweets); | |
return this.data; | |
} | |
} |
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
export class ComponentName extends React.Component { | |
constructor(props) { | |
super(props) | |
} | |
render() { | |
return ( | |
<Text>Hello</Text> | |
) | |
} | |
} |
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
const styles = StyleSheet.create({ | |
list: { | |
height: '100%' | |
}, | |
avatar: { | |
width: 50, | |
height: 50, | |
borderRadius: 25, | |
}, | |
row: { | |
flex: 1, | |
flexDirection: 'row', | |
padding: 20, | |
borderBottomWidth: 1, | |
borderBottomColor: '#f2f2f2', | |
}, | |
tweet: { | |
paddingLeft: 20, | |
flex: 1, | |
}, | |
meta: { | |
flex: 1, | |
flexDirection: 'row' | |
}, | |
actions: { | |
flex: 1, | |
flexDirection: 'row', | |
justifyContent: 'flex-start', | |
marginTop: 10, | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment