Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViewBindingProperty can't be shared between classes #16

Closed
yoobi opened this issue Sep 17, 2020 · 4 comments
Closed

ViewBindingProperty can't be shared between classes #16

yoobi opened this issue Sep 17, 2020 · 4 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@yoobi
Copy link

yoobi commented Sep 17, 2020

Hello, I've made the update to 1.2.0 but since then when I switch from a fragment to another fragment I get this error
I'm using databinding (not viewbinding) however I've enabled it in my gradle as in the README.

Here is my gradle:

buildFeatures {
        dataBinding = true
        viewBinding = true
    }

dependencies {
    implementation 'com.kirich1409.viewbindingpropertydelegate:viewbindingpropertydelegate:1.2.0'
    // To use only without reflection variants of viewBinding
    implementation 'com.kirich1409.viewbindingpropertydelegate:vbpd-noreflection:1.2.0'
}
java.lang.IllegalStateException: Instance of ViewBindingProperty can't be shared between classes
        at by.kirich1409.viewbindingdelegate.ViewBindingProperty.getValue(ViewBindingProperty.kt:29)
        at com.application.poc.ui.search.SearchFragment.getBinding(Unknown Source:7)
        at com.application.poc.ui.search.SearchFragment.onDestroyView(SearchFragment.kt:103)
        at androidx.fragment.app.Fragment.performDestroyView(Fragment.java:2909)
        at androidx.fragment.app.FragmentManager.destroyFragmentView(FragmentManager.java:1356)
        at androidx.fragment.app.FragmentManager.removeCancellationSignal(FragmentManager.java:742)
        at androidx.fragment.app.FragmentManager$2.onComplete(FragmentManager.java:370)
        at androidx.fragment.app.FragmentAnim$2$1.run(FragmentAnim.java:175)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6944)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Here is the code:

class SearchFragment: Fragment(R.layout.fragment_search) {

    private val binding: FragmentSearchBinding by viewBinding(FragmentSearchBinding::bind)
    private lateinit var searchAdapter: SearchAdapter
    private val viewModel: SearchViewModel by lazy {
        ViewModelProvider(this).get(SearchViewModel::class.java)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        searchAdapter = SearchAdapter()
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        setHasOptionsMenu(true)
        binding.lifecycleOwner = this
        binding.rvSearchHistory.adapter = searchAdapter

        viewModel.termList.observe(viewLifecycleOwner, {
            it?.let {
                if(it is Resource.Success) searchAdapter.submitList(it.data.map { searchEntity ->
                    searchEntity.searchText
                })
            }
        })
    }

    override fun onDestroyView() {
        super.onDestroyView()
        binding.rvSearchHistory.adapter = null
    }
}
@kirich1409 kirich1409 self-assigned this Sep 17, 2020
@kirich1409 kirich1409 added the bug Something isn't working label Sep 17, 2020
@kirich1409 kirich1409 modified the milestones: 1.2.0, 1.2.1 Sep 17, 2020
@kirich1409
Copy link
Collaborator

What version of Kotlin do you use?

@yoobi
Copy link
Author

yoobi commented Sep 17, 2020

I'm currently using Kotlin 1.4.10

@kirich1409
Copy link
Collaborator

The issue will be fixed in 1.2.1. The release will be available soon

@yoobi
Copy link
Author

yoobi commented Sep 17, 2020

Sure thanks a lot for your work and reactivity :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants