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

[Feature request] Add a floating button #21

Closed
egorikftp opened this issue Apr 7, 2020 · 2 comments
Closed

[Feature request] Add a floating button #21

egorikftp opened this issue Apr 7, 2020 · 2 comments
Assignees

Comments

@egorikftp
Copy link
Contributor

Hey, I would like to propose an idea for the library.
In our huge project, we faced with a situation, when the developer should change different options inside Tricks and after that restart application by clicking some button. After click, we save in preferences all necessary data and force stop application.

For this purpose will be very useful the new type of Trick (Please see "Apply" button on screenshot).

What do you think about this? 🙂
Best regards.

@pandulapeter
Copy link
Owner

Thanks for the awesome idea!

At first I didn't know how to approach this from the API perspective but now I think I have a good solution. Here are the changes that can be used from version 1.10.0. To summarize:

  • The Slider, Toggle, SingleSelectionList and MultipleSelectionList tricks now contain an optional parameter called 'needsConfirmation' (false by default). If this confirmation is enabled, the usual callback that belongs to the trick (onValueChanged or onItemSelectionChanged) will not be called immediately as before, only after the Apply button that you suggested is pressed.
  • The Apply button appears and disappears dynamically (it's only visible if there are changes to be applied) - the animation and the gradient are work-in-progress...
  • There also is a Reset button which, by default, appeares besides Apply - the Beagle.imprint() function's shouldShowResetButton can be used to hide it.
  • The texts that appear on the button can be changed in the Appearance instance that is provided to Beagle.imprint().
  • If multiple pending changes are waiting to be applied, they will be called one after the other the moment the user presses the Apply button. If you need to perform an action after the last callback is called (like restarting the app), you can check the value of Beagle.hasPendingChanges. Now that I think about it, it might be a good idea to add a separate callback for this in a future version.
  • The demo app has been updated to contain examples for Toggle and SingleSelectionList.

This is very early stuff so it's possible to contain bugs... Please let me know if you find any.

And of course if the API is not suitable for what you had in mind, we'll get back to brainstorming :)

@pandulapeter pandulapeter self-assigned this Apr 8, 2020
@pandulapeter
Copy link
Owner

I've fixed some issues, added some new features and improved some of the recent things in 1.10.1. With those changes in mind, my suggestion for your specific usecase:

  • For all modules that modify settings needing an app restart to take effect, set the needsConfirmation constructor parameter to true when defining the trick.
  • In the lambdas for these tricks update the value stored in shared preferences, as these callbacks will only get invoked when the user presses "Apply".
  • Set a lamda value for Beagle.onAllChangesApplied where you kill the application process / restart the app / whatever. This is new in v1.10.1 and will get called after the lambdas I mentioned previously.
  • If you'd like to fine-tune the behavior, the Beagle.imprint() function can handle a new, Behavior object besides the old Appearance. The relevant properties:
    • In Appearance: applyButtonText and resetButtonText as mentioned before
    • In Behavior: shouldShowResetPendingChangesButton and shouldResetPendingChangesOnClose. The latter is new: if you set it to true, all pending changes will be reset when the user closes the drawer without pressing "Apply".

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

No branches or pull requests

2 participants