Состояние компонента обновлено, но никогда не отображается повторно
Я пытаюсь внести изменения в этот компонент: https://github.com/wix/react-native-calendars/tree/master/src/calendar
В основном просто, чтобы скрыть дни, когда пользователь нажимает месяц.
ЦСИ / календарь / index.js
this.state = {
currentMonth,
hideDate: false
};
hideCalendar = () => {
this.setState({ hideDate: !this.state.hideDate });
//this.forceUpdate();
}
return (
<View style={[this.style.container, this.props.style]}>
<CalendarHeader
...
hideCalendar={this.hideCalendar}
/>
{
!this.state.hideDate && <View style={this.style.monthView}>{weeks}</View>
}
</View>);
SRC / календарь / заголовок / index.js
return (
<View>
<View style={this.style.header}>
{leftArrow}
<View style={{ flexDirection: 'row' }}>
<TouchableOpacity
onPress={() => this.props.hideCalendar()}
hitSlop={{left: 20, right: 20, top: 20, bottom: 20}}
>
<Text allowFontScaling={false} style={this.style.monthText} accessibilityTraits='header'>
{this.props.month.toString(this.props.monthFormat)}
</Text>
{indicator}
</TouchableOpacity>
</View>
{rightArrow}
</View>
{
!this.props.hideDayNames &&
<View style={this.style.week}>
{this.props.weekNumbers && <Text allowFontScaling={false} style={this.style.dayHeader}></Text>}
{weekDaysNames.map((day, idx) => (
<Text allowFontScaling={false} key={idx} accessible={false} style={this.style.dayHeader} numberOfLines={1} importantForAccessibility='no'>{day}</Text>
))}
</View>
}
</View>
);
Идея очень проста, реализовать новый hideDate
состояние на уровне индекса и пусть hideCalendar
в CalendarHeader
обрабатывать обработчик кнопок. Я не уверен, какая часть могла пойти не так, потому что состояние обновляется, но без this.forceUpdate()
, календарь просто не будет перерисовываться
1 ответ
Может быть, обязательный метод поможет? Когда вы передаете собственность:
hideCalendar={this.hideCalendar.bind(this)}