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

SwitchModule. Ui data not re-initialize. Reset selected state #115

Open
l1onPro opened this issue Nov 15, 2022 · 5 comments
Open

SwitchModule. Ui data not re-initialize. Reset selected state #115

l1onPro opened this issue Nov 15, 2022 · 5 comments
Assignees
Labels
question Further information is requested

Comments

@l1onPro
Copy link

l1onPro commented Nov 15, 2022

I'm trying to write a method that resets all feature flags in a default state. But when I re-initialize new data for the panel, the data that was changed does not change in ui. They only change if the application is restarted. If I try to do this through the add(), remove() methods, the screen twitches. How can i solve this problem?

@l1onPro l1onPro changed the title ui data not re-initialize SingleSelectionListModule. Ui data not re-initialize. Reset selected state Nov 15, 2022
@pandulapeter
Copy link
Owner

pandulapeter commented Nov 15, 2022

Hi!

Using Beagle.add() (without remove()) should be a good solution, if you have constant ID-s for all of the modules. (Every module has an id parameter in its constructor, but that's optional - by default it's a random string, that's why the animation glitches happened).

Another approach would be to find the modules that are already added using Beagle.find() and change their values. A bit cumbersome but it looks like this:

internal fun createTestSection() = listOf(
    TextModule(
        text = "Test",
        type = TextModule.Type.SECTION_HEADER
    ),
    SingleSelectionListModule(
        id = "test_single_selection",
        title = "Single selection list",
        items = listOf(
            TestDataItem("A"),
            TestDataItem("B"),
            TestDataItem("C"),
        ),
        initiallySelectedItemId = "A"
    ),
    CheckBoxModule(
        id = "checkbox_1",
        text = "Feature flag 1"
    ),
    CheckBoxModule(
        id = "checkbox_2",
        text = "Feature flag 2"
    ),
    TextModule(
        text = "Reset all flags",
        type = TextModule.Type.BUTTON,
        onItemSelected = {
            Beagle.find<SingleSelectionListModule<TestDataItem>>("test_single_selection")?.setCurrentValue(Beagle, "A")
            Beagle.find<CheckBoxModule>("checkbox_1")?.setCurrentValue(Beagle, false)
            Beagle.find<CheckBoxModule>("checkbox_2")?.setCurrentValue(Beagle, false)
        }
    ),
)

private data class TestDataItem(val identifier: String) : BeagleListItemContract {
    override val id = identifier
    override val title = "Item $identifier".toText()
}

Let me know if it helps!

Edit: if you ever want to save the states of modules to shared preferences using the isValuePersisted parameter, you must set a constant ID.

@pandulapeter pandulapeter self-assigned this Nov 15, 2022
@pandulapeter pandulapeter added the question Further information is requested label Nov 15, 2022
@l1onPro
Copy link
Author

l1onPro commented Nov 15, 2022

Thanks!

I have a static id and use Beagle.add() without remove(), but it work good until you set value from debug panel than UI state does not change (only after application restart). Can be bug?

If use Beagle.find() all good!

@pandulapeter
Copy link
Owner

I double-checked the functionality and couldn't see any issues. Could you provide more details, maybe code examples?

@l1onPro
Copy link
Author

l1onPro commented Dec 30, 2022

        .observeOn(AndroidSchedulers.mainThread())  
        .subscribe {
            Beagle.add(
                *mutableListOf<Module<*>>().apply {
                    addAll(headerComponent.invoke())
                    add(DividerModule("headerDivider"))
                    addAll(featuresComponent.invoke(application, it))
                    add(DividerModule("featuresDivider"))
                }.toTypedArray()
            )
        }

Understood, more details:

First case:

  1. Open menu
  2. Switch SingleSelectionListModule item
  3. Clicked on the data reset so that a new value comes to subscribe
  4. menu has not been updated
  5. Restart app
  6. menu has been updated

But second case:

  1. Open menu
  2. Switch SingleSelectionListModule item
  3. Restart app
  4. Clicked on the data reset so that a new value comes to subscribe
  5. menu has been updated

@l1onPro
Copy link
Author

l1onPro commented Mar 19, 2023

Correction, I started using the Switch Module, the problem is the same.

The value does not change if the value was changed earlier by switching through the UI menu. If you do not switch manually, through the ui, then everything is updated correctly

@l1onPro l1onPro changed the title SingleSelectionListModule. Ui data not re-initialize. Reset selected state SwitchModule. Ui data not re-initialize. Reset selected state Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants