Fixes #362 - Downgrade to ConstraintLayout 2.0.0-alpha2
There is currently an issue with visibility changes in ConstraintLayout 2.0.0-alpha3 https://issuetracker.google.com/issues/122090772 For now we're going to manually implement KeyTriggers.master
parent
3db9f2cb6a
commit
88a54b7b30
|
@ -10,9 +10,9 @@ import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.constraintlayout.motion.widget.MotionLayout
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.navigation.Navigation
|
import androidx.navigation.Navigation
|
||||||
import kotlinx.android.synthetic.main.fragment_home.*
|
|
||||||
import kotlinx.android.synthetic.main.fragment_home.view.*
|
import kotlinx.android.synthetic.main.fragment_home.view.*
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.ext.requireComponents
|
import org.mozilla.fenix.ext.requireComponents
|
||||||
|
@ -43,19 +43,90 @@ class HomeFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Temporary so we can easily test settings
|
// Temporary so we can easily test settings
|
||||||
menuButton.setOnClickListener {
|
view.menuButton.setOnClickListener {
|
||||||
Navigation.findNavController(it).navigate(R.id.action_homeFragment_to_settingsActivity, null, null)
|
Navigation.findNavController(it).navigate(R.id.action_homeFragment_to_settingsActivity, null, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
toolbar.setCompoundDrawablesWithIntrinsicBounds(searchIcon, null, null, null)
|
view.toolbar.setCompoundDrawablesWithIntrinsicBounds(searchIcon, null, null, null)
|
||||||
val roundToInt = (toolbarPaddingDp * Resources.getSystem().displayMetrics.density).roundToInt()
|
val roundToInt = (toolbarPaddingDp * Resources.getSystem().displayMetrics.density).roundToInt()
|
||||||
toolbar.compoundDrawablePadding = roundToInt
|
view.toolbar.compoundDrawablePadding = roundToInt
|
||||||
toolbar.setOnClickListener { it ->
|
view.toolbar.setOnClickListener { it ->
|
||||||
Navigation.findNavController(it).navigate(R.id.action_homeFragment_to_searchFragment, null, null)
|
Navigation.findNavController(it).navigate(R.id.action_homeFragment_to_searchFragment, null, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// There is currently an issue with visibility changes in ConstraintLayout 2.0.0-alpha3
|
||||||
|
// https://issuetracker.google.com/issues/122090772
|
||||||
|
// For now we're going to manually implement KeyTriggers.
|
||||||
|
view.homeLayout.setTransitionListener(object : MotionLayout.TransitionListener {
|
||||||
|
private val firstKeyTrigger = KeyTrigger(
|
||||||
|
firstKeyTriggerFrame,
|
||||||
|
{ view.toolbar_wrapper.transitionToDark() },
|
||||||
|
{ view.toolbar_wrapper.transitionToLight() }
|
||||||
|
)
|
||||||
|
private val secondKeyTrigger = KeyTrigger(
|
||||||
|
secondKeyTriggerFrame,
|
||||||
|
{ view.toolbar_wrapper.transitionToDarkNoBorder() },
|
||||||
|
{ view.toolbar_wrapper.transitionToDarkFromNoBorder() }
|
||||||
|
)
|
||||||
|
|
||||||
|
override fun onTransitionChange(
|
||||||
|
motionLayout: MotionLayout?,
|
||||||
|
startId: Int,
|
||||||
|
endId: Int,
|
||||||
|
progress: Float
|
||||||
|
) {
|
||||||
|
firstKeyTrigger.conditionallyFire(progress)
|
||||||
|
secondKeyTrigger.conditionallyFire(progress)
|
||||||
|
}
|
||||||
|
override fun onTransitionCompleted(p0: MotionLayout?, p1: Int) { }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("MagicNumber")
|
||||||
|
private class KeyTrigger(
|
||||||
|
frame: Int,
|
||||||
|
private val onPositiveCross: () -> Unit,
|
||||||
|
private val onNegativeCross: () -> Unit
|
||||||
|
) {
|
||||||
|
private val fireThreshhold = (frame + 0.5F) / 100.0F
|
||||||
|
private var negativeReset = false
|
||||||
|
private var positiveReset = false
|
||||||
|
private var lastFirePosition = 0f
|
||||||
|
private val triggerSlack = 0.1f
|
||||||
|
|
||||||
|
fun conditionallyFire(progress: Float) {
|
||||||
|
var offset: Float
|
||||||
|
var lastOffset: Float
|
||||||
|
|
||||||
|
if (negativeReset) {
|
||||||
|
offset = progress - fireThreshhold
|
||||||
|
lastOffset = lastFirePosition - fireThreshhold
|
||||||
|
if (offset * lastOffset < 0.0f && offset < 0.0f) {
|
||||||
|
onNegativeCross.invoke()
|
||||||
|
negativeReset = false
|
||||||
|
}
|
||||||
|
} else if (Math.abs(progress - fireThreshhold) > triggerSlack) {
|
||||||
|
negativeReset = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (positiveReset) {
|
||||||
|
offset = progress - fireThreshhold
|
||||||
|
lastOffset = lastFirePosition - fireThreshhold
|
||||||
|
if (offset * lastOffset < 0.0f && offset > 0.0f) {
|
||||||
|
onPositiveCross.invoke()
|
||||||
|
positiveReset = false
|
||||||
|
}
|
||||||
|
} else if (Math.abs(progress - fireThreshhold) > triggerSlack) {
|
||||||
|
positiveReset = true
|
||||||
|
}
|
||||||
|
|
||||||
|
lastFirePosition = progress
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val toolbarPaddingDp = 12f
|
const val toolbarPaddingDp = 12f
|
||||||
|
const val firstKeyTriggerFrame = 55
|
||||||
|
const val secondKeyTriggerFrame = 90
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,11 @@
|
||||||
motion:framePosition="50"
|
motion:framePosition="50"
|
||||||
android:elevation="0dp" />
|
android:elevation="0dp" />
|
||||||
|
|
||||||
|
<!--
|
||||||
|
https://github.com/mozilla-mobile/fenix/issues/362
|
||||||
|
There is currently an issue with visibility changes in ConstraintLayout 2.0.0-alpha3
|
||||||
|
https://issuetracker.google.com/issues/122090772
|
||||||
|
For now we're going to manually implement KeyTriggers.
|
||||||
<KeyTrigger
|
<KeyTrigger
|
||||||
motion:target="@id/toolbar_wrapper"
|
motion:target="@id/toolbar_wrapper"
|
||||||
motion:framePosition="55"
|
motion:framePosition="55"
|
||||||
|
@ -71,6 +76,7 @@
|
||||||
motion:onPositiveCross="transitionToDarkNoBorder"
|
motion:onPositiveCross="transitionToDarkNoBorder"
|
||||||
motion:onNegativeCross="transitionToDarkFromNoBorder"
|
motion:onNegativeCross="transitionToDarkFromNoBorder"
|
||||||
/>
|
/>
|
||||||
|
-->
|
||||||
|
|
||||||
</KeyFrameSet>
|
</KeyFrameSet>
|
||||||
</Transition>
|
</Transition>
|
||||||
|
|
|
@ -12,7 +12,7 @@ private object Versions {
|
||||||
const val sentry = "1.7.10"
|
const val sentry = "1.7.10"
|
||||||
|
|
||||||
const val androidx_appcompat = "1.0.2"
|
const val androidx_appcompat = "1.0.2"
|
||||||
const val androidx_constraint_layout = "2.0.0-alpha3"
|
const val androidx_constraint_layout = "2.0.0-alpha2"
|
||||||
const val androidx_preference = "1.1.0-alpha02"
|
const val androidx_preference = "1.1.0-alpha02"
|
||||||
const val androidx_legacy = "1.0.0"
|
const val androidx_legacy = "1.0.0"
|
||||||
const val androidx_annotation = "1.0.1"
|
const val androidx_annotation = "1.0.1"
|
||||||
|
|
Loading…
Reference in New Issue