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.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewOutlineProvider
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.Navigation
|
||||
|
@ -24,7 +23,6 @@ import org.mozilla.fenix.mvi.ActionBusFactory
|
|||
import org.mozilla.fenix.ext.requireComponents
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
||||
class HomeFragment : Fragment() {
|
||||
override fun onCreateView(
|
||||
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_constraintTop_toBottomOf="@id/menuButton" />
|
||||
|
||||
<FrameLayout
|
||||
<org.mozilla.fenix.home.SearchView
|
||||
android:id="@+id/toolbar_wrapper"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -69,6 +69,6 @@
|
|||
android:textColor="@color/searchText"
|
||||
android:textSize="14sp"
|
||||
android:transitionName="firstTransitionName"/>
|
||||
</FrameLayout>
|
||||
</org.mozilla.fenix.home.SearchView>
|
||||
|
||||
</androidx.constraintlayout.motion.widget.MotionLayout>
|
|
@ -58,6 +58,20 @@
|
|||
motion:framePosition="50"
|
||||
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>
|
||||
</Transition>
|
||||
|
||||
|
|
Loading…
Reference in New Issue