根据RN文档,您必须调用async / await函数才能打开Android Date Picker。我试过安装异步生成器转换Babel预设,并添加一个.babelrc文件,
{ "plugins": ["transform-async-to-generator"] }
但这似乎在使用标签添加任何RN组件时会引发意外的令牌错误(例如<Image ... />会引发意外的令牌错误)。这就是我打开Android Date Picker的功能
async openAndroidDatePicker: function() {
try {
const {action, year, month, day} = await DatePickerAndroid.open({
date: new Date()
});
} catch ({code, message}) {
console.warn('Cannot open date picker', message);
}
}
解决了。我的函数语法错误...这对我有用:
async openAndroidDatePicker() {
try {
const {action, year, month, day} = await DatePickerAndroid.open({
date: new Date()
});
} catch ({code, message}) {
console.warn('Cannot open date picker', message);
}
}
请记住,我在本示例中使用的是createClass,而不是es6类。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句