{"id":19447467,"url":"https://github.com/neophron88/viewbinding-delegate","last_synced_at":"2025-02-25T08:47:46.467Z","repository":{"id":100618436,"uuid":"554285015","full_name":"neophron88/ViewBinding-Delegate","owner":"neophron88","description":null,"archived":false,"fork":false,"pushed_at":"2023-03-12T15:04:42.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-01-07T23:15:50.897Z","etag":null,"topics":["viewbinding-delegate"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/neophron88.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-19T14:55:52.000Z","updated_at":"2022-10-19T15:17:46.000Z","dependencies_parsed_at":"2023-05-16T09:00:25.438Z","dependency_job_id":null,"html_url":"https://github.com/neophron88/ViewBinding-Delegate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neophron88%2FViewBinding-Delegate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neophron88%2FViewBinding-Delegate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neophron88%2FViewBinding-Delegate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neophron88%2FViewBinding-Delegate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neophron88","download_url":"https://codeload.github.com/neophron88/ViewBinding-Delegate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240636666,"owners_count":19832922,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["viewbinding-delegate"],"created_at":"2024-11-10T16:18:07.482Z","updated_at":"2025-02-25T08:47:46.437Z","avatar_url":"https://github.com/neophron88.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ViewBindingDelegate\n\nA delegate that makes it easier to work with [Android View Binding](https://d.android.com/topic/libraries/view-binding).  \n\nTo enable view binding, set the viewBinding build option to true in the module-level build.gradle file, as shown in the following example:\n\n```groovy\nandroid {\n    buildFeatures {\n        viewBinding true\n    }\n}\n```\nPlease note that you need to copy the source code to work with the delegate, because it's not currently in some repository.\n\n## Fragment sample\n\n###\tThe usual way -\n\n```kotlin\nclass SampleFragment : Fragment() {\n\n    private var _binding: FragmentSampleBinding? = null\n    private val binding get() = _binding!!\n\n    override fun onCreateView(\n        inflater: LayoutInflater,\n        container: ViewGroup?,\n        savedInstanceState: Bundle?\n    ): View {\n        _binding = FragmentSampleBinding.inflate(inflater, container, false)\n        return binding.root\n    }\n\n    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {\n        super.onViewCreated(view, savedInstanceState)\n\n        with(binding) {\n            textView.text = \"Some text\"\n            button.setOnClickListener {\n                //some action\n            }\n        }\n\n    }\n\n    override fun onDestroyView() {\n        super.onDestroyView()\n        _binding = null\n    }\n\n}\n```\n###\tWith the delegate\n\nThe delegate considers fragment's view lifecycle, clears the reference when current view is destroyed and prevent memory leaks.\n\n```kotlin\nclass ListFragment : Fragment(R.layout.fragment_sample) {\n\n    private val binding: FragmentSampleBinding by viewBindings()\n\n    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {\n        super.onViewCreated(view, savedInstanceState)\n\n        with(binding) {\n            textView.text = \"Some text\"\n            button.setOnClickListener {\n                //some action\n            }\n        }\n    }\n```\n\n## Activity sample\n\n```kotlin\nclass MainActivity : AppCompatActivity() {\n\n    private val binding: ActivityMainBinding by viewBindings()\n\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        setContentView(binding.root)\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneophron88%2Fviewbinding-delegate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneophron88%2Fviewbinding-delegate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneophron88%2Fviewbinding-delegate/lists"}