Пример #1
0
        void OnPagePropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            // Setting TabBarItem.Title in iOS 10 causes rendering bugs
            // Work around this by creating a new UITabBarItem on each change
            if (e.PropertyName == Page.TitleProperty.PropertyName && !PlatformVersion.IsAtLeast(10))
            {
                var page     = (Page)sender;
                var renderer = page.ToHandler(_mauiContext);
                if (renderer == null)
                {
                    return;
                }

                if (renderer.ViewController.TabBarItem != null)
                {
                    renderer.ViewController.TabBarItem.Title = page.Title;
                }
            }
            else if (e.PropertyName == Page.IconImageSourceProperty.PropertyName || e.PropertyName == Page.TitleProperty.PropertyName && PlatformVersion.IsAtLeast(10))
            {
                var page = (Page)sender;

                IPlatformViewHandler renderer = page.ToHandler(_mauiContext);

                if (renderer?.ViewController.TabBarItem == null)
                {
                    return;
                }

                SetTabBarItem(renderer);
            }
        }
Пример #2
0
        public void OnLongPress(MotionEvent e)
        {
            if (!HasAnyDragGestures())
            {
                return;
            }

            SendEventArgs <DragGestureRecognizer>(rec =>
            {
                if (!rec.CanDrag)
                {
                    return;
                }

                var element = GetView();
                // TODO MAUI FIX FOR COMPAT
                //var renderer = AppCompat.Platform.GetRenderer(element);
                var v = (AView)element.Handler.PlatformView;

                if (v.Handle == IntPtr.Zero)
                {
                    return;
                }

                var args = rec.SendDragStarting(element);

                if (args.Cancel)
                {
                    return;
                }

                CustomLocalStateData customLocalStateData = new CustomLocalStateData();
                customLocalStateData.DataPackage          = args.Data;


                // TODO MAUI
                string clipDescription  = String.Empty;               //AutomationPropertiesProvider.ConcatenateNameAndHelpText(element) ?? String.Empty;
                ClipData.Item item      = null;
                List <string> mimeTypes = new List <string>();

                if (!args.Handled)
                {
                    if (args.Data.Image != null)
                    {
                        mimeTypes.Add("image/jpeg");
                        item = ConvertToClipDataItem(args.Data.Image, mimeTypes);
                    }
                    else
                    {
                        string text = clipDescription ?? args.Data.Text;
                        if (Uri.TryCreate(text, UriKind.Absolute, out _))
                        {
                            item = new ClipData.Item(AUri.Parse(text));
                            mimeTypes.Add(ClipDescription.MimetypeTextUrilist);
                        }
                        else
                        {
                            item = new ClipData.Item(text);
                            mimeTypes.Add(ClipDescription.MimetypeTextPlain);
                        }
                    }
                }

                var dataPackage        = args.Data;
                ClipData.Item userItem = null;
                if (dataPackage.Image != null)
                {
                    userItem = ConvertToClipDataItem(dataPackage.Image, mimeTypes);
                }

                if (dataPackage.Text != null)
                {
                    userItem = new ClipData.Item(dataPackage.Text);
                }

                if (item == null)
                {
                    item     = userItem;
                    userItem = null;
                }

                ClipData data = new ClipData(clipDescription, mimeTypes.ToArray(), item);

                if (userItem != null)
                {
                    data.AddItem(userItem);
                }

                var dragShadowBuilder = new AView.DragShadowBuilder(v);

                customLocalStateData.SourcePlatformView = v;
                customLocalStateData.SourceElement      = element;

                if (PlatformVersion.IsAtLeast(24))
                {
                    v.StartDragAndDrop(data, dragShadowBuilder, customLocalStateData, (int)ADragFlags.Global | (int)ADragFlags.GlobalUriRead);
                }
                else
#pragma warning disable CS0618 // Type or member is obsolete
                {
                    v.StartDrag(data, dragShadowBuilder, customLocalStateData, (int)ADragFlags.Global | (int)ADragFlags.GlobalUriRead);
                }
#pragma warning restore CS0618 // Type or member is obsolete
            });
        }
