javascript - 如何在函数中创建模态页面?
问题描述
日历/index.js
constructor(props) {
this.state = {
CalendarModalVisible: false
};
}
toggleCalendarModal = () => {
this.setState({ CalendarModalVisible: !this.state.CalendarModalVisible });
}
setModalPage = () => {
return(
<Modal isVisible={this.state.CalendarModalVisible} onBackdropPress={() =>
{ this.toggleCalendarModal() }} >
<View style={this.style.modal_container} >
</View>
</Modal>
);
}
renderDay(day, id) {
....
return (
<TouchableOpacity onPress={() => { this.setModalPage();
this.toggleCalendarModal() }}>
<View style={[this.style.home_day, { height: days_len }]} key={day}
>
<View style={{ flex: 1, alignItems: 'center' }} key={id}>
<DayComp
...
>
{date}
</DayComp>
</View>
</View>
</TouchableOpacity>
);
renderWeek(days, id) {
const week = [];
days.forEach((day, id2) => {
week.push(this.renderDay(day, id2));
}, this);
return (<View style={[this.style.home_week} key=
{id}>{week}
</View>);
render() { ...}
return( <View
...calendar component
</View>
);
我正在修改 react-native-calendar 模块中的 calendar/index.js。我制作了像 iphone 日历一样的日历页面。如果我在 renderday 函数中单击视图 home_day,我希望显示模式页面..... setModalPage 函数运行良好,但模式页面没有显示。我该如何解决这个问题..?
编辑
我自己解决问题。我在 toggleCalendarModal 函数中添加了 {this.forceUpdate()}。
解决方案
推荐阅读
- python - Django - 多过滤查询集返回空查询集
- ssl - 两个虚拟主机上的一个多站点 SSL(Ubuntu 16.04 上的 Apache2)
- c# - UserManager.FindAsync(model.UserName, model.Password) 返回 null
- intellij-idea - 我在哪里可以获得构建 Restful API 的详细信息?
- html - 如何摆脱不必要的垂直滚动条?
- marklogic - Marklogic DataHub 错误:缺少指定的流。(MISSING_FLOW
- mysql - 按sql中的总数排序
- java - IntelliJ Build 181.5281.24 消耗超过 1GB 的 RAM
- python - django 如何将字段序列化为 DateTimeRangeField
- vba - 删除 Outlook 项目中的模块