Coder Social home page Coder Social logo

Comments (7)

SwiftyWang avatar SwiftyWang commented on September 7, 2024 2

Normally we use DialogFragment like using a normal fragment. We create view in onCreateView and use views in onViewCreated (or onCreateView).
When use Fragment.viewBinding with viewBindingRootId . It will throw exception in Utils L46. Seems view hasn't added into dialog window. I checked androidx DialogFragment source code. It add view to dialog in onActivityCreated which after onCreateView and onViewCreated.

Now I am using viewBinding function without given rootViewId seems working.

After reading some source code, seems without given rootViewId, The lib will binding view from Fragment::requireView but with given rootViewId it will try to find view from dialog window. Internal logics in these two methods are different.

from viewbindingpropertydelegate.

outofdate avatar outofdate commented on September 7, 2024 2

Yeah, we got the same issue, as we are accessing bindings in onViewCreated. After some digging we find out the same reason - dialog window view is without our view, as it is added in onActivityCreated of DialogFragment.

from viewbindingpropertydelegate.

kirich1409 avatar kirich1409 commented on September 7, 2024 2

DialogFragment can be used as usual Fragment that will be added as View in layout or can be shown as Dialog. A ViewBinding require a View. I will think how it can be done better. Right now DialogFragment implementation isn't good a don't work everywhere. Let's discuss how to do that better

from viewbindingpropertydelegate.

kirich1409 avatar kirich1409 commented on September 7, 2024

Hi. I need to see code of the Fragment where you have the issue

from viewbindingpropertydelegate.

kirich1409 avatar kirich1409 commented on September 7, 2024

And stacktrace when crash occured

from viewbindingpropertydelegate.

nzeeei avatar nzeeei commented on September 7, 2024

Is there any reason why the author is finding the view in dialog view, not fragment view? Have the same issue

from viewbindingpropertydelegate.

rantianhua avatar rantianhua commented on September 7, 2024

@kirich1409 Maybe this way is better:

    val view = dialog?.findViewById<View>(viewBindingRootId)
    if (view != null) {
        return view
    }
    return requireView().requireViewByIdCompat(viewBindingRootId)

Find the view from the dialog at first, then find it from the fragment view.

from viewbindingpropertydelegate.

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.