Closed tkorri closed 5 years ago
Hi @tkorri. How are you setting the view as initially hidden? If you apply android:visibility="gone"
to the whole <uk.co.markormesher.android_fab.FloatingActionButton />
view you won't be able to influence the visibility using the hide()
and show()
methods.
The reason for this is that the FAB is a composite view with several components inside (the FAB itself, the speed-dial menu and the content cover) and it's built to hide and show them as required, rather than hide/show the entire container.
If you need the FAB to start as hidden, call fab.hide(true)
when your layout is initialised - this will hide it instantly (the true
argument causes it to be immediate, rather than animated) and will allow you to hide/show it as required using the hide()
and show()
methods. Give that a try and let me know how you get on.
@markormesher Yes, I initially used android:visibility="gone"
to hide the view, which makes the show()/hide() calls to fail.
I tried using hide() in the view initialization and it kind of works. But the issue with this approach is that the button is visible on the screen for brief moment until it's hidden. I.e. the button blinks once on the screen.
So it would be really nice to have a way to set button as hidden in the layout xml.
@tkorri Are you able to share your code where you're using this? I don't see the flicker when I test it on my device (make sure you're passing true
to hide immediately and without animation), but it's possible that your app and/or phone render just slowly enough to show a brief flicker. If that's the case, I can have a look into implementing some kind of "initial visibility" flag or expanding the view to interact with the android:visibility
flag.
@markormesher Unfortunately I cannot share the code of the app I'm working on. The layout where the button is used is quite complex and it loads bunch of stuff in the background at the same time.
I tried calling hide() with immediate set to true, but the result is the same. The flickering is more frequent with older phones like Nexus 6P, Nexus 5 but I've also seen it sometimes with Pixel 2.
@tkorri Thanks for the info. I'll try to find some time this weekend or next week to publish a new version of the plugin that uses the android:visibility
flag and still gives the expected behaviour.
If the floating action button's visibility is initially set as gone, then the show() method won't work properly.
Show() returns immediately if FloatingActionButton.isShown is true. The problem is that isShown is always initialized as true regardless of the view's visibility attribute.