Exemplo n.º 1
0
 public ViewPool(Transform parent, PrefabRef <TView> prefab, PresentOptions options) : this(parent, prefab.ExtractPrefab(parent))
 {
     if ((options & PresentOptions.UseLoadedViews) != 0)
     {
         Rui.FillPoolWithChildrenViews(this, parent, prefab, this.prefab, options);
     }
 }
Exemplo n.º 2
0
        ViewPool <TView, TData> Pool(PrefabRef <TView> prefabRef)
        {
            ViewPool <TView, TData> pool;

            if (pools.TryGetValue(prefabRef, out pool) == false)
            {
                var prefab = prefabRef.ExtractPrefab(parent);

                // if we have pool for this concrete prefab already we use that pool
                // and also make this pool default for this prefab key
                if (pools.TryGetValue(prefab, out pool) == false)
                {
                    pool          = new ViewPool <TView, TData>(parent, prefab);
                    pools[prefab] = pool;
                }
                pools[prefabRef] = pool;

                // TODO implement proper prefab logic here
                if (options.Has(PresentOptions.UseLoadedViews))
                {
                    Rui.FillPoolWithChildrenViews(pool, parent, prefabRef, prefab, options);
                }
                recycleAction.ForEach(a => pool.AddRecycleAction(a));
                if (instantiateAction != null)
                {
                    pool.AddInstantiateAction(instantiateAction);
                }
            }
            return(pool);
        }
Exemplo n.º 3
0
        ViewPool <TView, TData> Pool(PrefabRef <TView> prefabRef)
        {
            ViewPool <TView, TData> pool;

            if (pools.TryGetValue(prefabRef, out pool) == false)
            {
                var prefab = prefabRef.ExtractPrefab(parent);

                // if we have pool for this concrete prefab already we use that pool
                // and also make this pool default for this prefab key
                if (pools.TryGetValue(prefab, out pool) == false)
                {
                    pool          = new ViewPool <TView, TData>(parent, prefab);
                    pools[prefab] = pool;
                }
                pools[prefabRef] = pool;

                // TODO wft fix this!
                //if (loadViewsFromParent) Rui.FillPoolWithChildrenViews(pool, parent, prefab.GetType());
                recycleAction.ForEach(a => pool.AddRecycleAction(a));
                if (instantiateAction != null)
                {
                    pool.AddInstantiateAction(instantiateAction);
                }
            }
            return(pool);
        }
Exemplo n.º 4
0
        public static TableConnectionsAndComponents <TView, TData> PresentWithLayout <TData, TView>(
            this IReactiveCollection <TData> data,
            RectTransform rect,
            PrefabRef <TView> prefab,
            Action <TData, TView> fillFactory,
            IScrollViewLayout layout         = null, // Linear layout is default
            TableDelegates <TView> delegates = null,
            PresentOptions options           = PresentOptions.UseChildWithSameTypeAsView) where TView : ReusableView
        {
            var components = CreateBasicTableComponents(data, rect, fillFactory, prefab: prefab,
                                                        layout: layout, delegates: delegates, options: options | PresentOptions.NeedLayout);

            components.viewPort = new AllVisibleViewPort();
            return(ControlItemVisibilityAndRecycle(components));
        }
Exemplo n.º 5
0
        public static SimplePresentComponents <TView, T> Present <T, TView>(
            this IReactiveCollection <T> coll,
            Transform parent,
            PrefabRef <TView> prefab       = default,
            Action <T, TView> show         = null,
            Func <T, IEventStream> updater = null,
            Func <T, PrefabRef <TView> > prefabSelector = null,
            IViewPool <TView, T> pool        = null,
            PresentOptions options           = PresentOptions.UseChildWithSameTypeAsView,
            TableDelegates <TView> delegates = null
            ) where TView : ReusableView
        {
            var components  = CreateBasicTableComponents(coll, parent, show, pool, prefab, prefabSelector, null, delegates, updater, options);
            var viewStorage = components.viewLoader;

            components.addConnection = coll.update.Subscribe(e =>
            {
                switch (e.type)
                {
                case ReactiveCollectionEventType.Reset:
                    viewStorage.UnloadAll();
                    viewStorage.ReloadAll(e.newData);
                    break;

                case ReactiveCollectionEventType.Insert:
                    viewStorage.LoadView(e.position, e.newItem);
                    break;

                case ReactiveCollectionEventType.Remove:
                    viewStorage.UnloadView(e.position);
                    break;

                case ReactiveCollectionEventType.Set:
                    viewStorage.UnloadView(e.position);
                    viewStorage.LoadView(e.position, e.newItem);
                    break;
                }
            });
            viewStorage.ReloadAll(coll);
            // TODO think about how destroy should work
            components.addConnection     = new AnonymousDisposable(() => components.viewLoader.UnloadAll());
            components.animationsEnabled = true;
            return(components);
        }
