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

Observable to track visibility changes #543

Open
mohsin opened this issue Feb 29, 2020 · 4 comments
Open

Observable to track visibility changes #543

mohsin opened this issue Feb 29, 2020 · 4 comments

Comments

@mohsin
Copy link

mohsin commented Feb 29, 2020

I see that there is a consumer to set the view's visibility but I couldn't find an observable variant for the same. I'm trying to do something like this (for now I used a workaround but ideally an observable that emits visibility changes would be the best for this job):

secondItem.visibility()
  .subscribe ({ 
    if(it == View.VISIBLE) {
      (itemWhichShouldFillLayout.layoutParams as LinearLayout.LayoutParams).weight = 0.65f
    } else {
      (itemWhichShouldFillLayout.layoutParams as LinearLayout.LayoutParams).weight = 0.8f
    }
})
@JakeWharton
Copy link
Owner

JakeWharton commented Feb 29, 2020 via email

@mohsin
Copy link
Author

mohsin commented Mar 2, 2020

Like I said, I wrote a workaround to solve this for me without using any listener coz my specific application needed to check visibility only when a button was clicked so I coded it to recheck visibility every time the button click occurred and made the relevant views visible or gone based on an if condition. But I’m sure it would be good to have a hot observable in the view class for this.

But as per the Android docs I believe there is one onVisibility Changed listener for this.

@SwiftyWang
Copy link

SwiftyWang commented Jul 10, 2020

Like I said, I wrote a workaround to solve this for me without using any listener coz my specific application needed to check visibility only when a button was clicked so I coded it to recheck visibility every time the button click occurred and made the relevant views visible or gone based on an if condition. But I’m sure it would be good to have a hot observable in the view class for this.

But as per the Android docs I believe there is one onVisibility Changed listener for this.

Same issue. This listener is a protected function. Seems cannot write a kt extension to observe the change. Any ideas?

@36289108
Copy link

I see that there is a consumer to set the view's visibility but I couldn't find an observable variant for the same. I'm trying to do something like this (for now I used a workaround but ideally an observable that emits visibility changes would be the best for this job):

secondItem.visibility()
  .subscribe ({ 
    if(it == View.VISIBLE) {
      (itemWhichShouldFillLayout.layoutParams as LinearLayout.LayoutParams).weight = 0.65f
    } else {
      (itemWhichShouldFillLayout.layoutParams as LinearLayout.LayoutParams).weight = 0.8f
    }
})

Hola
_@hola _

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

4 participants