|
| 1 | +本组件会打开一个标准的Android日期选择器的对话框。 |
| 2 | + |
| 3 | +### 示例 |
| 4 | +```js |
| 5 | +try { |
| 6 | + const {action, year, month, day} = await DatePickerAndroid.open({ |
| 7 | + // 要设置默认值为今天的话,使用`new Date()`即可。 |
| 8 | + // 下面显示的会是2020年5月25日。月份是从0开始算的。 |
| 9 | + date: new Date(2020, 4, 25) |
| 10 | + }); |
| 11 | + if (action !== DatePickerAndroid.dismissedAction) { |
| 12 | + // 这里开始可以处理用户选好的年月日三个参数:year, month (0-11), day |
| 13 | + } |
| 14 | +} catch ({code, message}) { |
| 15 | + console.warn('Cannot open date picker', message); |
| 16 | +} |
| 17 | +``` |
| 18 | + |
| 19 | +### 方法 |
| 20 | + |
| 21 | +<div class="props"> |
| 22 | + <div class="prop"><h4 class="propTitle"><a class="anchor" name="open"></a><span |
| 23 | + class="propType">static </span>open<span class="propType">(options: Object)</span> <a class="hash-link" |
| 24 | + href="#open">#</a> |
| 25 | + </h4> |
| 26 | + <div><p>Opens the standard Android date picker dialog.</p> |
| 27 | + <p>The available keys for the <code>options</code> object are: |
| 28 | + <em> <code>date</code> (<code>Date</code> object or timestamp in milliseconds) - date to show by default |
| 29 | + </em> <code>minDate</code> (<code>Date</code> or timestamp in milliseconds) - minimum date that can be |
| 30 | + selected |
| 31 | + * <code>maxDate</code> (<code>Date</code> object or timestamp in milliseconds) - minimum date that can |
| 32 | + be selected</p> |
| 33 | + <p>Returns a Promise which will be invoked an object containing <code>action</code>, <code>year</code>, |
| 34 | + <code>month</code> (0-11), |
| 35 | + <code>day</code> if the user picked a date. If the user dismissed the dialog, the Promise will |
| 36 | + still be resolved with action being <code>DatePickerAndroid.dismissedAction</code> and all the other |
| 37 | + keys |
| 38 | + being undefined. <strong>Always</strong> check whether the <code>action</code> before reading the |
| 39 | + values.</p> |
| 40 | + <p>Note the native date picker dialog has some UI glitches on Android 4 and lower |
| 41 | + when using the <code>minDate</code> and <code>maxDate</code> options.</p></div> |
| 42 | + </div> |
| 43 | + <div class="prop"><h4 class="propTitle"><a class="anchor" name="datesetaction"></a><span |
| 44 | + class="propType">static </span>dateSetAction<span class="propType">()</span> <a class="hash-link" |
| 45 | + href="#datesetaction">#</a> |
| 46 | + </h4> |
| 47 | + <div><p>A date has been selected.</p></div> |
| 48 | + </div> |
| 49 | + <div class="prop"><h4 class="propTitle"><a class="anchor" name="dismissedaction"></a><span |
| 50 | + class="propType">static </span>dismissedAction<span class="propType">()</span> <a class="hash-link" |
| 51 | + href="#dismissedaction">#</a> |
| 52 | + </h4> |
| 53 | + <div><p>The dialog has been dismissed.</p></div> |
| 54 | + </div> |
| 55 | +</div> |
0 commit comments