Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TargetSdkVersion29で BottomNavigationが点滅する件

yu mitsuhori
October 01, 2019

TargetSdkVersion29で BottomNavigationが点滅する件

potatotips#65での発表資料です

yu mitsuhori

October 01, 2019
Tweet

More Decks by yu mitsuhori

Other Decks in Programming

Transcript

  1. TargetSdkVersion29で
    BottomNavigationが点滅する件
    養命酒(Yu Mitsuhori)
    potatotips #65

    View Slide

  2. whoami
    - 三堀裕(みつほりゆう)
    - CCCグループ(株)Blabo 所属
    - 共創マーケティングプラットフォーム
    「Blabo!」のAndroid版を主に担当
    - @1013Youmeee
    - youmitsu
    - youmeee

    View Slide

  3. Android 10 Released!!

    View Slide

  4. Let’s migrate to API level 29(Android 10)!!

    View Slide

  5. しかしBottomNavigationでissue発見...
    - そんなすんなり行くほど世の中甘くない。。
    - 今日はそのissueについての紹介です

    View Slide

  6. BottomNavigationとは
    - Androidにおけるいわゆる下タブ
    - https://material.io/components/bottom-navigation/

    View Slide

  7. - コードはこちらに公開しています
    - https://github.com/youmitsu/BottomNavigationBugTestApp
    APILevel29でなぜか点滅する
    選択されているMenuItemが
    別タブに移る際に点滅する。。

    View Slide

  8. 再現条件を整理してみる
    - TargetSdkVersion, CompileSdkVersionは29
    - material-component-android:1.1.0-alpha09を使用
    - Android10の端末で再現
    - Android Pie(9)以下の端末では再現しない
    =>ライブラリが対応できていないことによるバグっぽい。。?
    - 一応他のバージョンでも試したところ1.0.0の時点から起きる

    View Slide

  9. material-componentsにissueをあげてみる
    https://github.com/material-components/material-components-android/issues/628

    View Slide

  10. すでに上がっていました。。

    View Slide

  11. すでに上がっていた方を見てみる
    https://github.com/material-components/material-components-android/issues/530

    View Slide

  12. 原因判明
    - どうやらBottomNavigationMenuViewのバグっぽい
    - プロパティで使われているTransitionSetが悪さしている?
    - ただ既存コードであるし、Android10にあげた途端に再現するようになるのは少し
    謎。。(深追いはしません)
    https://github.com/material-components/material-components-android/issues/530#issu
    ecomment-533597823

    View Slide

  13. View Slide

  14. 対処法①~気長に待つ~
    - Fixされるのを待つ
    - Android10はリリースされたばかりなのでご愛嬌

    View Slide

  15. 対処法②~リフレクションを使う~
    https://github.com/material-components/material-components-android/issues/530#issu
    ecomment-534331153

    View Slide

  16. 対処法②~リフレクションを使う~
    lateinit var binding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    ...
    binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
    binding.bottomNav.fixBlinking() // 初期化時に下記の拡張関数を呼んであげれば
    OK
    }
    private fun BottomNavigationView.fixBlinking() {
    val menuView = getChildAt(0) as BottomNavigationMenuView
    with(menuView::class.java.getDeclaredField("set")) {
    isAccessible = true
    val transitionSet = (get(menuView) as androidx.transition.AutoTransition).apply {
    for (i in transitionCount downTo 0) {
    val transition = getTransitionAt(i) as? Fade ?: continue
    removeTransition(transition)
    }
    }
    set(menuView, transitionSet)
    }
    }
    リフレクションでmenuViewに
    アタッチされているFadeTransitionを
    removeする
    BottomNavigationMenuViewの
    transitionSetのプロパティを取得
    TransitionSetをセットし
    直す

    View Slide

  17. 対処法②~proguardの修正も必要~
    - releaseビルド時に難読化されてしまうとリフレクション時にプロパティ名を正しく参
    照できなくなる
    - BottomNavigationMenuViewをproguard-rulesでkeepするように記述
    # 以下を追記
    -keep class com.google.android.material.bottomnavigation.BottomNavigationMenuView { *; }
    proguard-rules.pro

    View Slide

  18. まとめ
    - issueを出す時はすでに起票されていないかちゃんとチェックしよう
    - compileSdkVersionが29では、現状material-components-androidの
    BottomNavigationが点滅してしまう
    - できれば修正されるのを待つ。
    対応が待てなければリフレクションを使って、無理やり対応することになりそう
    (他に対処方法ご存知の方がいれば教えていただけると助かります。。)

    View Slide