繁体   English   中英

设置CalendarList高度动态响应本机

[英]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函数设置正确的高度?

更改日历高度不会触发状态更改,因此日历不会重新呈现。

如果要重新渲染日历,请更改实际上设置日历列表状态的内容。

看一下组件,看看触发重新渲染CalendarList.js的道具

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM