/// <summary>
        /// The shadow is to be created
        /// </summary>
        /// <param name="context"></param>
        /// <param name="viewElement"></param>
        /// <returns></returns>
        /// <remarks>
        /// It is assumed that this is invoked whilst operating under a transaction.
        /// </remarks>
        public IShadow CreateShadow(IShadowContext context, IPrimitive viewElement)
        {
            var shadow = Create((TContext)context, (TElement)viewElement);

            Transaction.Current.Add(() => OnShadowCreated((TContext)context, (IShadow <TItem>)shadow, (TElement)viewElement));
            return(shadow);
        }
        /// <summary>
        /// The shadow has been removed.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="shadow"></param>
        /// <param name="current"></param>
        public void RemoveShadow(IShadowContext context, IShadow shadow, IPrimitive current)
        {
            Remove((TContext)context, (IShadow <TItem>)shadow, (TElement)current);

            OnShadowDestroyed((TContext)context, (IShadow <TItem>)shadow, (TElement)current);

            // and here, we dispose of the shadow
            Transaction.Current.Add(shadow.Dispose);
        }
예제 #3
0
        /// <summary>
        /// Update a shadow given current and next values.
        /// </summary>
        /// <typeparam name="TItem"></typeparam>
        /// <param name="context"></param>
        /// <param name="current"></param>
        /// <param name="next"></param>
        /// <param name="shadow"></param>
        /// <param name="added"></param>
        /// <param name="removed"></param>
        public static void Update <TItem>(IShadowContext context, IPrimitive current,
                                          IPrimitive next,
                                          IShadow <TItem> shadow,
                                          Action <IShadow <TItem> > added   = default,
                                          Action <IShadow <TItem> > removed = default)
        {
            // current == null and next != null implies -> new
            // current != null && next != null implies -> update/change
            // current != null && next == null, implies -> remove

            try
            {
                // now, we do have a problem in that the shadow may not exist...//
                // if so then its a create
                if (shadow != null)
                {
                    // the shadow could well change...
                    // in this case, we need to ...

                    var sameElementType = current.AreSameType(next);

                    if (!sameElementType)
                    {
                        if (current != null)
                        {
                            // this isn't right, since the layout hasn't been retained
                            context.MapperFactory.Remove(context, shadow, current);
                            // we could want to 'drop' the content view here, how would we do that ?
                            removed?.Invoke(shadow);
                            shadow = default;
                        }
                    }
                    else
                    {
                        context.MapperFactory.Update(context, shadow, current, next);
                    }
                }

                if (shadow == null)
                {
                    var baseShadow = context.MapperFactory.Create(context, next);

                    shadow = (IShadow <TItem>)baseShadow;

                    added?.Invoke(shadow);
                }
            }
            catch (Exception exception)
            {
                Logging.Instance.LogError(exception, "Shadow:Update Current:{current} Next:{next} ShadowType:{shadowType}", current, next, shadow?.GetType().FriendlyName());
                throw;
            }
        }
        /// <summary>
        /// Create an <see cref="IShadow"/> instance for a specified <see cref="IElement"/>
        /// </summary>
        /// <param name="context"></param>
        /// <param name="element"></param>
        /// <param name="update"></param>
        /// <returns></returns>
        /// <remarks>
        /// The creation of the shadow is transactional, the actual Item within the Shadow isn't assigned until the transactions are committed.
        /// The option to not perform an update is primarily for those situations in which a placeholder view/shadow is being created
        /// and it will be bound at a slightly later date.</remarks>
        public IShadow Create(IShadowContext context, IPrimitive element, bool update = true)
        {
            var mapper = GetShadowMapper(element);

            var shadow = mapper.CreateShadow(context, element);

            if (update)
            {
                mapper.UpdateShadow(context, shadow, null, element);
            }

            return(shadow);
        }
예제 #5
0
        /// <summary>
        /// Simple extension to assign / update a <see cref="IShadow{TItem}"/> when it has content within it, with
        /// updates being automatically wrapped in a <see cref="Transaction"/>
        /// </summary>
        /// <typeparam name="TItem"></typeparam>
        /// <param name="context"></param>
        /// <param name="shadow"></param>
        /// <param name="current"></param>
        /// <param name="next"></param>
        /// <param name="set"></param>
        /// <param name="clear"></param>
        public static void UpdateContent <TItem>(this IShadow shadow, IShadowContext context, IPrimitive current,
                                                 IPrimitive next,
                                                 Action <IShadow <TItem> > set,
                                                 Action <IShadow <TItem> > clear)
        {
            var content = shadow.Get <IShadow <TItem> >(ContentKey);

            Shadow.Update(context, current, next, content, (s) =>
            {
                Transaction.Current.Add(() =>
                {
                    shadow.Set <IShadow <TItem> >(ContentKey, s);
                    set(s);
                });
            }, (s) =>
            {
                Transaction.Current.Add(() =>
                {
                    shadow.State.Delete <IShadow <TItem> >(ContentKey);
                    clear(s);
                });
            });
        }
예제 #6
0
 private static IDataConnector <IPrimitive> ConnectorFactory(IShadowContext context, IShadow <Xamarin.Forms.StackLayout> shadow)
 {
     return(new ShadowGroupConnector <Xamarin.Forms.View>(context, new StackLayoutConnection(shadow)));
 }
        /// <summary>
        /// A shadow instance is being removed, perform any logic prior to removal.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="shadow"></param>
        /// <param name="current"></param>
        public void Remove(IShadowContext context, IShadow shadow, IPrimitive current)
        {
            var viewHandler = GetShadowMapper(current);

            viewHandler.RemoveShadow(context, shadow, current);
        }
        /// <summary>
        /// Update an existing <see cref="IShadow"/> from its current state to a new state.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="shadow"></param>
        /// <param name="current"></param>
        /// <param name="next"></param>
        public void Update(IShadowContext context, IShadow shadow, IPrimitive current, IPrimitive next)
        {
            var viewHandler = GetShadowMapper(current ?? next);

            viewHandler.UpdateShadow(context, shadow, current, next);
        }
 /// <summary>
 /// The shadow is potentially going to be updated
 /// </summary>
 /// <param name="context"></param>
 /// <param name="shadow"></param>
 /// <param name="current"></param>
 /// <param name="next"></param>
 public void UpdateShadow(IShadowContext context, IShadow shadow, IPrimitive current,
                          IPrimitive next)
 {
     UpdateImplementation((TContext)context, (IShadow <TItem>)shadow, (TElement)current, (TElement)next);
 }
예제 #10
0
 private static IDataConnector <IPrimitive> ConnectorFactory(IShadowContext context, IShadow <Xamarin.Forms.CollectionView> shadow)
 {
     return(new CollectionViewConnector(shadow));
 }