Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convenient Jetpack compose call #126

Closed
ln-12 opened this issue Dec 1, 2020 · 2 comments
Closed

Convenient Jetpack compose call #126

ln-12 opened this issue Dec 1, 2020 · 2 comments
Assignees
Labels
documentation Improvements or additions to documentation
Milestone

Comments

@ln-12
Copy link

ln-12 commented Dec 1, 2020

In Jetpack compose, you can do something like text = stringResource(id = R.string.email) inside a composable which uses ContextAmbient inside. For now, with this plugin, the code would look something like text = getMyString().toString(context = ContextAmbient.current.applicationContext). Moreover, I would have to write a function for each string resource as I can't access them like in R.string.something. Is there a more convenient way of doing it?

@Alex009
Copy link
Member

Alex009 commented Dec 1, 2020

hi @ln-12 ! your sample getMyString().toString(context = ContextAmbient.current.applicationContext) use StringDesc, but for your case text = stringResource(id = R.string.email) you need StringResource.
in MR class generated by plugin you have MR.strings with StringResource fields - for android in StringResource you have field resourceId. so you can just call text = stringResource(id = MR.strings.email.resourceId)

for better support of StringDesc in Compose i think we should add later support module where work with ContextAmbient will be inbox

@ln-12
Copy link
Author

ln-12 commented Dec 1, 2020

Ah cool, the hint text = stringResource(id = MR.strings.email.resourceId) did the trick. That's much better, thanks. Is this stated in the readme? If not I think it would be a great idea to mention this method for the use with compose :)

@Alex009 Alex009 added the documentation Improvements or additions to documentation label Dec 5, 2020
@Alex009 Alex009 added this to the 0.13.2 milestone Dec 5, 2020
@Alex009 Alex009 modified the milestones: 0.13.2, 0.13.3, 0.14.0 Dec 15, 2020
@Alex009 Alex009 self-assigned this Dec 29, 2020
@Alex009 Alex009 closed this as completed Jan 3, 2021
@Alex009 Alex009 mentioned this issue Jan 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants