Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save and restore view state for UIButton #323

Merged
merged 2 commits into from Sep 9, 2020

Conversation

Juanpe
Copy link
Owner

@Juanpe Juanpe commented Sep 9, 2020

Fix #309

Short description πŸ“

As @greatsk55 said, there is a problem when a button is skeletonizing. It seems the skeleton layer appears below the title label of the button.

Solution πŸ“¦

Before the skeleton appears, all views save their current view state to recover when the skeleton disappears. But some UI elements must override these methods because they require special behavior.

To solve this problem, we need to override the saveViewState and recoveryViewState methods for UIButton.
Also, when the skeleton is shown, we set the title value to nil and when the skeleton is hidden we retrieve the original title.

Implementation πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

  • Create a model to save the required view state for buttons. RecoverableButtonViewState.
  • Create the UIButton extension to override the methods.
  • Override the prepareViewForSkeleton method for UIButton, where we set the value of the title.

@Juanpe Juanpe merged commit 0521be6 into develop Sep 9, 2020
@Juanpe Juanpe deleted the fix/save_and_restore_button_view_state branch September 9, 2020 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

when i called btn.showAnimatedSkeleton(), UIButton can't hide text
1 participant