Flatten props and add keys to array elements

This commit is contained in:
Julia Friesel
2018-08-16 10:59:56 +02:00
parent a17cc89ec5
commit ad83a0844b
3 changed files with 17 additions and 8 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ export default class CycleChart extends Component {
this.renderColumn = ({item, index}) => { this.renderColumn = ({item, index}) => {
return ( return (
<DayColumn <DayColumn
item={item} {...item}
index={index} index={index}
navigate={this.props.navigation.navigate} navigate={this.props.navigation.navigate}
{...getInfoForNeighborColumns(index, this.state.columns)} {...getInfoForNeighborColumns(index, this.state.columns)}
+10 -7
View File
@@ -15,10 +15,6 @@ const label = styles.column.label
const getFhmAndLtlInfo = setUpFertilityStatusFunc() const getFhmAndLtlInfo = setUpFertilityStatusFunc()
export default class DayColumn extends Component { export default class DayColumn extends Component {
constructor(props) {
super(props)
}
passDateToDayView(dateString) { passDateToDayView(dateString) {
const cycleDay = getOrCreateCycleDay(dateString) const cycleDay = getOrCreateCycleDay(dateString)
this.props.navigate('cycleDay', { cycleDay }) this.props.navigate('cycleDay', { cycleDay })
@@ -36,7 +32,7 @@ export default class DayColumn extends Component {
temperatureExclude, temperatureExclude,
bleeding, bleeding,
mucus mucus
} = this.props.item } = this.props
const nfpLineInfo = getFhmAndLtlInfo(dateString, temperature) const nfpLineInfo = getFhmAndLtlInfo(dateString, temperature)
const columnElements = [] const columnElements = []
@@ -50,6 +46,7 @@ export default class DayColumn extends Component {
size={30} size={30}
color='#900' color='#900'
style={{ marginTop: 20 }} style={{ marginTop: 20 }}
key='bleeding'
/> />
) )
} }
@@ -62,6 +59,7 @@ export default class DayColumn extends Component {
left = {config.columnMiddle - styles.mucusIcon.width / 2} left = {config.columnMiddle - styles.mucusIcon.width / 2}
{...styles.mucusIcon} {...styles.mucusIcon}
backgroundColor={styles.mucusIconShades[mucus]} backgroundColor={styles.mucusIconShades[mucus]}
key='mucus'
/> />
) )
columnElements.push(mucusIcon) columnElements.push(mucusIcon)
@@ -74,6 +72,7 @@ export default class DayColumn extends Component {
width={styles.nfpLine.strokeWidth} width={styles.nfpLine.strokeWidth}
height={200} height={200}
{...styles.nfpLine} {...styles.nfpLine}
key='fhm'
/>) />)
columnElements.push(fhmLine) columnElements.push(fhmLine)
} }
@@ -84,6 +83,7 @@ export default class DayColumn extends Component {
width={'100%'} width={'100%'}
top={nfpLineInfo.drawLtlAt} top={nfpLineInfo.drawLtlAt}
{...styles.nfpLine} {...styles.nfpLine}
key='ltl'
/>) />)
columnElements.push(ltlLine) columnElements.push(ltlLine)
} }
@@ -93,8 +93,11 @@ export default class DayColumn extends Component {
<DotAndLine <DotAndLine
y={y} y={y}
exclude={temperatureExclude} exclude={temperatureExclude}
rightY={this.props.rightY}
rightTemperatureExclude={this.props.rightTemperatureExclude}
leftY={this.props.leftY} leftY={this.props.leftY}
rightY={this.props.righty} leftTemperatureExclude={this.props.leftTemperatureExclude}
key='dotandline'
/> />
) )
} }
@@ -111,7 +114,7 @@ export default class DayColumn extends Component {
</Text> </Text>
) )
columnElements.push( columnElements.push(
<View position='absolute' bottom={0}> <View position='absolute' bottom={0} key='date'>
{cycleDayLabel} {cycleDayLabel}
{dateLabel} {dateLabel}
</View> </View>
+6
View File
@@ -4,6 +4,10 @@ import styles from './styles'
import config from './config' import config from './config'
export default class DotAndLine extends Component { export default class DotAndLine extends Component {
shouldComponentUpdate(newProps) {
return Object.keys(newProps).some(key => newProps[key] != this.props[key])
}
render() { render() {
const y = this.props.y const y = this.props.y
const exclude = this.props.exclude const exclude = this.props.exclude
@@ -28,6 +32,7 @@ export default class DotAndLine extends Component {
top={y - (dotStyle.height / 2)} top={y - (dotStyle.height / 2)}
left={config.columnMiddle - (dotStyle.width / 2)} left={config.columnMiddle - (dotStyle.width / 2)}
style={dotStyle} style={dotStyle}
key='dot'
/> />
) )
return [lineToLeft, lineToRight, dot] return [lineToLeft, lineToRight, dot]
@@ -61,5 +66,6 @@ function makeLine(leftY, rightY, direction, excludeLine) {
], ],
}} }}
{...lineStyle} {...lineStyle}
key ={direction}
/>) />)
} }