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

Question regarding Delegated Property deprecation #66

Open
AlexTrotsenko opened this issue Nov 23, 2023 · 2 comments
Open

Question regarding Delegated Property deprecation #66

AlexTrotsenko opened this issue Nov 23, 2023 · 2 comments

Comments

@AlexTrotsenko
Copy link

AlexTrotsenko commented Nov 23, 2023

I have noticed, that now Delegated Property are marked as Deprecated in the Readme's Overview:
https://github.com/wada811/ViewBinding-ktx/blob/master/README.md#overview

But looks like it's the only place where it's done. In the Delegated Property section below or in the source code they are not marked as Depricated either.

If they are deprecated - I am wondered what's the reason? Is it because of the IllegalStateException in the Fragment case?
If so - what is the current and the future state of these api?
Are you planing to remove them or make @RequiresOptIn ?

Btw, I am wondered if approach of using Delegated Property with Fragments has any draw-backs comparing to using the official approach described at https://developer.android.com/topic/libraries/view-binding#fragments

P.S. I acknowledge, that withBinding approach is obviously preferable solution for the new Activities/Fragments, but migrating to it in the old classes might be an effort depending on the side of the code base.

@wada811
Copy link
Owner

wada811 commented Nov 24, 2023

The deprecation statement in the Readme might be too strong.
As you may have noticed, the Delegated Property was temporarily marked as @Deprecated because the withBinding approach was the preferred solution. However, due to the high migration cost for older classes, the decision to officially deprecate it was reconsidered.

The reason for deprecation is the IllegalStateException in the case of Fragments. However, there are no plans to remove, mark as @Deprecated, or use @RequiresOptIn for Delegated Properties, considering the high migration cost.

Comparing Delegated Property with the official approach, there are few drawbacks to using Delegated Property. If there is a possibility of accessing the binding outside the onCreateView and onDestroyView methods, in the official approach, you would use the _binding variable. However, with Delegated Property, using the binding variable casually might lead to a more frequent occurrence of IllegalStateException.

It's worth noting that even in the official approach, if you use the binding variable without considering the IllegalStateException, a similar exception can occur. Therefore, I don't believe the drawbacks of Delegated Property are significant.

@wada811
Copy link
Owner

wada811 commented Nov 24, 2023

I would like to write withBinding as recommended. And I think I'll stop marking Delegated Property as deprecated in the Readme.

wada811 added a commit that referenced this issue Nov 24, 2023
Question regarding Delegated Property deprecation
#66
wada811 added a commit to wada811/DataBinding-ktx that referenced this issue Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants