Surface render events in famo.us

前端 未结 3 845
名媛妹妹
名媛妹妹 2021-01-15 06:06

I\'m looking for an event that tells me when a surface has been rendered so I can call methods like surface.focus().

If I call focus immediately after I create the s

3条回答
  •  时光取名叫无心
    2021-01-15 06:39

    I marked johntraver's response as the answer, but I also wanted to include a complete working example for the InputSurface for people like me just learning famous. This code subclasses InputSurface so that the focus method will work.

    Once the InputSurface is rendered it gains focus.

    TextBox.js

    define(function(require, exports, module) {
        var InputSurface      = require('famous/surfaces/InputSurface');
        var EventHandler      = require('famous/core/EventHandler');
        function TextBox(options) {
            InputSurface.apply(this, arguments);
            this._superDeploy = InputSurface.prototype.deploy;
        }
        TextBox.prototype = Object.create(InputSurface.prototype);
        TextBox.prototype.constructor = TextBox;
        TextBox.prototype.deploy = function deploy(target) {
            this.eventHandler.trigger('surface-has-rendered', this);
            this._superDeploy(target);
        };
        module.exports = TextBox;
    });
    

    implementation

    this.email = new TextBox({
        size: [300, 40],
        placeholder:'email'
    });
    
    var event_handler = new EventHandler();
    
    event_handler.on('surface-has-rendered', function(control){
        control.focus();
    });
    
    this.email.pipe(event_handler);
    

提交回复
热议问题