Skip to content

Commit a3d70ad

Browse files
authored
Omnibar outline and transition adjustments (#5975)
Task/Issue URL: https://app.asana.com/1/137249556945/project/1208671518894266/task/1210095910664825?focus=true ### Description This PR makes 3 small changes to the omnibar. 1. Stop the contents of the omnibar "wiggling" when transitioning between focus and unfocused state. 2. Do not visually enlarge the omnibar's card when focus, only resize enough for the stroke to appear outside. 3. Decrease the bottom omnibar card's shadow and get it closer aligned with the shadow visible on the top omnibar card.
1 parent 2f228de commit a3d70ad

File tree

3 files changed

+66
-47
lines changed

3 files changed

+66
-47
lines changed

app/src/main/java/com/duckduckgo/app/browser/omnibar/experiments/FadeOmnibarLayout.kt

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ import android.view.ViewTreeObserver.OnGlobalLayoutListener
2626
import android.view.animation.DecelerateInterpolator
2727
import android.widget.ImageView
2828
import android.widget.LinearLayout
29+
import androidx.core.animation.addListener
2930
import androidx.core.view.isVisible
3031
import androidx.core.view.marginBottom
3132
import androidx.core.view.marginEnd
3233
import androidx.core.view.marginStart
3334
import androidx.core.view.marginTop
35+
import androidx.core.view.updateLayoutParams
3436
import androidx.core.view.updatePadding
3537
import com.duckduckgo.anvil.annotations.InjectWith
3638
import com.duckduckgo.app.browser.R
@@ -45,6 +47,7 @@ import com.duckduckgo.app.browser.omnibar.model.OmnibarPosition
4547
import com.duckduckgo.common.ui.view.gone
4648
import com.duckduckgo.common.ui.view.hide
4749
import com.duckduckgo.common.ui.view.show
50+
import com.duckduckgo.common.ui.view.toDp
4851
import com.duckduckgo.di.scopes.FragmentScope
4952
import com.duckduckgo.mobile.android.R as CommonR
5053
import com.google.android.material.card.MaterialCardView
@@ -98,17 +101,6 @@ class FadeOmnibarLayout @JvmOverloads constructor(
98101
}
99102
private val omnibarCardFocusedMarginTop by lazy { resources.getDimensionPixelSize(CommonR.dimen.experimentalOmnibarCardFocusedMarginTop) }
100103
private val omnibarCardFocusedMarginBottom by lazy { resources.getDimensionPixelSize(CommonR.dimen.experimentalOmnibarCardFocusedMarginBottom) }
101-
private val omnibarContentPadding by lazy { resources.getDimensionPixelSize(CommonR.dimen.experimentalOmnibarContentPadding) }
102-
private val omnibarContentFocusedPaddingHorizontal by lazy {
103-
resources.getDimensionPixelSize(
104-
CommonR.dimen.experimentalOmnibarContentFocusedPaddingHorizontal,
105-
)
106-
}
107-
private val omnibarContentFocusedPaddingVertical by lazy {
108-
resources.getDimensionPixelSize(
109-
CommonR.dimen.experimentalOmnibarContentFocusedPaddingVertical,
110-
)
111-
}
112104
private val omnibarOutlineWidth by lazy { resources.getDimensionPixelSize(CommonR.dimen.experimentalOmnibarOutlineWidth) }
113105
private val omnibarOutlineFocusedWidth by lazy { resources.getDimensionPixelSize(CommonR.dimen.experimentalOmnibarOutlineFocusedWidth) }
114106

@@ -127,18 +119,21 @@ class FadeOmnibarLayout @JvmOverloads constructor(
127119
val navBar = rootContainer.findViewById<BrowserNavigationBarView>(R.id.omnibarNavigationBar)
128120
if (omnibarPosition == OmnibarPosition.TOP) {
129121
rootContainer.removeView(navBar)
122+
123+
omnibarCard.elevation = 1f.toDp(context)
130124
} else {
131125
navigationBar = navBar
132126

133127
// When omnibar is at the bottom, we're adding an additional space at the top
134128
toolbarContainer.updatePadding(
135129
top = toolbarContainerPaddingTopWhenAtBottom,
136130
)
137-
138131
// at the same time, we remove that space from the navigation bar which now sits below the omnibar
139132
navBar.findViewById<LinearLayout>(R.id.rootView).updatePadding(
140133
top = 0,
141134
)
135+
136+
omnibarCard.elevation = 0.5f.toDp(context)
142137
}
143138
}
144139

@@ -153,6 +148,19 @@ class FadeOmnibarLayout @JvmOverloads constructor(
153148
findInPage.findInPageContainer.viewTreeObserver.removeOnGlobalLayoutListener(findInPageLayoutVisibilityChangeListener)
154149
}
155150

151+
override fun onSizeChanged(
152+
w: Int,
153+
h: Int,
154+
oldw: Int,
155+
oldh: Int,
156+
) {
157+
super.onSizeChanged(w, h, oldw, oldh)
158+
if (w != oldw || h != oldh) {
159+
// This allows the view to adjust to configuration changes, even if it's currently in the focused state.
160+
unlockContentDimensions()
161+
}
162+
}
163+
156164
override fun render(viewState: ViewState) {
157165
super.render(viewState)
158166
outlineProvider = if (viewState.viewMode is ViewMode.CustomTab) {
@@ -216,41 +224,25 @@ class FadeOmnibarLayout @JvmOverloads constructor(
216224
val startCardMarginBottom = omnibarCard.marginBottom
217225
val startCardMarginStart = omnibarCard.marginStart
218226
val startCardMarginEnd = omnibarCard.marginEnd
219-
val startContentPaddingTop = omnibarCard.contentPaddingTop
220-
val startContentPaddingBottom = omnibarCard.contentPaddingBottom
221-
val startContentPaddingStart = omnibarCard.contentPaddingLeft
222-
val startContentPaddingEnd = omnibarCard.contentPaddingRight
223227
val startCardStrokeWidth = omnibarCard.strokeWidth
224228

225229
val endCardMarginTop: Int
226230
val endCardMarginBottom: Int
227231
val endCardMarginStart: Int
228232
val endCardMarginEnd: Int
229-
val endContentPaddingTop: Int
230-
val endContentPaddingBottom: Int
231-
val endContentPaddingStart: Int
232-
val endContentPaddingEnd: Int
233233
val endCardStrokeWidth: Int
234234

235235
if (focused) {
236236
endCardMarginTop = omnibarCardFocusedMarginTop
237237
endCardMarginBottom = omnibarCardFocusedMarginBottom
238238
endCardMarginStart = omnibarCardFocusedMarginHorizontal
239239
endCardMarginEnd = omnibarCardFocusedMarginHorizontal
240-
endContentPaddingTop = omnibarContentFocusedPaddingVertical
241-
endContentPaddingBottom = omnibarContentFocusedPaddingVertical
242-
endContentPaddingStart = omnibarContentFocusedPaddingHorizontal
243-
endContentPaddingEnd = omnibarContentFocusedPaddingHorizontal
244240
endCardStrokeWidth = omnibarOutlineFocusedWidth
245241
} else {
246242
endCardMarginTop = omnibarCardMarginTop
247243
endCardMarginBottom = omnibarCardMarginBottom
248244
endCardMarginStart = omnibarCardMarginHorizontal
249245
endCardMarginEnd = omnibarCardMarginHorizontal
250-
endContentPaddingTop = omnibarContentPadding
251-
endContentPaddingBottom = omnibarContentPadding
252-
endContentPaddingStart = omnibarContentPadding
253-
endContentPaddingEnd = omnibarContentPadding
254246
endCardStrokeWidth = omnibarOutlineWidth
255247
}
256248

@@ -264,10 +256,6 @@ class FadeOmnibarLayout @JvmOverloads constructor(
264256
val animatedCardMarginBottom = (startCardMarginBottom + (endCardMarginBottom - startCardMarginBottom) * fraction).toInt()
265257
val animatedCardMarginStart = (startCardMarginStart + (endCardMarginStart - startCardMarginStart) * fraction).toInt()
266258
val animatedCardMarginEnd = (startCardMarginEnd + (endCardMarginEnd - startCardMarginEnd) * fraction).toInt()
267-
val animatedContentPaddingTop = (startContentPaddingTop + (endContentPaddingTop - startContentPaddingTop) * fraction).toInt()
268-
val animatedContentPaddingBottom = (startContentPaddingBottom + (endContentPaddingBottom - startContentPaddingBottom) * fraction).toInt()
269-
val animatedContentPaddingStart = (startContentPaddingStart + (endContentPaddingStart - startContentPaddingStart) * fraction).toInt()
270-
val animatedContentPaddingEnd = (startContentPaddingEnd + (endContentPaddingEnd - startContentPaddingEnd) * fraction).toInt()
271259
val animatedCardStrokeWidth = (startCardStrokeWidth + (endCardStrokeWidth - startCardStrokeWidth) * fraction).toInt()
272260

273261
val params = omnibarCard.layoutParams as MarginLayoutParams
@@ -277,20 +265,54 @@ class FadeOmnibarLayout @JvmOverloads constructor(
277265
params.bottomMargin = animatedCardMarginBottom
278266
omnibarCard.setLayoutParams(params)
279267

280-
omnibarCard.setContentPadding(
281-
animatedContentPaddingStart,
282-
animatedContentPaddingTop,
283-
animatedContentPaddingEnd,
284-
animatedContentPaddingBottom,
285-
)
286-
287268
omnibarCard.strokeWidth = animatedCardStrokeWidth
288269
}
289270

271+
animator.addListener(
272+
onStart = {
273+
lockContentDimensions()
274+
},
275+
onEnd = {
276+
// Only unlock content size when we're back to unfocused state.
277+
if (!focused) {
278+
unlockContentDimensions()
279+
}
280+
},
281+
onCancel = {
282+
// Ensuring that onEnd, and consequently #unlockContentDimensions(), is not called when transition is canceled,
283+
// which can result in content jumping to match_parent while the transition is not finished yet.
284+
// We only want to unlock when we're fully transitioned back to unfocused state.
285+
animator.removeAllListeners()
286+
},
287+
)
288+
290289
animator.start()
291290
focusAnimator = animator
292291
}
293292

293+
/**
294+
* Lock content dimensions so that the view doesn't respond to the wrapping card's size changes.
295+
*
296+
* When focused, we resize the wrapping card to make the stroke appear "outside" but we don't want the content to expand with it.
297+
*/
298+
private fun lockContentDimensions() {
299+
omniBarContentContainer.updateLayoutParams {
300+
width = omniBarContentContainer.measuredWidth
301+
height = omniBarContentContainer.measuredHeight
302+
}
303+
}
304+
305+
/**
306+
* Unlock content dimensions so that the view can correctly respond to changes in the viewport size,
307+
* like resizing the app window or changing device orientation.
308+
*/
309+
private fun unlockContentDimensions() {
310+
omniBarContentContainer.updateLayoutParams {
311+
width = ViewGroup.LayoutParams.MATCH_PARENT
312+
height = ViewGroup.LayoutParams.MATCH_PARENT
313+
}
314+
}
315+
294316
private fun onFindInPageShown() {
295317
omniBarContentContainer.gone()
296318
customTabToolbarContainerWrapper.gone()

app/src/main/res/layout/view_fade_omnibar.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@
5858
android:layout_marginTop="@dimen/experimentalOmnibarCardMarginTop"
5959
android:layout_marginBottom="@dimen/experimentalOmnibarCardMarginBottom"
6060
app:strokeColor="?daxColorAccentBlue"
61-
app:contentPadding="@dimen/experimentalOmnibarContentPadding"
6261
app:strokeWidth="@dimen/experimentalOmnibarOutlineWidth">
6362

6463
<androidx.constraintlayout.widget.ConstraintLayout
6564
android:id="@+id/omniBarContentContainer"
6665
android:layout_width="match_parent"
67-
android:layout_height="match_parent">
66+
android:layout_height="match_parent"
67+
android:layout_gravity="center">
6868

6969
<ProgressBar
7070
android:id="@+id/pageLoadingIndicator"

common/common-ui/src/main/res/values/design-experiments-dimens.xml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@
2626
<dimen name="experimentalOmnibarCardMarginHorizontal">16dp</dimen>
2727
<dimen name="experimentalOmnibarCardMarginTop">4dp</dimen>
2828
<dimen name="experimentalOmnibarCardMarginBottom">12dp</dimen>
29-
<dimen name="experimentalOmnibarCardFocusedMarginHorizontal">12dp</dimen>
30-
<dimen name="experimentalOmnibarCardFocusedMarginTop">0dp</dimen>
31-
<dimen name="experimentalOmnibarCardFocusedMarginBottom">8dp</dimen>
32-
<dimen name="experimentalOmnibarContentPadding">0dp</dimen>
33-
<dimen name="experimentalOmnibarContentFocusedPaddingHorizontal">4dp</dimen>
34-
<dimen name="experimentalOmnibarContentFocusedPaddingVertical">@dimen/experimentalOmnibarOutlineFocusedWidth</dimen>
29+
<dimen name="experimentalOmnibarCardFocusedMarginHorizontal">14dp</dimen>
30+
<dimen name="experimentalOmnibarCardFocusedMarginTop">2dp</dimen>
31+
<dimen name="experimentalOmnibarCardFocusedMarginBottom">10dp</dimen>
3532
<dimen name="experimentalOmnibarOutlineWidth">0dp</dimen>
3633
<dimen name="experimentalOmnibarOutlineFocusedWidth">2dp</dimen>
3734
</resources>

0 commit comments

Comments
 (0)