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

Suggestion: Use View Binding instead of synthetic binding and findViewById #1088

Closed
thatfiredev opened this issue Mar 26, 2020 · 9 comments · Fixed by #1096
Closed

Suggestion: Use View Binding instead of synthetic binding and findViewById #1088

thatfiredev opened this issue Mar 26, 2020 · 9 comments · Fixed by #1096

Comments

@thatfiredev
Copy link
Member

(Our bot will not be happy with this issue)

Now that we're using Gradle 3.6.1, we could enable View Binding on our samples. Two reasons why I would recommend this change:

  • Kotlin synthetic binding is not recommended;
  • ViewBinding removes the need for findViewById, which would make our app implementation simpler, since it's meant for demonstration purposes.
@google-oss-bot
Copy link

This issue does not seem to follow the issue template. Make sure you provide all the required information.

@samtstern
Copy link
Contributor

@rosariopfernandes oh that's really cool! I had no idea this was available. I never liked Kotlin synthetic binding but I was trying to be one of the Kotlin Cool Kids 😎

@thatfiredev
Copy link
Member Author

Hahah, I see. Does that mean this is a go?

@samtstern
Copy link
Contributor

samtstern commented Mar 26, 2020 via email

@thatfiredev
Copy link
Member Author

ViewBinding is included in 3.6.1 stable. No need to use any alpha/beta tools.

@samtstern
Copy link
Contributor

samtstern commented Mar 26, 2020 via email

@gaglileo
Copy link

I have noticed that using ViewBinding, the camera in Kotlin MLKit sample app is finally working

@thatfiredev
Copy link
Member Author

@samtstern As I was implementing this, I noticed that some of our layouts only contain a single view (e.g. analytics/fragment_main.xml). I think for these cases it's simpler to use findViewById() instead of View Binding, since the number of lines will remain the same and we'll actually have less binding classes being generated by the plugin during build.
Unless we want to use View Binding in all views for consistency. WDYT?

@samtstern
Copy link
Contributor

@rosariopfernandes I don't have a strong opinion here, I think either choice you could make for a single-view layout is a reasonable one! Whatever you think looks best as you implement is fine with me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants