xamarin / AndroidSupportComponents

Xamarin bindings for Android Support libraries - For AndroidX see https://github.com/xamarin/AndroidX
MIT License
146 stars 56 forks source link

Bindings for android.arch.lifecycle:extensions:1.0.0 #76

Closed cosminstirbu closed 6 years ago

cosminstirbu commented 6 years ago

Hi,

I am looking for the ViewModelProvider class in Xamarin.Android.Arch.* namespaces but I can't seem to find it.

It seems to me like it should be the preferred way of tying the C# ViewModel lifecycle to the Activity / Fragment's lifecycle.

Or how do you guys usually handle the ViewModel's lifecycle and the Activity / Fragment's lifecycle?

Thank you, Cosmin

cosminstirbu commented 6 years ago

Hmm, or maybe I'm wrong, since the get(Class<T> modelClass) methods return a T that extends ViewModel - and we wouldn't want that in our shared code.

Still, it feels that these new architecture components classes can be leveraged to better handle the view model's lifecycle and the activity's/fragment lifecycle.

theladyjaye commented 6 years ago

What's the verdict on this? I was looking for ViewModelProvider as well and it doesn't seemed to be in the bindings yet. Did I miss it or it's just not there yet?

cosminstirbu commented 6 years ago

Also, coming back to the remark that get(Class<T> modelClass) returns a T that extends ViewModel - we can still create a subclass of the Android ViewModel that holds a reference to the .NET ViewModel so we can still leverage the ViewModelProvider.

cosminstirbu commented 6 years ago

@Redth - I was able to create my own bindings on top of android.arch.lifecycle:extensions:1.0.0 in a sample project and reference them in a sample Xamarin.Android project.

I was looking into opening a PR, but when I run ./build.sh on master branch I receive the following build errors:

"/Users/cosminstirbu/AndroidSupportComponents/AndroidSupport.sln" (Build target) (1) ->
"/Users/cosminstirbu/AndroidSupportComponents/support-v13/source/V13.csproj" (default target) (2) ->
"/Users/cosminstirbu/AndroidSupportComponents/support-compat/source/Compat.csproj" (default target) (3:2) ->
(CoreCompile target) -> 
  obj/Release/generated/src/Android.Support.V4.App.NotificationCompat.cs(302,24): error CS0534: 'NotificationCompat.Action' does not implement inherited abstract member 'NotificationCompatBase.Action.GetDataOnlyRemoteInputs()' [/Users/cosminstirbu/AndroidSupportComponents/support-compat/source/Compat.csproj]
  obj/Release/generated/src/Android.Support.V4.App.NotificationCompat.cs(302,24): error CS0534: 'NotificationCompat.Action' does not implement inherited abstract member 'NotificationCompatBase.Action.GetRemoteInputs()' [/Users/cosminstirbu/AndroidSupportComponents/support-compat/source/Compat.csproj]

    96473 Warning(s)
    2 Error(s)

Should I fork a different branch in order to create the PR? The Contribution Guidelines suggests using dev branch, but the dev branch seems really outdated.

I'd really like these bindings to be part of the Xamarin packages, so if you can help make some progress on this I'd really appreciate it.

Thank you, Cosmin

Redth commented 6 years ago

Thanks Cosmin, are you running on the stable Xamarin channel? master should be where you PR against (will have to update the contributing.md, forgot it still mentions dev). In any case, that error probably happens because of latest stable (I'm reverting to stable to check and see that it compiles there, and if not, I'll be sure to push some fixes to get master compiling on latest stable).

We decided to only bind the small subset of Architecture Component libraries that are required dependencies by other support libraries for now. We haven't seen a lot of demand for the Architecture Components as there are a number of alternative and more cross platform ways to do data binding in .NET. Not against adding them by any means, they just haven't been a priority yet.

cosminstirbu commented 6 years ago

Hi,

Yes, I am running the latest stable Xamarin channel.

You are right - most of the Architecture Component libraries are not really necessary on .NET. The piece I think is indeed needed is the ViewModelProvider which helps handling the relation between a ViewModel's lifecycle and a Activity / Fragment lifecycle, especially taking into account Activity recreation during configuration changes (such as screen rotation).

I'll wait for master to work again against latest stable and after that I'll continue working on the PR.

Thank you, Cosmin

Redth commented 6 years ago

@cosminstirbu you can try master now, it should compile against the latest stable Xamarin.Android.

loki666 commented 6 years ago

is there a planned release of Xamarin.Android.Arch.Lifecycle.Runtime 1.0.3 on NuGet ? TIA

sillerjp commented 6 years ago

Hi,

I'm creating a Xamarin binding project and I'm getting: Didn't find class "android.arch.lifecycle.ViewModelProviders" when inflating a view.

I do have all Arch packages installed. Is this something that is not included in the packages? Any suggestions to get around this?

Thanks

tuyen-vuduc commented 6 years ago

@loki666 I think you noticed there is a prelease version of Xamarin.Android.Arch.Lifecycle.Runtime 1.0.3

@JPSiller I think you should provide more details your issue, a sample repo will be great.

Cheers.

newky2k commented 6 years ago

@loki666 Xamarin.Android.Arch.Lifecycle.Runtime is now at version 1.0.3.1

@JPSiller if you are still having this issue could you please provide a sample

sillerjp commented 6 years ago

@newky2k I'm not currently working on that project but I may start developing the binding library again in the following weeks, I'll keep you posted.

newky2k commented 6 years ago

@JPSiller ok cool. if this is still an issue i can reopen it