Modal promise
Introduction¶
Modal behavior wrapped into promise.
- Author: Rex
- Promise
Live demos¶
Usage¶
Install plugin¶
Load minify file¶
- Load plugin (minify file) in preload stage
scene.load.plugin('rexmodalplugin', 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexmodalplugin.min.js', true);
- Add modal behavior
scene.plugins.get('rexmodalplugin').promise(gameObject, config) .then(function(closeEventData) { })
Import plugin¶
- Install rex plugins from npm
npm i phaser3-rex-plugins
- Add modal behavior
scene.plugins.get('rexModal').promise(gameObject, config) .then(function(closeEventData) { })
Import class¶
- Install rex plugins from npm
npm i phaser3-rex-plugins
- Import class
import { ModalPromise } from 'phaser3-rex-plugins/plugins/modal.js';
- Add modal behavior
ModalPromise(gameObject, config) .then(function(closeEventData) { })
Promise¶
scene.plugins.get('rexModal').promise(gameObject, config)
.then(function(closeEventData) {
})
config
: See Modal behavior
Close¶
scene.plugins.get('rexModal').close(gameObject);
// scene.plugins.get('rexModal').close(gameObject, closeEventData);
gameObject.emit('modal.requestClose');
// gameObject.emit('modal.requestClose', closeEventData);
- Fire
'modal.requestClose'
event on game object, which will invokemodal.requestClose()
method. After closing dialog,resolve
part of promise will be triggered.
graph TB
Promise["promose('gameObject, config)"]
OnOpen["gameObject.on('modal.open')"]
RequestCloseEvent["gameObject.emit('modal.requestClose', closeEventData)"]
TimeOut["Timeout<br>Any touch"]
OnClose["gameObject.on('modal.close')"]
Resolve["then(function(closeEventData) { })"]
Promise --> |Transition-in| OnOpen
OnOpen --> |manualClose| RequestCloseEvent
OnOpen --> |Not manualClose| TimeOut
RequestCloseEvent --> |Transition-out| OnClose
TimeOut --> |Transition-out| OnClose
OnClose --> Resolve
Events¶
- To invoke
modal.requestClose()
methodgameObject.emit('modal.requestClose', closeEventData);
- On opened dialog
gameObject.on('modal.open', function(modalBehavior) { })
- On closed dialog
gameObject.on('modal.close', function(closeEventData, modalBehavior) { })