bytedance / scene

Android Single Activity Framework compatible with Fragment.
Apache License 2.0
2.08k stars 199 forks source link

结合ViewBinding使用的回收时机 #62

Closed Iridescentangle closed 3 years ago

Iridescentangle commented 3 years ago

请教一下,我想要结合ViewBinding来使用,目前选择了hi-dhl/Binding 因为现有对ViewBinding的封装都是针对Activity Fragment Dialog Adapter和自定义View的,所以我考虑自己来做这个Scene.viewbind()的扩展函数.然后在过程中发现

         * 感谢 architecture-components-samples 提供的思路
         *
         * 最原始的处理的方案 监听 Fragment 的生命周期,会存在 Fragment 和 Fragment 中的 View 生命周期不一致问题
         * 详情查看 [issue][https://github.com/hi-dhl/Binding/issues/15]
         */
        fragment.lifecycle.observerWhenCreated {
            fragment.viewLifecycleOwnerLiveData.observe(fragment) { viewOwner ->
                viewOwner.lifecycle.observerWhenDestroyed {
                    viewBinding = null
                }
            }
        }

Issue-Fragment生命周期监听方法不正确 我想知道Scene是否也要考虑到同样的问题,如果有的话应该在哪个时机去执行viewBinding的回收操作呢

qii commented 3 years ago

Scene 没这问题,只有一套 Lifecycle,Support Fragment 实际上有两套 Lifecycle,View 和 Fragment 本身