[英]Set CalendarList height dynamically react-native
我想根据活动月份中天的结构设置CalendarList组件的高度
我创建了一个函数来确定CalendarList
的正确高度
calendarHeightCalculator() {
const currentMonth = moment(this.props.calendarStore.currentMonth, "YYYY-MM")
if (currentMonth.startOf("month").weekday() === 5 && currentMonth.daysInMonth() > 30) {
return 340
}
if (currentMonth.startOf("month").weekday() === 6 && currentMonth.daysInMonth() > 29) {
return 340
}
return 300
}
CalendarList组件通过其height属性调用该函数的每个重新渲染
<CalendarList
current={this.state.visibleMonth}
//onVisibleMonthsChange={this._monthChangeEvent}CalendarList
pastScrollRange={this.state.scrollRange.past}
futureScrollRange={this.state.scrollRange.future}
firstDay={1}
theme={calendarTheme}
markingType={'multi-dot'}
pagingEnabled={true}
scrollEnabled={false}
horizontal={true}
onDayPress={this._selectDate}
markedDates={this.state.markedDates}
calendarHeight={sizing.height(280)}
calendarHeight={this.calendarHeightCalculator()} // <- this is the culprit
dayComponent={(props) => (<CustomDay {...props} />)}
/>
我可以确认通过广泛使用console.log
每次重新渲染都会调用它,并返回正确的高度值。 但是, CalendarList
仅对初始值做出反应,而忽略以下重新渲染吗?
如何通过我的calendarHeightCalculator
函数设置正确的高度?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.