Giter Club home page Giter Club logo

Comments (4)

XiongKe94 avatar XiongKe94 commented on May 28, 2024

FragmentViewBinding 里面代码为
`class FragmentViewBinding(
classes: Class,
fragment: Fragment
) : FragmentDelegate(fragment) {

private val layoutInflater = classes.inflateMethod()
private val bindView = classes.bindMethod()

override fun getValue(thisRef: Fragment, property: KProperty<*>): T {
    return viewBinding?.run {
        return this

    } ?: let {

        try {
            /**
             * 检查目的,是为了防止在 onCreateView() or after onDestroyView() 使用 binding。
             * 另外在销毁之后,如果再次使用,由于 delegate property 会被再次初始化出现的异常
             *
             * 捕获这个异常的原因,是为了兼容之前的版本,防止因为升级,造成崩溃
             */
            check(thisRef.viewLifecycleOwner.lifecycle.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) {
                "cannot use binding in before onCreateView() or after onDestroyView() from 1.1.4. about [issue](https://github.com/hi-dhl/Binding/issues/31#issuecomment-1109733307)"
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }


        val bind: T
        if (thisRef.view == null) {
            // 这里为了兼容在 navigation 中使用 Fragment
            bind = layoutInflater.invoke(null, thisRef.layoutInflater) as T
        } else {
            bind = bindView.invoke(null, thisRef.view) as T

        }

        return bind.apply { viewBinding = this }
    }
}

}`

from binding.

hi-dhl avatar hi-dhl commented on May 28, 2024

收到,能贴一下,使用这部分的代码吗

from binding.

XiongKe94 avatar XiongKe94 commented on May 28, 2024

你说的是调用的时候吗? 就是正常调用呀

from binding.

XiongKe94 avatar XiongKe94 commented on May 28, 2024

手机多次运行也不会报错,这个错误是在GP后台看到的。

from binding.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.