Open Alex009 opened 3 years ago
annotation class MRmapping
annotation class MRname(val name: String)
(!) names should be improved
@MRmapping
interface Strings {
@MRname("unknown_error")
val unknownError: StringResource
}
connect plugin to module, which have access to MR. plugin will generate for all annotated interfaces (from all modules, not only umbrella module) function:
private fun MR.mapping(): ListViewModel.Strings {
return object: ListViewModel.Strings {
override val unknownError: StringResource
get() = MR.strings.unknown_error
}
}
and we can use already generated proxy:
val viewModel = MyViewModel(strings = MR.mapping())
interfaces should work with all resource types
annotation processing - https://github.com/google/ksp/blob/master/docs/quickstart.md
can be useful - https://github.com/Tetraquark/KSP-Testing
By the way, you should consider generating the implementation which can switch resources in runtime during configuration changes, for example, as described at https://github.com/icerockdev/moko-resources/issues/201#issuecomment-922340943. cc @Nailik
In multi-module projects with injection of resources from umbrella module (like https://github.com/icerockdev/moko-template) we have this separation:
feature module
:umbrella module (mpp-library
- containsresources
and generateMR
class:and when we should pass many resources to feature module we do routine work with creating proxy anonymous object.