fix(ui): app crash when some ui events' handlers throw exception
This commit is contained in:
@@ -84,40 +84,32 @@ module.exports = function(__runtime__, scope){
|
|||||||
var gestureDetector = new android.view.GestureDetector(context, {
|
var gestureDetector = new android.view.GestureDetector(context, {
|
||||||
onDown: function(e){
|
onDown: function(e){
|
||||||
e = wrapMotionEvent(e);
|
e = wrapMotionEvent(e);
|
||||||
scope.__exitIfError__(function(){
|
emit("touch_down", e, view);
|
||||||
view.emit("touch_down", e, view);
|
|
||||||
});
|
|
||||||
return e.consumed;
|
return e.consumed;
|
||||||
},
|
},
|
||||||
onShowPress: function(e){
|
onShowPress: function(e){
|
||||||
e = wrapMotionEvent(e);
|
e = wrapMotionEvent(e);
|
||||||
view.emit("show_press", e, view);
|
emit("show_press", e, view);
|
||||||
},
|
},
|
||||||
onSingleTapUp: function(e){
|
onSingleTapUp: function(e){
|
||||||
e = wrapMotionEvent(e);
|
e = wrapMotionEvent(e);
|
||||||
scope.__exitIfError__(function(){
|
emit("single_tap", e, view);
|
||||||
view.emit("single_tap", e, view);
|
|
||||||
});
|
|
||||||
return e.consumed;
|
return e.consumed;
|
||||||
},
|
},
|
||||||
onScroll: function(e1, e2, distanceX, distanceY){
|
onScroll: function(e1, e2, distanceX, distanceY){
|
||||||
e1 = wrapMotionEvent(e1);
|
e1 = wrapMotionEvent(e1);
|
||||||
e2 = wrapMotionEvent(e2);
|
e2 = wrapMotionEvent(e2);
|
||||||
scope.__exitIfError__(function(){
|
emit("scroll", e1, e2, distanceX, distanceY, view);
|
||||||
view.emit("scroll", e1, e2, distanceX, distanceY, view);
|
|
||||||
});
|
|
||||||
return e1.consumed || e2.consumed;
|
return e1.consumed || e2.consumed;
|
||||||
},
|
},
|
||||||
onLongPress: function(e){
|
onLongPress: function(e){
|
||||||
e = wrapMotionEvent(e);
|
e = wrapMotionEvent(e);
|
||||||
view.emit("long_press", e, view);
|
emit("long_press", e, view);
|
||||||
},
|
},
|
||||||
onFling: function(e1, e2, velocityX, velocityY){
|
onFling: function(e1, e2, velocityX, velocityY){
|
||||||
e1 = wrapMotionEvent(e1);
|
e1 = wrapMotionEvent(e1);
|
||||||
e2 = wrapMotionEvent(e2);
|
e2 = wrapMotionEvent(e2);
|
||||||
scope.__exitIfError__(function(){
|
emit("fling", e1, e2, velocityX, velocityY, view);
|
||||||
view.emit("fling", e1, e2, velocityX, velocityY, view);
|
|
||||||
});
|
|
||||||
return e1.consumed || e2.consumed;
|
return e1.consumed || e2.consumed;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -127,32 +119,26 @@ module.exports = function(__runtime__, scope){
|
|||||||
}
|
}
|
||||||
event = wrapMotionEvent(event);
|
event = wrapMotionEvent(event);
|
||||||
event.consumed = false;
|
event.consumed = false;
|
||||||
scope.__exitIfError__(function(){
|
emit("touch", event, view);
|
||||||
view.emit("touch", event, view);
|
|
||||||
});
|
|
||||||
return event.consumed;
|
return event.consumed;
|
||||||
})
|
})
|
||||||
view.setOnLongClickListener(function(v){
|
view.setOnLongClickListener(function(v){
|
||||||
var event = {};
|
var event = {};
|
||||||
event.consumed = false;
|
event.consumed = false;
|
||||||
scope.__exitIfError__(function(){
|
emit("long_click", event, view);
|
||||||
view.emit("long_click", event, view);
|
|
||||||
});
|
|
||||||
return event.consumed;
|
return event.consumed;
|
||||||
});
|
});
|
||||||
view.setOnClickListener(function(v){
|
view.setOnClickListener(function(v){
|
||||||
view.emit("click", view);
|
emit("click", view);
|
||||||
});
|
});
|
||||||
view.setOnKeyListener(function(v, keyCode, event){
|
view.setOnKeyListener(function(v, keyCode, event){
|
||||||
event = wrapMotionEvent(event);
|
event = wrapMotionEvent(event);
|
||||||
scope.__exitIfError__(function(){
|
emit("key", keyCode, event, v);
|
||||||
view.emit("key", keyCode, event, v);
|
|
||||||
});
|
|
||||||
return event.consumed;
|
return event.consumed;
|
||||||
});
|
});
|
||||||
if(typeof(view.setOnCheckedChangeListener) == 'function'){
|
if(typeof(view.setOnCheckedChangeListener) == 'function'){
|
||||||
view.setOnCheckedChangeListener(function(v, isChecked){
|
view.setOnCheckedChangeListener(function(v, isChecked){
|
||||||
view.emit("check", isChecked, view);
|
emit("check", isChecked, view);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
view._id = function(id){
|
view._id = function(id){
|
||||||
@@ -172,6 +158,12 @@ module.exports = function(__runtime__, scope){
|
|||||||
view.performLongClick();
|
view.performLongClick();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function emit(){
|
||||||
|
var args = arguments;
|
||||||
|
scope.__exitIfError__(function(){
|
||||||
|
view.emit.apply(view, args);
|
||||||
|
});
|
||||||
|
}
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,6 +184,24 @@ module.exports = function(__runtime__, scope){
|
|||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function functionApply(func, args){
|
||||||
|
if(args.length == 0)
|
||||||
|
return func();
|
||||||
|
if(args.length == 1)
|
||||||
|
return func(args[0]);
|
||||||
|
if(args.length == 2)
|
||||||
|
return func(args[0], args[1]);
|
||||||
|
if(args.length == 3)
|
||||||
|
return func(args[0], args[1], args[2]);
|
||||||
|
if(args.length == 4)
|
||||||
|
return func(args[0], args[1], args[2], args[3]);
|
||||||
|
if(args.length == 5)
|
||||||
|
return func(args[0], args[1], args[2], args[3], args[4]);
|
||||||
|
if(args.length == 6)
|
||||||
|
return func(args[0], args[1], args[2], args[3], args[5]);
|
||||||
|
throw new Error("too many arguments: " + args.length);
|
||||||
|
}
|
||||||
|
|
||||||
var proxy = __runtime__.ui;
|
var proxy = __runtime__.ui;
|
||||||
proxy.__proxy__ = {
|
proxy.__proxy__ = {
|
||||||
set: function(name, value){
|
set: function(name, value){
|
||||||
|
|||||||
Reference in New Issue
Block a user