0

My question is related to my another question here: SVG using CSS3 animations in GWT

But it is more simple. Is there a way in GWT to call method after a presenter has been fully loaded?

For example lets have a SVG picture in one window (presenter) and text in another window(presenter). A button is there that when clicked it changes text presenter for SVG image presenter and vice versa (calling the go() method). I need to strip all CSS from svg an reapply it, but it has to be done AFTER the presenter is changed and image loaded. If I do it in the go() method, it will not work. Currently hacking it with schudleFixedDelay(), but want something less hacky.

EDIT1: I mean when presenter contents are fully displayed in DOM, then I want to launch some code. It probably doesn't have anything to do with loading SVG image, just displaying it. How to know when everything from the presenter has been displayed and added to the DOM?

EDIT2: Ok so the scheduleDeferred function is really what I am looking for. I know this function and use it, but I had more specific problem it seems. The scheduleDeferred function calls my method to fix the coordinats just fine. But when I was using it before, it did not work because of the method to fix coordinates. It seems, when I call removeAttribute("class") on SVG element, I cannot setAttribute("class", "classname") just after that. I had to make a scheduleFixedDelay there for at least 100ms, or it does not work. Not sure if the delay will work everywhere (mobiles, tablets...), but I don't know why it does not work without the delay. This is probably a solution for me.

Community
  • 1
  • 1
ezpzlmnsqz1337
  • 394
  • 1
  • 5
  • 16
  • If you load your SVG files as SVGResource (check lib-gwt-svg for this extension) - SVG's will be inlined in the bootstrap itself, e.r. loaded instantly (if that's an option and loading all SVG's at once fits your logic) – Роман Гуйван Jun 02 '16 at 14:37
  • Yes I am using lib-gwt-svg and i know it is "loaded instantly" (bad formulation of my question). I just want to launch some code AFTER the presenter contents (including svg image) are displayed. It does not work correctly if I fix the coordinates "in the background" when the presenter contents aren't fully displayed. – ezpzlmnsqz1337 Jun 03 '16 at 06:30
  • Why do you need `removeAttribute("class")` immediately followed by `setAttribute("class", "classname")`? You can skip the first step. – Andrei Volgin Jun 03 '16 at 17:25
  • I need to do this because if I set the class to the same class the element already has, the browser sees nothing has changed and will not refresh the style. I need to refresh the style, because browser keeps handling transform style property with coordinates of SVG, instead of CSS, so I have my SVG elements wrongly placed. If I remove the class, and then add the same class, browser sees the style has changed and starts handling the transform attribute with CSS coordinates corectly. (this CSS to SVG coordinates change bug happens when the SVG image is hidden, and then shown again) – ezpzlmnsqz1337 Jun 07 '16 at 11:26

1 Answers1

0

Unless you use code splitting, GWT code is loaded all at once - before your app executes its first line of code. I assume you mean either "all presenter code is executed" or "the SVG image completed loading".

Depending on how you load the image, you can use Image class which implements load handlers (i.e. you can use onLoad()).

Alternatively, instead of a fixed delay you should use scheduleDeferred method in a Scheduler class, as explained here: GWT: Timer and Scheduler Classes

Community
  • 1
  • 1
Andrei Volgin
  • 40,755
  • 6
  • 49
  • 58
  • Scheduler.get().scheduleDeferred does not help, that is why I had to use fixed delay. But I guess it will need different delay on each device (tablets, mobile phones etc.) Yes I mean something like "all presenter code executed and its contents already displayed", then I want to launch my CSS coordinates fix code. – ezpzlmnsqz1337 Jun 03 '16 at 06:27
  • 1
    Browsers are, generally speaking, single-threaded. If `show the next view` -> `scheduleDeferred()` (i.e. wait for the view to render) -> `do something in that view` does not help, I suspect there is a problem in your code logic. – Andrei Volgin Jun 03 '16 at 08:23
  • Ok so basicaly scheduleDefferred is really THE FUNCTION I'm looking for I guess. The error then is probably that I need to set up delay between removing the classes and reapplying them. I'll try schedule deffered for removing classes and then fixed delay for reapplying. Thanks. – ezpzlmnsqz1337 Jun 03 '16 at 08:30
  • You can use scheduleDeffered() in more than one place - everywhere you need to wait for the rendering to finish. – Andrei Volgin Jun 03 '16 at 17:23
  • As I describe in [here](http://stackoverflow.com/questions/37292829/svg-using-css3-animations-in-gwt), I fixed the SVG problem with changing of the SVG code. Even though these answers are probably right, it didn't fix my problem as the problem probably couldn't be saved like this. – ezpzlmnsqz1337 Apr 24 '17 at 08:21