Exemplo n.º 1
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.º 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
        // 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);
        }