Xamarin Shell Navigating with Data and Exposure Notification API

Xamarin Shell Navigating with Data and Exposure Notification API

 
1.Xamarin.Form Shell Passing Data When Navigating

Overview:

If you know a little about Xamarin.Form, then you should also know that Xamarin.Form is used to create a cross-platform application. It supports so many astonishing features such as Collection view, UI extensions, Swipe view, mastering multilingual in Xamarin.Forms, etc.

In this example, we will know about navigation by using an example and we will also see how we can use it.

Navigation is used to move from one page to another. As you know that there are many pages in a single application so you have to move from one page to another. Sometimes you have to move with data or sometimes without the data which depends on your requirement. Further, we will see an example of this.

Navigation can be seen as below image:
 
Data and Exposure Notification API


Different navigation pages are available. We have to use them according to your requirement.

1. Content Page
2. MasterDetail Page
3. Navigation Page
4. Tabbed Page
5. Carousel Page

Data and Exposure Notification API

Now we will see the normal navigation page example.


Xaml File

<Shell.FlyoutHeader>
<Grid BackgroundColor="Black">
<Image Aspect="AspectFill"
               Source="BackImg.jpeg"
               Opacity="0.6" />
<Label Text="RLMasterApp"
TextColor="White"
FontAttributes="Bold"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Start" />
</Grid>
</Shell.FlyoutHeader>

<!--This is the body section-->
<FlyoutItem Title="Page1"
                Icon="Fileicon.png">
<Tab>
<ShellContent>
<Pageviews:Page1 />
</ShellContent>
</Tab>
</FlyoutItem>
<FlyoutItem Title="Page2"
                Icon="Fileicon.png">
<Tab>
<ShellContent>
<Pageviews:Page2 />
</ShellContent>
</Tab>
</FlyoutItem>
</Shell>

.cs file
async void Button_Clicked(Object sender,System.EventArgs e)
        {
Routing.RegisterRoute(nameof(Page1Details), typeof(Page1Details));
             await Shell.Current.GoToAsync($"{nameof(Page1Details)}?Content={jsonStr}");
        }

In the example, we saw how we can move from one page to another page without the data. We have used the FlyoutItem in our example.

Now we will pass the data from the main page of our application to the destination page. The data could be of any type either you could be getting from the database for showing to the user.

You can also perform normal navigation and you can also perform this in MVVM.

How to pass data from one page to another during navigation?  There are some options available for this and what option to choose totally depends on you. You have to select the option accordingly. Options are as below:

1. Constructor argument
2. Model State
3. MVVM argument

1. Constructor argument: 

If you are using constructor then you can use the default navigation of Xamarin.Form.

You have to create a new instance class. If you are using a constructor argument some MVVM Frameworks are also built on this principle.

You have to pass the data in the instance which is very easy but it is not sufficient because you have to send the data back to the ViewModel.

Example:

await navigationPage.PushAsync(new MyNewPage("my argument"));

2. MVVM arguments: 

If you are using the MVVM Framework then this can be very helpful to you which is shown in the below example.

Example:
// Prism
_navigationService.NavigateAsync("MainPage", navigationParams);

3. Model State:
 
It is a method to store the data in your model. For example, you have a login function in your application, the data is stored in the model when you log in which is the way of storing the data which can be used on another page and we can access it.

Example:
private string _email;

public void Login(string email, string password)
{
   // if success log in
   _email = email;
}

Now we will see the example of how to pass data through objects. It will transfer the data from one page to another with navigation. In our application transfers data from page one to another page.

Xaml File
<ContentPage.Content>
<StackLayout Orientation="Vertical" VerticalOptions="CenterAndExpand">
<Label HorizontalOptions="CenterAndExpand" Text="This is Page1"/>
<Button Text="Go to next page" Clicked="Button_Clicked"/>
</StackLayout>
</ContentPage.Content>

