Skip to content

Instantly share code, notes, and snippets.

@vojtatranta
Created November 30, 2016 10:56
Show Gist options
  • Save vojtatranta/333b7348eb50f9af16830e03d816713f to your computer and use it in GitHub Desktop.
Save vojtatranta/333b7348eb50f9af16830e03d816713f to your computer and use it in GitHub Desktop.
// před tim
<TouchableOpacity onPress={() => this.handleToggleDay('Mo')} style={[styles.weekIcontouch, this.selected('Mo')]}>
<Text style={[styles.weekIcon, this.selectedText('Mo')]}>{I18n.t('_general.week.mondayShort')}</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.handleToggleDay('Tu')}>
<Text>{I18n.t('_general.week.tuesdayShort')}</Text>
</TouchableOpacity>
... a dalsi dny v tydnu
//komponenta
class TouchableDay extends React.Component {
_handlePress = () => {
this.props.onDayPress(this.props.dayCode)
}
return() {
return (
<TouchableOpacity onPresst={this._handlePress} style={this.props.style}>
{this.props.children}
</TouchableOpacity>
)
}
}
// použití
class Days extends React.Component {
_handleDayPress = (dayCode) => {
console.log(dayCode)
}
render() {
const days = ['mo', 'tu', 'we', 'th', 'fr', 'sa', 'su']
return (
days.map(day => {
return <TouchableDay dayCode={day} onDayPress={this._handleDayPress}><Text>{I18n.t('_general.week.%s', day)}</Text></TouchableDay>
})
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment