{"id":37022868,"url":"https://github.com/pubiqq/lifecycleprops","last_synced_at":"2026-01-14T02:44:22.139Z","repository":{"id":57734541,"uuid":"477332221","full_name":"pubiqq/lifecycleprops","owner":"pubiqq","description":"Property delegates that enable you to associate properties with lifecycle-aware components.","archived":false,"fork":false,"pushed_at":"2025-06-18T18:46:28.000Z","size":492,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-18T19:44:48.222Z","etag":null,"topics":["android","android-library","android-lifecycle","autocleared","lifecycle","lifecycle-aware","lifecycleprops","viewbinding"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pubiqq.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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,"zenodo":null}},"created_at":"2022-04-03T12:17:18.000Z","updated_at":"2025-06-18T18:42:49.000Z","dependencies_parsed_at":"2024-01-22T16:33:50.086Z","dependency_job_id":"cce61249-0b32-4c61-82e2-845e006497e4","html_url":"https://github.com/pubiqq/lifecycleprops","commit_stats":{"total_commits":31,"total_committers":1,"mean_commits":31.0,"dds":0.0,"last_synced_commit":"9684da87eef2d0ed6cfbcdee1756602466b38554"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/pubiqq/lifecycleprops","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pubiqq%2Flifecycleprops","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pubiqq%2Flifecycleprops/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pubiqq%2Flifecycleprops/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pubiqq%2Flifecycleprops/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pubiqq","download_url":"https://codeload.github.com/pubiqq/lifecycleprops/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pubiqq%2Flifecycleprops/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408733,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T01:52:23.358Z","status":"online","status_checked_at":"2026-01-14T02:00:06.678Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["android","android-library","android-lifecycle","autocleared","lifecycle","lifecycle-aware","lifecycleprops","viewbinding"],"created_at":"2026-01-14T02:44:21.444Z","updated_at":"2026-01-14T02:44:22.127Z","avatar_url":"https://github.com/pubiqq.png","language":"Kotlin","readme":"\u003ch1 align=\"center\"\u003eLifecycleProps\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"LICENSE.txt\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-Apache%202.0-blue?style=flat\" alt=\"Apache-2.0 License\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://developer.android.com/about/versions/lollipop\"\u003e\u003cimg src=\"https://img.shields.io/badge/Android-21%2B-brightgreen?style=flat\" alt=\"API 21+\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://search.maven.org/artifact/io.github.pubiqq/lifecycleprops\"\u003e\u003cimg src=\"https://img.shields.io/maven-central/v/io.github.pubiqq/lifecycleprops?style=flat\u0026label=Maven%20Central\u0026color=orange\" alt=\"Available on Maven Central\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.jetbrains.com/kotlin-multiplatform/\"\u003e\u003cimg src=\"https://img.shields.io/badge/Kotlin-Multiplatform-%237f52ff?logo=kotlin\" alt=\"Kotlin Multiplatform\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003eProperty delegates that enable you to associate properties with \u003ca href=\"https://developer.android.com/topic/libraries/architecture/lifecycle\"\u003elifecycle-aware components\u003c/a\u003e.\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"./assets/banner.png\" width=\"540\" alt=\"\" /\u003e\n\u003c/p\u003e\n\n## Setup\n\nAdd dependency to the module-level `build.gradle` file:\n\n```kotlin\ndependencies {\n    implementation(\"io.github.pubiqq:lifecycleprops:latest.release\")\n}\n```\n\nMake sure you have `mavenCentral()` repository in the list of repositories.\n\n## Usage\n\n### Lifecycle-aware delegates\n\nTo associate a property to the lifecycle of a `LifecycleOwner` object (such as `AppCompatActivity`, `Fragment`,\n`NavBackStackEntry`, etc.), use the `lifecycleAware` function:\n\n```kotlin\nclass MyActivity : AppCompatActivity() {\n\n    // Associates the read-only property with the `MyActivity` lifecycle\n    val locationService: MyLocationService by lifecycleAware(\n        initializer = { MyLocationService(context, locationCallback) },\n        onStart = { start() },\n        onStop = { stop() }\n    )\n\n    // Associates the read/write property with the `MyActivity` lifecycle\n    var banner: MyBanner by lifecycleAware(\n        onStart() = { start() },\n        onResume() = { resume() },\n        onPause() = { pause() },\n        onStop() = { stop() }\n    )\n\n    // ...\n\n    banner = MyBanner.Builder(context).build()  // manual initialization of the read/write property\n}\n```\n\nTo associate a property with the `Fragment`'s view lifecycle, use `viewLifecycleAware`:\n\n```kotlin\nclass MyFragment : Fragment() {\n\n    // Associates the read-only property with the `MyFragment`'s view lifecycle\n    val locationService: MyLocationService by viewLifecycleAware(\n        initializer = { MyLocationService(context, locationCallback) },\n        onStart = { start() },\n        onStop = { stop() }\n    )\n\n    // Associates the read/write property with the `MyFragment`'s view lifecycle\n    var banner: MyBanner by viewLifecycleAware(\n        onStart() = { start() },\n        onResume() = { resume() },\n        onPause() = { pause() },\n        onStop() = { stop() }\n    )\n\n    // ...\n\n    banner = MyBanner.Builder(context).build()  // manual initialization of a read/write property\n}\n```\n\n### Custom configurations\n\n\u003e [!IMPORTANT]\n\u003e The API that provides configurations support for lifecycle-aware delegates is marked with the\n\u003e `ExperimentalConfigurationApi` annotation.\n\u003e\n\u003e Usages of such API will be reported as warnings unless an explicit opt-in with the `OptIn` annotation, e.g.\n\u003e `@OptIn(ExperimentalConfigurationApi::class)`, or with the\n\u003e `-opt-in=com.pubiqq.lifecycleprops.ExperimentalConfigurationApi` compiler option is given.\n\nBy default, lifecycle-aware delegates for read-only properties:\n\n- Lazily initialize the associated property.\n- Close (if [`AutoCloseable`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-auto-closeable/#autocloseable)) and\n  null out the property value when an `ON_DESTROY` event occurs.\n\nLifecycle-aware delegates for read/write properties:\n\n- Ensure that a value will not be reassigned to an already initialized property (otherwise an\n  [`IllegalStateException`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/#illegalstateexception)\n  will be thrown).\n- Ensure that each provided event handler will be invoked for the property (otherwise an\n  [`IllegalStateException`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/#illegalstateexception)\n  will be thrown).\n- Close (if [`AutoCloseable`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-auto-closeable/#autocloseable)) and\n  null out the property value when an `ON_DESTROY` event occurs.\n\nIf you want to change the behavior of the lifecycle-aware property, you can specify your own custom configuration:\n\n```kotlin\n@file:OptIn(ExperimentalConfigurationApi::class)\n\n// Custom configuration for read-only properties\nclass MyLifecycleAwareReadOnlyConfiguration\u003cin T : Any\u003e : LifecycleAwareReadOnlyConfiguration\u003cT\u003e {\n\n    override val initializationStrategy: LifecycleAwareInitializationStrategy =\n        LifecycleAwareInitializationStrategy.OnAnyAccess\n\n    override val allowSkipHandlerAccessToUninitializedProperty: Boolean = false\n\n    override val shouldNullOutTheProperty: Boolean = true\n\n    override fun onClear(value: T) = Unit\n}\n\n// Custom configuration for read/write properties\nclass MyLifecycleAwareReadWriteConfiguration\u003cin T : Any\u003e : LifecycleAwareReadWriteConfiguration\u003cT\u003e {\n\n    override val allowReassign: Boolean = true\n\n    override val allowSkipHandlerAccessToUninitializedProperty: Boolean = true\n\n    override val shouldNullOutTheProperty: Boolean = true\n\n    override fun onClear(value: T) = Unit\n}\n```\n\nand apply it to the target property:\n\n```kotlin\n@file:OptIn(ExperimentalConfigurationApi::class)\n\nclass MyActivity : AppCompatActivity() {\n\n    // Associates the read-only property with the `MyActivity` lifecycle (`MyLifecycleAwareReadOnlyConfiguration` is used)\n    val locationService: MyLocationService by lifecycleAware(\n        configuration = MyLifecycleAwareReadOnlyConfiguration(),\n        initializer = { MyLocationService(context, locationCallback) },\n        onStart = { start() },\n        onStop = { stop() }\n    )\n\n    // Associates the read/write property with the `MyActivity` lifecycle (`MyLifecycleAwareReadWriteConfiguration` is used)\n    var banner: MyBanner by lifecycleAware(\n        configuration = MyLifecycleAwareReadWriteConfiguration(),\n        onStart() = { start() },\n        onResume() = { resume() },\n        onPause() = { pause() },\n        onStop() = { stop() }\n    )\n\n    // ...\n\n    banner = MyBanner.Builder(context).build()  // manual initialization of the read/write property\n}\n```\n\nAlso, you can set configurations globally, in which case they will be applied to lifecycle-aware properties by default:\n\n```kotlin\n@file:OptIn(ExperimentalConfigurationApi::class)\n\nwith(LifecycleProps) {\n    // Sets default configurations for lifecycle-aware properties\n    setLifecycleAwareConfigurations(\n        readOnlyPropsConfiguration = MyLifecycleAwareReadOnlyConfiguration(),\n        readWritePropsConfiguration = MyLifecycleAwareReadWriteConfiguration()\n    )\n}\n\nwith(LifecyclePropsAndroid) {\n    // Sets default configurations for Android-specific lifecycle-aware properties\n    setViewLifecycleAwareConfigurations(\n        readOnlyPropsConfiguration = MyLifecycleAwareReadOnlyConfiguration(),\n        readWritePropsConfiguration = MyLifecycleAwareReadWriteConfiguration()\n    )\n}\n```\n\n## Samples\n\nCheck out the [sample](https://github.com/pubiqq/lifecycleprops/tree/main/sample) project to see the library in action.\nAlso see:\n\n- [AutoCleared](./docs/AutoCleared.md)\n- [ViewBinding delegates](./docs/ViewBindingDelegates.md)\n\n## License\n\n    Copyright 2021 pubiqq\n    \n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n    \n        http://www.apache.org/licenses/LICENSE-2.0\n    \n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpubiqq%2Flifecycleprops","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpubiqq%2Flifecycleprops","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpubiqq%2Flifecycleprops/lists"}