【发布时间】:2019-05-06 09:48:38
【问题描述】:
我正在尝试使用react-native-calendars library by wix 构建日历。
例如,当我在 Calendar Component 中单击 2018 年 12 月 5 日时,它应该在 Agenda Component 上导航到 2018 年 12 月 5 日。这就是我想要做的。
这是我的 Calendar Component 代码,我试图在其中获取 id 并绑定它:
class Calendar extends Component {
constructor(props) {
super(props);
this.state = {
active: 'true'
}
}
render() {
const {onSelect} = this.props;
return (
<View>
<CalendarList
keyExtractor = {day=>day.id}
onDayPress={(day) => {onSelect.bind(this, day)}}
pastScrollRange={12}
futureScrollRange={12}
scrollEnabled={true}
showScrollIndicator={true}
/>
</View>
);
}
}
Calendar.propTypes = {
onSelect: PropTypes.func,
}
这是我的代码CalendarScreen,我在其中进行导航。
const CalendarScreen = ({navigation}) => (
<View >
<Calendar navigation={navigation}
onSelect={(id)=>{
navigation.navigate('Agenda', {id}) }}>
<StatusBar backgroundColor="#28F1A6" />
</Calendar >
</View>
);
Calendar.propTypes = {
navigation: PropTypes.object.isRequired
}
export default CalendarScreen;
我也提到了here的解决方案。但没有运气。
编辑:
这是我的Agenda Component
class WeeklyAgenda extends Component {
constructor(props) {
super(props);
this.state = {
items: {}
};
}
render() {
return (
<View style={{height:600}}>
<Agenda
items={this.state.items}
loadItemsForMonth={this.loadItems.bind(this)}
selected={Date()}
renderItem={this.renderItem.bind(this)}
renderEmptyDate={this.renderEmptyDate.bind(this)}
rowHasChanged={this.rowHasChanged.bind(this)}
onRefresh = {() => { this.setState({refeshing : true})}}
refreshing = {this.state.refreshing}
refreshControl = {null}
pastScrollRange={1}
futureScrollRange = {3}
/>
);
}
这是AgendaScreen
const AgendaScreen = ({navigation}) => (
<View style={{height: 100}}>
<WeeklyAgenda navigation={navigation}>
<StatusBar backgroundColor="#28F1A6" />
</WeeklyAgenda >
</View>
);
WeeklyAgenda.propTypes = {
navigation: PropTypes.object.isRequired
}
export default AgendaScreen;
【问题讨论】:
-
您是否收到错误消息?
-
@RachelGallen 不,没有错误。
标签: javascript reactjs react-native bind react-navigation