This repository was archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 524
[WIP] Adding left side navigation to Layouts above 1024dp #18
Draft
kford55
wants to merge
3
commits into
material-components:develop
Choose a base branch
from
kford55:reply-bigfoot
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+394
−43
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
Reply/app/src/main/java/com/materialstudies/reply/ui/nav/RailNavigationFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package com.materialstudies.reply.ui.nav | ||
|
||
import android.animation.ValueAnimator | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.observe | ||
import com.materialstudies.reply.R | ||
import com.materialstudies.reply.databinding.FragmentRailNavigationBinding | ||
import com.materialstudies.reply.util.FastOutUltraSlowIn | ||
import com.materialstudies.reply.util.lerp | ||
import kotlin.math.abs | ||
|
||
class RailNavigationFragment : Fragment(), NavigationAdapter.NavigationAdapterListener { | ||
|
||
/** | ||
* Enumeration of states in which the account picker can be in. | ||
*/ | ||
enum class RailState { | ||
|
||
/** | ||
* The account picker is not visible. The navigation drawer is in its default state. | ||
*/ | ||
CLOSED, | ||
|
||
/** | ||
* the account picker is visible and open. | ||
*/ | ||
OPEN, | ||
|
||
/** | ||
* The account picker sandwiching animation is running. The account picker is neither open | ||
* nor closed. | ||
*/ | ||
SETTLING | ||
} | ||
|
||
private lateinit var binding: FragmentRailNavigationBinding | ||
|
||
private var railState: RailState = RailState.OPEN | ||
private var railAnim: ValueAnimator? = null | ||
private val railInterp = FastOutUltraSlowIn() | ||
private var railProgress: Float = 1F | ||
set(value) { | ||
if (field != value) { | ||
onRailProgressChanged(value) | ||
val newState = when (value) { | ||
1F -> RailState.OPEN | ||
0F -> RailState.CLOSED | ||
else -> RailState.SETTLING | ||
} | ||
if (railState != newState) onRailStateChanged(newState) | ||
railState = newState | ||
field = value | ||
} | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
binding = FragmentRailNavigationBinding.inflate(inflater, container, false) | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
binding.run { | ||
val adapter = NavigationAdapter(this@RailNavigationFragment) | ||
navRecyclerView.adapter = adapter | ||
NavigationModel.navigationList.observe(this@RailNavigationFragment) { | ||
adapter.submitList(it) | ||
} | ||
NavigationModel.setNavigationMenuItemChecked(0) | ||
|
||
if (!resources.getBoolean(R.bool.drawerLockedOpen)) { | ||
logoImageView.setOnClickListener { toggleRail() } | ||
} | ||
} | ||
} | ||
|
||
override fun onNavMenuItemClicked(item: NavigationModelItem.NavMenuItem) { | ||
// TODO | ||
} | ||
|
||
override fun onNavEmailFolderClicked(folder: NavigationModelItem.NavEmailFolder) { | ||
// TODO | ||
} | ||
|
||
private fun toggleRail() { | ||
val initialProgress = railProgress | ||
val newProgress = when (railState) { | ||
RailState.CLOSED -> 1F | ||
RailState.OPEN -> 0F | ||
RailState.SETTLING -> return | ||
} | ||
railAnim?.cancel() | ||
railAnim = ValueAnimator.ofFloat(initialProgress, newProgress).apply { | ||
addUpdateListener { railProgress = animatedValue as Float } | ||
interpolator = railInterp | ||
duration = (abs(newProgress - initialProgress) * 250F).toLong() | ||
} | ||
railAnim?.start() | ||
} | ||
|
||
private fun onRailProgressChanged(progress: Float) { | ||
// TODO | ||
val railWidth = lerp( | ||
resources.getDimension(R.dimen.min_rail_nav_width), | ||
resources.getDimension(R.dimen.max_rail_nav_width), | ||
0F, | ||
1F, | ||
progress | ||
) | ||
|
||
binding.run { | ||
val params = railContainer.layoutParams | ||
params.width = railWidth.toInt() | ||
railContainer.layoutParams = params | ||
|
||
settingsIcon.alpha = progress | ||
logoTitleTextView.alpha = progress | ||
} | ||
} | ||
|
||
private fun onRailStateChanged(state: RailState) { | ||
// TODO: Look into animating the height of the fab manually instead of shrinking. | ||
// when (state) { | ||
// RailState.CLOSED -> { | ||
// binding.composeFab.shrink() | ||
// } | ||
// } | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
Reply/app/src/main/java/com/materialstudies/reply/util/FastOutUltraSlowIn.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* 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 | ||
* | ||
* https://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 com.materialstudies.reply.util | ||
|
||
import android.view.animation.Interpolator | ||
import androidx.core.view.animation.PathInterpolatorCompat | ||
|
||
/** | ||
* A custom Interpolator that dramatically slows as an animation end, avoiding sudden motion | ||
* stops for large moving components (ie. shared element cards). | ||
*/ | ||
class FastOutUltraSlowIn : Interpolator { | ||
|
||
private val pathInterpolator = PathInterpolatorCompat.create( | ||
0.185F, | ||
0.770F, | ||
0.135F, | ||
0.975F | ||
) | ||
|
||
override fun getInterpolation(fraction: Float): Float { | ||
return pathInterpolator.getInterpolation(fraction) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright (c) 2019 Google Inc. | ||
|
||
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. | ||
--> | ||
<layout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" > | ||
|
||
<fragment | ||
android:id="@+id/rail_navigation" | ||
android:layout_width="@dimen/max_rail_nav_width" | ||
android:layout_height="match_parent" | ||
android:name="com.materialstudies.reply.ui.nav.RailNavigationFragment" | ||
app:layout_constraintLeft_toLeftOf="parent" /> | ||
|
||
<fragment | ||
android:id="@+id/nav_host_fragment" | ||
android:name="androidx.navigation.fragment.NavHostFragment" | ||
android:layout_width="0dp" | ||
android:layout_height="match_parent" | ||
app:defaultNavHost="true" | ||
app:navGraph="@navigation/navigation_graph" | ||
app:layout_constraintLeft_toRightOf="@id/rail_navigation" | ||
app:layout_constraintRight_toRightOf="parent"/> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
|
||
</layout> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: I think this could be combined into a single
binding.fab?.apply {
(same applies to other changes below)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeaa me and @hunterstich were talking about this yesterday. This as of now is a get stuff moving and started (probably gonna push the nav stuff until some of the other parts are built) but there is some changes we have to make to make this cleaner and hopefully less gross around the optionals and all that as there's definitely some lifecycle things that can cause issues here.