simple-scroll-snap icon indicating copy to clipboard operation
simple-scroll-snap copied to clipboard

Please fix instantiation.

Open daniel-keen opened this issue 1 year ago • 0 comments

If I understand correctly, currently in order to instantiate an object and add it to the simple scroll snap I would do something like this:

public MyPrefabView MyPrefab;
void Test()
{
    scrollSnap.AddToBack(MyPrefab.gameObject);
    var item = scrollSnap.Panels[0].GetComponent<MyPrefabView>();
    item.Initialize(someData);
}

In case like this, I would always have to use GetComponent for my panel if I need to work with that panel. Perhaps, it would be better if we can avoid using GetComponent? Also, I think it can be confusing that "ScrollSnap.Add" methods instantiate passed objects under the hood and not assigning existing ones instead. For instance,

void Test()
{
    var item = Instantiate(MyPrefab, scrollSnap.Content);
    item.Initialize(someData);
    scrollSnap.AddToBack(item.gameObject);
}

daniel-keen avatar Jun 06 '24 11:06 daniel-keen