Why does Vaadin 14 not reload GIF pictures in mobile view?

Hi!

I’m have two GIF pictures of two cylinders. In desktop view, they smooth run up and down if I press the “Stop” or “Start” button.
They gif pictures are replaced when I press the buttons. In mobile view, the GIF pictures does not reload at all, they just swapped and no dynamics appear.

This is how it looks like in desktop view. They GIF pictures does its animation and everything is fine. But in mobile view, they GIF pictures only swap. It’s ONE iterations GIF-pictures by the way. So why does the GIF pictures swap? It’s like my mobile cannot handle GIF-animations from Vaadin.

@Route
@PWA(name = "Vaadin Application",
        shortName = "Vaadin App",
        description = "This is an example Vaadin application.",
        enableInstallPrompt = true)
@CssImport("./styles/shared-styles.css")
@CssImport(value = "./styles/vaadin-text-field-styles.css", themeFor = "vaadin-text-field")
public class MainView extends AppLayout {
	
	private static final String START = "Start";
	private static final String STOP = "Stop";

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Autowired
	private Top top;
	
	private Image img_out = new Image("/img/Cylinder_OUT.gif", "Ut");
	private Image img_in = new Image("/img/Cylinder_IN.gif", "In");
	
	@PostConstruct
	private void init() {
		addToNavbar(top.getDrawerToge(), top.getBarImage());
		addToDrawer(top.getTabs());
		
		// Test
		VerticalLayout content = new VerticalLayout();
		//content.setClassName("stekpanna_png");
		Button button = new Button(START);
		button.setClassName("startStop");
		button.addClickListener(e -> {
			if(button.getText().equals(START)) {
				//content.setClassName("stekpanna_gif");
				
				// Begin to delete the pictures first
				content.remove(img_in);
				content.remove(img_out);
				
				// Then add them again
				img_out = new Image("/img/Cylinder_OUT.gif", "Ut");
				img_in = new Image("/img/Cylinder_IN.gif", "In");
				content.add(img_out);
				content.add(img_in);
				
				// Set CSS
				img_out.setClassName("height_img");
				img_in.setClassName("cylinder_ut_in");
				
				// Change the button name
				button.setText(STOP);
			}else {
				// Begin to delete the pictures first
				content.remove(img_out);
				content.remove(img_in);
				
				// Then add them again
				img_out = new Image("/img/Cylinder_OUT.gif", "Ut");
				img_in = new Image("/img/Cylinder_IN.gif", "In");
				content.add(img_in);
				content.add(img_out);
				
				// Set CSS 
				img_in.setClassName("height_img");
				img_out.setClassName("cylinder_in_ut");
				
				// Change the button name
				button.setText(START);
			}
		});
		content.add(button);
		setContent(content);
	}
	
	private MainView() {}


}

CSS code:

.barImage{
	height: 44px;
}

.cylinder_ut_in{
	position: relative;
	left: 150px;	
        top: -100px;
        height: 100px;
}

.cylinder_in_ut{
	position: relative;
        left: 150px;	
        top: -100px;
        height: 100px;
}

.height_img{
        height: 100px;
}

.startStop{
	
}

18216879.png

Nobody knows why one loop GIF pictures only reloads once in mobile view?

Daniel,

Just thinking out load, it may be that the mobile only shows one animation to save battery. If that is the case it isn’t related to Vaadin, but the mobile browser. You can find out quickly if it’s one or the other by making a plain HTML file with the gifs and see if the browser handles that differently.

Martin Israelsen:
Daniel,

Just thinking out load, it may be that the mobile only shows one animation to save battery. If that is the case it isn’t related to Vaadin, but the mobile browser. You can find out quickly if it’s one or the other by making a plain HTML file with the gifs and see if the browser handles that differently.

I solved the issue. The issue was Chrome/Edge. I switched to FireFox and now Vaadin animation works.
Perhaps Vaadin Team should look at this? Just to make sure it works for all web browsers?

There is no “Vaadin animation” involved. it sounds like mobile chrome browser behaves differently with single-loop-gif images than other browsers do. If that’s indeed the case, there is nothing vaadin can do.

Kaspar Scherrer:
There is no “Vaadin animation” involved. it sounds like mobile chrome browser behaves differently with single-loop-gif images than other browsers do. If that’s indeed the case, there is nothing vaadin can do.

Hmm…
Yes, you’re right. It’s the web browsers fault. But if this is a common issue, it might be an answer to it too?

I don’t think it’s a common issue for Vaadiners, because gif is not that commonly used, especially single loop gifs.

But outside of Vaadin, that is indeed a common issue. It looks like there exist several javascript libraries to control gif images. The first that I find is [libgif-js]
(https://github.com/buzzfeed/libgif-js). If you used this, maybe you could find a way where it works perfectly.
If you find your solution, that would also be a great opportunity to create your own vaadin add-on so from then on, other developers with the same need don’t have to go through the same pain.

Kaspar Scherrer:
I don’t think it’s a common issue for Vaadiners, because gif is not that commonly used, especially single loop gifs.

But outside of Vaadin, that is indeed a common issue. It looks like there exist several javascript libraries to control gif images. The first that I find is [libgif-js]
(https://github.com/buzzfeed/libgif-js). If you used this, maybe you could find a way where it works perfectly.
If you find your solution, that would also be a great opportunity to create your own vaadin add-on so from then on, other developers with the same need don’t have to go through the same pain.

I know how to control GIF pictures with Vaadin.
Use 1 iteration GIF pictures and reload them with Image class. Then you have the ability to restart GIF-pictures.

Not stopping them.

So replacing GIF pictures is a simple solution. Only works in FireFox.