Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

[Toolbar] Recommended way to retrieve references to added views? #13705

Closed
data-sync-user opened this issue Aug 12, 2020 · 1 comment
Closed
Labels
needs:triage Issue needs triage

Comments

@data-sync-user
Copy link

data-sync-user commented Aug 12, 2020

We add various views to our Toolbar and may want to modify these view's states at a later date, e.g. #267 where we want to update the pinned UI state based on url updates. We currently encapsulate adding our buttons in a single function, e.g.:

object ToolbarIntegration {

    /**
     * Add the components of toolbar.
     */
    @SuppressWarnings("LongMethod")
    fun setup(toolbar: BrowserToolbar,
              toolbarStateProvider: ToolbarStateProvider,
              onToolbarEvent: (event: NavigationEvent, value: String?) -> Unit): ToolbarComponents {
        val context = toolbar.context

        val pinButton = Toolbar.ActionToggleButton(imageResource = R.drawable.pin_unfilled,
                imageResourceSelected = R.drawable.pin_filled,
                visible = toolbarStateProvider::isPinEnabled) { isSelected ->
            onToolbarEvent(PIN_ACTION, if (isSelected) NavigationEvent.VAL_CHECKED else NavigationEvent.VAL_UNCHECKED)
 
        // A bunch more buttons are added...
        }

However, we have no great way of retrieving a reference to these added views, e.g. how do we access pinButton again? Is there a recommended way or should the framework change to support this? One outside-framework approach I came up with is to wrap all of our added views in a separate class but this can create a lot of boilerplate:

class ToolbarComponents(val pinButton: Toolbar.ActionToggleButton)

object ToolbarIntegration {
    fun setup(toolbar...
        // ...
        return ToolbarComponents(pinButton = ...)
}

Maybe the way the Android framework would fix this is: findViewByTag and a ViewHolder system?

┆Issue is synchronized with this Jira Task

@data-sync-user
Copy link
Author

➤ Sebastian Kaspari commented:

I don't think we should provide access to the views for now (because we want to have the freedom to change the underlying views without breaking code that has specific assumptions about the views). #267 is a problem we should fix - but not by letting every app deal with the views manually.

@github-actions github-actions bot added the needs:triage Issue needs triage label Aug 12, 2020
@liuche liuche closed this as completed Aug 12, 2020
@data-sync-user data-sync-user changed the title FNX3-22266 ⁃ [Toolbar] Recommended way to retrieve references to added views? [Toolbar] Recommended way to retrieve references to added views? Jun 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs:triage Issue needs triage
Projects
None yet
Development

No branches or pull requests

2 participants