How implement adapter in xamarin.forms - list

How implement adapter in xamarin.forms (xaml) simple ? But all example is for andorid or iOS. Can writing example for xamarin.forms

Adapters are part of the native Android UI framework for displaying data using the MVC pattern. In the world of Xamarin Forms, the best analogue is a ViewModel and the Model View ViewModel pattern (MVVM). In its simplest form, a ViewModel is any class that the view binds to by having an instance of that class assigned to the View's BindingContext. This is, by itself, enough to perform one-time binding where the values in that class' properties are read by the View when the View is created. If you want more advanced binding where updates to the underlying ViewModel are reflected in the View, you need to implement INotifyPropertyChanged and send notifications to the View. Also, rather than roll your own, I would recommend that you look into using an existing MVVM framework such as MvvmLight.
To acheieve what you are looking for, you would have a ViewModel expose a property that is of an IEnumerable or IList. You could then bind one of the repeating views such as ListView to this property and see the underlying data reflected in the view. By implementing INotifyPropertyChanged (or using a framework that does that for you), you can have new items added to the collections exposed by those properties appear in the UI.

Related

In Swiftui, how to minimize passing functions to sub-views

I am working on a todo app that interacts with an API to store data. My view structure looks like this (simplified):
ContentView: List of { ProjectView }
ProjectView: List of { TaskView }
The ContentView has a webServer variable that provides functions like storeTask(task: Task) and deleteTask(task: Task).
So now I want my TaskView to be able to modify tasks. The most straightforward pattern seems to provide storeTask and deleteTask to TaskView to keep the view ignorant of the implementation details. That means that I have to pass these two functions through the whole tree of sub-views: ContentView -> ProjectView -> TaskView. But then, a minor change in function signature requires a changes for every view that's part of the view hierarchy.
This feels like an inefficient pattern as it's already complex for the simple app I am building. What are other approaches? For context, I remember this same issue from working on React, and using approaches like Redux to deal with this. I'm wondering whether there's a standard approach for simplifying this in SwiftUI?
The most common architecture pattern in SwiftUI is MVVM (Model-View-ViewModel). There are many articles online explaining it, but essentially the layers break into:
Model - manage a piece of data
View - manage the UI
ViewModel - manage the data (models) to be displayed in the UI (view)
To answer your question, you would need to create ViewModel layer that manages your data and pass that ViewModel throughout your Views (as #Asperi mentioned in the comments).
Here is a great article explaining MVVM: https://matteomanferdini.com/mvvm-pattern-ios-swift/
Here is one of my Github repo's that uses MVVM Architecture in SwiftUI to make a todo-list app, similar to your project. If you take a look at the ViewModel layers you will find examples of what you're trying to do. https://github.com/ndsarno/TodoList-MVVM-Advanced

In which case we can use view or controller rendering?

I know this is a very basic question, but it matters a lot for developers. Basically, I just need to know that when developers should use view rendering and controller rendering.
To put it briefly, view rendering is to simply display data. It can be controller by the front end via filtering or transforming it but it will not interact with any of the underlying business logic.
Whereas a controller rendering is more so used when the user is going to manipulate that data on the backend and will have to follow those business rules.
Is that sufficient?

MVC - View's Role

I'm having a difficult time in implementing MVC's View and View's responsibilities. By the way I'm implementing the MVC in new way, not smalltalk's traditional way (controller between model and view. View does not have a relation with model vice versa)
My problem is sth like following. My View have a test list shown as a table, each table row corrensponds to a single test and user can select more than one test. And each test (row) may have 0 or more options for the selected test. After clicking 'start test' button, my application is supposed to execute selected tests with their selected options.
How should I implement this part of my application so that controller is informed about the selected tests and parameters? Should the view provide the information about selected tests and parameters?(makes View a little intelligent, not dumb as desirerd ?)
Should the view provide information by going through all rows of table and checking the parameters(hence no dedicated 'selected tests and params structure' or should it store selected tests and test parameters in a dedicated structure and post it when controller requires?
Or controller knows the view and it can grab all the data it needs from View?
I would expect the controller to have intimate knowledge of both the view and model. So I prefer "...controller knows the view and it can grab all the data it needs from View", as it means you keep the most difficult part to test, the view, as simple as possible.

EmberJS view components and separate data store

I'm looking at creating a google maps component. But I would like it to be self contained so it will have its own model, controllers and views. So for example the component will fetch its own data from the server and I'll also be able to refresh the data when needed. Ideally I'd simply add the component to the current template that is showing, so for example: {{map-view}} and then everything the component needs to do will take care of its self.
The component will also need to listen to triggered events from other controllers as a user will be able to search for a specific location and the map will need to change its position.
Is this possible to do in EmberJS? As I haven't found anything like this, specially when having its own model. I know there is a component in EmberJS but it seems very limited. Am I wrong in thinking this?
the controller cannot have its own model all values must be passed to component. Please refer to ember docs and this Discussion
You can make a google map component and pass the location and marker data to the component. this data will get updated due to ember data binding.
so you can have something like this
{{map-view location=userEnteredValue}}
you can search for ember component talk by Kris Selden on youtube which includes a google map component good for you to start with.
updated
https://gist.github.com/krisselden/8189650

Ember.js converting controller / view architecture to components

I have an existing DetailController and DetailView in my app that has some pretty complicated UI / data manipulation logic (hotkeys, copy paste, duplication, autocomplete, etc) -- the view sends UI events to the controller; the controller handles the logic.
I want to convert this to an Ember component.
Does this basically mean I merge the view and controller into DetailComponent? This seems messy and wrong to me.
If not, how do I use controllers and views internally within a component? That is, I still want the complete isolation and well-defined public interface of the component, but internally within the component, I'd like to use controllers and views for organization. Is that possible?
Is it possible to use {{render}}, {{view}}, {{partial}} within the component template?
Does this basically mean I merge the view and controller into DetailComponent? This seems messy and wrong to me.
Yes that is what it means.
internally within the component, I'd like to use controllers and views for organization. Is that possible?
So component basically replaces a single view/controller pair. Beyond that a component is just an extension of Ember.View and can be organized just like any other view.
Is it possible to use {{render}}, {{view}}, {{partial}} within the component template?
Yes. Any of those helpers will work.