Kotlin. error: Event fields must be declared as public non-final.
- Dominant language
- Kotlin
- Stars
- 7.8k
- Forks
- 768
- PR merge metrics
- No merged PRs in 30d
Description
- [x] I have searched [existing issues](https://github.com/facebook/litho/issues) and this is not a duplicate
## Version
```gradle
implementation "com.facebook.soloader:soloader:0.6.0"
// ext.litho_version = '0.32.0'
implementation "com.facebook.litho:litho-core:$litho_version"
implementation "com.facebook.litho:litho-widget:$litho_version"
kapt "com.facebook.litho:litho-processor:$litho_version"
implementation "com.facebook.litho:litho-fresco:$litho_version"
implementation "com.facebook.litho:litho-sections-core:$litho_version"
implementation "com.facebook.litho:litho-sections-widget:$litho_version"
compileOnly "com.facebook.litho:litho-sections-annotations:$litho_version"
kapt "com.facebook.litho:litho-sections-processor:$litho_version"
```
## Issues and Steps to Reproduce
**Create a Kotlin Custom Event**
```kotlin
import com.facebook.litho.annotations.Event
@Event
class StorefrontRowMinimizedEvent(
var storefrontRowId: String = ""
)
```
**Use this event in a Spec**
```kotlin
@LayoutSpec(events = [StorefrontRowMinimizedEvent::class])
object StorefrontItemComponentSpec {
private const val TAG : String = "StorefrontItem"
```
**You will see error**
```
Event fields must be declared as public non-final.
private java.lang.String storefrontRowId;
^
```
**This is how it was compiled in Java**
```java
import java.lang.System;
@com.facebook.litho.annotations.Event()
@kotlin.Metadata(...)
public final class StorefrontRowMinimizedEvent {
@org.jetbrains.annotations.NotNull()
private java.lang.String storefrontRowId;
@org.jetbrains.annotations.NotNull()
public final java.lang.String getStorefrontRowId() {
return null;
}
public final void setStorefrontRowId(@org.jetbrains.annotations.NotNull()
java.lang.String p0) {
}
public StorefrontRowMinimizedEvent(@org.jetbrains.annotations.NotNull()
java.lang.String storefrontRowId) {
super();
}
public StorefrontRowMinimizedEvent() {
super();
}
}
```
**Special emphasis on**
```java
@org.jetbrains.annotations.NotNull()
private java.lang.String storefrontRowId;
```
## Expected Behavior
**This should have been public because, in Kotlin, everything is public by default. Also, even if you mark it public it's still private 😢. The output should be something like this:**
```java
@org.jetbrains.annotations.NotNull()
public java.lang.String storefrontRowId;
```
**Workaround for now. Use Java**
```java
import com.facebook.litho.annotations.Event;
@Event
public class StorefrontItemSelectedEvent {
public String StorefrontItemId;
}
```
## Link to Code
Intentionally not added because this is fairly easy to reproduce.
***Please show some code we can use to reproduce this issue. Consider using [PlaygroundComponentSpec](https://github.com/facebook/litho/blob/master/sample/src/main/java/com/facebook/samples/litho/playground/PlaygroundComponentSpec.java) to provide a small example of the issue***
Contributor guide
Assessment
This issue has not been assessed yet.