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

Что нового в Fragment 1.4

Что нового в Fragment 1.4

Видео версия https://youtu.be/UWuuqbNIWpE

Крайний релиз Jetpack Fragment вышел очень интересным на фичи, что заслужил озвучить изменения в отдельном видео, а именно:
🔥 Новый менеджер состояний
🔥 Несколько back stack
🔥 FragmentStrictMode
💪 Новые проверки кода в Android Lint
🚀 Улучшение работы анимаций
🔨 Исправление багов в работе ЖЦ Fragment

Kirill Rozov

December 12, 2021
Tweet

More Decks by Kirill Rozov

Other Decks in Programming

Transcript

  1. Что изменили ! Исправили множество багов с навигацией ! Управление

    состоянием Fragment ! Заложена поддержка для множественного back stack ! Упрощение жизненного цикла Fragment [результатов пока не видно]
  2. penaltyDeath 2021-12-11 17:08:56.170 12010-12010/dev.androidbroadcast.fragmentdemo E/FragmentStrictMode: Policy violation with PENALTY_DEATH in

    dev.androidbroadcast.fragmentdemo.FirstFragment androidx.fragment.app.strictmode.SetUserVisibleHintViolation: Attempting to set user visible hint to true for fragment FirstFragment{300fd8d} (9fbf6047-2ed5-4952-b7bd-4d513035c141 id=0x7f0800c5) at androidx.fragment.app.strictmode.FragmentStrictMode.onSetUserVisibleHint(FragmentStrictMode.kt:131) at androidx.fragment.app.Fragment.setUserVisibleHint(Fragment.java:1335) at dev.androidbroadcast.fragmentdemo.FirstFragment.onViewCreated(FirstFragment.kt:26) at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:3019) at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:551) at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261) at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:113) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1374) at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2841) at androidx.fragment.app.FragmentManager.dispatchViewCreated(FragmentManager.java:2777) at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:3020) at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:551) at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261) at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:113) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1374) at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2841) at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2784) at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:262) at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:478) at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:246)
  3. penaltyLog 2021-12-11 17:10:19.516 12163-12163/dev.androidbroadcast.fragmentdemo D/FragmentStrictMode: Policy violation in dev.androidbroadcast.fragmentdemo.FirstFragment androidx.fragment.app.strictmode.SetUserVisibleHintViolation:

    Attempting to set user visible hint to true for fragment FirstFragment{300fd8d} (e2010f02-eb83-416b-a7ac-05aaa3befd12 id=0x7f0800c5) at androidx.fragment.app.strictmode.FragmentStrictMode.onSetUserVisibleHint(FragmentStrictMode.kt:131) at androidx.fragment.app.Fragment.setUserVisibleHint(Fragment.java:1335) at dev.androidbroadcast.fragmentdemo.FirstFragment.onViewCreated(FirstFragment.kt:26) at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:3019) at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:551) at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261) at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:113) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1374) at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2841) at androidx.fragment.app.FragmentManager.dispatchViewCreated(FragmentManager.java:2777) at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:3020) at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:551) at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261) at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:113) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1374) at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2841) at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2784) at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:262) at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:478) at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:246)
  4. detectFragmentReuse !" Повторное использование Fragment, который был удален из FragmentManager

    val firstFragment = fragmentManager.findFragmentByTag(FRAGMENT_TAG_FIRST) !7 return fragmentManager.commit { remove(firstFragment) } fragmentManager.commit { !" Добавление Fragment, удалённого ранее add(R.id.fragment_container, firstFragment, FRAGMENT_TAG_FIRST) }
  5. detectFragmentTagUsage !" Использование тэга при добавление Fragment в XML <fragment

    android:name="dev.androidbroadcast.fragmentdemo.FirstFragment" android:tag="first" android:layout_width="match_parent" android:layout_height="match_parent" !"
  6. supportFragmentManager.commit { setReorderingAllowed(true) replace<ProfileFragment>(R.id.fragment_container) addToBackStack("profile") } SavedState Back Stack HomeFragment

    ProZleFragment EditProZleFragment supportFragmentManager.commit { setReorderingAllowed(true) replace<EditProfileFragment>(R.id.fragment_container) addToBackStack("profile") }
  7. NotiZcationsFragment SavedState proZle Back Stack HomeFragment ProZleFragment EditProZleFragment supportFragmentManager.saveBackStack("profile") supportFragmentManager.commit

    { setReorderingAllowed(true) replace<NotificationsFragment>(R.id.fragment_container) addToBackStack("notifications") }
  8. Новые проверки в Android Lint ! UseGetLayoutInflater Использование неправильного LayoutInflater

    в DialogFragment ! DialogFragmentCallbacksDetector Переопределение callback у Dialog, а не DialogFragment ! FragmentAddMenuProvider Использование неверного Lifecycle при использовании addMenuProvider ! DetachAndAttachFragmentInSameFragmentTransaction Выполнение attach и detach для одного и того же Fragment в рамках одной транзакции