向后导航时使用FirestoreRecyclerAdapter和导航组件的转换问题

时间:2020-03-02 17:27:00

标签: android android-recyclerview firebaseui android-navigation android-transitions

在我当前的项目中,我有一个包含Android Navigation ComponentFirebase UI的主/详细应用程序。我试图对ImageView实现共享元素事务。在我导航到详细信息片段的情况下可以正常工作,但是用RecyclerView弹出片段无法实现。

实际上,过渡没有应用。我认为这是时间问题。

这是保存onViewCreated的片段的RecyclerView

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    binding.lifecycleOwner = viewLifecycleOwner
    binding.viewModel = viewModel

    viewModel.posts.observe(viewLifecycleOwner) { query ->

        val settings = FirestoreRecyclerOptions.Builder<FeedItem>()
                .setQuery(query, FeedItem::class.java)
                .setLifecycleOwner(viewLifecycleOwner)
                .build()

        binding.recyclerView.adapter = FeedAdapter(settings, viewModel) // FirestoreRecyclerAdapter
    }

    viewModel.toPostEvent.observe(viewLifecycleOwner) {

        it.consume()?.run { event ->
           // get the image in the card
           val image: ImageView = openPostEvent.view.findViewById(R.id.image);
           val extras = FragmentNavigatorExtras(image to "postImage")

           findNavController()
              .navigate(FeedFragmentDirections.actionPost(event.postId), extras)

    }

    setupRecyclerView()
}

private fun setupRecyclerView() {
    postponeEnterTransition()

    binding.recyclerView.run {
        layoutManager = LinearLayoutManager(context)
        doOnPreDraw { startPostponedEnterTransition() }
    }
}

如果我将Enter-Transaction延迟一秒钟,我会看到动画。但是这种延迟不是我想要的。

private fun setupRecyclerView() {
    // just delay the transition for one second
    postponeEnterTransition(1000, TimeUnit.MILLISECONDS)
    binding.recyclerView.run {
        layoutManager = LinearLayoutManager(context)
    }
}

我在网上发现了一些有关RecyclerView的问题的帖子,几乎每种解决方案都建议延迟到OnPreDraw,所以我想我错过了有关FirestoreRecyclerAdapter的一些特色。 / p>

非常感谢我的提示!

干杯!

0 个答案:

没有答案