Last active
August 29, 2015 14:10
-
-
Save falkolab/3657846b9a795d83c07d to your computer and use it in GitHub Desktop.
TIMOB-18128 monkey patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var patches = require('patches'); | |
patches.fix_displayCaps(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var patches = require('patches'); | |
// Tests for fixes | |
patches.fix_TIMOB_18128($.myChildren); | |
function doAdd(e) { | |
for(var i=0;i<500;i++) { | |
$.myChildren.add(Ti.UI.createLabel({text:'label '+i})); | |
Ti.API.info('length '+$.myChildren.children.length); | |
} | |
for(var i=0;i<1000;i++) { | |
$.myChildren.children; | |
$.myChildren.getChildren(); | |
$.myChildren.children.length; | |
Ti.API.info('test '+ i); | |
} | |
} | |
function doRemove(e) { | |
for(var i=0;i<500;i++) { | |
$.myChildren.remove($.myChildren.children[0]); | |
Ti.API.info('length '+$.myChildren.children.length); | |
} | |
for(var i=0;i<1000;i++) { | |
$.myChildren.children; | |
$.myChildren.getChildren(); | |
$.myChildren.children.length; | |
Ti.API.info('test '+ i); | |
} | |
} | |
function doRemoveAll(e) { | |
$.myChildren.removeAllChildren(); | |
Ti.API.info('length '+$.myChildren.children.length); | |
for(var i=0;i<500;i++) { | |
$.myChildren.children; | |
$.myChildren.getChildren(); | |
$.myChildren.children.length; | |
Ti.API.info('test '+ i); | |
} | |
} | |
for (var i = 0; i < 1000; i++) { | |
Ti.Platform.displayCaps; | |
Ti.Platform.getDisplayCaps(); | |
} | |
Ti.Gesture.addEventListener('orientationchange', function(){ | |
Ti.API.info(Ti.Platform.displayCaps.platformHeight); | |
}); | |
$.index.open(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Alloy> | |
<Window class="container" layout="vertical"> | |
<Label id="label" onClick="doAdd">Add Labels</Label> | |
<Label id="label" onClick="doRemove">Remove Label</Label> | |
<Label id="label" onClick="doRemoveAll">Remove All Labels</Label> | |
<View id="myChildren" layout="vertical"></View> | |
</Window> | |
</Alloy> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// commonjs library | |
// https://jira.appcelerator.org/browse/TIMOB-18128 | |
/** | |
* Bugfix for TIMOB-18128 | |
* @param {Object} view View object to be fixed | |
*/ | |
exports.fix_TIMOB_18128 = function fix_TIMOB_18128(view) { | |
if (view.TIMOB_18128__children) | |
return; | |
function getChildren() { | |
return this.TIMOB_18128__children; | |
} | |
Object.defineProperty(view, "children", { | |
get : getChildren | |
}); | |
_.extend(view, { | |
TIMOB_18128__children : [], | |
TIMOB_18128__add : view.add, | |
TIMOB_18128__remove : view.remove, | |
TIMOB_18128__removeAllChildren : view.removeAllChildren, | |
getChildren : getChildren, | |
add : function(view) { | |
this.TIMOB_18128__children.push(view); | |
this.TIMOB_18128__add(view); | |
}, | |
remove : function(view) { | |
var idx = this.TIMOB_18128__children.indexOf(view); | |
idx !== -1 && this.TIMOB_18128__children.splice(idx, 1); | |
this.TIMOB_18128__remove(view); | |
}, | |
removeAllChildren : function(view) { | |
this.TIMOB_18128__children.length = 0; | |
this.TIMOB_18128__removeAllChildren(); | |
} | |
}); | |
}; | |
exports.fix_displayCaps = function fix_displayCaps() { | |
if (Ti.Platform.fix_displayCaps) | |
return; | |
Ti.Platform.fix_displayCaps = Ti.Platform.displayCaps; | |
function getDisplayCaps() { | |
return Ti.Platform.fix_displayCaps; | |
} | |
Object.defineProperty(Ti.Platform, "displayCaps", { | |
get : getDisplayCaps | |
}); | |
Ti.Platform.getDisplayCaps = getDisplayCaps; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment