Giter Club home page Giter Club logo

Comments (25)

jamesl77 avatar jamesl77 commented on July 17, 2024 2

DataTemplateSelector derives from DataTemplate. So I think you can just have one property called DataTemplate FlowItemTemplate.
Xamarin Forms ListView does it like this for the ItemTemplate property: https://blog.xamarin.com/customizing-list-view-cells-xamarin-forms-datatemplateselector/

Optionally, if you want to offer the ability to select based on item's index, you could have a FlowItemTemplateSelector which looks like this:

public abstract class FlowItemTemplateSelector : DataTemplate
{
         public abstract DataTemplate SelectTemplate(int index, object item);
}

I am not sure about having both FlowColumnCount and FlowAutoColumnCount. Maybe have just int? FlowColumnCount which by default is null, meaning control auto computes the number of columns based on FlowLisView's width and flow item's width.
I would change FlowColumnDefaultMinimumWidth to just int? FlowColumnWidth. If it's null and you need item width, use the item's MinimumWidth.

from dltoolkit.forms.controls.

opcodewriter avatar opcodewriter commented on July 17, 2024 1

well, you could still keep the FlowColumnTemplateSelector, something like this:

<dltoolkit:FlowListView.FlowColumnsTemplateSelectors>
                    <dltoolkit:FlowColumnTemplateSelector Template="{StaticResource MyTemplate1}" />
                     <dltoolkit:FlowColumnTemplateSelector Template="{StaticResource MyTemplate2}" />
</dltoolkit:FlowListView.FlowColumnsTemplateSelectors>

not sure this is the cleanest way..

from dltoolkit.forms.controls.

daniel-luberda avatar daniel-luberda commented on July 17, 2024 1
<flv:FlowListView FlowColumnCount="3" FlowItemsSource="{Binding Items}" 
    SeparatorVisibility="None" HasUnevenRows="false"
    FlowItemTappedCommand="{Binding ItemTappedCommand}" FlowLastTappedItem="{Binding LastTappedItem}">

    <flv:FlowListView.FlowColumnTemplate>
        <DataTemplate>
            <Label HorizontalOptions="Fill" VerticalOptions="Fill" 
                XAlign="Center" YAlign="Center" Text="{Binding Title}"/>
        </DataTemplate>
    </flv:FlowListView.FlowColumnTemplate>

</flv:FlowListView>     

It also supports DataTemplateSelector. Testers are welcome.

from dltoolkit.forms.controls.

daniel-luberda avatar daniel-luberda commented on July 17, 2024

Hi @opcodewriter,

Can I specify a DataTemplate for the cell?

Yes, FlowColumnTemplateSelector is just a sample implementation of FlowColumnTemplateSelector. You can create your own:

    public class CustomAdvancedTemplateSelector : FlowColumnTemplateSelector
    {
        public override Type GetColumnType(object bindingContext)
        {
            // YOUR CUSTOM LOGIC HERE

            if (bindingContext == null)
                return typeof(ContentView);

            return typeof(FlowListViewExpandCell);
        }
    }

If I change the width and height of a cell, does it refresh correctly?

FlowListView is ListView derivative, so the same behavior is expected as in ListView. Basically it does layout of columns in one ViewCell with usage of AbsoluteLayout (for performance reasons).

from dltoolkit.forms.controls.

opcodewriter avatar opcodewriter commented on July 17, 2024

@daniel-luberda Thanks but, for the 1st question, it won't work

I need to be able to give a DataTemplate not a Type. Right now, you use the Type to create an instance of the view by calling Activator.CreateInstance(columnTypes[i])

I realized this is actually not possible, I have to modify the code of the library to use DataTemplate.

In my opinion, supporting DataTemplate is important for people who use DataTemplate defined in XAML, instead of creating the cell View manually in code.

from dltoolkit.forms.controls.

daniel-luberda avatar daniel-luberda commented on July 17, 2024

I also wanted to use DataTemplate but finally because of performance issues, I didn't. Please notice, DataTemplate always creates a new View instance. That's not what we want here (view reusing, etc). If you have any idea how to overcome this, please let me know.

from dltoolkit.forms.controls.

daniel-luberda avatar daniel-luberda commented on July 17, 2024

BTW: You can still define Views in XAML, the only difference is, it's a separate file.

from dltoolkit.forms.controls.

opcodewriter avatar opcodewriter commented on July 17, 2024

You also create a new instance now, so using a DataTemplate would be the same thing.

But yes, you would need to modify RowLayoutChanged to check for modifications:
just need to cache the DataTemplates.

Something like this (see comments for the new code):