Пример #3
0
        static void UpdateMenuItem(AToolbar toolbar,
                                   ToolbarItem item,
                                   int?menuItemIndex,
                                   IMauiContext mauiContext,
                                   Color?tintColor,
                                   PropertyChangedEventHandler toolbarItemChanged,
                                   List <IMenuItem> previousMenuItems,
                                   List <ToolbarItem> previousToolBarItems,
                                   Action <Context, IMenuItem, ToolbarItem>?updateMenuItemIcon = null)
        {
            var context = mauiContext.Context ??
                          throw new ArgumentNullException($"{nameof(mauiContext.Context)}");

            IMenu menu = toolbar.Menu;

            item.PropertyChanged -= toolbarItemChanged;
            item.PropertyChanged += toolbarItemChanged;

            IMenuItem menuitem;

            Java.Lang.ICharSequence?newTitle = null;

            if (!String.IsNullOrWhiteSpace(item.Text))
            {
                if (item.Order != ToolbarItemOrder.Secondary && tintColor != null && tintColor != null)
                {
                    var             color       = item.IsEnabled ? tintColor.ToPlatform() : tintColor.MultiplyAlpha(0.302f).ToPlatform();
                    SpannableString titleTinted = new SpannableString(item.Text);
                    titleTinted.SetSpan(new ForegroundColorSpan(color), 0, titleTinted.Length(), 0);
                    newTitle = titleTinted;
                }
                else
                {
                    newTitle = new Java.Lang.String(item.Text);
                }
            }
            else
            {
                newTitle = new Java.Lang.String();
            }

            if (menuItemIndex == null || menuItemIndex >= previousMenuItems?.Count)
            {
                menuitem = menu.Add(0, AView.GenerateViewId(), 0, newTitle) ??
                           throw new InvalidOperationException($"Failed to create menuitem: {newTitle}");
                previousMenuItems?.Add(menuitem);
            }
            else
            {
                if (previousMenuItems == null || previousMenuItems.Count < menuItemIndex.Value)
                {
                    return;
                }

                menuitem = previousMenuItems[menuItemIndex.Value];

                if (!menuitem.IsAlive())
                {
                    return;
                }

                menuitem.SetTitle(newTitle);
            }

            menuitem.SetEnabled(item.IsEnabled);
            menuitem.SetTitleOrContentDescription(item);

            if (updateMenuItemIcon != null)
            {
                updateMenuItemIcon(context, menuitem, item);
            }
            else
            {
                UpdateMenuItemIcon(mauiContext, menuitem, item, tintColor);
            }

            if (item.Order != ToolbarItemOrder.Secondary)
            {
                menuitem.SetShowAsAction(ShowAsAction.Always);
            }

            menuitem.SetOnMenuItemClickListener(new GenericMenuClickListener(((IMenuItemController)item).Activate));

            if (item.Order != ToolbarItemOrder.Secondary && !PlatformVersion.IsAtLeast(26) && (tintColor != null && tintColor != null))
            {
                var view = toolbar.FindViewById(menuitem.ItemId);
                if (view is ATextView textView)
                {
                    if (item.IsEnabled)
                    {
                        textView.SetTextColor(tintColor.ToPlatform());
                    }
                    else
                    {
                        textView.SetTextColor(tintColor.MultiplyAlpha(0.302f).ToPlatform());
                    }
                }
            }
        }
Пример #4
0
        async Task SyncPlatformCookiesAsync(string url)
        {
            var uri = CreateUriForCookies(url);

            if (uri == null)
            {
                return;
            }

            var myCookieJar = VirtualView.Cookies;

            if (myCookieJar == null)
            {
                return;
            }

            await InitialCookiePreloadIfNecessary(url);

            var cookies = myCookieJar.GetCookies(uri);

            if (cookies == null)
            {
                return;
            }

            var retrieveCurrentWebCookies = await GetCookiesFromPlatformStore(url);

            List <NSHttpCookie> deleteCookies = new List <NSHttpCookie>();

            foreach (var cookie in retrieveCurrentWebCookies)
            {
                if (cookies[cookie.Name] != null)
                {
                    continue;
                }

                deleteCookies.Add(cookie);
            }

            List <Cookie> cookiesToSet = new List <Cookie>();

            foreach (Cookie cookie in cookies)
            {
                bool changeCookie = true;

                // This code is used to only push updates to cookies that have changed.
                // This doesn't quite work on on iOS 10 if we have to delete any cookies.
                // I haven't found a way on iOS 10 to remove individual cookies.
                // The trick we use on Android with writing a cookie that expires doesn't work
                // So on iOS10 if the user wants to remove any cookies we just delete
                // the cookie for the entire domain inside of DeleteCookies and then rewrite
                // all the cookies
                if (PlatformVersion.IsAtLeast(11) || deleteCookies.Count == 0)
                {
                    foreach (var nsCookie in retrieveCurrentWebCookies)
                    {
                        // if the cookie value hasn't changed don't set it again
                        if (nsCookie.Domain == cookie.Domain &&
                            nsCookie.Name == cookie.Name &&
                            nsCookie.Value == cookie.Value)
                        {
                            changeCookie = false;
                            break;
                        }
                    }
                }

                if (changeCookie)
                {
                    cookiesToSet.Add(cookie);
                }
            }

            await SetCookie(cookiesToSet);
            await DeleteCookies(deleteCookies);
        }