CrossPlatformLiveData 1.0.1
See the version list below for details.
dotnet add package CrossPlatformLiveData --version 1.0.1
NuGet\Install-Package CrossPlatformLiveData -Version 1.0.1
<PackageReference Include="CrossPlatformLiveData" Version="1.0.1" />
paket add CrossPlatformLiveData --version 1.0.1
#r "nuget: CrossPlatformLiveData, 1.0.1"
// Install CrossPlatformLiveData as a Cake Addin #addin nuget:?package=CrossPlatformLiveData&version=1.0.1 // Install CrossPlatformLiveData as a Cake Tool #tool nuget:?package=CrossPlatformLiveData&version=1.0.1
CrossPlatformLiveData
Android LiveData inspired .NET implementation - lifecycle aware rx streams
CrossPlatformLiveData is a C# library inspired by Android Jetpack LiveData, intended for platform independent use with Xamarin and other cross platform frameworks.
CrossPlatformLiveData is a light weight solution to effective implementation of MVVM architecture pattern.
Features:
- Rx stream with UI lifecycle awareness,
- Last value cache - state preservation,
- Everything that you need to implement MVVM pattern
Installation
- Core/Logic project - add CrossPlatformLiveData nuget,
- Android project - add CrossPlatformLiveData, CrossPlatformLiveData.Android nuggets,
- iOS project - add CrossPlatformLiveData, CrossPlatformLiveData.iOS nuggets
CrossPlatformLiveData.Android provides base UI classes with LifecycleManger linked to lifecycle events:
LiveDataActivity, LiveDataAppCompatActivity, LiveDataAppCompatDialogFragment, LiveDataFragment, LiveDataFragmentActivity, LiveDataSupportDialogFragment, LiveDataSupportFragment
CrossPlatformLiveData.iOS provides base UI classes with LifecycleManger linked to lifecycle events:
LiveDataViewController
For other platforms all you need to do is provide LifecycleManger with lifecyle events when they occur, implementation should be self explanatory.
Usage
Logic/Core:
Add LiveData fields in ViewModel/Presenter class:
public ILiveData<string> SampleLiveData { get; } = new LiveData<string>();
Post new value to LiveData:
SampleLiveData.PostValue("Hello World!");
UI:
Observe LiveData streams with LifecycleManager
viewModel.SampleLiveData.Observe(LifecycleManager, OnNextSample, e => {//handle error here}));
private void OnNextSample(string newText)
{
someTextView.Text = newText;
}
RxWrapper (Optional)
Optionally you can use RxWrapper template class that reduces boilerplate code by bundling value, request status, and exception in single model:
public ILiveData<RxWrapper<SampleResponse>> NetworkingLiveData { get; } = new LiveData<RxWrapper<SampleResponse>>();
//Notify UI that request is pending
NetworkingLiveData.PostValue(RxWrapper<SampleResponse>.Pending());
//Data fetch has succeded
NetworkingLiveData.PostValue(RxWrapper<SampleResponse>.Ok(model1));
//Error has occured during network call
NetworkingLiveData.PostValue(RxWrapper<SampleResponse>.Error(new Exception("No network")));
private void OnNextNetworkingData(RxWrapper<SampleResponse> response)
{
switch (response.Status)
{
case RxStatus.Ok:
//Update UI on succes
break;
case RxStatus.Pending:
//Show loading spinner
break;
case RxStatus.Error:
//Display error alert
break;
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.CSharp (>= 4.5.0)
- System.Reactive (>= 4.0.0)
- System.Runtime (>= 4.3.1)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on CrossPlatformLiveData:
Package | Downloads |
---|---|
CrossPlatformLiveData.iOS
Base iOS classes for CrossPlatformLiveData |
|
CrossPlatformLiveData.Android
Base Android classes for CrossPlatformLiveData |
GitHub repositories
This package is not used by any popular GitHub repositories.