Updates ConstraintLayout to alpha4
parent
3ad204712a
commit
4a385068e0
|
@ -15,7 +15,6 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.constraintlayout.motion.widget.MotionLayout
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.navigation.Navigation
|
||||
|
@ -139,34 +138,6 @@ class HomeFragment : Fragment(), CoroutineScope {
|
|||
requireComponents.analytics.metrics.track(Event.SearchBarTapped(Event.SearchBarTapped.Source.HOME))
|
||||
}
|
||||
|
||||
// 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) { }
|
||||
})
|
||||
|
||||
val isPrivate = (activity as HomeActivity).browsingModeManager.isPrivate
|
||||
|
||||
view.toolbar_wrapper.isPrivateModeEnabled = isPrivate
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
package org.mozilla.fenix.home
|
||||
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
@SuppressWarnings("MagicNumber")
|
||||
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
|
||||
}
|
||||
}
|
|
@ -73,6 +73,6 @@ class SearchView(context: Context, attrs: AttributeSet) : FrameLayout(context, a
|
|||
}
|
||||
|
||||
companion object {
|
||||
const val transitionDurationMs = 500
|
||||
const val transitionDurationMs = 200
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,33 +48,33 @@
|
|||
app:layout_constraintTop_toBottomOf="@id/menuButton" />
|
||||
|
||||
<org.mozilla.fenix.home.SearchView
|
||||
android:id="@+id/toolbar_wrapper"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginTop="64dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:elevation="@dimen/toolbar_elevation"
|
||||
android:background="?attr/toolbarWrapperBackground"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/wordmark">
|
||||
android:id="@+id/toolbar_wrapper"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginTop="64dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:elevation="@dimen/toolbar_elevation"
|
||||
android:background="?attr/toolbarWrapperBackground"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/wordmark">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="12sp"
|
||||
android:paddingEnd="12sp"
|
||||
android:paddingTop="16sp"
|
||||
android:paddingBottom="16sp"
|
||||
android:drawablePadding="12sp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/search_hint"
|
||||
android:textColor="?attr/toolbarTextColor"
|
||||
android:textSize="14sp" />
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="12sp"
|
||||
android:paddingEnd="12sp"
|
||||
android:paddingTop="16sp"
|
||||
android:paddingBottom="16sp"
|
||||
android:drawablePadding="12sp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/search_hint"
|
||||
android:textColor="?attr/toolbarTextColor"
|
||||
android:textSize="14sp" />
|
||||
</org.mozilla.fenix.home.SearchView>
|
||||
|
||||
<View
|
||||
|
|
|
@ -3,81 +3,74 @@
|
|||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<MotionScene
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:motion="http://schemas.android.com/apk/res-auto">
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:motion="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<Transition
|
||||
motion:constraintSetStart="@+id/start"
|
||||
motion:constraintSetEnd="@+id/end">
|
||||
<OnSwipe
|
||||
motion:dragDirection="dragUp"
|
||||
motion:touchAnchorId="@id/homeScrollView"
|
||||
motion:touchAnchorSide="top" />
|
||||
motion:dragDirection="dragUp"
|
||||
motion:touchAnchorId="@id/homeScrollView"
|
||||
motion:touchAnchorSide="top" />
|
||||
|
||||
<KeyFrameSet>
|
||||
<KeyPosition
|
||||
motion:motionTarget="@id/wordmark"
|
||||
motion:keyPositionType="pathRelative"
|
||||
motion:framePosition="50"
|
||||
motion:target="@id/wordmark"
|
||||
motion:percentX="0.9" />
|
||||
|
||||
|
||||
<KeyAttribute
|
||||
motion:target="@id/wordmark"
|
||||
motion:motionTarget="@id/wordmark"
|
||||
motion:framePosition="50"
|
||||
android:translationY="0dp"
|
||||
android:alpha="1" />
|
||||
<KeyAttribute
|
||||
motion:target="@id/wordmark"
|
||||
motion:motionTarget="@id/wordmark"
|
||||
motion:framePosition="90"
|
||||
android:alpha="0" />
|
||||
|
||||
<KeyAttribute
|
||||
motion:target="@id/menuButton"
|
||||
motion:motionTarget="@id/menuButton"
|
||||
motion:framePosition="50"
|
||||
android:translationY="0dp"
|
||||
android:alpha="1" />
|
||||
<KeyAttribute
|
||||
motion:target="@id/menuButton"
|
||||
motion:motionTarget="@id/menuButton"
|
||||
motion:framePosition="90"
|
||||
android:alpha="0" />
|
||||
<KeyAttribute
|
||||
motion:target="@id/privateBrowsingButton"
|
||||
motion:motionTarget="@id/privateBrowsingButton"
|
||||
motion:framePosition="50"
|
||||
android:translationY="0dp"
|
||||
android:alpha="1" />
|
||||
<KeyAttribute
|
||||
motion:target="@id/privateBrowsingButton"
|
||||
motion:motionTarget="@id/privateBrowsingButton"
|
||||
motion:framePosition="90"
|
||||
android:alpha="0" />
|
||||
|
||||
<KeyAttribute
|
||||
motion:target="@id/toolbar_wrapper"
|
||||
motion:motionTarget="@id/toolbar_wrapper"
|
||||
motion:framePosition="0"
|
||||
android:elevation="@dimen/toolbar_elevation" />
|
||||
|
||||
<KeyAttribute
|
||||
motion:target="@id/toolbar_wrapper"
|
||||
motion:motionTarget="@id/toolbar_wrapper"
|
||||
motion:framePosition="50"
|
||||
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
|
||||
motion:target="@id/toolbar_wrapper"
|
||||
motion:motionTarget="@id/toolbar_wrapper"
|
||||
motion:framePosition="55"
|
||||
motion:onPositiveCross="transitionToDark"
|
||||
motion:onNegativeCross="transitionToLight"
|
||||
/>
|
||||
motion:onNegativeCross="transitionToLight" />
|
||||
|
||||
<KeyTrigger
|
||||
motion:target="@id/toolbar_wrapper"
|
||||
motion:framePosition="90"
|
||||
motion:onPositiveCross="transitionToDarkNoBorder"
|
||||
motion:onNegativeCross="transitionToDarkFromNoBorder"
|
||||
/>
|
||||
-->
|
||||
|
||||
motion:motionTarget="@id/toolbar_wrapper"
|
||||
motion:framePosition="90"
|
||||
motion:onPositiveCross="transitionToDarkNoBorder"
|
||||
motion:onNegativeCross="transitionToDarkFromNoBorder" />
|
||||
</KeyFrameSet>
|
||||
</Transition>
|
||||
|
||||
|
@ -86,14 +79,15 @@
|
|||
|
||||
<ConstraintSet android:id="@+id/end">
|
||||
<Constraint
|
||||
android:id="@+id/wordmark"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:alpha="0"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
motion:layout_constraintStart_toStartOf="parent"
|
||||
motion:layout_constraintTop_toTopOf="parent" />
|
||||
android:id="@+id/wordmark"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:alpha="0"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:translationY="-10dp"
|
||||
motion:layout_constraintStart_toStartOf="parent"
|
||||
motion:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Constraint
|
||||
android:id="@+id/toolbar_wrapper"
|
||||
|
@ -105,12 +99,13 @@
|
|||
motion:layout_constraintTop_toTopOf="parent"
|
||||
motion:layout_constraintStart_toStartOf="parent"
|
||||
motion:layout_constraintEnd_toEndOf="parent"
|
||||
android:elevation="0dp"/>
|
||||
android:elevation="0dp" />
|
||||
|
||||
<Constraint
|
||||
android:id="@+id/menuButton"
|
||||
android:alpha="0"
|
||||
android:layout_marginTop="16dp"
|
||||
android:translationY="-10dp"
|
||||
android:layout_height="@dimen/glyph_button_height"
|
||||
android:layout_width="@dimen/glyph_button_height"
|
||||
motion:layout_constraintEnd_toEndOf="parent"
|
||||
|
@ -119,11 +114,10 @@
|
|||
<Constraint
|
||||
android:id="@+id/privateBrowsingButton"
|
||||
android:alpha="0"
|
||||
android:translationY="-10dp"
|
||||
android:layout_height="@dimen/glyph_button_height"
|
||||
android:layout_width="@dimen/glyph_button_height"
|
||||
motion:layout_constraintEnd_toStartOf="@id/menuButton"
|
||||
motion:layout_constraintTop_toTopOf="@id/menuButton"/>
|
||||
|
||||
</ConstraintSet>
|
||||
|
||||
</MotionScene>
|
||||
</MotionScene>
|
||||
|
|
|
@ -13,7 +13,7 @@ private object Versions {
|
|||
const val leanplum = "4.3.1"
|
||||
|
||||
const val androidx_appcompat = "1.1.0-alpha04"
|
||||
const val androidx_constraint_layout = "2.0.0-alpha2"
|
||||
const val androidx_constraint_layout = "2.0.0-alpha4"
|
||||
const val androidx_preference = "1.1.0-alpha03"
|
||||
const val androidx_legacy = "1.0.0"
|
||||
const val androidx_annotation = "1.1.0-beta01"
|
||||
|
|
Loading…
Reference in New Issue