I'm not much up on the intricacies of memory leaks and event handlers, so I can't say that this safe for long-running applications. But it works for me with the big caveat that I can't access my instance objects from the methods called on the event. For example:
public void onBrowserEvent( Event event )
{
String type = event.getType();
if ( type.equals( "touchstart" ) ) {
DOM.getElementById( "header" ).getStyle().setProperty( "opacity", "0" );
DOM.getElementById( "footer" ).getStyle().setProperty( "opacity", "0" );
} else if ( type.equals( "touchend" ) ) {
final Style headerStyle = DOM.getElementById( "header" ).getStyle();
final Style footerStyle = DOM.getElementById( "footer" ).getStyle();
new Animation()
{
protected void onUpdate( double progress )
{
int scrollY = BrowserUtils.getScrollY();
headerStyle.setPropertyPx( "top", scrollY );
headerStyle.setProperty( "opacity", "" + ( 1 * progress ) );
footerStyle.setPropertyPx( "top", ( ( BrowserUtils.getInnerHeight() - 36 ) + scrollY ) );
footerStyle.setProperty( "opacity", "" + ( 1 * progress ) );
}
}.run( 125, Duration.currentTimeMillis() + 300 );
}
}
I have to go through some machinations to get references to the objects that are defined as instance variables. No matter what I did, when the event was triggered (maybe because the event firer is a native trigger and not something else...don't know) my instance variables were not in scope, and thus undefined. That's probably a bug and I'll post an issue on it. Rather than being annoying, it could contribute to some really hard-to-debug errors because you wouldn't think that referencing your instance methods would one way in a java method, but after being called from JavaScript in connection with an event, they are non-referenecable.