Permalink
Browse files

Merge pull request #269 from chrisbanes/cb/motionlayout-fixes

Fixes around MotionLayout usage
  • Loading branch information...
chrisbanes committed Feb 9, 2019
2 parents c1d9b73 + 709cd97 commit 0dbc532f399fc8a281c102b533a2b1e7ab71c341
@@ -142,4 +142,10 @@

# Need to keep MvRxViewModelFactory companion classes for MvRx
# See https://github.com/airbnb/MvRx/issues/185
-keepnames class * implements com.airbnb.mvrx.MvRxViewModelFactory
-keepnames class * implements com.airbnb.mvrx.MvRxViewModelFactory

# Keep FAB show/hide methods for MotionLayout KeyTriggers
-keep class * extends com.google.android.material.floatingactionbutton.FloatingActionButton {
public void show();
public void hide();
}
@@ -0,0 +1,26 @@
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package app.tivi.extensions

import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.constraintlayout.widget.ConstraintSet

inline fun MotionLayout.forEachConstraintSet(f: (ConstraintSet) -> Unit) {
for (id in constraintSetIds) {
f(getConstraintSet(id))
}
}
@@ -26,6 +26,7 @@ import androidx.core.net.toUri
import androidx.fragment.app.commit
import app.tivi.R
import app.tivi.databinding.FragmentLibraryBinding
import app.tivi.extensions.forEachConstraintSet
import app.tivi.home.HomeActivity
import app.tivi.home.HomeNavigator
import app.tivi.home.library.followed.FollowedFragment
@@ -71,12 +72,15 @@ class LibraryFragment : TiviMvRxFragment() {
view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

view.setOnApplyWindowInsetsListener { _, insets ->
val lp = binding.summaryStatusScrim.layoutParams
lp.height = insets.systemWindowInsetTop
binding.summaryStatusScrim.requestLayout()
binding.libraryMotion.forEachConstraintSet {
it.constrainHeight(R.id.summary_status_scrim, insets.systemWindowInsetTop)
}
binding.libraryMotion.rebuildMotion()
// Just return insets
insets
}
// Finally, request some insets
view.requestApplyInsets()

binding.libraryFiltersRv.adapter = filterController.adapter

@@ -24,13 +24,16 @@ import android.view.View
import android.view.ViewGroup
import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.core.os.bundleOf
import androidx.core.view.isGone
import androidx.core.view.isVisible
import app.tivi.R
import app.tivi.SharedElementHelper
import app.tivi.data.entities.ActionDate
import app.tivi.data.entities.Episode
import app.tivi.data.entities.Season
import app.tivi.data.entities.TiviShow
import app.tivi.databinding.FragmentShowDetailsBinding
import app.tivi.extensions.forEachConstraintSet
import app.tivi.showdetails.ShowDetailsNavigator
import app.tivi.util.TiviMvRxFragment
import com.airbnb.mvrx.MvRx
@@ -73,13 +76,15 @@ class ShowDetailsFragment : TiviMvRxFragment() {
binding.textCreator = textCreator

binding.detailsMotion.setOnApplyWindowInsetsListener { _, insets ->
val lp = binding.detailsStatusBarAnchor.layoutParams
lp.height = insets.systemWindowInsetTop
binding.detailsStatusBarAnchor.requestLayout()

binding.detailsMotion.forEachConstraintSet {
it.constrainHeight(R.id.details_status_bar_anchor, insets.systemWindowInsetTop)
}
binding.detailsMotion.rebuildMotion()
// Just return insets
insets
}
// Finally, request some insets
view.requestApplyInsets()

// Make the MotionLayout draw behind the status bar
binding.detailsMotion.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
@@ -103,11 +108,13 @@ class ShowDetailsFragment : TiviMvRxFragment() {
when (currentId) {
R.id.end -> {
binding.detailsAppbarBackground.cutProgress = 0f
binding.detailsPoster.visibility = View.GONE
binding.detailsPoster.isGone = true
binding.detailsFollowFab.isGone = true
}
R.id.start -> {
binding.detailsAppbarBackground.cutProgress = 1f
binding.detailsPoster.visibility = View.VISIBLE
binding.detailsPoster.isVisible = true
binding.detailsFollowFab.isVisible = true
}
}
}
@@ -31,10 +31,11 @@
android:layout_height="match_parent"
app:layoutDescription="@xml/scene_library">

<!-- The height of this is updated via an OnApplyWindowInsetsListener -->
<View
android:id="@+id/summary_status_scrim"
android:layout_width="match_parent"
android:layout_height="24dp"
android:layout_height="0px"
android:background="?android:attr/colorPrimaryDark"
android:elevation="4dp" />

@@ -129,11 +129,11 @@
app:layout_constraintTop_toBottomOf="@id/details_appbar_background"
app:spanCount="4" />

<!-- This needs to be updated to use WindowInsets. See https://issuetracker.google.com/issues/112605433 -->
<!-- The height of this is updated via an OnApplyWindowInsetsListener -->
<View
android:id="@+id/details_status_bar_anchor"
android:layout_width="match_parent"
android:layout_height="24dp"
android:layout_height="0px"
android:background="@drawable/status_bar_translucent_scrim" />

<app.tivi.ui.widget.CheckableFloatingActionButton

0 comments on commit 0dbc532

Please sign in to comment.