Skip to content
Permalink
Browse files

Stop MotionLayout taking swipes over expanded pane

  • Loading branch information...
chrisbanes committed Sep 19, 2019
1 parent 9f21743 commit 37fb0c33042a25a31039b75b28722e6ee5b005b2
@@ -38,7 +38,6 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@{contentDescription}"
android:foreground="?android:attr/selectableItemBackground"
android:transitionGroup="true">

<ImageView
@@ -0,0 +1,53 @@
/*
* 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.ui.widget

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import androidx.constraintlayout.motion.widget.MotionLayout

class TiviMotionLayout @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : MotionLayout(context, attrs, defStyleAttr) {

/**
* Whether this MotionLayout should react to nested scrolls and touch events
*/
var motionEnabled = true

override fun onStartNestedScroll(child: View, target: View, axes: Int, type: Int): Boolean {
return motionEnabled && super.onStartNestedScroll(child, target, axes, type)
}

override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
if (event.action == MotionEvent.ACTION_DOWN && !motionEnabled) {
return false
}
return super.onInterceptTouchEvent(event)
}

override fun onTouchEvent(event: MotionEvent): Boolean {
if (event.action == MotionEvent.ACTION_DOWN && !motionEnabled) {
return false
}
return super.onTouchEvent(event)
}
}
@@ -39,6 +39,7 @@
android:background="@drawable/placeholder_72dp"
android:scaleType="centerCrop"
android:theme="@style/ThemeOverlay.MaterialComponents.Dark"
app:foregroundScrim="@{ android.graphics.Color.BLACK }"
app:layout_constrainedHeight="true"
app:layout_constraintDimensionRatio="h,4:3"
app:layout_constraintEnd_toEndOf="parent"
@@ -47,15 +48,6 @@
app:layout_constraintTop_toTopOf="parent"
app:tmdbBackdropPath="@{state.episode.invoke().tmdbBackdropPath}" />

<app.tivi.ui.widget.TintingToolbar
android:id="@+id/ep_details_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.MaterialComponents.ActionBar"
app:layout_constraintTop_toBottomOf="@id/ep_details_status_bar_anchor"
app:navigationIcon="@drawable/ic_close_24dp" />

<app.tivi.ui.widget.BaselineGridTextView
android:id="@+id/ep_details_title"
android:layout_width="0dp"
@@ -66,6 +58,7 @@
android:ellipsize="end"
android:text="@{state.episode.invoke().title}"
android:textAppearance="?attr/textAppearanceHeadline6"
android:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar"
app:layout_constraintBottom_toBottomOf="@id/ep_details_fanart"
app:layout_constraintEnd_toStartOf="@id/ep_details_fab"
app:layout_constraintStart_toStartOf="@id/ep_details_fanart"

This file was deleted.

@@ -172,7 +172,10 @@ class ShowDetailsFragment : TiviMvRxFragment() {
binding.detailsExpandedPane.addStateChangeCallbacks(object : PageStateChangeCallbacks {
override fun onPageAboutToCollapse(collapseAnimDuration: Long) {}

override fun onPageAboutToExpand(expandAnimDuration: Long) {}
override fun onPageAboutToExpand(expandAnimDuration: Long) {
// Make sure we're in the collapsed state
binding.detailsMotion.transitionToState(R.id.show_details_closed)
}

override fun onPageCollapsed() {
backPressedCallback.isEnabled = false
@@ -184,11 +187,15 @@ class ShowDetailsFragment : TiviMvRxFragment() {
remove(fragment)
}
}

// Re-enable MotionLayout's motion handling
binding.detailsMotion.motionEnabled = true
}

override fun onPageExpanded() {
backPressedCallback.isEnabled = true

// Disable MotionLayout's motion handling while the pane is expanded
binding.detailsMotion.motionEnabled = false
binding.detailsMotion.requestLayout()
}
})
@@ -29,7 +29,7 @@
type="app.tivi.showdetails.details.ShowDetailsViewState" />
</data>

<androidx.constraintlayout.motion.widget.MotionLayout
<app.tivi.ui.widget.TiviMotionLayout
android:id="@+id/details_motion"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -149,7 +149,8 @@
<me.saket.inboxrecyclerview.page.ExpandablePageLayout
android:id="@+id/details_expanded_pane"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:clickable="true" />

</FrameLayout>

@@ -173,5 +174,5 @@
app:layout_constraintEnd_toEndOf="@id/details_appbar_background"
app:layout_constraintTop_toTopOf="@id/details_appbar_background" />

</androidx.constraintlayout.motion.widget.MotionLayout>
</app.tivi.ui.widget.TiviMotionLayout>
</layout>

0 comments on commit 37fb0c3

Please sign in to comment.
You can’t perform that action at this time.