kishikawakatsumi / JavaScriptBridge

Write iOS apps in Javascript! JavaScriptBridge provides the way to write iOS apps with JavaScript. Powered by JavaScriptCore.framework.
http://d.hatena.ne.jp/KishikawaKatsumi/20140104/1388848644
MIT License
528 stars 65 forks source link

JSBScriptingSupport + Meta Class Support #5

Closed DropDev closed 10 years ago

DropDev commented 10 years ago

In the file JSBScriptingSupport.m line 75 (method + (id)defineClass:instanceMembers:staticMembers: in) when you make a class method or known as a meta method it does not work because there is no coding their to add the class method after input of the staticMembers argument.

kishikawakatsumi commented 10 years ago

Done. e4032b27f72b6d97d370414904e41188ba1fcd45

Please try it.

For example:

var MyView = JSB.defineClass('MyView : UIView', {
  // instance methods
  touchesBeganWithEvent: function(touches, ev) {
    JSB.dump(touches);
    JSB.dump(ev);
    return;
  }
}, {
  // class methods
  layerClass: function() {
    return CAGradientLayer;
  }
});
DropDev commented 10 years ago

i can confirm that it is not working yet.

kishikawakatsumi commented 10 years ago

Please show the sample code?

I checked at least above code is working.

defineClass is create Objective-C class, to interacting system frameworks (delegates, datasources, and so on). If you are creating JavaScript object, just use JavaScript syntax.

DropDev commented 10 years ago

this did not show, the + methods did not work for example.

var MyView = JSB.defineClass('MyView : UIView', { // instance methods touchesBeganWithEvent: function(touches, ev) { JSB.dump(touches); JSB.dump(ev); return; } }, { // class methods layerClass: function() { return CAGradientLayer; } });

the method + layerClass did not work.

kishikawakatsumi commented 10 years ago

I added example code about overriding class methods. It named gradientViewController.js in UICatalog project. https://github.com/kishikawakatsumi/JavaScriptBridge/blob/master/Examples/UICatalog/UICatalog/js/gradientViewController.js

It is simple example, it has a view controller and a view. The view override + layerClass class method to use CAGradientLayer.

Please check it.

kishikawakatsumi commented 10 years ago

I think what you saying is: If define the class like shown below,

var MyButton = JSB.defineClass('MyButton : UIButton', {

 }, {
 buttonWithType: function(type) {
   return UIButton.new();
 }
});

var button = MyButton.buttonWithType(0); // Failed!!

MyButton is the subclass of UIButton overriding buttonWithType: class method. But invoking buttonWithType: method fails.

Is this what you mean?

If I understand correctly, currently it is in the specifications.
The features like 'Class definitions' or 'Method overriding' are made for responding to system framework, such as delegates, data sources, UIViewContoller's methods, and so on.

Currently, JavaScriptCore has the limitation that is dynamically generated JSExport protocols does not work. It can not support because of the limitation.