1

In my project I use Compose in Fragments.

My FirstScreenFragment:

class FirstScreenFragment : Fragment() {
    @SuppressLint("InflateParams")
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
    ): View {
        val viewPager = activity?.findViewById<ViewPager2>(R.id.viewPager)
        return ComposeView(requireContext()).apply {
            setContent {
                OnBoardingPage(
                    viewPager = viewPager,
                    backgroundColor = R.color.light_green,
                    fragmentPicture = R.drawable.first_fragment_picture,
                    title = "Fitness Client Tracker",
                    textContent = "Welcome",
                    currentPage = 1
                )
            }
        }
    }
}

I got error:

E/RecyclerView: No adapter attached; skipping layout

And after second fragment:

W/ssclienttracke: Class androidx.compose.runtime.snapshots.SnapshotStateList failed lock verification and will run slower. Common causes for lock verification issues are non-optimized dex code and incorrect proguard optimizations.

I don't see any fragments skipped but why is this happening?

EDIT: ViewPagerFragment:

return ComposeView(requireContext()).apply {
    setContent {
        val fragmentList = arrayListOf(
            FirstScreenFragment(),
            SecondScreenFragment(),
            ThirdScreenFragment()
        )
        val adapter = ViewPagerAdapter(
            fragmentList,
            requireActivity().supportFragmentManager,
            lifecycle
        )
        AndroidView(factory = { context ->
            val view = LayoutInflater.from(context)
                .inflate(R.layout.fragment_view_pager, null, false)
            val viewPager = view.findViewById<ViewPager2>(R.id.viewPager)
            viewPager.adapter = adapter
            view
        })
    }
}

ViewPagerAdapter:

class ViewPagerAdapter(
    list: ArrayList<Fragment>,
    fm: FragmentManager,
    lifecycle: Lifecycle
) :
    FragmentStateAdapter(fm, lifecycle) {
    private val fragmentList = list
    override fun getItemCount(): Int {
        return fragmentList.size
    }

    override fun createFragment(position: Int): Fragment {
        return fragmentList[position]
    }
}

Still didn't find the right solution, so if u know write it.

Equlo
  • 115
  • 10
  • 1
    Why it is happening? Because RecyclerView is attached before it has an adapter attached to it. Is it some critical error and can be mostly ignored? Yes. [This could help you answer the question.](https://stackoverflow.com/questions/28510578/no-adapter-attached-skipping-layout) – TheLibrarian Dec 07 '22 at 13:14
  • Any updates about this? I have the similar problem, after few hours of research I found that it happen in my app only after I enable compose in module. – Andrey Feb 01 '23 at 20:28
  • Unfortunately not, I switched fully to Compose and made onboarding without ViewPager + some of guys on Android discord channel said that library was always buggy. – Equlo Feb 04 '23 at 19:01

0 Answers0