我试图将事件绑定在datepicker的标头内。但它不起作用。 另一个问题是无法访问标题部分内部的功能。 这是我的代码:
static navigationOptions = ({ navigation }) => {
const { state } = navigation;
var isNavigate = true;
var searchStartDate = "";
return {
title: "Tracking" ,
headerRight: (
<View style={[styles.right, { flexDirection: 'row' }]}>
<DatePicker
cancelBtnText='Cancel'
confirmBtnText='Done'
hideText='true'
mode="date"
customStyles={{
dateIcon: {
position: 'absolute',
right: 0,
top: 4,
marginBottom: 5,
marginLeft: 0,
flex: 1
},
}}
onDateChange={() => params.Tracking()} />
</View>
)
}
};
Tracking() {
}
constructor(props) {
super(props);
this.state = {
loading: false,
showCalendar: false
}
}
答案 0 :(得分:0)
尝试在headerRight中添加简单组件,如果它有效,则可以添加DatePicker或任何其他组件。请考虑以下示例:
class Home extends Component {
static navigationOptions = ({ navigation }) => ({
title: 'Title',
headerRight: (
<Button
title='Button'
onPress={Home.instance.onButtonPress}
/>
)
});
constructor(props) {
super(props);
Home.instance = this;
}
onButtonPress = () => {
alert('I am pressed')
}
}