https://github.com/cashapp/InflationInject
Constructor-inject views during XML layout inflation
https://github.com/cashapp/InflationInject
Last synced: 12 months ago
JSON representation
Constructor-inject views during XML layout inflation
- Host: GitHub
- URL: https://github.com/cashapp/InflationInject
- Owner: cashapp
- License: apache-2.0
- Archived: true
- Created: 2017-06-12T18:13:08.000Z (almost 9 years ago)
- Default Branch: trunk
- Last Pushed: 2023-10-17T18:28:37.000Z (over 2 years ago)
- Last Synced: 2024-05-21T15:19:55.887Z (almost 2 years ago)
- Language: Kotlin
- Homepage:
- Size: 583 KB
- Stars: 905
- Watchers: 28
- Forks: 55
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-list - cashapp/InflationInject - Constructor-inject views during XML layout inflation (Kotlin)
README
# Inflation Injection
**Attention**: This tool is now deprecated. Please switch to
[Compose UI](https://developer.android.com/jetpack/compose) or manually pass dependencies
to the legacy view system. Existing versions will also continue to work, but feature
development and bug fixes have stopped.
---
Constructor-inject views during XML layout inflation.
Looking for Assisted Inject? It's [built in to Dagger now](https://dagger.dev/dev-guide/assisted-injection.html)!
## Usage
Write your layout XML like normal.
```xml
```
Use `@InflationInject` in `CustomView`:
```java
public final class CustomView extends View {
private final Picasso picasso;
@InflationInject
public CustomView(
@Inflated Context context,
@Inflated AttributeSet attrs,
Picasso picasso
) {
super(context, attrs);
this.picasso = picasso;
}
// ...
}
```
In order to allow Dagger to create your custom views, add `@InflationModule` to a Dagger module and
add the generated module name to its `includes=`.
```java
@InflationModule
@Module(includes = InflationInject_PresenterModule.class)
abstract class PresenterModule {}
```
The annotation processor will generate the `InflationInject_PresenterModule` for us. It will not be
resolved until the processor runs.
Finally, inject `InflationInjectFactory` and add it to your `LayoutInflater`.
```java
InflationInjectFactory factory = DaggerMainActivity_MainComponent.create().factory();
getLayoutInflater().setFactory(factory);
setContentView(R.layout.main_view);
```
## Download
```groovy
repositories {
mavenCentral()
}
dependencies {
implementation 'app.cash.inject:inflation-inject:1.0.1'
annotationProcessor 'app.cash.inject:inflation-inject-processor:1.0.1'
}
```
Snapshots of the development version are available in Sonatype's snapshots repository.
```groovy
repositories {
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
implementation 'app.cash.inject:inflation-inject:1.1.0-SNAPSHOT'
annotationProcessor 'app.cash.inject:inflation-inject-processor:1.1.0-SNAPSHOT'
}
```
# License
Copyright 2017 Square, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.