public class FlowListViewInternalCell : ViewCell
{
        readonly IList<DataTemplate> _flowColumnDataTemplates;`

        protected override void OnBindingContextChanged()
        {      
              ....
            else // RECREATE COLUMNS
            {
                if (_rootLayout.Children.Count > 0)
                {
                    _rootLayout.Children.Clear();
                    _flowColumnDataTemplates.Clear();  // clear the data templates
                }

                for (int i = 0; i < containerCount; i++)
                {
                    var view = (View)columnTypes[i].CreateContent();

                    _flowColumnDataTemplates.Add(columnTypes[i]);  // save the data templates

                    view.GestureRecognizers.Add(new TapGestureRecognizer()
                    {
                        Command = new Command(async (obj) =>
                        {
                            await ExecuteTapGestureRecognizer(view);
                        })
                    });

                    SetBindingContextForView(view, container[i]);
                    AddViewToLayout(view, containerCount, i);
                }
            }
              ....
        }

        private bool RowLayoutChanged(int containerCount, IList<DataTemplate> columnTypes)
        {
            // Check if desired number of columns is equal to current number of columns
            if (_rootLayout.Children.Count != containerCount)
            {
                return true;
            }
            else
            {
                // Check if desired column view types are equal to current columns view types
                for (int i = 0; i < containerCount; i++)
                {
                    if (_flowColumnDataTemplates[i] != columnTypes[i])
                    {
                        return true;
                    }

                    //if (_rootLayout.Children[i] != columnTypes[i])
                    //{
                    //    return true;
                    //}
                }
            }

            return false;
        }
} 

from dltoolkit.forms.controls.

opcodewriter avatar opcodewriter commented on July 17, 2024
public abstract class FlowColumnTemplateSelector
{
    public abstract DataTemplate GetColumnType(object bindingContext);
}

from dltoolkit.forms.controls.

daniel-luberda avatar daniel-luberda commented on July 17, 2024

You also create a new instance now, so using a DataTemplate would be the same thing.

Not exactly. I don't create instances every time (they're reused if possible, eg. view type didn't change). Take a look here: https://github.com/daniel-luberda/DLToolkit.Forms.Controls/blob/master/FlowListView/DLToolkit.Forms.Controls.FlowListView/FlowListViewInternalCell.cs#L253-L254

from dltoolkit.forms.controls.

opcodewriter avatar opcodewriter commented on July 17, 2024

Yes, I know. You can achieve same thing with DataTemplate, you just need to save them in the FlowListViewInternalCell so you can compare them with the new ones in the RowLayoutChanged

See my code.

I actually did this and works great.

from dltoolkit.forms.controls.

daniel-luberda avatar daniel-luberda commented on July 17, 2024

I didn't see your code yet as I'm not at home. Do you mean comparing DataTemplate type? If it's possible, we could Obsolete old template selectors and create new DataTemplate based. But:

FlowListView need a List of DataTemplates - I had some problems with it (it wasn't supported by XAML compiler). I don't know if anything changed in that matter.

from dltoolkit.forms.controls.

opcodewriter avatar opcodewriter commented on July 17, 2024

What problems did you have exactly? Maybe I can help.

from dltoolkit.forms.controls.

daniel-luberda avatar daniel-luberda commented on July 17, 2024

This works:

<DataTemplate>
    <ContentView/>
</DataTemplate>

This doesn't:

<DataTemplates>
    <DataTemplate>
        <ContentView/>
    </DataTemplate>
    <DataTemplate>
        <ContentView/>
    </DataTemplate>
</DataTemplates>

We need multiple DataTemplate definitions. But I didn't test it on recent XF versions.

from dltoolkit.forms.controls.

daniel-luberda avatar daniel-luberda commented on July 17, 2024

@opcodewriter I have an idea:

  • DataTemplate FlowColumnTemplate property (not a list, just a single one)
  • int FlowColumntCount property which will be used when FlowAutoColumnCount is disabled
  • Multiple templates can be solved with DataTemplateSelector
  • That way, we still have full XAML syntax support

What do you think?

from dltoolkit.forms.controls.

daniel-luberda avatar daniel-luberda commented on July 17, 2024

@jamesl77 These are really nice suggestions. I'll implement it and obsolete old properties (they'll still work for compatibility).

from dltoolkit.forms.controls.

opcodewriter avatar opcodewriter commented on July 17, 2024

Compatibility is an issue, but in the same time keeping the obsolete code and mixing with new code, just for the sake of compatibility, I'm not sure is a good thing on the long run. At some point you need to get rid of it, there's a reason why it's obsolete I assume :)
Why not go to a major version of the library? The library right now is stable enough I guess? So people who use your library at current version are fine with it.

from dltoolkit.forms.controls.

daniel-luberda avatar daniel-luberda commented on July 17, 2024

Nuget 2.0.0-alpha1 released. I also created new samples project:

https://github.com/daniel-luberda/DLToolkit.Forms.Controls/blob/master/Samples/DLToolkitControlsSamples/SamplesFlowListView/SimplePage.xaml

from dltoolkit.forms.controls.

opcodewriter avatar opcodewriter commented on July 17, 2024

So which way did you go in the end? Mixing old and new?

from dltoolkit.forms.controls.

daniel-luberda avatar daniel-luberda commented on July 17, 2024

For now, no compatibility. But it's very easy to add as we only need to add old properties and translate them to the new DataTemplate based code. It won't have any impact for internal code. What do you think?

from dltoolkit.forms.controls.

opcodewriter avatar opcodewriter commented on July 17, 2024

I'm for clean code. Like I said before, the library is small, and pretty stable. No reason to keep deprecated code.

from dltoolkit.forms.controls.

3-50 avatar 3-50 commented on July 17, 2024

Please, add compatibility in the new version. Old code works well.

from dltoolkit.forms.controls.

opcodewriter avatar opcodewriter commented on July 17, 2024

@3-50 using current released version still works and will still work. I can't speak in the name of @daniel-luberda but I think if any critical bug will appear it's still going to be fixed in current released version.

from dltoolkit.forms.controls.

daniel-luberda avatar daniel-luberda commented on July 17, 2024

@3-50 The new API allows you to use the same source data which is used in a Xamarin.Forms ListView, just with column support. I also allows dev to use DataTemplates which devs are used to. Old one is quite stable, I don't know of any issues with it. If some issues will be found in old version, I'll publish bug fixes release, so don't worry.

from dltoolkit.forms.controls.

3-50 avatar 3-50 commented on July 17, 2024

@opcodewriter, @daniel-luberda Thank you for your answer.

from dltoolkit.forms.controls.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.