根據RN文檔,您必須調用異步/等待函數才能打開Android日期選擇器。我試着安裝異步到發電機轉化巴貝爾預設並增加了.babelrc文件,React Native:你如何實現DatePickerAndroid?
{ "plugins": ["transform-async-to-generator"] }
但這似乎只是拋出一個意外的標記錯誤添加使用標籤(例如<圖像的任何RN組件時。 .. />會拋出和意外的令牌錯誤)。這是我的功能打開Android日期選取器看起來像
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);
}
}
你能否使用RN Core的DatePickerAndroid API? –
我還沒有使用RN核心DatePickerAndroid呢..因爲庫實現相當簡單... – Riten