facebook / litho

A declarative framework for building efficient UIs on Android.
https://fblitho.com
Apache License 2.0
7.71k stars 766 forks source link

[meta-task] Kotlin outstanding issues #267

Closed passy closed 4 months ago

passy commented 7 years ago

This issue is to keep track of remaining issues and where applicable work-arounds when using Litho with Kotlin.

Issues

Other Gotchas

Future work

We should consider generating Kotlin code to fully leverage the new language features like data classes, allow for Anko-like DSLs and get rid of builders.

pavlospt commented 7 years ago

@passy @PropDefault does not work for which cases? Is there a branch with Kotlin sample available?

passy commented 7 years ago

@pavlospt I'm working on fixing that today. I think Pasquale's Kotlin sample could use this in a spot.

pavlospt commented 7 years ago

@passy Have you tried @get:PropDefault val something = 1f for example ?

passy commented 7 years ago

@pavlospt Sadly, that generates even worse code for us at the moment. I've got a work-around ready with a long-ish explanation on the commit which should land probably tomorrow.

pavlospt commented 7 years ago

Ok, great! Will wait to check that commit tomorrow :) Please ping it here as well in case I miss it :P

passy commented 7 years ago

@pavlospt As if you'd ever miss a commit! 😜

pavlospt commented 7 years ago

@passy My colleagues usually say the same thing, no wonder why 😂

yanex commented 6 years ago

@passy What kind of bugs do you experience with kapt? If you can reproduce something going bad, please submit the issue to kotl.in/issue, and we will fix it shortly.

passy commented 6 years ago

@yanex Hey! Thanks for commenting here. :)

Sadly, the main problem for us has exactly been reproducible. Everyone on our team who's worked with this has found themselves in a situation where compilation would fail for seemingly random reasons and only clearing the caches would help.

In particular, we've seen NonExistentClass in stubs appear at times. Again, one ./gradlew clean and it would be gone, but it can lead to some quite frustrating development cycles where you think you made a mistake in the codegen, but it turns out to be non-determinism in kapt.

If I see a reproducible case, I will definitely send it your way. :)

pasqualeanatriello commented 6 years ago

I would add that the main issue there is that gradle clean and rebuild makes the development cycle really too slow 😢

yanex commented 6 years ago

@passy Please check if you use the new version of kapt (aka kapt3, you can find the setup instructions here https://kotlinlang.org/docs/reference/kapt.html).

The original kapt definitely had architectural problems that led to random NonExistentClass errors, that is why it is deprecated now (and will be removed in Kotlin 1.2.20). If you experience NonExistingClass errors with apply plugin: 'kotlin-kapt', then it is something new.

yanex commented 6 years ago

@pasqualeanatriello Kotlin incremental compilation does not support changes in Java files yet. So whenever the annotation processor generates the different .java source, Kotlin recompiles much more files that it is needed. Hopefully, we are already working on this, and we hope things will become much better very soon.

passy commented 6 years ago

If you experience NonExistingClass errors with apply plugin: 'kotlin-kapt', then it is something new.

Yes, it was with kotlin-kapt. The old one didn't seem to work for us at all. We rely on annotated source files being able to reference the generated files based on them. It seemed like this wasn't support with the old kapt, but works with the new.

I didn't know about the correctErrorTypes = true option, though. Perhaps that could help us track this down if it should come up again.

kar commented 6 years ago

What's the status on this? Is it feasible to use litho with Kotlin in a real life project currently?

pavlospt commented 6 years ago

Hey @kar , you can find Kotlin-powered samples inside the repository! Check sample-barebones-kotlin and sample-kotlin for more details :)

pavlospt commented 6 years ago

@passy I think it can be closed and also remove the IMPORTANT notice from this doc: https://github.com/facebook/litho/blob/master/docs/_docs/getting-started/gradle-kt.md

passy commented 6 years ago

I'll update the comment. As long as we don't use it in production internally, I think it's best to keep the note there to set the right expectations.

pavlospt commented 6 years ago

@passy sure sounds reasonable!

yschimke commented 6 years ago

I made a bad judgement call of adopting https://github.com/vinc3m1/litho-kotlin, but it had really nice results. I hope you guys bring it back as an official DSL sooner rather than later.

colriot commented 4 years ago

Will not close this one for now, but wanted to bring this to your attention: https://github.com/facebook/litho/blob/master/sample-kotlin/src/main/kotlin/com/facebook/samples/litho/kotlin/lithography/components/FavouriteButton.kt To use that you need to add litho-core-kotlin and maybe litho-widget-kotlin to your build.gradle file.

cc @yschimke