Created
July 30, 2019 10:42
-
-
Save gHashTag/f29d818155481fb2131b21e4b9802e40 to your computer and use it in GitHub Desktop.
Пикер (выбор одного из множества)
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 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