@@ -6,25 +6,43 @@ import android.util.AttributeSet
66import androidx.core.view.ViewCompat
77import androidx.core.view.WindowInsetsCompat
88import com.google.android.material.floatingactionbutton.FloatingActionButton
9+ import org.fossify.commons.R
910import org.fossify.commons.extensions.applyColorFilter
1011import org.fossify.commons.extensions.getContrastColor
12+ import org.fossify.commons.extensions.updateMarginWithBase
1113
1214open class MyFloatingActionButton : FloatingActionButton {
15+ private var applyWindowInsets = false
16+
1317 constructor (context: Context ) : super (context)
1418
15- constructor (context: Context , attrs: AttributeSet ) : super (context, attrs)
19+ constructor (context: Context , attrs: AttributeSet ) : super (context, attrs) {
20+ init (context, attrs)
21+ }
1622
1723 constructor (context: Context , attrs: AttributeSet , defStyle: Int ) : super (
1824 context,
1925 attrs,
2026 defStyle
21- )
27+ ) {
28+ init (context, attrs)
29+ }
30+
31+ private fun init (context : Context , attrs : AttributeSet ) {
32+ context.theme.obtainStyledAttributes(attrs, R .styleable.MyFloatingActionButton , 0 , 0 ).apply {
33+ try {
34+ applyWindowInsets = getBoolean(R .styleable.MyFloatingActionButton_applyWindowInsets , false )
35+ } finally {
36+ recycle()
37+ }
38+ }
2239
23- init {
24- ViewCompat .setOnApplyWindowInsetsListener(this ) { _, insets ->
25- val system = insets.getInsetsIgnoringVisibility(WindowInsetsCompat .Type .systemBars())
26- translationY = - system.bottom.toFloat()
27- insets
40+ if (applyWindowInsets) {
41+ ViewCompat .setOnApplyWindowInsetsListener(this ) { _, insets ->
42+ val system = insets.getInsetsIgnoringVisibility(WindowInsetsCompat .Type .systemBars())
43+ updateMarginWithBase(bottom = system.bottom)
44+ insets
45+ }
2846 }
2947 }
3048
0 commit comments