[TIMOB-23117] Hyperloop: Android: Support calls to super-class
| GitHub Issue | n/a |
|---|---|
| Type | Improvement |
| Priority | High |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2016-05-10T23:04:28.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | Release 5.4.0 |
| Components | Android, Hyperloop |
| Labels | n/a |
| Reporter | Andrey Tkachenko |
| Assignee | Christopher Williams |
| Created | 2016-03-28T19:05:24.000+0000 |
| Updated | 2018-08-06T17:49:28.000+0000 |
Description
Hyperloop Android (not sure if it works in iOS) currently cannot call the superclass inside a Hyperloop-based subclass. We should support that in order to match a common OOP-pattern.
[~hansknoechel] Do you have some sample code for the usage you're expecting? I assume this is when you override a method in a JS subclass and want to be able to call the super implementation in it?
The initial request contained a constructor method:
and a super-class call:MyView = android.view.View.extend({ MyView: function() { // Constructor called? } });If you can think of a better structure, please go ahead! :-)var MyView = View.extend({ onMeasure: function(widthMeasureSpec, heightMeasureSpec) { View.prototype.onMeasure.call(this, widthMeasureSpec, heightMeasureSpec); // or this.super.onMeasure.call(this, widthMeasureSpec, heightMeasureSpec); } }https://github.com/appcelerator/hyperloop.next/pull/29
This PR is for an implementation that uses a this.super property. So it'd look more like this:
var MyView = View.extend({ onMeasure: function (widthMeasureSpec, heightMeasureSpec) { this.super.onMeasure(widthMeasureSpec, heightMeasureSpec); // do your own custom work now. } });Another note, the PR I posted does not attempt to address overriding constructors as mentioned above. Quite honestly how to achieve that has me a bit stumped right now...
Alright. Should we file an own ticket for the constructor call?
@Chris Williams @Hans Knoechel how can I get the current application context using this same approach? By getting a reference to the current *Activity* on native code I can just call *getApplicationContext()* and that's it. On the other hand, with Hyperloop I'd need to go past the first super class (Activity -> ContextThemeWrapper -> ContextWrapper -> Context.getApplicationContext()). How do you see that happening?
Cleaning up older fixed issues. If this issue should not have been closed as fixed, please reopen.