[AC-6371] Android DrawerLayout parameters/object not accessible within eventListener "change"
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Resolved |
Resolution | Done |
Resolution Date | 2019-10-29T20:05:38.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | android, drawerlayout, event, parameters |
Reporter | Arjan |
Assignee | Shak Hossain |
Created | 2019-09-19T10:22:00.000+0000 |
Updated | 2019-10-29T20:05:39.000+0000 |
Description
I was trying to get the state of the drawer view by attaching the "change" event. But within the listener you can't access any parameters from the current object. No local reference.
SDK; 8.1.1.GA
Platform: Android
Code example (index controller);
var win = Ti.UI.createWindow();
var leftView = Ti.UI.createView({ backgroundColor:'red' });
var centerView = Ti.UI.createView({ backgroundColor:'yellow' });
var rightView = Ti.UI.createView({ backgroundColor:'orange' });
var drawer = Ti.UI.Android.createDrawerLayout({
leftView: leftView,
centerView: centerView,
rightView: rightView
});
var btn = Ti.UI.createButton({ title: 'RIGHT' });
btn.addEventListener('click', function() {
drawer.toggleRight();
});
centerView.add(btn);
win.addEventListener('open', function(){
console.log('window opened');
var activity = win.getActivity(),
actionBar = activity.getActionBar();
if (actionBar) {
actionBar.displayHomeAsUp = true;
actionBar.onHomeIconItemSelected = function() {
drawer.toggleLeft();
};
}
});
win.addEventListener('close', function(){
console.log('window closed');
});
drawer.addEventListener('open', function() {
console.log('drawer opened');
});
drawer.addEventListener('close', function() {
console.log('drawer closed');
});
drawer.addEventListener("change", onDrawerChange);
function onDrawerChange(e) {
console.log("[ drawerView has changed");
console.info(this); // error
console.info(e); // error
}
win.add(drawer);
win.open();
Errors;
[ERROR] : TiExceptionHandler: (main) [386,30549] ti:/titanium.js:178
[ERROR] : TiExceptionHandler: serialized[k] = this[k];
[ERROR] : TiExceptionHandler: ^
[ERROR] : TiExceptionHandler: Error: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
[ERROR] : TiExceptionHandler: at ListItem.value (ti:/titanium.js:178:24)
[ERROR] : TiExceptionHandler: at JSON.stringify (<anonymous>)
[ERROR] : TiExceptionHandler: at ti:/console.js:26:63
[ERROR] : TiExceptionHandler: at Array.map (<anonymous>)
[ERROR] : TiExceptionHandler: at join (ti:/console.js:18:53)
[ERROR] : TiExceptionHandler: at Object.exports.info (ti:/console.js:52:20)
[ERROR] : TiExceptionHandler: at DrawerLayout.onDrawerChange (/alloy/controllers/appWindow.js:174:9)
[ERROR] : TiExceptionHandler: at DrawerLayout.value (ti:/events.js:50:21)
[ERROR] : TiExceptionHandler: at DrawerLayout.value (ti:/events.js:102:19)
[ERROR] : TiExceptionHandler:
[ERROR] : TiExceptionHandler: ti.modules.titanium.ui.widget.listview.TiListItem.handleAccessory(TiListItem.java:64)
[ERROR] : TiExceptionHandler: ti.modules.titanium.ui.widget.listview.TiListItem.processProperties(TiListItem.java:50)
[ERROR] : TiExceptionHandler: org.appcelerator.kroll.KrollProxy.setModelListener(KrollProxy.java:1345)
[ERROR] : TiExceptionHandler: org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:508)
[ERROR] : TiExceptionHandler: org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:498)
[ERROR] : TiExceptionHandler: org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:464)
[ERROR] : TiExceptionHandler: org.appcelerator.titanium.proxy.TiViewProxy.getBackgroundSelectedColor(TiViewProxy.java:1074)
[ERROR] : TiExceptionHandler: org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
[ERROR] : TiExceptionHandler: org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:63)
[ERROR] : TiExceptionHandler: org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:976)
[ERROR] : V8Exception: Exception occurred at ti:/titanium.js:178: Uncaught Error: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
Hello, I am not able to reproduce the error in SDK 8.2.0.GA and I can log the change. Can you try with that SDK? Thanks.
Hi Sharif, Ran a test on 8.2.1.GA, result: 1) the errors are gone 2) parent window events (open/closed) are still triggerred though I used above example, copied it to a new project, compiled it with 8.2.1.GA Console output;