Ejemplo n.º 1
0
            public void StopWatchingForChangesOnLayout(VisualElement visualElement, object handle)
            {
                if (!(handle is System.Runtime.CompilerServices.ConditionalWeakTable <AView, DualScreenGlobalLayoutListener> table))
                {
                    return;
                }

                DualScreenGlobalLayoutListener ggl = null;
                var view        = Platform.Android.Platform.GetRenderer(visualElement);
                var androidView = view?.View;

                if (androidView == null || !(table.TryGetValue(androidView, out ggl)))
                {
                    foreach (var pair in table)
                    {
                        ggl = pair.Value;
                    }
                }

                if (ggl == null)
                {
                    return;
                }

                try
                {
                    ggl.Invalidate();
                }
                catch
                {
                    // just in case something along the call path here is disposed of
                }

                if (androidView == null || !androidView.IsAlive())
                {
                    return;
                }

                try
                {
                    androidView.ViewTreeObserver.RemoveOnGlobalLayoutListener(ggl);
                }
                catch
                {
                    // just in case something along the call path here is disposed of
                }
            }
Ejemplo n.º 2
0
            public object WatchForChangesOnLayout(VisualElement visualElement, Action action)
            {
                if (action == null)
                {
                    return(null);
                }

                var view        = Platform.Android.Platform.GetRenderer(visualElement);
                var androidView = view?.View;

                if (androidView == null || !androidView.IsAlive())
                {
                    return(null);
                }

                var listener = new DualScreenGlobalLayoutListener(action, androidView);

                var table = new System.Runtime.CompilerServices.ConditionalWeakTable <AView, DualScreenGlobalLayoutListener>();

                androidView.ViewTreeObserver.AddOnGlobalLayoutListener(listener);
                table.Add(androidView, listener);
                return(table);
            }