If yout want to get BottomSheet state via rx, you should use this
Created
December 1, 2017 07:50
-
-
Save kettsun0123/525dfd337ee26f0801a470449da682fa to your computer and use it in GitHub Desktop.
RxBottomSheetBehavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package xyz.kettsun.sample.widget | |
import android.support.design.widget.BottomSheetBehavior | |
import android.view.View | |
import io.reactivex.subjects.BehaviorSubject | |
class RxBottomSheetBehavior<V: View>(behavior: BottomSheetBehavior<V>) { | |
companion object { | |
fun <V: View>from(view :V): RxBottomSheetBehavior<V> { | |
val original = BottomSheetBehavior.from(view) | |
return RxBottomSheetBehavior(original) | |
} | |
} | |
private val originalCallback = object : BottomSheetBehavior.BottomSheetCallback() { | |
override fun onSlide(bottomSheet: View, slideOffset: Float) { | |
//no-op | |
} | |
override fun onStateChanged(bottomSheet: View, newState: Int) { | |
state.onNext(newState) | |
} | |
} | |
val state: BehaviorSubject<Int> = BehaviorSubject.createDefault(BottomSheetBehavior.STATE_COLLAPSED) | |
init { | |
behavior.setBottomSheetCallback(originalCallback) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment