Cleans up animation between search bar states
parent
9e76498eed
commit
0e9c77b036
|
@ -11,7 +11,6 @@ import android.transition.TransitionInflater
|
||||||
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 android.view.ViewOutlineProvider
|
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.navigation.Navigation
|
import androidx.navigation.Navigation
|
||||||
|
@ -24,7 +23,6 @@ import org.mozilla.fenix.mvi.ActionBusFactory
|
||||||
import org.mozilla.fenix.ext.requireComponents
|
import org.mozilla.fenix.ext.requireComponents
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
|
||||||
class HomeFragment : Fragment() {
|
class HomeFragment : Fragment() {
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix.home
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.drawable.TransitionDrawable
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.widget.FrameLayout
|
||||||
|
import org.mozilla.fenix.R
|
||||||
|
|
||||||
|
class SearchView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) {
|
||||||
|
private val lightDrawable = resources.getDrawable(R.drawable.home_search_background_light)
|
||||||
|
private val darkDrawable = resources.getDrawable(R.drawable.home_search_background_dark)
|
||||||
|
private val darkNoBorderDrawable = resources.getDrawable(R.drawable.home_search_background_dark_no_border)
|
||||||
|
|
||||||
|
private val lightToDark = TransitionDrawable(arrayOf(lightDrawable, darkDrawable))
|
||||||
|
private val darkToNoBorder = TransitionDrawable(arrayOf(darkDrawable, darkNoBorderDrawable))
|
||||||
|
|
||||||
|
fun transitionToLight() {
|
||||||
|
background = lightToDark
|
||||||
|
lightToDark.reverseTransition(500)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun transitionToDark() {
|
||||||
|
background = lightToDark
|
||||||
|
lightToDark.startTransition(500)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun transitionToDarkFromNoBorder() {
|
||||||
|
background = darkToNoBorder
|
||||||
|
darkToNoBorder.reverseTransition(500)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun transitionToDarkNoBorder() {
|
||||||
|
background = darkToNoBorder
|
||||||
|
darkToNoBorder.startTransition(500)
|
||||||
|
}
|
||||||
|
}
|
|
@ -40,7 +40,7 @@
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/menuButton" />
|
app:layout_constraintTop_toBottomOf="@id/menuButton" />
|
||||||
|
|
||||||
<FrameLayout
|
<org.mozilla.fenix.home.SearchView
|
||||||
android:id="@+id/toolbar_wrapper"
|
android:id="@+id/toolbar_wrapper"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -69,6 +69,6 @@
|
||||||
android:textColor="@color/searchText"
|
android:textColor="@color/searchText"
|
||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
android:transitionName="firstTransitionName"/>
|
android:transitionName="firstTransitionName"/>
|
||||||
</FrameLayout>
|
</org.mozilla.fenix.home.SearchView>
|
||||||
|
|
||||||
</androidx.constraintlayout.motion.widget.MotionLayout>
|
</androidx.constraintlayout.motion.widget.MotionLayout>
|
|
@ -49,15 +49,29 @@
|
||||||
android:alpha="0" />
|
android:alpha="0" />
|
||||||
|
|
||||||
<KeyAttribute
|
<KeyAttribute
|
||||||
motion:target="@id/toolbar_wrapper"
|
motion:target="@id/toolbar_wrapper"
|
||||||
motion:framePosition="0"
|
motion:framePosition="0"
|
||||||
android:elevation="@dimen/toolbar_elevation" />
|
android:elevation="@dimen/toolbar_elevation" />
|
||||||
|
|
||||||
<KeyAttribute
|
<KeyAttribute
|
||||||
motion:target="@id/toolbar_wrapper"
|
motion:target="@id/toolbar_wrapper"
|
||||||
motion:framePosition="50"
|
motion:framePosition="50"
|
||||||
android:elevation="0dp" />
|
android:elevation="0dp" />
|
||||||
|
|
||||||
|
<KeyTrigger
|
||||||
|
motion:target="@id/toolbar_wrapper"
|
||||||
|
motion:framePosition="55"
|
||||||
|
motion:onPositiveCross="transitionToDark"
|
||||||
|
motion:onNegativeCross="transitionToLight"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<KeyTrigger
|
||||||
|
motion:target="@id/toolbar_wrapper"
|
||||||
|
motion:framePosition="90"
|
||||||
|
motion:onPositiveCross="transitionToDarkNoBorder"
|
||||||
|
motion:onNegativeCross="transitionToDarkFromNoBorder"
|
||||||
|
/>
|
||||||
|
|
||||||
</KeyFrameSet>
|
</KeyFrameSet>
|
||||||
</Transition>
|
</Transition>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue