Skip to content

Instantly share code, notes, and snippets.

@gHashTag
Created July 30, 2019 10:42
Show Gist options
  • Save gHashTag/f29d818155481fb2131b21e4b9802e40 to your computer and use it in GitHub Desktop.
Save gHashTag/f29d818155481fb2131b21e4b9802e40 to your computer and use it in GitHub Desktop.
Пикер (выбор одного из множества)
import React, { Component } from 'react'
import { View, StyleSheet } from 'react-native'
import ButtonTransactionItem from './ButtonTransactionItem'
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
backgroundColor: 'white',
height: 50
}
})
const data = [
{
id: 1,
title: 'All'
},
{
id: 2,
title: 'Recieved'
},
{
id: 3,
title: 'Send'
}
]
const numbers = ['one', 'two', 'three']
class ButtonTransactionMenu extends Component {
state = {
one: true,
two: false,
three: false
}
_onChangeState = number => () => {
const defaultObject = numbers.reduce(
(acc, el) => ({ ...acc, [el]: false }),
{}
)
this.setState({ ...defaultObject, [numbers[number - 1]]: true })
}
render() {
const { container } = styles
return (
<View style={container}>
{data.map(({ id, title }) => (
<ButtonTransactionItem
key={id}
title={title}
check={this.state[numbers[id - 1]]}
onPress={this._onChangeState(id)}
/>
))}
</View>
)
}
}
export { ButtonTransactionMenu }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment