Commit f20b1cb2 authored by MozLando's avatar MozLando
Browse files

Merge #7447

7447: For #7475: Fix tabcounter flicker r=rocketsroger a=hakkikaancaliskan

**Warning**: I'm amateur. Double check everything.

I've fixed tab counter flicker issue in fenix and @gabrielluong wanted to upstream that changes to ac.
<!-- Text above this line will be added to the commit once "bors" merges this PR -->

### Pull Request checklist
<!-- Before submitting the PR, please address each item -->
- [x] **Quality**: This PR builds and passes detekt/ktlint checks (A pre-push hook is recommended)
- [x] **Tests**: This PR includes thorough tests or an explanation of why it does not
- [ ] **Changelog**: This PR includes [a changelog entry](https://github.com/mozilla-mobile/android-components/blob/master/docs/changelog.md) or does not need one
- [ ] **Accessibility**: The code in this PR follows [accessibility best practices](https://github.com/mozilla-mobile/shared-docs/blob/master/android/accessibility_guide.md) or does not include any user facing features

### After merge
- **Milestone**: Make sure issues closed by this pull request are added to the [milestone](https://github.com/mozilla-mobile/android-components/milestones) of the version currently in development.
- **Breaking Changes**: If this is a breaking change, please push a draft PR on [Reference Browser](https://github.com/mozilla-mobile/reference-browser

) to address the breaking issues.


Co-authored-by: default avatarHakkı Kaan Çalışkan <caliskankaan@pm.me>
parents 40d123bd 18779e44
Loading
Loading
Loading
Loading
+7 −10
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ import mozilla.components.support.ktx.android.view.onNextGlobalLayout
import mozilla.components.support.utils.DrawableUtils
import java.text.NumberFormat

@Suppress("LargeClass")
open class TabCounter @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
@@ -35,7 +34,6 @@ open class TabCounter @JvmOverloads constructor(
    internal var currentTextRatio: Float = 0.toFloat()

    init {

        // Default TabCounter tint, could be override by the caller
        @ColorInt val defaultTabCounterTint = ContextCompat.getColor(context, R.color.mozac_ui_tabcounter_default_tint)
        val typedArray = context.obtainStyledAttributes(attrs, R.styleable.TabCounter, defStyle, 0)
@@ -48,10 +46,8 @@ open class TabCounter @JvmOverloads constructor(
        box = findViewById(R.id.counter_box)
        bar = findViewById(R.id.counter_bar)
        text = findViewById(R.id.counter_text)
        text.text = DEFAULT_TABS_COUNTER_TEXT
        val shiftOneDpForDefaultText = TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP, 1f, context.resources.displayMetrics).toInt()
        text.setPadding(0, 0, 0, shiftOneDpForDefaultText)

        setCount(count)

        if (tabCounterTint != defaultTabCounterTint) {
            tintDrawables(tabCounterTint)
@@ -60,6 +56,9 @@ open class TabCounter @JvmOverloads constructor(
        animationSet = createAnimatorSet()
    }

    /**
     * Returns current tab count from tab counter view.
     */
    fun getText(): CharSequence {
        return text.text
    }
@@ -182,7 +181,7 @@ open class TabCounter @JvmOverloads constructor(
        // Fadeout in 66ms, after firstAnimator with delay 32ms (54~58, 4 frames).
        val fadeOut = ObjectAnimator.ofFloat(bar, "alpha",
            ANIM_BAR_FADEOUT_FROM, ANIM_BAR_FADEOUT_TO).setDuration(ANIM_BAR_FADEOUT_DURATION)
        fadeOut.startDelay = (ANIM_BAR_FADEOUT_DELAY).toLong() // delay 3 frames after firstAnimator
        fadeOut.startDelay = (ANIM_BAR_FADEOUT_DELAY) // delay 3 frames after firstAnimator

        // Move down on y-axis, from -7.0 to 0 in 16ms, after fadeOut (58~59 1 frame).
        val moveDown2 = ObjectAnimator.ofFloat(bar, "translationY",
@@ -216,7 +215,7 @@ open class TabCounter @JvmOverloads constructor(
        // FadeIn in 66 ms, after fadeOut with delay 96ms (57~61, 4 frames).
        val fadeIn = ObjectAnimator.ofFloat(text, "alpha",
            ANIM_TEXT_FADEIN_FROM, ANIM_TEXT_FADEIN_TO).setDuration(ANIM_TEXT_FADEIN_DURATION)
        fadeIn.startDelay = (ANIM_TEXT_FADEIN_DELAY).toLong() // delay 6 frames after fadeOut
        fadeIn.startDelay = (ANIM_TEXT_FADEIN_DELAY) // delay 6 frames after fadeOut

        // Move down on y-axis, from 0 to 4.4 in 66ms, with fadeIn (57~61, 4 frames).
        val moveDown = ObjectAnimator.ofFloat(text, "translationY",
@@ -259,11 +258,9 @@ open class TabCounter @JvmOverloads constructor(
    }

    companion object {

        internal const val MAX_VISIBLE_TABS = 99

        internal const val SO_MANY_TABS_OPEN = "∞"
        internal const val DEFAULT_TABS_COUNTER_TEXT = ":)"

        internal const val ONE_DIGIT_SIZE_RATIO = 0.6f
        internal const val TWO_DIGITS_SIZE_RATIO = 0.5f
+3 −4
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@ package mozilla.components.ui.tabcounter

import androidx.test.ext.junit.runners.AndroidJUnit4
import mozilla.components.support.test.robolectric.testContext
import mozilla.components.ui.tabcounter.TabCounter.Companion.DEFAULT_TABS_COUNTER_TEXT
import mozilla.components.ui.tabcounter.TabCounter.Companion.ONE_DIGIT_SIZE_RATIO
import mozilla.components.ui.tabcounter.TabCounter.Companion.SO_MANY_TABS_OPEN
import mozilla.components.ui.tabcounter.TabCounter.Companion.TWO_DIGITS_SIZE_RATIO
@@ -18,12 +17,12 @@ import org.junit.runner.RunWith
class TabCounterTest {

    @Test
    fun `Default tab count is a smiley face`() {
    fun `Default tab count is 0`() {
        val tabCounter = TabCounter(testContext)

        assertEquals(DEFAULT_TABS_COUNTER_TEXT, tabCounter.getText())
        assertEquals("0", tabCounter.getText())

        assertEquals(0.toFloat(), tabCounter.currentTextRatio)
        assertEquals(ONE_DIGIT_SIZE_RATIO, tabCounter.currentTextRatio)
    }

    @Test