Не сразу отображаются items в recyclerView, но только после первой смены конфигурации (поворота экрана)

Коллеги проблема такая - в recyclerview внутри DialogFragment элементы отображаются не сразу, а сначала открывается пустой и только после первого поворота экрана - заполненный. Причину не могу понять. Буду благодарен если кто-то сможет подсказать куда копать. (LOGS в onCreateDialog с первого раза показывает что customView не null, а уже присвоен лаяут.) Код:

ДиалогФрагмент:

class ChooseCategoryDialogFragment : DialogFragment(), ChooseCategoryAdapter.OnItemClickListener {

    private val viewModel: EditTransactionViewModel by viewModels({ requireParentFragment() })
    private var _binding: FragmentDialogRecyclerBinding? = null
    private val binding get() = _binding!!

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        super.onCreateDialog(savedInstanceState)
        _binding = FragmentDialogRecyclerBinding.inflate(LayoutInflater.from(context))

        return AlertDialog.Builder(requireContext())
            .setTitle(requireContext().resources.getString(R.string.choose_category))
            .setView(binding.root)
            .setNegativeButton(requireContext().resources.getString(R.string.cancel_action), null)
            .create()
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        super.onCreateView(inflater, container, savedInstanceState)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val category = viewModel.spendCategoryName.value
        val chooseCatAdapter = ChooseCategoryAdapter(this, category)

        binding.apply {
            recyclerView.apply {
                viewModel.categories.observe(viewLifecycleOwner) {
                    chooseCatAdapter.submitList(it)
                }
                layoutManager = LinearLayoutManager(requireContext())
                adapter = chooseCatAdapter
                setHasFixedSize(true)
            }
        }
    }

Адаптер:

class ChooseCategoryAdapter(
    private val listener: OnItemClickListener,
    private val curCatName: String?
) : ListAdapter<Category, ChooseCategoryAdapter.ChooseCatViewHolder>(ChooseCatComparator()) {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChooseCatViewHolder {
        val binding = ItemDialogRecyclerBinding.inflate(
            LayoutInflater.from(parent.context),
            parent,
            false
        )
        return ChooseCatViewHolder(binding)
    }

    override fun onBindViewHolder(holder: ChooseCatViewHolder, position: Int) {
        val curItem = getItem(position)
        holder.bind(curItem)
    }

    inner class ChooseCatViewHolder(private val binding: ItemDialogRecyclerBinding) :
        RecyclerView.ViewHolder(binding.root) {

        init {
            binding.apply {
                root.setOnClickListener {
                    val position = adapterPosition
                    if (position != RecyclerView.NO_POSITION) {
                        val category = getItem(position)
                        listener.onItemClick(category)
                    }
                }
                radioButton.setOnClickListener {
                    val position = adapterPosition
                    if (position != RecyclerView.NO_POSITION) {
                        val category = getItem(position)
                        listener.onItemClick(category)
                    }
                }
            }
        }

        fun bind(category: Category) {
            binding.apply {
                tvCatname.text = category.catName
                radioButton.isChecked = category.catName == curCatName
            }
        }
    }

    interface OnItemClickListener {
        fun onItemClick(category: Category)
    }

    class ChooseCatComparator : DiffUtil.ItemCallback<Category>() {
        override fun areItemsTheSame(oldItem: Category, newItem: Category) =
            oldItem == newItem

        override fun areContentsTheSame(oldItem: Category, newItem: Category) =
            oldItem.catName == newItem.catName
    }
}

Ответы (1 шт):

Автор решения: Alex Rodionow

Finally спустя 2 недели я нашел ответ: надо было удалить строку setHasFixedSize(true), потому что она мешала окну диалогФрагмента подогнать размер под приходящие данные.

→ Ссылка