.CS File
public partial class Page1 :ContentPage
    {
        public Page1()
        {
InitializeComponent();
        }

        async void Button_Clicked(Object sender,System.EventArgs e)
        {
Routing.RegisterRoute(nameof(Page1Details), typeof(Page1Details));

            Person test1 = new Person()
            {
                Name = "Samir",
                Address = "Kathmandu,Nepal"
            };
var jsonStr = JsonConvert.SerializeObject(test1);

            await Shell.Current.GoToAsync($"{nameof(Page1Details)}?Content={jsonStr}");
        }
    }

In MVVM
.CS File
namespace RLMasterApp.ViewModel
{
    [QueryProperty(nameof(Content), nameof(Content))]
    public class DetailViewModel :BindableObject
    {
        string content = "";
        public string Content
        {
            get => content;
            set
            {
                content = Uri.UnescapeDataString(value ?? string.Empty);
OnPropertyChanged();
PerformOperation(content);
            }
        }


        private string name { get; set; }
        public string Name
        {
            get { return name; }
            set
            {
                name = value;
OnPropertyChanged("Name");
            }
        }

        private string address { get; set; }
        public string Address
        {
            get { return address; }
            set
            {
                address = value;
OnPropertyChanged("Address");
            }
        }


        private void PerformOperation(string getcont)
        {
var content = JsonConvert.DeserializeObject<Person>(getcont);
            Name = content.Name;
            Address = content.Address;
        }

        public DetailViewModel()
        {

        }
    }
}

Output
 
Data and Exposure Notification API


 

2. Exposure Notification APISupport
 
Overview:

Both Apple and Google are building APIs for compatible BLE-based contact tracking implementations that rely heavily on generating and storing unique identities rolling over a device transmitted to nearby devices. Devices that detect nearby identities store these identities when they are in range (or contact) for up to 14 days.

When a person has confirmed a diagnosis, they tell their device which then submits the locally stored, self-generated rolling unique identifiers from the last 14 days to a back end service provided by the app implementing the Notification API.
 
Data and Exposure Notification API

 


Confirming a diagnosis

The native API’s and spec mention that to submit a self positive diagnosis, you should ensure that the diagnosis is actually verified through the health authority for the app. How this is done is largely left up to the individual app implementation.

The technique in our sample uses which would be generated on the Administrative side of the app and added to the back-end server’s database. One would be given out to each person with a positive test result which would then be entered into the app when submitting a self diagnosis. If the code submitted by the user exists in the database, the keys will be stored. This mechanism should prevent users from submitting false claims of diagnoses.

What We Still Need?

•    Final APIs release by Google
•   Understand if we have Xamarin coverage of final APIs. (Google Play Services / IOS updates that may be needed)
•    Understand the limitations / OS versions required for the opt-in for
o    IOS/Android devices
o    Android: 5.0+ IOS 13.x? beta+
•    Document how to opt-in, use the APIs, and have a COVID Tracing API landing page for Xamarin to point users to.

Key Areas to Demonstrate

•    Bluetooth Permission (i.e. “App would like to use Bluetooth”)
•    Notifications Enabled (i.e. “send you notifications”)
•    General Instructions
o    Keep phone on you when you leave the house.
o    Keep the application running.
o    Keep Bluetooth enabled.
•    Sample App / API FAQ
o    Specifically, limitations of the APIs / Bluetooth / Notifications

Conclusion:

In this blog we have seen how we can move from one page to another, how much we can move with it, how we can work with data and also what methods to use. Apart from that we also saw about the Exposure notification API when and how it is used. Hope you found and learn something new in this blog.


Author Bio: 
 

 
 
Vinod Satapara – Technical Director, iFour Technolab Netherlands.
Technocrat and entrepreneur with years of experience building large scale enterprise web, cloud and mobile applications using latest technologies like ASP.NET, CORE, .NET MVC, Angular and Blockchain. Keen interest in addressing business problems using latest technologies and have been associated with Mobile Application development companies.

Post a Comment

0 Comments