Exemplo n.º 6
0
        public static TableConnectionsAndComponents <TView, TData> PresentInScrollWithLayout <TData, TView>(
            this IReactiveCollection <TData> data,
            ReactiveScrollRect scroll,
            PrefabRef <TView> prefab   = default,
            Action <TData, TView> show = null,
            Func <TData, PrefabRef <TView> > prefabSelector = null,
            IScrollViewLayout layout         = null, // Linear layout is default
            TableDelegates <TView> delegates = null,
            PresentOptions options           = PresentOptions.UseChildWithSameTypeAsView
            ) where TView : ReusableView
        {
            var components = CreateBasicTableComponents(
                data,
                scroll.scroll.content,
                show,
                prefab: prefab,
                prefabSelector: prefabSelector,
                layout: layout,
                delegates: delegates,
                options: options | PresentOptions.NeedLayout);

            return(PresentInScrollWithLayout(components, scroll));
        }
Exemplo n.º 7
0
 public static void FillPoolWithChildrenViews <TView, TData>(IViewPool <TView, TData> pool, Transform parent, PrefabRef <TView> prefabRef,
                                                             TView prefab, PresentOptions options) where TView : ReusableView
 {
     if (parent == null)
     {
         return;
     }
     foreach (var obj in parent)
     {
         var view = ((Transform)obj).GetComponent <TView>();
         if (view != null)
         {
             if (view.prefabRef != null && view.prefabRef == prefab)
             {
                 pool.AddViewToUse((TView)view.prefabRef, view);
             }
             else if (options.Has(PresentOptions.UseChildWithSameTypeAsView) && view.GetType() == prefabRef.ExtractType())
             {
                 view.prefabRef = prefab;
                 pool.AddViewToUse((TView)view.prefabRef, view);
             }
             else if (options.Has(PresentOptions.UseChildWithSameNameAsView) && view.name == prefabRef.ExtractName())
             {
                 view.prefabRef = prefab;
                 pool.AddViewToUse((TView)view.prefabRef, view);
             }
         }
     }
 }
Exemplo n.º 8
0
        // Creates everithing except viewport.
        public static TableConnectionsAndComponents <TView, TData> CreateBasicTableComponents <TData, TView>(
            IReactiveCollection <TData> data,
            Transform parent,
            Action <TData, TView> show,
            IViewPool <TView, TData> pool = null,
            PrefabRef <TView> prefab      = default,
            Func <TData, PrefabRef <TView> > prefabSelector = null,
            IScrollViewLayout layout           = null, // Linear layout is default
            TableDelegates <TView> delegates   = null,
            Func <TData, IEventStream> updater = null,
            PresentOptions options             = PresentOptions.None
            ) where TView : ReusableView
        {
            var components = new TableConnectionsAndComponents <TView, TData>();

            if (pool == null)
            {
                if (prefabSelector != null)
                {
                    pool = new DistinctivePool <TView, TData>(parent, prefabSelector, options);
                }
                else
                {
                    var actualPrefab = prefab.ExtractPrefab(parent);
                    pool = new ViewPool <TView, TData>(parent, actualPrefab);
                    if (options.Has(PresentOptions.UseLoadedViews))
                    {
                        FillPoolWithChildrenViews(pool, parent, prefab, actualPrefab, options);
                    }
                }
            }

            if (updater != null)
            {
                var showCopy = show;
                Action <TData, TView> showAndSubscribe = (item, view) =>
                {
                    showCopy(item, view);
                    view.connections += updater(item).Subscribe(() => showCopy(item, view));
                };
                show = showAndSubscribe;
            }
            delegates = delegates ?? new TableDelegates <TView>();
            if (delegates.onInsert != null)
            {
                show += (d, view) =>
                {
                    if (components.animationsEnabled)
                    {
                        delegates.onInsert(view);
                    }
                }
            }
            ;
            if (options.Has(PresentOptions.PreserveSiblingOrder))
            {
                show += (d, view) => { view.tr.SetSiblingIndex(view.indexInModel); };
            }
            components.viewLoader = new LinearViewLoader <TView, TData>(pool, show, delegates.onRemove);
            components.delegates  = delegates;
            components.collection = data;

            if (options.Has(PresentOptions.NeedLayout) && layout == null)
            {
                layout = LinearLayout();
            }
            components.layout = layout;
            return(components);
        }
Exemplo n.º 9
0
 public SimpleViewPool(Transform parent, PrefabRef <TView> prefab, PresentOptions options) : base(parent, prefab, options)
 {
 }