現在のスクリーンの上に表示するアラートダイアログです。ユーザに対する問いかけ、警告、エラーメッセージを表示するのに利用できます。タイトルやコンテンツやボタンは簡単にカスタマイズでき、実行しているプラットフォームに併せてスタイルが自動的に切り替わります。
There are three components used to show dialogs: Dialog, AlertDialog and Toast. The Dialog component is a general dialog where you can put any content. AlertDialog has some default styles that make it easy to show errors, warnings or questions to the user.
And Toast is a message (with optional button) that does not stop the app flow.
To show or hide the dialog the isOpen prop is used.
<Dialog isOpen={this.state.dialogShown}>
Hi!
<Button onClick={this.hideDialog.bind(this)}>
Close
</Button>
</Dialog>
The ons.notification object contains some useful methods to easily show alerts, confirmation dialogs and prompts:
ons.notification.alert(message, options)ons.notificaiton.confirm(message, options)ons.notification.prompt(message, options)ons.notification.toast(message, options)They all return a Promise object that can be used to handle the input from the user.
ons.notification.confirm('Are you ready?')
.then((response) => {
// Handle response.
});
| 名前 | 型 / デフォルト値 | 概要 |
|---|---|---|
| modifier | String | ダイアログの見た目を指定します。 Optional. |
| cancelable | この属性を設定すると、ダイアログの背景をタップしたりAndroidデバイスのバックボタンを押すとダイアログが閉じるようになります。 Optional. | |
| disabled | この属性がある時、アラートダイアログはdisabled状態になります。 Optional. | |
| animation |
String
default |
ダイアログを表示する際のアニメーション名を指定します。デフォルトでは”none”か”default”が指定できます。 Optional. |
| animation-options | Expression | アニメーション時のduration, timing, delayをオブジェクトリテラルで指定します。例:{duration: 0.2, delay: 1, timing: ‘ease-in’} Optional. |
| mask-color |
String
rgba(0, 0, 0, 0.2) |
背景のマスクの色を指定します。”rgba(0, 0, 0, 0.2)”がデフォルト値です。 Optional. |
| visible | Boolean |
要素が見える場合にtrue。
Optional.
|
| 名前 | 概要 |
|---|---|
| disabled |
無効化されている場合にtrue。
|
| cancelable | そのダイアログがキャンセル可能かどうかを表します。キャンセル可能なダイアログは、背景をタップするかAndroidデバイスのバックボタンを押すことで閉じることが出来るようになります。 |
| maskColor | 背景のマスクの色を指定します。”rgba(0, 0, 0, 0.2)”がデフォルト値です。 |
| visible |
要素が見える場合にtrue。
|
| onDeviceBackButton | バックボタンハンドラ。 |
| animationOptions | アニメーション時のduration, timing, delayをオブジェクトリテラルで指定します。例:{duration: 0.2, delay: 1, timing: ‘ease-in’} |
| Name | 概要 |
|---|---|
| material | マテリアルデザインのスタイル |
| rowfooter | フッターの複数のボタンを水平に配置 |
| シグネチャ | 概要 |
|---|---|
| show([options]) | ダイアログを表示します。 |
| hide([options]) | ダイアログを閉じます。 |
ダイアログを表示します。
返り値: 表示される要素を解決するPromiseオブジェクトを返します。
| 名前 | 型 | 概要 |
|---|---|---|
| options | Object | オプションを指定するオブジェクトです。 |
| options.animation | String | アニメーション名を指定します。指定できるのは、”fade”, “none”のいずれかです。 |
| options.animationOptions | String |
アニメーション時のduration, delay, timingを指定します。e.g. {duration: 0.2, delay: 0.4, timing: ‘ease-in’}
|
| options.callback | Function | ダイアログが表示され終わった時に呼び出されるコールバックを指定します。 |
ダイアログを閉じます。
返り値: 隠れた要素を解決するPromiseオブジェクトを返します。
| 名前 | 型 | 概要 |
|---|---|---|
| options | Object | オプションを指定するオブジェクト。 |
| options.animation | String | アニメーション名を指定します。”fade”, “none”のいずれかを指定します。 |
| options.animationOptions | String |
アニメーション時のduration, delay, timingを指定します。e.g. {duration: 0.2, delay: 0.4, timing: ‘ease-in’}
|
| options.callback | Function | このダイアログが閉じた時に呼び出されるコールバックを指定します。 |
| 名前 | 概要 |
|---|---|
| preshow | アラートダイアログが表示される直前に発火します。 |
| postshow | アラートダイアログが表示された直後に発火します。 |
| prehide | アラートダイアログが隠れる直前に発火します。 |
| posthide | アラートダイアログが隠れた後に発火します。 |
| dialogcancel | Fired when the dialog is canceled. (翻訳中) |
アラートダイアログが表示される直前に発火します。
| 名前 | 型 | 概要 |
|---|---|---|
| event | Object | Event object. |
| event.alertDialog | Object | アラートダイアログのオブジェクト。 |
| event.cancel | Function | この関数を実行すると、アラートダイアログの表示を止めます。 |
アラートダイアログが表示された直後に発火します。
| 名前 | 型 | 概要 |
|---|---|---|
| event | Object | Event object. |
| event.alertDialog | Object | アラートダイアログのオブジェクト。 |
アラートダイアログが隠れる直前に発火します。
| 名前 | 型 | 概要 |
|---|---|---|
| event | Object | Event object. |
| event.alertDialog | Object | アラートダイアログのオブジェクト。 |
| event.cancel | Function | この関数を実行すると、アラートダイアログが閉じようとするのを止めます。 |
アラートダイアログが隠れた後に発火します。
| 名前 | 型 | 概要 |
|---|---|---|
| event | Object | Event object. |
| event.alertDialog | Object | アラートダイアログのオブジェクト。 |
Fired when the dialog is canceled. (翻訳中)
| 名前 | 型 | 概要 |
|---|
Onsen UIに関する質問は、Stack Overflowにてonsen-uiタグを付与してください。Onsen UIチームはあなたの問題解決をお手伝いします。
バグ報告や機能要望については、GitHub Issuesに記載をお願いいたします。
あわせて、下記の情報も参考にしてください。