CrossPlatformLiveData.Android 1.0.2

There is a newer version of this package available.
See the version list below for details.
Install-Package CrossPlatformLiveData.Android -Version 1.0.2
dotnet add package CrossPlatformLiveData.Android --version 1.0.2
<PackageReference Include="CrossPlatformLiveData.Android" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CrossPlatformLiveData.Android --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CrossPlatformLiveData.Android, 1.0.2"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install CrossPlatformLiveData.Android as a Cake Addin
#addin nuget:?package=CrossPlatformLiveData.Android&version=1.0.2

// Install CrossPlatformLiveData.Android as a Cake Tool
#tool nuget:?package=CrossPlatformLiveData.Android&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

CrossPlatformLiveData

Android LiveData inspired .NET implementation - lifecycle aware rx streams

Build Status Nuget

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

CrossPlatformLiveData - MVVM pattern

Installation

  • Nuget Core/Logic project - add CrossPlatformLiveData nuget,
  • Nuget Android project - add CrossPlatformLiveData, CrossPlatformLiveData.Android nuggets,
  • Nuget 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;
	}
}

TMS logo

Product Versions
MonoAndroid monoandroid90
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 369 5/4/2020
1.0.3 347 10/18/2019
1.0.2 333 9/12/2019
1.0.1 323 9/11/2019