我正在为一个大学项目创建一个药物提醒应用程序,我正在使用 react-native-calendars 库中的 Agenda 标签。这是我的应用程序现在的样子:1
我想添加一个功能,在单击日历时更改日历中每个项目的颜色 - 本质上是为了突出显示用户已服用药物。(几乎就像一个待办事项清单)。
我之前尝试实现此功能,但它会突出显示所有项目,而不是每个项目。
以下是没有此功能的当前代码:
export default class App extends React.Component {
state = {
toggled: false,
items: {},
}
toggleSwitch = (value) => {
this.setState({toggled: value})
}
render() {
return (
<View style={styles.background}>
<View style={styles.medicationHeaderContainer}>
<Text style={styles.medicationHeader}> Medication </Text>
</View>
<View style={styles.reminderAlertContainer}>
<Text style={styles.reminderAlertText}> Reminders </Text>
<Switch
onValueChange={this.toggleSwitch}
value={this.state.toggled}
style={styles.reminderAlertSwitch}/>
</View>
<Agenda
items={{'2012-05-22': [{name: '9 AM - One 200 mg Paracetamol '}],
'2012-05-23': [{name: '9 AM - One 200 mg Paracetamol'}, {name: '10 AM - One 500 mg Magnesium Tablet'}],
'2012-05-24': [{name: '9 AM - One 200 mg Paracetamol'}],
'2012-05-25': [{name: '9 AM - One 200 mg Paracetamol'}, {name: '10 AM - One 500 mg Magnesium Tablet'}]
}}
selected={'2012-05-22'}
renderItem={this.renderItem.bind(this)}
>
</Agenda>
</View>
);
}
renderItem(item) {
return (
<View style={styles.item} onPress={() => Alert.alert(item.name)}>
<View>
<Text>{item.name}</Text>
</View>
<TouchableOpacity
onPress={() => Alert.alert(item.name)}
/>
</View>
);
}}
和样式表:
const styles = StyleSheet.create({
background: {
flex: 1,
backgroundColor: "#fff"
},
medicationHeaderContainer: {
marginTop: 40,
height: "10%",
backgroundColor: "#fff"
},
medicationHeader: {
fontSize: 40,
bottom: -30,
fontWeight: "bold",
marginLeft: 15
},
reminderAlertContainer: {
marginTop: 5,
height: '7%',
width: '95%',
backgroundColor: "#85C1E9",
borderBottomStartRadius: 10,
borderBottomEndRadius: 10,
borderTopStartRadius: 10,
borderTopEndRadius: 10,
marginLeft: 10
},
reminderAlertText: {
fontSize: 30,
bottom: -10,
marginLeft: 15,
color: '#fff',
fontWeight: "bold",
},
reminderAlertSwitch: {
bottom: 20,
marginLeft: 320
},
item: {
backgroundColor: 'white',
flex: 1,
borderRadius: 5,
padding: 10,
marginRight: 10,
marginTop: 17
},
emptyDate: {
height: 15,
flex: 1,
paddingTop: 30
},});